Skip to content

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

Closed
@frewsxcv

Description

@frewsxcv
#![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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)A-lifetimesArea: Lifetimes / regionsT-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