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

Associated constants lifetime error that only seems to trigger with Servo #42790

Closed
frewsxcv opened this issue Jun 21, 2017 · 4 comments
Closed
Labels
A-associated-items Area: Associated items (types, constants & functions) A-lifetimes Area: Lifetimes / regions T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@frewsxcv
Copy link
Member

#![feature(associated_consts)]

fn main() {}

pub struct SomeStruct<T: Nameable> {
    t: T,
}

impl<T: Nameable> Nameable for SomeStruct<T> {
    const NAME: &'static str = T::NAME;
}

pub trait Nameable {
    const NAME: &'static str = "generic runnable";
}

Given the code above, it seems to compile on the playpen.

But if I add that same code to the 'script' crate in Servo (as you can see in this branch), I get this error:

error[E0311]: the parameter type `T` may not live long enough
   --> /Users/corey/dev/servo/components/script/script_thread.rs:229:32
    |
229 |     const NAME: &'static str = T::NAME;
    |                                ^^^^^^^
    |
    = help: consider adding an explicit lifetime bound for `T`
note: the parameter type `T` must be valid for the expression at 229:31...
   --> /Users/corey/dev/servo/components/script/script_thread.rs:229:32
    |
229 |     const NAME: &'static str = T::NAME;
    |                                ^^^^^^^
note: ...so that a type/lifetime parameter is in scope here
   --> /Users/corey/dev/servo/components/script/script_thread.rs:229:32
    |
229 |     const NAME: &'static str = T::NAME;
    |                                ^^^^^^^

error: aborting due to previous error

error: Could not compile `script`.

At the time of writing, Servo is on nightly-2017-06-09, and the code compiles fine when isolated to a single file.

@frewsxcv frewsxcv added A-associated-items Area: Associated items (types, constants & functions) A-lifetimes Area: Lifetimes / regions T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 21, 2017
@est31
Copy link
Member

est31 commented Jun 21, 2017

This might be due to some kind of cache poisoning (#42796).

@est31
Copy link
Member

est31 commented Jun 21, 2017

Errrm maybe this is just because your branch uses an age old rustc rustc 1.17.0-nightly (8c72b7651 2017-03-11)? Seems it doesn't have #41515 yet which looks like the thing you are missing.

@est31
Copy link
Member

est31 commented Jun 21, 2017

Can you rebase and report back whether the issue persists?

@frewsxcv
Copy link
Member Author

Welp, that's embarrassing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) A-lifetimes Area: Lifetimes / regions T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants