Address feedback
This commit is contained in:
parent
c4c9415132
commit
f3ac328d58
10 changed files with 113 additions and 30 deletions
|
@ -1428,7 +1428,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
item_name,
|
item_name,
|
||||||
field_ty,
|
field_ty,
|
||||||
call_expr,
|
call_expr,
|
||||||
ProbeScope::AllTraits,
|
ProbeScope::TraitsInScope,
|
||||||
)
|
)
|
||||||
.ok()
|
.ok()
|
||||||
.map(|pick| (variant, field, pick))
|
.map(|pick| (variant, field, pick))
|
||||||
|
@ -1500,59 +1500,88 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
item_name,
|
item_name,
|
||||||
ty,
|
ty,
|
||||||
call_expr,
|
call_expr,
|
||||||
ProbeScope::AllTraits,
|
ProbeScope::TraitsInScope,
|
||||||
) else { return; };
|
) else { return; };
|
||||||
|
|
||||||
let name = self.ty_to_value_string(actual);
|
let name = self.ty_to_value_string(actual);
|
||||||
let inner_id = kind.did();
|
let inner_id = kind.did();
|
||||||
|
let mutable = if let Some(AutorefOrPtrAdjustment::Autoref { mutbl, .. }) =
|
||||||
|
pick.autoref_or_ptr_adjustment
|
||||||
|
{
|
||||||
|
Some(mutbl)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
if tcx.is_diagnostic_item(sym::LocalKey, inner_id) {
|
if tcx.is_diagnostic_item(sym::LocalKey, inner_id) {
|
||||||
err.help("use `with` or `try_with` to access the contents of threadlocals");
|
err.help("use `with` or `try_with` to access thread local storage");
|
||||||
} else if Some(kind.did()) == tcx.lang_items().maybe_uninit() {
|
} else if Some(kind.did()) == tcx.lang_items().maybe_uninit() {
|
||||||
err.help(format!(
|
err.help(format!(
|
||||||
"if this `{name}` has been initialized, \
|
"if this `{name}` has been initialized, \
|
||||||
use one of the `assume_init` methods to access the inner value"
|
use one of the `assume_init` methods to access the inner value"
|
||||||
));
|
));
|
||||||
} else if tcx.is_diagnostic_item(sym::RefCell, inner_id) {
|
} else if tcx.is_diagnostic_item(sym::RefCell, inner_id) {
|
||||||
match pick.autoref_or_ptr_adjustment {
|
match mutable {
|
||||||
Some(AutorefOrPtrAdjustment::Autoref {
|
Some(Mutability::Not) => {
|
||||||
mutbl: Mutability::Not, ..
|
|
||||||
}) => {
|
|
||||||
err.span_suggestion_verbose(
|
err.span_suggestion_verbose(
|
||||||
expr.span.shrink_to_hi(),
|
expr.span.shrink_to_hi(),
|
||||||
format!(
|
format!(
|
||||||
"use `.borrow()` to borrow the {ty}, \
|
"use `.borrow()` to borrow the `{ty}`, \
|
||||||
panicking if any outstanding mutable borrows exist."
|
panicking if any outstanding mutable borrows exist."
|
||||||
),
|
),
|
||||||
".borrow()",
|
".borrow()",
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Some(AutorefOrPtrAdjustment::Autoref {
|
Some(Mutability::Mut) => {
|
||||||
mutbl: Mutability::Mut, ..
|
|
||||||
}) => {
|
|
||||||
err.span_suggestion_verbose(
|
err.span_suggestion_verbose(
|
||||||
expr.span.shrink_to_hi(),
|
expr.span.shrink_to_hi(),
|
||||||
format!(
|
format!(
|
||||||
"use `.borrow_mut()` to mutably borrow the {ty}, \
|
"use `.borrow_mut()` to mutably borrow the `{ty}`, \
|
||||||
panicking if any outstanding borrows exist."
|
panicking if any outstanding borrows exist."
|
||||||
),
|
),
|
||||||
".borrow_mut()",
|
".borrow_mut()",
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
_ => return,
|
None => return,
|
||||||
}
|
}
|
||||||
} else if tcx.is_diagnostic_item(sym::Mutex, inner_id) {
|
} else if tcx.is_diagnostic_item(sym::Mutex, inner_id) {
|
||||||
err.span_suggestion_verbose(
|
err.span_suggestion_verbose(
|
||||||
expr.span.shrink_to_hi(),
|
expr.span.shrink_to_hi(),
|
||||||
format!(
|
format!(
|
||||||
"use `.lock()` to borrow the {ty}, \
|
"use `.lock()` to borrow the `{ty}`, \
|
||||||
blocking the current thread until it can be acquired"
|
blocking the current thread until it can be acquired"
|
||||||
),
|
),
|
||||||
".lock().unwrap()",
|
".lock().unwrap()",
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
);
|
);
|
||||||
|
} else if tcx.is_diagnostic_item(sym::RwLock, inner_id) {
|
||||||
|
match mutable {
|
||||||
|
Some(Mutability::Not) => {
|
||||||
|
err.span_suggestion_verbose(
|
||||||
|
expr.span.shrink_to_hi(),
|
||||||
|
format!(
|
||||||
|
"use `.read()` to borrow the `{ty}`, \
|
||||||
|
blocking the current thread until it can be acquired"
|
||||||
|
),
|
||||||
|
".read().unwrap()",
|
||||||
|
Applicability::MaybeIncorrect,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Some(Mutability::Mut) => {
|
||||||
|
err.span_suggestion_verbose(
|
||||||
|
expr.span.shrink_to_hi(),
|
||||||
|
format!(
|
||||||
|
"use `.write()` to mutably borrow the `{ty}`, \
|
||||||
|
blocking the current thread until it can be acquired"
|
||||||
|
),
|
||||||
|
".write().unwrap()",
|
||||||
|
Applicability::MaybeIncorrect,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
None => return,
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
|
@ -276,6 +276,7 @@ symbols! {
|
||||||
Rust,
|
Rust,
|
||||||
RustcDecodable,
|
RustcDecodable,
|
||||||
RustcEncodable,
|
RustcEncodable,
|
||||||
|
RwLock,
|
||||||
RwLockReadGuard,
|
RwLockReadGuard,
|
||||||
RwLockWriteGuard,
|
RwLockWriteGuard,
|
||||||
Send,
|
Send,
|
||||||
|
|
|
@ -614,7 +614,7 @@ impl<T, const N: usize> Cell<[T; N]> {
|
||||||
/// A mutable memory location with dynamically checked borrow rules
|
/// A mutable memory location with dynamically checked borrow rules
|
||||||
///
|
///
|
||||||
/// See the [module-level documentation](self) for more.
|
/// See the [module-level documentation](self) for more.
|
||||||
#[rustc_diagnostic_item = "RefCell"]
|
#[cfg_attr(not(test), rustc_diagnostic_item = "RefCell")]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub struct RefCell<T: ?Sized> {
|
pub struct RefCell<T: ?Sized> {
|
||||||
borrow: Cell<BorrowFlag>,
|
borrow: Cell<BorrowFlag>,
|
||||||
|
|
|
@ -76,6 +76,7 @@ use crate::sys_common::rwlock as sys;
|
||||||
///
|
///
|
||||||
/// [`Mutex`]: super::Mutex
|
/// [`Mutex`]: super::Mutex
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#[cfg_attr(not(test), rustc_diagnostic_item = "RwLock")]
|
||||||
pub struct RwLock<T: ?Sized> {
|
pub struct RwLock<T: ?Sized> {
|
||||||
inner: sys::MovableRwLock,
|
inner: sys::MovableRwLock,
|
||||||
poison: poison::Flag,
|
poison: poison::Flag,
|
||||||
|
|
|
@ -95,7 +95,7 @@ use crate::fmt;
|
||||||
/// [loader lock]: https://docs.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-best-practices
|
/// [loader lock]: https://docs.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-best-practices
|
||||||
/// [`JoinHandle::join`]: crate::thread::JoinHandle::join
|
/// [`JoinHandle::join`]: crate::thread::JoinHandle::join
|
||||||
/// [`with`]: LocalKey::with
|
/// [`with`]: LocalKey::with
|
||||||
#[rustc_diagnostic_item = "LocalKey"]
|
#[cfg_attr(not(test), rustc_diagnostic_item = "LocalKey")]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub struct LocalKey<T: 'static> {
|
pub struct LocalKey<T: 'static> {
|
||||||
// This outer `LocalKey<T>` type is what's going to be stored in statics,
|
// This outer `LocalKey<T>` type is what's going to be stored in statics,
|
||||||
|
|
|
@ -16,15 +16,25 @@ fn main() {
|
||||||
|
|
||||||
other_item.borrow().method();
|
other_item.borrow().method();
|
||||||
//~^ ERROR no method named `method` found for struct `RefCell` in the current scope [E0599]
|
//~^ ERROR no method named `method` found for struct `RefCell` in the current scope [E0599]
|
||||||
//~| HELP use `.borrow()` to borrow the Struct<u32>, panicking if any outstanding mutable borrows exist.
|
//~| HELP use `.borrow()` to borrow the `Struct<u32>`, panicking if any outstanding mutable borrows exist.
|
||||||
|
|
||||||
other_item.borrow_mut().some_mutable_method();
|
other_item.borrow_mut().some_mutable_method();
|
||||||
//~^ ERROR no method named `some_mutable_method` found for struct `RefCell` in the current scope [E0599]
|
//~^ ERROR no method named `some_mutable_method` found for struct `RefCell` in the current scope [E0599]
|
||||||
//~| HELP use `.borrow_mut()` to mutably borrow the Struct<u32>, panicking if any outstanding borrows exist.
|
//~| HELP use `.borrow_mut()` to mutably borrow the `Struct<u32>`, panicking if any outstanding borrows exist.
|
||||||
|
|
||||||
let another_item = std::sync::Mutex::new(Struct { p: 42_u32 });
|
let another_item = std::sync::Mutex::new(Struct { p: 42_u32 });
|
||||||
|
|
||||||
another_item.lock().unwrap().method();
|
another_item.lock().unwrap().method();
|
||||||
//~^ ERROR no method named `method` found for struct `Mutex` in the current scope [E0599]
|
//~^ ERROR no method named `method` found for struct `Mutex` in the current scope [E0599]
|
||||||
//~| HELP use `.lock()` to borrow the Struct<u32>, blocking the current thread until it can be acquired
|
//~| HELP use `.lock()` to borrow the `Struct<u32>`, blocking the current thread until it can be acquired
|
||||||
|
|
||||||
|
let another_item = std::sync::RwLock::new(Struct { p: 42_u32 });
|
||||||
|
|
||||||
|
another_item.read().unwrap().method();
|
||||||
|
//~^ ERROR no method named `method` found for struct `RwLock` in the current scope [E0599]
|
||||||
|
//~| HELP use `.read()` to borrow the `Struct<u32>`, blocking the current thread until it can be acquired
|
||||||
|
|
||||||
|
another_item.write().unwrap().some_mutable_method();
|
||||||
|
//~^ ERROR no method named `some_mutable_method` found for struct `RwLock` in the current scope [E0599]
|
||||||
|
//~| HELP use `.write()` to mutably borrow the `Struct<u32>`, blocking the current thread until it can be acquired
|
||||||
}
|
}
|
|
@ -16,15 +16,25 @@ fn main() {
|
||||||
|
|
||||||
other_item.method();
|
other_item.method();
|
||||||
//~^ ERROR no method named `method` found for struct `RefCell` in the current scope [E0599]
|
//~^ ERROR no method named `method` found for struct `RefCell` in the current scope [E0599]
|
||||||
//~| HELP use `.borrow()` to borrow the Struct<u32>, panicking if any outstanding mutable borrows exist.
|
//~| HELP use `.borrow()` to borrow the `Struct<u32>`, panicking if any outstanding mutable borrows exist.
|
||||||
|
|
||||||
other_item.some_mutable_method();
|
other_item.some_mutable_method();
|
||||||
//~^ ERROR no method named `some_mutable_method` found for struct `RefCell` in the current scope [E0599]
|
//~^ ERROR no method named `some_mutable_method` found for struct `RefCell` in the current scope [E0599]
|
||||||
//~| HELP use `.borrow_mut()` to mutably borrow the Struct<u32>, panicking if any outstanding borrows exist.
|
//~| HELP use `.borrow_mut()` to mutably borrow the `Struct<u32>`, panicking if any outstanding borrows exist.
|
||||||
|
|
||||||
let another_item = std::sync::Mutex::new(Struct { p: 42_u32 });
|
let another_item = std::sync::Mutex::new(Struct { p: 42_u32 });
|
||||||
|
|
||||||
another_item.method();
|
another_item.method();
|
||||||
//~^ ERROR no method named `method` found for struct `Mutex` in the current scope [E0599]
|
//~^ ERROR no method named `method` found for struct `Mutex` in the current scope [E0599]
|
||||||
//~| HELP use `.lock()` to borrow the Struct<u32>, blocking the current thread until it can be acquired
|
//~| HELP use `.lock()` to borrow the `Struct<u32>`, blocking the current thread until it can be acquired
|
||||||
|
|
||||||
|
let another_item = std::sync::RwLock::new(Struct { p: 42_u32 });
|
||||||
|
|
||||||
|
another_item.method();
|
||||||
|
//~^ ERROR no method named `method` found for struct `RwLock` in the current scope [E0599]
|
||||||
|
//~| HELP use `.read()` to borrow the `Struct<u32>`, blocking the current thread until it can be acquired
|
||||||
|
|
||||||
|
another_item.some_mutable_method();
|
||||||
|
//~^ ERROR no method named `some_mutable_method` found for struct `RwLock` in the current scope [E0599]
|
||||||
|
//~| HELP use `.write()` to mutably borrow the `Struct<u32>`, blocking the current thread until it can be acquired
|
||||||
}
|
}
|
|
@ -9,7 +9,7 @@ note: the method `method` exists on the type `Struct<u32>`
|
||||||
|
|
|
|
||||||
LL | pub fn method(&self) {}
|
LL | pub fn method(&self) {}
|
||||||
| ^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^
|
||||||
help: use `.borrow()` to borrow the Struct<u32>, panicking if any outstanding mutable borrows exist.
|
help: use `.borrow()` to borrow the `Struct<u32>`, panicking if any outstanding mutable borrows exist.
|
||||||
|
|
|
|
||||||
LL | other_item.borrow().method();
|
LL | other_item.borrow().method();
|
||||||
| +++++++++
|
| +++++++++
|
||||||
|
@ -25,7 +25,7 @@ note: the method `some_mutable_method` exists on the type `Struct<u32>`
|
||||||
|
|
|
|
||||||
LL | pub fn some_mutable_method(&mut self) {}
|
LL | pub fn some_mutable_method(&mut self) {}
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
help: use `.borrow_mut()` to mutably borrow the Struct<u32>, panicking if any outstanding borrows exist.
|
help: use `.borrow_mut()` to mutably borrow the `Struct<u32>`, panicking if any outstanding borrows exist.
|
||||||
|
|
|
|
||||||
LL | other_item.borrow_mut().some_mutable_method();
|
LL | other_item.borrow_mut().some_mutable_method();
|
||||||
| +++++++++++++
|
| +++++++++++++
|
||||||
|
@ -41,11 +41,43 @@ note: the method `method` exists on the type `Struct<u32>`
|
||||||
|
|
|
|
||||||
LL | pub fn method(&self) {}
|
LL | pub fn method(&self) {}
|
||||||
| ^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^
|
||||||
help: use `.lock()` to borrow the Struct<u32>, blocking the current thread until it can be acquired
|
help: use `.lock()` to borrow the `Struct<u32>`, blocking the current thread until it can be acquired
|
||||||
|
|
|
|
||||||
LL | another_item.lock().unwrap().method();
|
LL | another_item.lock().unwrap().method();
|
||||||
| ++++++++++++++++
|
| ++++++++++++++++
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
error[E0599]: no method named `method` found for struct `RwLock` in the current scope
|
||||||
|
--> $DIR/inner_type.rs:33:18
|
||||||
|
|
|
||||||
|
LL | another_item.method();
|
||||||
|
| ^^^^^^ method not found in `RwLock<Struct<u32>>`
|
||||||
|
|
|
||||||
|
note: the method `method` exists on the type `Struct<u32>`
|
||||||
|
--> $DIR/inner_type.rs:9:5
|
||||||
|
|
|
||||||
|
LL | pub fn method(&self) {}
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^
|
||||||
|
help: use `.read()` to borrow the `Struct<u32>`, blocking the current thread until it can be acquired
|
||||||
|
|
|
||||||
|
LL | another_item.read().unwrap().method();
|
||||||
|
| ++++++++++++++++
|
||||||
|
|
||||||
|
error[E0599]: no method named `some_mutable_method` found for struct `RwLock` in the current scope
|
||||||
|
--> $DIR/inner_type.rs:37:18
|
||||||
|
|
|
||||||
|
LL | another_item.some_mutable_method();
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^ method not found in `RwLock<Struct<u32>>`
|
||||||
|
|
|
||||||
|
note: the method `some_mutable_method` exists on the type `Struct<u32>`
|
||||||
|
--> $DIR/inner_type.rs:11:5
|
||||||
|
|
|
||||||
|
LL | pub fn some_mutable_method(&mut self) {}
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
help: use `.write()` to mutably borrow the `Struct<u32>`, blocking the current thread until it can be acquired
|
||||||
|
|
|
||||||
|
LL | another_item.write().unwrap().some_mutable_method();
|
||||||
|
| +++++++++++++++++
|
||||||
|
|
||||||
|
error: aborting due to 5 previous errors
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0599`.
|
For more information about this error, try `rustc --explain E0599`.
|
||||||
|
|
|
@ -17,7 +17,7 @@ thread_local! {
|
||||||
fn main() {
|
fn main() {
|
||||||
STRUCT.method();
|
STRUCT.method();
|
||||||
//~^ ERROR no method named `method` found for struct `LocalKey` in the current scope [E0599]
|
//~^ ERROR no method named `method` found for struct `LocalKey` in the current scope [E0599]
|
||||||
//~| HELP use `with` or `try_with` to access the contents of threadlocals
|
//~| HELP use `with` or `try_with` to access thread local storage
|
||||||
|
|
||||||
let item = std::mem::MaybeUninit::new(Struct { p: 42_u32 });
|
let item = std::mem::MaybeUninit::new(Struct { p: 42_u32 });
|
||||||
item.method();
|
item.method();
|
||||||
|
|
|
@ -4,7 +4,7 @@ error[E0599]: no method named `method` found for struct `LocalKey` in the curren
|
||||||
LL | STRUCT.method();
|
LL | STRUCT.method();
|
||||||
| ^^^^^^ method not found in `LocalKey<Struct<u32>>`
|
| ^^^^^^ method not found in `LocalKey<Struct<u32>>`
|
||||||
|
|
|
|
||||||
= help: use `with` or `try_with` to access the contents of threadlocals
|
= help: use `with` or `try_with` to access thread local storage
|
||||||
note: the method `method` exists on the type `Struct<u32>`
|
note: the method `method` exists on the type `Struct<u32>`
|
||||||
--> $DIR/inner_type2.rs:6:5
|
--> $DIR/inner_type2.rs:6:5
|
||||||
|
|
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue