Skip to content

non-fatal overflow for slightly different goals in MIR borrowck results in ICE #238

@lcnr

Description

@lcnr
#![recursion_limit = "8"]
fn main() {
    let _: Box<dyn Send> = Box::new(&&&&&&&1);
}

results in

error: internal compiler error: errors selecting obligation during MIR typeck: query type op DefId(0:7 ~ main[c42f]::main) [Ambiguity]
  |
  = note: delayed at /home/lcnr/rust/compiler/rustc_trait_selection/src/traits/query/type_op/custom.rs:105:18 - disabled backtrace

HIR typeck uses a custom select loop to coerce https://github.com/rust-lang/rust/blob/ae12bc21d8ec76bbb753d4da168e9b08e1b09ebf/compiler/rustc_hir_typeck/src/coercion.rs#L664-L771

MIR type check just prove CoerceUnsized directly https://github.com/rust-lang/rust/blob/ae12bc21d8ec76bbb753d4da168e9b08e1b09ebf/compiler/rustc_borrowck/src/type_check/mod.rs#L1227-L1244

Generally, to handle non-fatal overflow, MIR borrowck always has to prove the same goals as HIR typeck at the same depth. This is a problem with the new solver due to 2 reasons:

  • we don't use the recursion_depth of Obligations as the available dpeth in the trait solver, only for errors in the fulfillment loop
  • our overflow is actually non-fatal

This is kinda yikes

Metadata

Metadata

Assignees

No one assigned

    Labels

    from-craterA regression found via a crater run, not part of our test suite

    Type

    No type

    Projects

    Status

    todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions