Skip to content

ICE on higher-trait bounds #60218

Closed
@agalakhov

Description

@agalakhov

The following code:

use std::iter::Map;

trait Foo { }

impl<T> Foo for &'_ T where T: Foo { }
impl<T> Foo for Option<T> where T: Foo { }

impl Foo for u32 { }

fn trigger_error<I, F>(iterable: I, functor: F)
where
    for<'t> &'t I: IntoIterator,
    for<'t> Map<<&'t I as IntoIterator>::IntoIter, F>: Iterator,
    for<'t> <Map<<&'t I as IntoIterator>::IntoIter, F> as Iterator>::Item: Foo,
{
    
}

fn main() {
    trigger_error(Vec::<u32>::new(), |x: &u32| Some(x))
}

results in an ICE

error: internal compiler error: src/librustc/infer/lexical_region_resolve/mod.rs:632: collect_error_for_expanding_node() could not find error for var '_#2r in universe U11, lower_bounds=[
    RegionAndOrigin(RePlaceholder(Placeholder { universe: U1, name: BrNamed(crate0:DefIndex(1:14), 't) }),Subtype(TypeTrace(ObligationCause { span: src/main.rs:20:5: 20:18, body_id: HirId { owner: DefIndex(0:9), local_id: 24 }, code: ImplDerivedObligation(DerivedObligationCause { parent_trait_ref: Binder(<std::iter::Map<<&'t _ as std::iter::IntoIterator>::IntoIter, _> as std::iter::Iterator>), parent_code: ItemObligation(DefId(0/0:8 ~ playground[b1a9]::trigger_error[0])) }) }))),
    RegionAndOrigin(RePlaceholder(Placeholder { universe: U1, name: BrNamed(crate0:DefIndex(1:14), 't) }),Subtype(TypeTrace(ObligationCause { span: src/main.rs:20:5: 20:18, body_id: HirId { owner: DefIndex(0:9), local_id: 24 }, code: ImplDerivedObligation(DerivedObligationCause { parent_trait_ref: Binder(<std::iter::Map<<&'t _ as std::iter::IntoIterator>::IntoIter, _> as std::iter::Iterator>), parent_code: ItemObligation(DefId(0/0:8 ~ playground[b1a9]::trigger_error[0])) }) })))
], upper_bounds=[
    RegionAndOrigin(RePlaceholder(Placeholder { universe: U1, name: BrNamed(crate0:DefIndex(1:14), 't) }),Subtype(TypeTrace(ObligationCause { span: src/main.rs:20:5: 20:18, body_id: HirId { owner: DefIndex(0:9), local_id: 24 }, code: ImplDerivedObligation(DerivedObligationCause { parent_trait_ref: Binder(<std::iter::Map<<&'t _ as std::iter::IntoIterator>::IntoIter, _> as std::iter::Iterator>), parent_code: ItemObligation(DefId(0/0:8 ~ playground[b1a9]::trigger_error[0])) }) }))),
    RegionAndOrigin(RePlaceholder(Placeholder { universe: U1, name: BrNamed(crate0:DefIndex(1:14), 't) }),Subtype(TypeTrace(ObligationCause { span: src/main.rs:20:5: 20:18, body_id: HirId { owner: DefIndex(0:9), local_id: 24 }, code: ImplDerivedObligation(DerivedObligationCause { parent_trait_ref: Binder(<std::iter::Map<<&'t _ as std::iter::IntoIterator>::IntoIter, _> as std::iter::Iterator>), parent_code: ItemObligation(DefId(0/0:8 ~ playground[b1a9]::trigger_error[0])) }) })))
]

Tested this on stable and nightly. May be somehow related to #60070.

Metadata

Metadata

Assignees

Labels

A-trait-systemArea: Trait systemC-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions