Skip to content

Methods in impls allowed more restrictive lifetime bounds than in the trait. #18937

Closed
@eddyb

Description

@eddyb
trait Foo {
    fn foo<T>(self) -> u64;
}
impl Foo for () {
    fn foo<T: 'static>(self) -> u64 {
        //    ^^^^^^^ this should cause an error, the bound is missing from the
        // method definition in the trait, and calls are checked against that.
        std::intrinsics::TypeId::of::<&'static T>().hash()
    }
}
fn main() {
    println!("{}", ().foo::<&()>());
}
// error: internal compiler error: non-static region found when hashing a type

cc @nikomatsakis

Metadata

Metadata

Assignees

Labels

A-trait-systemArea: Trait systemA-type-systemArea: Type systemE-hardCall for participation: Hard difficulty. Experience needed to fix: A lot.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-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