Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
JanBeh opened this issue Dec 27, 2021 · 6 comments · Fixed by #92333
Closed

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

JanBeh opened this issue Dec 27, 2021 · 6 comments · Fixed by #92333
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. P-medium Medium priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly.

Comments

@JanBeh
Copy link
Contributor

JanBeh commented Dec 27, 2021

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

@JanBeh JanBeh added the C-bug Category: This is a bug. label Dec 27, 2021
@JanBeh
Copy link
Contributor Author

JanBeh commented Dec 27, 2021

Also consider the following code, which creates an error message that could be more precise. I wouldn't call the following example a bug, but maybe these two issues are related:

#![feature(generic_associated_types)]

use std::marker::PhantomData;

trait Machine<'a> {
    type Datum<'b>
    where
        Self: 'b;
}

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

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

impl<'a> Machine<'a> for LuaMachine<'a> {
    type Datum<'b>
    where
        Self: 'b,
    = LuaDatum<'a, 'b>;
}

type M<'a> = LuaMachine<'a>;
// This won't work:
type D<'a, 'b> = <M<'a> as Machine>::Datum<'b>;

fn main() {
    let _m: M = Default::default();
    // But this works:
    let _d: <M as Machine>::Datum<'_> = LuaDatum { _machine: &_m };
}

(Playground)

Error output:

   Compiling playground v0.0.1 (/playground)
error[E0106]: missing lifetime specifier
  --> src/main.rs:29:18
   |
29 | type D<'a, 'b> = <M<'a> as Machine>::Datum<'b>;
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected named lifetime parameter
   |
note: these named lifetimes are available to use
  --> src/main.rs:29:8
   |
29 | type D<'a, 'b> = <M<'a> as Machine>::Datum<'b>;
   |        ^^  ^^

For more information about this error, try `rustc --explain E0106`.
error: could not compile `playground` due to previous error

@compiler-errors
Copy link
Member

I think this is due to #90446 cc: @cjgillot, let me see if I can fix this real quick.

@compiler-errors
Copy link
Member

@rustbot claim

@BGR360
Copy link
Contributor

BGR360 commented Dec 28, 2021

@rustbot label +regression-from-stable-to-nightly +A-diagnostics

@rustbot rustbot added A-diagnostics Area: Messages for errors, warnings, and lints regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Dec 28, 2021
@rustbot
Copy link
Collaborator

rustbot commented Dec 28, 2021

Error: Label P-low can only be set by Rust team members

Please let @rust-lang/release know if you're having trouble with this bot.

@apiraino
Copy link
Contributor

Assigning priority as discussed in the Zulip thread of the Prioritization Working Group.

@rustbot label -I-prioritize +P-medium

@rustbot rustbot added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Dec 28, 2021
@bors bors closed this as completed in 98c61b6 Dec 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. P-medium Medium priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants