rust-lang / rust-lang/rust

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

Open
#144,282 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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> }))

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the ICE referenced as #140823 and trace the logged comparison in TypeError::Sorts(ExpectedFound), especially InferCtxt::can_eq and snapshot rollback. No source file or test is named in the report; done means determining whether rolled-back regions can leak into ExpectedFound and adding a regression test or documented resolution that prevents or safely handles the leakage.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.