Use single label for method not found due to unmet bound

This commit is contained in:
Esteban Küber 2024-01-26 20:44:43 +00:00
parent 757b726f86
commit 7df4a09fc4
13 changed files with 37 additions and 63 deletions

View File

@ -459,22 +459,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
);
}
let ty_span = match rcvr_ty.kind() {
let mut ty_span = match rcvr_ty.kind() {
ty::Param(param_type) => {
Some(param_type.span_from_generics(self.tcx, self.body_id.to_def_id()))
}
ty::Adt(def, _) if def.did().is_local() => Some(tcx.def_span(def.did())),
_ => None,
};
if let Some(span) = ty_span {
err.span_label(
span,
format!(
"{item_kind} `{item_name}` not found for this {}",
rcvr_ty.prefix_string(self.tcx)
),
);
}
if let SelfSource::MethodCall(rcvr_expr) = source {
self.suggest_fn_call(&mut err, rcvr_expr, rcvr_ty, |output_ty| {
@ -1190,13 +1181,33 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if !tcx.sess.source_map().is_span_accessible(span) {
continue;
}
let pre = if Some(span) == ty_span {
ty_span.take();
format!(
"{item_kind} `{item_name}` not found for this {} because it ",
rcvr_ty.prefix_string(self.tcx)
)
} else {
String::new()
};
let msg = match &bounds[..] {
[bound] => format!("doesn't satisfy {bound}"),
[bounds @ .., last] => format!("doesn't satisfy {} or {last}", bounds.join(", ")),
[bound] => format!("{pre}doesn't satisfy {bound}"),
[bounds @ .., last] => {
format!("{pre}doesn't satisfy {} or {last}", bounds.join(", "))
}
[] => unreachable!(),
};
err.span_label(span, msg);
}
if let Some(span) = ty_span {
err.span_label(
span,
format!(
"{item_kind} `{item_name}` not found for this {}",
rcvr_ty.prefix_string(self.tcx)
),
);
}
if rcvr_ty.is_numeric() && rcvr_ty.is_fresh() || restrict_type_params {
} else {

View File

@ -2,10 +2,7 @@ error[E0599]: the method `clone` exists for struct `Bar<NotClone>`, but its trai
--> $DIR/derive-assoc-type-not-impl.rs:18:30
|
LL | struct Bar<T: Foo> {
| ------------------
| |
| method `clone` not found for this struct
| doesn't satisfy `Bar<NotClone>: Clone`
| ------------------ method `clone` not found for this struct because it doesn't satisfy `Bar<NotClone>: Clone`
...
LL | struct NotClone;
| --------------- doesn't satisfy `NotClone: Clone`

View File

@ -2,10 +2,7 @@ error[E0599]: the method `clone` exists for struct `Foo<NonCopy>`, but its trait
--> $DIR/deriving-with-repr-packed-2.rs:18:11
|
LL | pub struct Foo<T>(T, T, T);
| -----------------
| |
| method `clone` not found for this struct
| doesn't satisfy `Foo<NonCopy>: Clone`
| ----------------- method `clone` not found for this struct because it doesn't satisfy `Foo<NonCopy>: Clone`
LL |
LL | struct NonCopy;
| -------------- doesn't satisfy `NonCopy: Clone` or `NonCopy: Copy`

View File

@ -19,10 +19,7 @@ error[E0599]: the size for values of type `Node<i32, RcFamily>` cannot be known
--> $DIR/issue-119942-unsatisified-gat-bound-during-assoc-ty-selection.rs:31:35
|
LL | enum Node<T, P: PointerFamily> {
| ------------------------------
| |
| variant or associated item `new` not found for this enum
| doesn't satisfy `Node<i32, RcFamily>: Sized`
| ------------------------------ variant or associated item `new` not found for this enum because it doesn't satisfy `Node<i32, RcFamily>: Sized`
...
LL | let mut list = RcNode::<i32>::new();
| ^^^ doesn't have a size known at compile-time

View File

@ -16,8 +16,7 @@ impl<T: X<Y<i32> = i32>> M for T {}
//~| NOTE
struct S;
//~^ NOTE method `f` not found for this
//~| NOTE doesn't satisfy `<S as X>::Y<i32> = i32` or `S: M`
//~^ NOTE method `f` not found for this struct because it doesn't satisfy `<S as X>::Y<i32> = i32` or `S: M`
impl X for S {
type Y<T> = bool;

View File

@ -1,11 +1,8 @@
error[E0599]: the method `f` exists for struct `S`, but its trait bounds were not satisfied
--> $DIR/method-unsatisfied-assoc-type-predicate.rs:27:7
--> $DIR/method-unsatisfied-assoc-type-predicate.rs:26:7
|
LL | struct S;
| --------
| |
| method `f` not found for this struct
| doesn't satisfy `<S as X>::Y<i32> = i32` or `S: M`
| -------- method `f` not found for this struct because it doesn't satisfy `<S as X>::Y<i32> = i32` or `S: M`
...
LL | a.f();
| ^ method cannot be called on `S` due to unsatisfied trait bounds

View File

@ -2,10 +2,7 @@ error[E0599]: the method `filterx` exists for struct `Map<Repeat, {closure@issue
--> $DIR/issue-30786.rs:120:22
|
LL | pub struct Map<S, F> {
| --------------------
| |
| method `filterx` not found for this struct
| doesn't satisfy `_: StreamExt`
| -------------------- method `filterx` not found for this struct because it doesn't satisfy `_: StreamExt`
...
LL | let filter = map.filterx(|x: &_| true);
| ^^^^^^^ method cannot be called on `Map<Repeat, {closure@issue-30786.rs:119:27}>` due to unsatisfied trait bounds
@ -23,10 +20,7 @@ error[E0599]: the method `countx` exists for struct `Filter<Map<Repeat, fn(&u64)
--> $DIR/issue-30786.rs:132:24
|
LL | pub struct Filter<S, F> {
| -----------------------
| |
| method `countx` not found for this struct
| doesn't satisfy `_: StreamExt`
| ----------------------- method `countx` not found for this struct because it doesn't satisfy `_: StreamExt`
...
LL | let count = filter.countx();
| ^^^^^^ method cannot be called due to unsatisfied trait bounds

View File

@ -49,10 +49,7 @@ error[E0599]: `Foo` is not an iterator
--> $DIR/method-call-err-msg.rs:19:7
|
LL | pub struct Foo;
| --------------
| |
| method `take` not found for this struct
| doesn't satisfy `Foo: Iterator`
| -------------- method `take` not found for this struct because it doesn't satisfy `Foo: Iterator`
...
LL | / y.zero()
LL | | .take()

View File

@ -12,10 +12,7 @@ error[E0599]: the method `foo_one` exists for struct `MyStruct`, but its trait b
--> $DIR/specialization-trait-not-implemented.rs:22:29
|
LL | struct MyStruct;
| ---------------
| |
| method `foo_one` not found for this struct
| doesn't satisfy `MyStruct: Foo`
| --------------- method `foo_one` not found for this struct because it doesn't satisfy `MyStruct: Foo`
...
LL | println!("{}", MyStruct.foo_one());
| ^^^^^^^ method cannot be called on `MyStruct` due to unsatisfied trait bounds

View File

@ -2,10 +2,7 @@ error[E0599]: the method `get` exists for struct `Victim<'_, Self>`, but its tra
--> $DIR/impl-derived-implicit-sized-bound-2.rs:28:19
|
LL | struct Victim<'a, T: Perpetrator + ?Sized> {
| ------------------------------------------
| |
| method `get` not found for this struct
| doesn't satisfy `Victim<'_, Self>: VictimTrait`
| ------------------------------------------ method `get` not found for this struct because it doesn't satisfy `Victim<'_, Self>: VictimTrait`
...
LL | self.getter().get();
| ^^^ method cannot be called on `Victim<'_, Self>` due to unsatisfied trait bounds

View File

@ -2,10 +2,7 @@ error[E0599]: the method `get` exists for struct `Victim<'_, Self>`, but its tra
--> $DIR/impl-derived-implicit-sized-bound.rs:31:19
|
LL | struct Victim<'a, T: Perpetrator + ?Sized>
| ------------------------------------------
| |
| method `get` not found for this struct
| doesn't satisfy `Victim<'_, Self>: VictimTrait`
| ------------------------------------------ method `get` not found for this struct because it doesn't satisfy `Victim<'_, Self>: VictimTrait`
...
LL | self.getter().get();
| ^^^ method cannot be called on `Victim<'_, Self>` due to unsatisfied trait bounds

View File

@ -2,10 +2,7 @@ error[E0599]: the function or associated item `partial_cmp` exists for struct `A
--> $DIR/derive-sugg-arg-arity.rs:5:23
|
LL | pub struct A;
| ------------
| |
| function or associated item `partial_cmp` not found for this struct
| doesn't satisfy `A: Iterator` or `A: PartialOrd<_>`
| ------------ function or associated item `partial_cmp` not found for this struct because it doesn't satisfy `A: Iterator` or `A: PartialOrd<_>`
...
LL | _ => match A::partial_cmp() {},
| ^^^^^^^^^^^ function or associated item cannot be called on `A` due to unsatisfied trait bounds

View File

@ -17,10 +17,7 @@ error[E0599]: the method `clone` exists for union `U5<CloneNoCopy>`, but its tra
--> $DIR/union-derive-clone.rs:35:15
|
LL | union U5<T> {
| -----------
| |
| method `clone` not found for this union
| doesn't satisfy `U5<CloneNoCopy>: Clone`
| ----------- method `clone` not found for this union because it doesn't satisfy `U5<CloneNoCopy>: Clone`
...
LL | struct CloneNoCopy;
| ------------------ doesn't satisfy `CloneNoCopy: Copy`