-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.
Description
This code results in a horrible error message:
use std::ops::Deref;
trait Trait {}
struct Struct;
impl Deref for Struct {
type Target = Trait;
fn deref(&self) -> &Trait {
unimplemented!();
}
}
<anon>:8:5: 10:6 error: method `deref` has an incompatible type for trait:
expected bound lifetime parameter ,
found concrete lifetime [E0053]
<anon>: 8 fn deref(&self) -> &Trait {
<anon>: 9 unimplemented!();
<anon>:10 }
<anon>:8:5: 10:6 help: see the detailed explanation for E0053
In particular, note the missing lifetime name on the second line of the error message.
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
GuillaumeGomez commentedon Jan 9, 2016
If there is no lifetime specified, should we print:
?
Amanieu commentedon Jan 9, 2016
The correct code in this case is to specify the return value of the function as
&(Trait + 'static)
. What happens here is thatTarget = Trait
gets expanded by the compiler intoTarget = Trait + 'static
, but the error message doesn't make this clear.estebank commentedon Jan 27, 2018
Proposed output in #47791: