Open
Description
The rust compiler gives a very poor error message when there is a lifetime expectation mismatch on trait usage.
I used this code: (playground link: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=581fa159f8ff99f2df447308fccd4bbc )
use std::cell::*;
#[derive(Default)]
struct Test {
pub foo: u32,
}
trait FooSetter {
fn set_foo(&mut self, value: u32);
}
impl FooSetter for Test {
fn set_foo(&mut self, value: u32) {
self.foo = value;
}
}
trait BaseSetter{
fn set(&mut self, value: u32);
}
impl BaseSetter for dyn FooSetter{
fn set(&mut self, value: u32){
self.set_foo(value);
}
}
struct TestHolder<'a> {
pub holder: Option<RefCell<&'a mut dyn FooSetter>>,
}
impl <'a>TestHolder<'a>{
pub fn test_foo(&self){
self.holder.as_ref().unwrap().borrow_mut().set(20);
}
}
fn main() {
let mut test = Test::default();
test.foo = 10;
{
let holder = TestHolder { holder: Some(RefCell::from(&mut test))};
holder.test_foo();
}
test.foo = 30;
}
I expected to see a useful error message, such as "expected trait BaseSetter<'a>
, found trait: BaseSetter<'static>
"
Instead, I was greeted with this almost useless error message: "expected trait BaseSetter
, found trait BaseSetter
"
The same error occurs on stable and nightly compilers
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: Lifetimes / regionsArea: Trait systemCategory: This is a bug.Diagnostics: Confusing error or lint that should be reworked.Diagnostics: An error or lint that needs small tweaks.Relevant to the compiler team, which will review and decide on the PR/issue.