Skip to content

The found type in TypeError::Sorts(ExpectedFound) may contain lifetime regions that have been rolled back #144282

@jagunter

Description

@jagunter

The ICE #140823 was triggered by attempting to compare found from ExpectedFound in TypeError::Sorts to another type via InferCtxt::can_eq. This eventually failed because found contained a lifetime that had been rolled back. Relevant logs from that issue tracing the failure are included below.

The issue was resolved by avoiding use of the types recorded in ExpectedFound. However, opening this issue since it seems like this leakage of rolled back lifetimes is probably undesirable from an internal rust compiler standpoint.

                   0ms DEBUG rustc_infer::infer::region_constraints created new region variable '?0 in U1 with origin BoundRegion(src/main.rs:12:17: 12:25 (#0), BrNamed(DefId(0:12 ~ rust_ice[c3ad]::ice::'a), 'a), HigherRankedType)
                   0ms DEBUG rustc_middle::ty::region type_flags('?0) = TypeFlags(HAS_RE_INFER | HAS_FREE_LOCAL_REGIONS | HAS_FREE_REGIONS)
                   0ms DEBUG rustc_infer::infer::relate::type_relating new ambient variance, self.ambient_variance=o
                   rustc_infer::infer::relate::type_relating::tys a=&!1_0.Named(DefId(0:10 ~ rust_ice[c3ad]::Desugared::callback::'a), "'a") Container<&!1_0.Named(DefId(0:10 ~ rust_ice[c3ad]::Desugared::callback::'a), "'a") u8>, b=Container<&'?0 u8>
                     0ms DEBUG rustc_type_ir::relate::combine super_combine_tys::<rustc_infer::infer::relate::type_relating::TypeRelating>(&!1_0.Named(DefId(0:10 ~ rust_ice[c3ad]::Desugared::callback::'a), "'a") Container<&!1_0.Named(DefId(0:10 ~ rust_ice[c3ad]::Desugared::callback::'a), "'a") u8>, Container<&'?0 u8>)
                     rustc_type_ir::relate::structurally_relate_tys a=&!1_0.Named(DefId(0:10 ~ rust_ice[c3ad]::Desugared::callback::'a), "'a") Container<&!1_0.Named(DefId(0:10 ~ rust_ice[c3ad]::Desugared::callback::'a), "'a") u8>, b=Container<&'?0 u8>
                       0ms TRACE rustc_type_ir::relate return=Err(Sorts(ExpectedFound { expected: &!1_0.Named(DefId(0:10 ~ rust_ice[c3ad]::Desugared::callback::'a), "'a") Container<&!1_0.Named(DefId(0:10 ~ rust_ice[c3ad]::Desugared::callback::'a), "'a") u8>, found: Container<&'?0 u8> }))
                 0ms TRACE rustc_type_ir::relate return=Err(Sorts(ExpectedFound { expected: &!1_0.Named(DefId(0:10 ~ rust_ice[c3ad]::Desugared::callback::'a), "'a") Container<&!1_0.Named(DefId(0:10 ~ rust_ice[c3ad]::Desugared::callback::'a), "'a") u8>, found: Container<&'?0 u8> }))
             0ms TRACE rustc_type_ir::relate return=Err(Sorts(ExpectedFound { expected: &!1_0.Named(DefId(0:10 ~ rust_ice[c3ad]::Desugared::callback::'a), "'a") Container<&!1_0.Named(DefId(0:10 ~ rust_ice[c3ad]::Desugared::callback::'a), "'a") u8>, found: Container<&'?0 u8> }))
         0ms DEBUG rustc_infer::infer::snapshot commit_if_ok() -- r.is_ok() = false
         rustc_infer::infer::snapshot::rollback_to 
           0ms DEBUG rustc_infer::infer::snapshot::undo_log rollback_to(0)
           0ms DEBUG rustc_infer::infer::region_constraints RegionConstraintCollector: rollback_to(RegionSnapshot)
    11ms DEBUG rustc_infer::infer::snapshot commit_if_ok() -- r.is_ok() = false
     rustc_infer::infer::snapshot::rollback_to 
       0ms DEBUG rustc_infer::infer::snapshot::undo_log rollback_to(0)
       0ms DEBUG rustc_infer::infer::region_constraints RegionConstraintCollector: rollback_to(RegionSnapshot)
  17ms DEBUG rustc_errors::diagnostic Created new diagnostic
  17ms DEBUG rustc_infer::infer set_tainted_by_errors(ErrorGuaranteed)
  17ms DEBUG rustc_trait_selection::error_reporting::infer report_and_explain_type_error(trace=TypeTrace { cause: ObligationCause { span: src/main.rs:12:17: 12:25 (#0), body_id: DefId(0:11 ~ rust_ice[c3ad]::ice), code: Misc }, values: Terms(ExpectedFound { expected: Term::Ty(std::boxed::Box<dyn [Binder { value: Trait(MyFn<&'a Container<&'a u8>>), bound_vars: [Region(BrNamed(DefId(0:10 ~ rust_ice[c3ad]::Desugared::callback::'a), 'a))] }] + 'static, std::alloc::Global>), found: Term::Ty(std::boxed::Box<dyn [Binder { value: Trait(MyFn<Container<&'a u8>>), bound_vars: [Region(BrNamed(DefId(0:12 ~ rust_ice[c3ad]::ice::'a), 'a))] }] + 'static, std::alloc::Global>) }) }, terr=Sorts(ExpectedFound { expected: &!1_0.Named(DefId(0:10 ~ rust_ice[c3ad]::Desugared::callback::'a), "'a") Container<&!1_0.Named(DefId(0:10 ~ rust_ice[c3ad]::Desugared::callback::'a), "'a") u8>, found: Container<&'?0 u8> }))

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions