Open lovefqy opened 3 years ago
This is an interaction between automatic dereferencing and 2 fields having the same name while one is not accessible.
Intellij rust resolves to both of the value
fields while rustc ignores the inaccessible of the two.
Simplified code:
mod refcell2 { // Necessary to make Ref2.value inaccessible
use std::ops::Deref;
pub struct Ref2<'b, T:'b> {
value: &'b T, //Overlaps with Item.value but is inaccessible
}
impl<T> Deref for Ref2<'_, T> {
type Target = T;
fn deref(&self) -> &T {
self.value
}
}
}
use refcell2::Ref2;
struct Item {
value: usize, //Overlaps with Ref2.value but is accessible
}
fn test(r: Ref2<Item>) {
//OK
let _val1: usize = (*r).value;
//mismatched types [E0308] expected `usize`, found `&Item`
//because it resolves to Item.value and the inaccessible Ref2.value
let _val2: usize = r.value;
}
This is likely a similar issue as in #6139
Environment
Problem description
Type inference error like this:
Steps to reproduce
In the editor