Skip to content

Underscore lifetimes are incorrectly accepted as lifetime bounds in impl headers #54902

Closed
@scottmcm

Description

@scottmcm

This is currently accepted in 2018: https://play.rust-lang.org/?gist=7ba2dee1134f9848b54b7364ea9568aa&version=nightly&edition=2018

trait Foo<'a> {}
impl<'b: '_> Foo<'b> for i32 {}

AFAICT, it desugars to

impl<'b: 'c, 'c> Foo<'b> for i32 {}

So it's "fine", but useless.

It should error, as trying to do this does in other places, such as

struct Foo<'a: '_>(&'a i32);

Tracking issue for the impl_header_lifetime_elision feature: #15872

On the current beta this gives

error[E0688]: cannot mix in-band and explicit lifetime definitions

so this was at least exposed by #54458

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language team

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions