Change wording to avoid being misleading

This commit is contained in:
Esteban Küber 2023-01-02 09:55:13 -08:00
parent 1eb828ecb1
commit 670a6f1ef5
8 changed files with 21 additions and 27 deletions

View File

@ -177,9 +177,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
MethodError::IllegalSizedBound(candidates, needs_mut, bound_span, self_expr) => {
let msg = format!("the `{}` method cannot be invoked on a trait object", item_name);
let msg = if needs_mut {
with_forced_trimmed_paths!(format!(
"the `{item_name}` method cannot be invoked on `{rcvr_ty}`"
))
} else {
format!("the `{item_name}` method cannot be invoked on a trait object")
};
let mut err = self.sess().struct_span_err(span, &msg);
err.span_label(bound_span, "this has a `Sized` requirement");
if !needs_mut {
err.span_label(bound_span, "this has a `Sized` requirement");
}
if !candidates.is_empty() {
let help = format!(
"{an}other candidate{s} {were} found in the following trait{s}, perhaps \

View File

@ -1,6 +1,6 @@
// run-rustfix
fn test(t: &mut dyn Iterator<Item=&u64>) -> u64 {
*t.min().unwrap() //~ ERROR the `min` method cannot be invoked on a trait object
*t.min().unwrap() //~ ERROR the `min` method cannot be invoked on
}
fn main() {

View File

@ -1,6 +1,6 @@
// run-rustfix
fn test(t: &dyn Iterator<Item=&u64>) -> u64 {
*t.min().unwrap() //~ ERROR the `min` method cannot be invoked on a trait object
*t.min().unwrap() //~ ERROR the `min` method cannot be invoked on
}
fn main() {

View File

@ -1,11 +1,8 @@
error: the `min` method cannot be invoked on a trait object
error: the `min` method cannot be invoked on `&dyn Iterator<Item = &u64>`
--> $DIR/mutability-mismatch-arg.rs:3:9
|
LL | *t.min().unwrap()
| ^^^
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
|
= note: this has a `Sized` requirement
|
help: you need `&mut dyn Iterator<Item = &u64>` instead of `&dyn Iterator<Item = &u64>`
|

View File

@ -4,7 +4,6 @@ pub trait MutTrait {
fn function(&mut self)
where
Self: Sized;
//~^ this has a `Sized` requirement
}
impl MutTrait for MutType {
@ -17,7 +16,6 @@ pub trait Trait {
fn function(&self)
where
Self: Sized;
//~^ this has a `Sized` requirement
}
impl Trait for Type {
@ -26,9 +24,9 @@ impl Trait for Type {
fn main() {
(&MutType as &dyn MutTrait).function();
//~^ ERROR the `function` method cannot be invoked on a trait object
//~^ ERROR the `function` method cannot be invoked on `&dyn MutTrait`
//~| HELP you need `&mut dyn MutTrait` instead of `&dyn MutTrait`
(&mut Type as &mut dyn Trait).function();
//~^ ERROR the `function` method cannot be invoked on a trait object
//~^ ERROR the `function` method cannot be invoked on `&mut dyn Trait`
//~| HELP you need `&dyn Trait` instead of `&mut dyn Trait`
}

View File

@ -1,20 +1,14 @@
error: the `function` method cannot be invoked on a trait object
--> $DIR/mutability-mismatch.rs:28:33
error: the `function` method cannot be invoked on `&dyn MutTrait`
--> $DIR/mutability-mismatch.rs:26:33
|
LL | Self: Sized;
| ----- this has a `Sized` requirement
...
LL | (&MutType as &dyn MutTrait).function();
| ^^^^^^^^
|
= help: you need `&mut dyn MutTrait` instead of `&dyn MutTrait`
error: the `function` method cannot be invoked on a trait object
--> $DIR/mutability-mismatch.rs:31:35
error: the `function` method cannot be invoked on `&mut dyn Trait`
--> $DIR/mutability-mismatch.rs:29:35
|
LL | Self: Sized;
| ----- this has a `Sized` requirement
...
LL | (&mut Type as &mut dyn Trait).function();
| ^^^^^^^^
|

View File

@ -1,5 +1,5 @@
fn test(t: &dyn Iterator<Item=&u64>) -> u64 {
t.min().unwrap() //~ ERROR the `min` method cannot be invoked on a trait object
t.min().unwrap() //~ ERROR the `min` method cannot be invoked on `&dyn Iterator<Item = &u64>`
}
fn main() {

View File

@ -1,11 +1,8 @@
error: the `min` method cannot be invoked on a trait object
error: the `min` method cannot be invoked on `&dyn Iterator<Item = &u64>`
--> $DIR/imm-ref-trait-object.rs:2:8
|
LL | t.min().unwrap()
| ^^^
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
|
= note: this has a `Sized` requirement
|
help: you need `&mut dyn Iterator<Item = &u64>` instead of `&dyn Iterator<Item = &u64>`
|