Fix overloaded deref unused mut false positive

This commit is contained in:
hkalbasi 2023-03-02 13:52:12 +03:30
parent 6377d50bd1
commit bf0f99f15d
3 changed files with 45 additions and 6 deletions

View file

@ -523,6 +523,34 @@ fn f(x: [(i32, u8); 10]) {
//^^^^^ 💡 error: cannot mutate immutable variable `a`
}
}
"#,
);
}
#[test]
fn overloaded_deref() {
check_diagnostics(
r#"
//- minicore: deref_mut
use core::ops::{Deref, DerefMut};
struct Foo;
impl Deref for Foo {
type Target = i32;
fn deref(&self) -> &i32 {
&5
}
}
impl DerefMut for Foo {
fn deref_mut(&mut self) -> &mut i32 {
&mut 5
}
}
fn f() {
// FIXME: remove this mut and detect error
let mut x = Foo;
let y = &mut *x;
}
"#,
);
}