Adjust messages, address some nits

This commit is contained in:
Michael Goulet 2022-08-18 12:16:35 +00:00
parent 2a16a127a0
commit d2f54b1990
23 changed files with 91 additions and 85 deletions

View File

@ -973,6 +973,23 @@ fn suggest_add_reference_to_arg(
|| ref_inner_ty_satisfies_pred
{
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) {
// We don't want a borrowing suggestion on the fields in structs,
// ```
// struct Foo {
// the_foos: Vec<Foo>
// }
// ```
if !matches!(
span.ctxt().outer_expn_data().kind,
ExpnKind::Root | ExpnKind::Desugaring(DesugaringKind::ForLoop)
) {
return false;
}
if snippet.starts_with('&') {
// This is already a literal borrow and the obligation is failing
// somewhere else in the obligation chain. Do not suggest non-sense.
return false;
}
// We have a very specific type of error, where just borrowing this argument
// might solve the problem. In cases like this, the important part is the
// original type obligation, not the last one that failed, which is arbitrary.
@ -986,50 +1003,33 @@ fn suggest_add_reference_to_arg(
err.message =
vec![(rustc_errors::DiagnosticMessage::Str(msg), Style::NoStyle)];
}
if snippet.starts_with('&') {
// This is already a literal borrow and the obligation is failing
// somewhere else in the obligation chain. Do not suggest non-sense.
return false;
}
err.span_label(
span,
&format!(
"expected an implementor of trait `{}`",
format!(
"the trait `{}` is not implemented for `{}`",
old_pred.print_modifiers_and_trait_path(),
old_pred.self_ty().skip_binder(),
),
);
// This if is to prevent a special edge-case
if matches!(
span.ctxt().outer_expn_data().kind,
ExpnKind::Root | ExpnKind::Desugaring(DesugaringKind::ForLoop)
) {
// We don't want a borrowing suggestion on the fields in structs,
// ```
// struct Foo {
// the_foos: Vec<Foo>
// }
// ```
if imm_ref_self_ty_satisfies_pred && mut_ref_self_ty_satisfies_pred {
err.span_suggestions(
span.shrink_to_lo(),
"consider borrowing here",
["&".to_string(), "&mut ".to_string()].into_iter(),
Applicability::MaybeIncorrect,
);
} else {
let is_mut = mut_ref_self_ty_satisfies_pred || ref_inner_ty_mut;
err.span_suggestion_verbose(
span.shrink_to_lo(),
&format!(
"consider{} borrowing here",
if is_mut { " mutably" } else { "" }
),
format!("&{}", if is_mut { "mut " } else { "" }),
Applicability::MaybeIncorrect,
);
}
if imm_ref_self_ty_satisfies_pred && mut_ref_self_ty_satisfies_pred {
err.span_suggestions(
span.shrink_to_lo(),
"consider borrowing here",
["&".to_string(), "&mut ".to_string()].into_iter(),
Applicability::MaybeIncorrect,
);
} else {
let is_mut = mut_ref_self_ty_satisfies_pred || ref_inner_ty_mut;
err.span_suggestion_verbose(
span.shrink_to_lo(),
&format!(
"consider{} borrowing here",
if is_mut { " mutably" } else { "" }
),
format!("&{}", if is_mut { "mut " } else { "" }),
Applicability::MaybeIncorrect,
);
}
return true;
}

View File

@ -1753,9 +1753,10 @@ fn adjust_fulfillment_error_for_expr_obligation(
{
for param in
[param_to_point_at, fallback_param_to_point_at, self_param_to_point_at]
.into_iter()
.flatten()
{
if let Some(param) = param
&& self.point_at_arg_if_possible(
if self.point_at_arg_if_possible(
error,
def_id,
param,
@ -1784,17 +1785,17 @@ fn adjust_fulfillment_error_for_expr_obligation(
..
}) => {
for param in [param_to_point_at, fallback_param_to_point_at, self_param_to_point_at]
.into_iter()
.flatten()
{
if let Some(param) = param
&& self.point_at_arg_if_possible(
error,
def_id,
param,
hir_id,
segment.ident.span,
args,
)
{
if self.point_at_arg_if_possible(
error,
def_id,
param,
hir_id,
segment.ident.span,
args,
) {
return true;
}
}
@ -1903,6 +1904,7 @@ fn point_at_field_if_possible(
if self.tcx.adjust_ident(expr_field.ident, variant_def_id) == field.ident(self.tcx)
{
error.obligation.cause.span = expr_field
.expr
.span
.find_ancestor_in_same_ctxt(error.obligation.cause.span)
.unwrap_or(expr_field.span);

View File

@ -1,8 +1,8 @@
error[E0277]: the trait bound `{float}: Foo` is not satisfied
--> $DIR/type_wf.rs:19:9
--> $DIR/type_wf.rs:19:12
|
LL | x: 5.0,
| ^^^^^^ the trait `Foo` is not implemented for `{float}`
| ^^^ the trait `Foo` is not implemented for `{float}`
|
= help: the trait `Foo` is implemented for `i32`
note: required by a bound in `S`

View File

@ -2,7 +2,7 @@ error[E0277]: can't drop `UnconstDrop` in const contexts
--> $DIR/const-block-const-bound.rs:20:11
|
LL | f(UnconstDrop);
| - ^^^^^^^^^^^ expected an implementor of trait `~const Destruct`
| - ^^^^^^^^^^^ the trait `~const Destruct` is not implemented for `UnconstDrop`
| |
| required by a bound introduced by this call
|
@ -23,7 +23,7 @@ error[E0277]: can't drop `NonDrop` in const contexts
--> $DIR/const-block-const-bound.rs:22:11
|
LL | f(NonDrop);
| - ^^^^^^^ expected an implementor of trait `~const Destruct`
| - ^^^^^^^ the trait `~const Destruct` is not implemented for `NonDrop`
| |
| required by a bound introduced by this call
|

View File

@ -2,7 +2,7 @@ error[E0277]: the trait bound `B<C>: Copy` is not satisfied
--> $DIR/deriving-copyclone.rs:31:13
|
LL | is_copy(B { a: 1, b: C });
| ------- ^^^^^^^^^^^^^^^^ expected an implementor of trait `Copy`
| ------- ^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `B<C>`
| |
| required by a bound introduced by this call
|
@ -26,7 +26,7 @@ error[E0277]: the trait bound `B<C>: Clone` is not satisfied
--> $DIR/deriving-copyclone.rs:32:14
|
LL | is_clone(B { a: 1, b: C });
| -------- ^^^^^^^^^^^^^^^^ expected an implementor of trait `Clone`
| -------- ^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `B<C>`
| |
| required by a bound introduced by this call
|
@ -50,7 +50,7 @@ error[E0277]: the trait bound `B<D>: Copy` is not satisfied
--> $DIR/deriving-copyclone.rs:35:13
|
LL | is_copy(B { a: 1, b: D });
| ------- ^^^^^^^^^^^^^^^^ expected an implementor of trait `Copy`
| ------- ^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `B<D>`
| |
| required by a bound introduced by this call
|

View File

@ -2,7 +2,7 @@ error[E0277]: the size for values of type `dyn Iterator<Item = &'a mut u8>` cann
--> $DIR/issue-20605.rs:2:17
|
LL | for item in *things { *item = 0 }
| ^^^^^^^ expected an implementor of trait `IntoIterator`
| ^^^^^^^ the trait `IntoIterator` is not implemented for `dyn Iterator<Item = &'a mut u8>`
|
= note: the trait bound `dyn Iterator<Item = &'a mut u8>: IntoIterator` is not satisfied
= note: required for `dyn Iterator<Item = &'a mut u8>` to implement `IntoIterator`

View File

@ -11,5 +11,5 @@ fn take_param<T:Foo>(foo: &T) { }
fn main() {
let x: Box<_> = Box::new(3);
take_param(&x);
//~^ ERROR the trait bound `Box<{integer}>: Foo` is not satisfied
//~^ ERROR the trait bound `Box<{integer}>: Copy` is not satisfied
}

View File

@ -1,4 +1,4 @@
error[E0277]: the trait bound `Box<{integer}>: Foo` is not satisfied
error[E0277]: the trait bound `Box<{integer}>: Copy` is not satisfied
--> $DIR/kindck-impl-type-params-2.rs:13:16
|
LL | take_param(&x);

View File

@ -1,4 +1,4 @@
error[E0277]: the trait bound `Box<{integer}>: Foo` is not satisfied
error[E0277]: the trait bound `Box<{integer}>: Copy` is not satisfied
--> $DIR/kindck-inherited-copy-bound.rs:21:16
|
LL | take_param(&x);

View File

@ -1,4 +1,4 @@
error[E0277]: the trait bound `Box<{integer}>: Foo` is not satisfied
error[E0277]: the trait bound `Box<{integer}>: Copy` is not satisfied
--> $DIR/kindck-inherited-copy-bound.rs:21:16
|
LL | take_param(&x);

View File

@ -5,7 +5,7 @@ LL | const _: () = check($exp);
| ----- required by a bound introduced by this call
...
LL | NonTrivialDrop,
| ^^^^^^^^^^^^^^ expected an implementor of trait `~const Destruct`
| ^^^^^^^^^^^^^^ the trait `~const Destruct` is not implemented for `NonTrivialDrop`
|
= note: the trait bound `NonTrivialDrop: ~const Destruct` is not satisfied
note: required by a bound in `check`
@ -52,7 +52,7 @@ LL | const _: () = check($exp);
| ----- required by a bound introduced by this call
...
LL | ConstDropImplWithBounds::<NonTrivialDrop>(PhantomData),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected an implementor of trait `~const Destruct`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `~const Destruct` is not implemented for `ConstDropImplWithBounds<NonTrivialDrop>`
|
note: required for `ConstDropImplWithBounds<NonTrivialDrop>` to implement `~const Destruct`
--> $DIR/const-drop-fail.rs:28:25

View File

@ -5,7 +5,7 @@ LL | const _: () = check($exp);
| ----- required by a bound introduced by this call
...
LL | NonTrivialDrop,
| ^^^^^^^^^^^^^^ expected an implementor of trait `~const Destruct`
| ^^^^^^^^^^^^^^ the trait `~const Destruct` is not implemented for `NonTrivialDrop`
|
= note: the trait bound `NonTrivialDrop: ~const Destruct` is not satisfied
note: required by a bound in `check`
@ -52,7 +52,7 @@ LL | const _: () = check($exp);
| ----- required by a bound introduced by this call
...
LL | ConstDropImplWithBounds::<NonTrivialDrop>(PhantomData),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected an implementor of trait `~const Destruct`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `~const Destruct` is not implemented for `ConstDropImplWithBounds<NonTrivialDrop>`
|
note: required for `ConstDropImplWithBounds<NonTrivialDrop>` to implement `~const Destruct`
--> $DIR/const-drop-fail.rs:28:25

View File

@ -21,7 +21,7 @@ error[E0277]: the trait bound `S: Trait` is not satisfied
--> $DIR/imm-ref-trait-object-literal.rs:13:7
|
LL | foo(s);
| --- ^ expected an implementor of trait `Trait`
| --- ^ the trait `Trait` is not implemented for `S`
| |
| required by a bound introduced by this call
|

View File

@ -2,7 +2,7 @@ error[E0277]: expected a `FnMut<(char,)>` closure, found `String`
--> $DIR/issue-62843.rs:4:32
|
LL | println!("{:?}", line.find(pattern));
| ---- ^^^^^^^ expected an implementor of trait `Pattern<'_>`
| ---- ^^^^^^^ the trait `Pattern<'_>` is not implemented for `String`
| |
| required by a bound introduced by this call
|

View File

@ -2,7 +2,7 @@ error[E0277]: the trait bound `i32: Tr` is not satisfied
--> $DIR/issue-84973-2.rs:11:9
|
LL | foo(a);
| --- ^ expected an implementor of trait `Tr`
| --- ^ the trait `Tr` is not implemented for `i32`
| |
| required by a bound introduced by this call
|

View File

@ -17,7 +17,7 @@ error[E0277]: the trait bound `f32: Tr` is not satisfied
--> $DIR/issue-84973-negative.rs:11:9
|
LL | bar(b);
| --- ^ expected an implementor of trait `Tr`
| --- ^ the trait `Tr` is not implemented for `f32`
| |
| required by a bound introduced by this call
|

View File

@ -2,7 +2,7 @@ error[E0277]: the trait bound `Fancy: SomeTrait` is not satisfied
--> $DIR/issue-84973.rs:6:24
|
LL | let o = Other::new(f);
| ---------- ^ expected an implementor of trait `SomeTrait`
| ---------- ^ the trait `SomeTrait` is not implemented for `Fancy`
| |
| required by a bound introduced by this call
|

View File

@ -2,7 +2,7 @@ error[E0277]: the size for values of type `[i32]` cannot be known at compilation
--> $DIR/slice-issue-87994.rs:3:12
|
LL | for _ in v[1..] {
| ^^^^^^ expected an implementor of trait `IntoIterator`
| ^^^^^^ the trait `IntoIterator` is not implemented for `[i32]`
|
= note: the trait bound `[i32]: IntoIterator` is not satisfied
= note: required for `[i32]` to implement `IntoIterator`
@ -17,7 +17,7 @@ error[E0277]: `[i32]` is not an iterator
--> $DIR/slice-issue-87994.rs:3:12
|
LL | for _ in v[1..] {
| ^^^^^^ expected an implementor of trait `IntoIterator`
| ^^^^^^ the trait `IntoIterator` is not implemented for `[i32]`
|
= note: the trait bound `[i32]: IntoIterator` is not satisfied
= note: required for `[i32]` to implement `IntoIterator`
@ -32,7 +32,7 @@ error[E0277]: the size for values of type `[K]` cannot be known at compilation t
--> $DIR/slice-issue-87994.rs:11:13
|
LL | for i2 in v2[1..] {
| ^^^^^^^ expected an implementor of trait `IntoIterator`
| ^^^^^^^ the trait `IntoIterator` is not implemented for `[K]`
|
= note: the trait bound `[K]: IntoIterator` is not satisfied
= note: required for `[K]` to implement `IntoIterator`
@ -47,7 +47,7 @@ error[E0277]: `[K]` is not an iterator
--> $DIR/slice-issue-87994.rs:11:13
|
LL | for i2 in v2[1..] {
| ^^^^^^^ expected an implementor of trait `IntoIterator`
| ^^^^^^^ the trait `IntoIterator` is not implemented for `[K]`
|
= note: the trait bound `[K]: IntoIterator` is not satisfied
= note: required for `[K]` to implement `IntoIterator`

View File

@ -2,7 +2,7 @@ error[E0277]: the trait bound `A: Trait` is not satisfied
--> $DIR/suggest-imm-mut-trait-implementations.rs:20:9
|
LL | foo(a);
| --- ^ expected an implementor of trait `Trait`
| --- ^ the trait `Trait` is not implemented for `A`
| |
| required by a bound introduced by this call
|
@ -22,7 +22,7 @@ error[E0277]: the trait bound `B: Trait` is not satisfied
--> $DIR/suggest-imm-mut-trait-implementations.rs:21:9
|
LL | foo(b);
| --- ^ expected an implementor of trait `Trait`
| --- ^ the trait `Trait` is not implemented for `B`
| |
| required by a bound introduced by this call
|
@ -40,7 +40,7 @@ error[E0277]: the trait bound `C: Trait` is not satisfied
--> $DIR/suggest-imm-mut-trait-implementations.rs:22:9
|
LL | foo(c);
| --- ^ expected an implementor of trait `Trait`
| --- ^ the trait `Trait` is not implemented for `C`
| |
| required by a bound introduced by this call
|

View File

@ -11,10 +11,10 @@ LL | struct Foo<T:Trait> {
| ^^^^^ required by this bound in `Foo`
error[E0277]: the trait bound `{integer}: Trait` is not satisfied
--> $DIR/on-structs-and-enums-locals.rs:11:9
--> $DIR/on-structs-and-enums-locals.rs:11:12
|
LL | x: 3
| ^^^^ the trait `Trait` is not implemented for `{integer}`
| ^ the trait `Trait` is not implemented for `{integer}`
|
note: required by a bound in `Foo`
--> $DIR/on-structs-and-enums-locals.rs:5:14

View File

@ -11,10 +11,10 @@ LL | pub enum Bar<T:Trait> {
| ^^^^^ required by this bound in `Bar`
error[E0277]: the trait bound `{integer}: Trait` is not satisfied
--> $DIR/on-structs-and-enums-xc1.rs:9:9
--> $DIR/on-structs-and-enums-xc1.rs:9:12
|
LL | x: 3
| ^^^^ the trait `Trait` is not implemented for `{integer}`
| ^ the trait `Trait` is not implemented for `{integer}`
|
note: required by a bound in `Foo`
--> $DIR/auxiliary/on_structs_and_enums_xc.rs:5:18

View File

@ -1,14 +1,18 @@
error[E0277]: the trait bound `Vec<Foo>: Clone` is not satisfied
error[E0277]: the trait bound `Foo: Clone` is not satisfied
--> $DIR/issue-71136.rs:5:5
|
LL | #[derive(Clone)]
| ----- in this derive macro expansion
LL | struct FooHolster {
LL | the_foos: Vec<Foo>,
| ^^^^^^^^^^^^^^^^^^ expected an implementor of trait `~const Clone`
| ^^^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `Foo`
|
= note: required for `Vec<Foo>` to implement `Clone`
= note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider annotating `Foo` with `#[derive(Clone)]`
|
LL | #[derive(Clone)]
|
error: aborting due to previous error

View File

@ -61,7 +61,7 @@ error[E0277]: `dummy2::TestType` cannot be sent between threads safely
--> $DIR/negated-auto-traits-error.rs:48:13
|
LL | is_send(Box::new(TestType));
| ------- ^^^^^^^^^^^^^^^^^^ expected an implementor of trait `Send`
| ------- ^^^^^^^^^^^^^^^^^^ the trait `Send` is not implemented for `Unique<dummy2::TestType>`
| |
| required by a bound introduced by this call
|