Skip to content

Broken help message for missing lifetime when using <_ as Trait> syntax in type alias #92324

Closed
@JanBeh

Description

@JanBeh

I tried this code:

use std::marker::PhantomData;
use std::rc::Rc;

trait Machine<'a> {
    type Datum;
}

#[derive(Default)]
struct LuaMachine<'a> {
    _phantom: PhantomData<fn(&'a ()) -> &'a ()>,
}

struct LuaDatum<'a> {
    _machine: Rc<LuaMachine<'a>>,
}

impl<'a> Machine<'a> for LuaMachine<'a> {
    type Datum = LuaDatum<'a>;
}

type M<'a> = LuaMachine<'a>;
type D<'a> = <M<'a> as Machine>::Datum;

fn main() {}

(Playground)

I expected to see this happen (which works correctly with rustc 1.57.0 stable):

help: consider using the `'a` lifetime
   |
22 | type D<'a> = <M<'a> as Machine<'a>>::Datum;
   |                        ~~~~~~~~~~~

But with rustc 1.59.0-nightly (f8abed9ed 2021-12-26), I get:

help: consider using the `'a` lifetime
   |
22 | type D<'a> = <M<'a> as Machine>::Datum<'a>;
   |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Meta

rustc --version --verbose:

rustc 1.59.0-nightly (f8abed9ed 2021-12-26)
binary: rustc
commit-hash: f8abed9ed48bace6be0087bcd44ed534e239b8d8
commit-date: 2021-12-26
host: x86_64-unknown-freebsd
release: 1.59.0-nightly
LLVM version: 13.0.0

Metadata

Metadata

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.P-mediumMedium priorityregression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions