Skip to content

Commit 317adda

Browse files
committed
Tweak output
1 parent fb5d215 commit 317adda

8 files changed

+68
-107
lines changed

compiler/rustc_hir_typeck/src/method/suggest.rs

+28-24
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
587587

588588
// Find all the requirements that come from a local `impl` block.
589589
let mut skip_list: FxHashSet<_> = Default::default();
590-
let mut spanned_predicates: FxHashMap<MultiSpan, _> = Default::default();
590+
let mut spanned_predicates = FxHashMap::default();
591591
for (p, parent_p, impl_def_id, cause) in unsatisfied_predicates
592592
.iter()
593593
.filter_map(|(p, parent, c)| c.as_ref().map(|c| (p, parent, c)))
@@ -615,13 +615,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
615615
) =>
616616
{
617617
let span = self_ty.span.ctxt().outer_expn_data().call_site;
618-
let mut spans: MultiSpan = span.into();
619-
spans.push_span_label(
618+
let entry = spanned_predicates.entry(span);
619+
let entry = entry.or_insert_with(|| {
620+
(FxHashSet::default(), FxHashSet::default(), Vec::new())
621+
});
622+
entry.0.insert(span);
623+
entry.1.insert((
620624
span,
621625
"unsatisfied trait bound introduced in this `derive` macro",
622-
);
623-
let entry = spanned_predicates.entry(spans);
624-
entry.or_insert_with(|| Vec::new()).push(p);
626+
));
627+
entry.2.push(p);
628+
skip_list.insert(p);
625629
}
626630

627631
// Unmet obligation coming from an `impl`.
@@ -659,28 +663,24 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
659663
let _ = format_pred(*pred);
660664
}
661665
skip_list.insert(p);
662-
let mut spans = if cause.span != *item_span {
663-
let mut spans: MultiSpan = cause.span.into();
664-
spans.push_span_label(
665-
cause.span,
666-
"unsatisfied trait bound introduced here",
667-
);
668-
spans
666+
let entry = spanned_predicates.entry(self_ty.span);
667+
let entry = entry.or_insert_with(|| {
668+
(FxHashSet::default(), FxHashSet::default(), Vec::new())
669+
});
670+
entry.2.push(p);
671+
if cause.span != *item_span {
672+
entry.0.insert(cause.span);
673+
entry.1.insert((cause.span, "unsatisfied trait bound introduced here"));
669674
} else {
670-
let mut spans = Vec::with_capacity(2);
671675
if let Some(trait_ref) = of_trait {
672-
spans.push(trait_ref.path.span);
676+
entry.0.insert(trait_ref.path.span);
673677
}
674-
spans.push(self_ty.span);
675-
spans.into()
678+
entry.0.insert(self_ty.span);
676679
};
677680
if let Some(trait_ref) = of_trait {
678-
spans.push_span_label(trait_ref.path.span, "");
681+
entry.1.insert((trait_ref.path.span, ""));
679682
}
680-
spans.push_span_label(self_ty.span, "");
681-
682-
let entry = spanned_predicates.entry(spans);
683-
entry.or_insert_with(|| Vec::new()).push(p);
683+
entry.1.insert((self_ty.span, ""));
684684
}
685685
Some(Node::Item(hir::Item {
686686
kind: hir::ItemKind::Trait(rustc_ast::ast::IsAuto::Yes, ..),
@@ -697,8 +697,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
697697
}
698698
}
699699
let mut spanned_predicates: Vec<_> = spanned_predicates.into_iter().collect();
700-
spanned_predicates.sort_by_key(|(span, _)| span.primary_span());
701-
for (span, predicates) in spanned_predicates {
700+
spanned_predicates.sort_by_key(|(span, _)| *span);
701+
for (_, (primary_spans, span_labels, predicates)) in spanned_predicates {
702702
let mut preds: Vec<_> = predicates
703703
.iter()
704704
.filter_map(|pred| format_pred(**pred))
@@ -711,6 +711,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
711711
} else {
712712
format!("the following trait bounds were not satisfied:\n{}", preds.join("\n"),)
713713
};
714+
let mut span: MultiSpan = primary_spans.into_iter().collect::<Vec<_>>().into();
715+
for (sp, label) in span_labels {
716+
span.push_span_label(sp, label);
717+
}
714718
err.span_note(span, &msg);
715719
unsatisfied_bounds = true;
716720
}

tests/ui/derives/derive-assoc-type-not-impl.stderr

-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ note: trait bound `NotClone: Clone` was not satisfied
1818
|
1919
LL | #[derive(Clone)]
2020
| ^^^^^ unsatisfied trait bound introduced in this `derive` macro
21-
= note: the following trait bounds were not satisfied:
22-
`NotClone: Clone`
23-
which is required by `Bar<NotClone>: Clone`
2421
= help: items from traits can only be used if the trait is implemented and in scope
2522
= note: the following trait defines an item `clone`, perhaps you need to implement it:
2623
candidate #1: `Clone`

tests/ui/derives/issue-91550.stderr

+6-10
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,16 @@ LL | struct Object<T>(T);
8181
LL | foo.use_ord_and_partial_ord();
8282
| ^^^^^^^^^^^^^^^^^^^^^^^ method cannot be called on `Object<NoDerives>` due to unsatisfied trait bounds
8383
|
84-
note: trait bound `NoDerives: Ord` was not satisfied
84+
note: the following trait bounds were not satisfied:
85+
`NoDerives: Ord`
86+
`NoDerives: PartialOrd`
8587
--> $DIR/issue-91550.rs:21:9
8688
|
8789
LL | impl<T: Ord + PartialOrd> Object<T> {
88-
| ^^^ ---------
89-
| |
90+
| ^^^ ^^^^^^^^^^ ---------
91+
| | |
92+
| | unsatisfied trait bound introduced here
9093
| unsatisfied trait bound introduced here
91-
note: trait bound `NoDerives: PartialOrd` was not satisfied
92-
--> $DIR/issue-91550.rs:21:15
93-
|
94-
LL | impl<T: Ord + PartialOrd> Object<T> {
95-
| ^^^^^^^^^^ ---------
96-
| |
97-
| unsatisfied trait bound introduced here
9894
help: consider annotating `NoDerives` with `#[derive(Eq, Ord, PartialEq, PartialOrd)]`
9995
|
10096
LL | #[derive(Eq, Ord, PartialEq, PartialOrd)]

tests/ui/methods/method-not-found-generic-arg-elision.stderr

+6-10
Original file line numberDiff line numberDiff line change
@@ -88,20 +88,16 @@ LL | struct Struct<T> {
8888
LL | s.method();
8989
| ^^^^^^ method cannot be called on `Struct<f64>` due to unsatisfied trait bounds
9090
|
91-
note: trait bound `f64: Eq` was not satisfied
91+
note: the following trait bounds were not satisfied:
92+
`f64: Eq`
93+
`f64: Ord`
9294
--> $DIR/method-not-found-generic-arg-elision.rs:74:36
9395
|
9496
LL | impl<T: Clone + Copy + PartialEq + Eq + PartialOrd + Ord> Struct<T> {
95-
| ^^ ---------
96-
| |
97+
| ^^ ^^^ ---------
98+
| | |
99+
| | unsatisfied trait bound introduced here
97100
| unsatisfied trait bound introduced here
98-
note: trait bound `f64: Ord` was not satisfied
99-
--> $DIR/method-not-found-generic-arg-elision.rs:74:54
100-
|
101-
LL | impl<T: Clone + Copy + PartialEq + Eq + PartialOrd + Ord> Struct<T> {
102-
| ^^^ ---------
103-
| |
104-
| unsatisfied trait bound introduced here
105101

106102
error: aborting due to 9 previous errors
107103

tests/ui/missing-trait-bounds/missing-trait-bounds-for-method-call.stderr

+6-10
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,16 @@ LL | struct Foo<T> {
77
LL | self.foo();
88
| ^^^ method cannot be called on `&Foo<T>` due to unsatisfied trait bounds
99
|
10-
note: trait bound `T: Default` was not satisfied
10+
note: the following trait bounds were not satisfied:
11+
`T: Bar`
12+
`T: Default`
1113
--> $DIR/missing-trait-bounds-for-method-call.rs:10:9
1214
|
1315
LL | impl<T: Default + Bar> Bar for Foo<T> {}
14-
| ^^^^^^^ --- ------
15-
| |
16+
| ^^^^^^^ ^^^ --- ------
17+
| | |
18+
| | unsatisfied trait bound introduced here
1619
| unsatisfied trait bound introduced here
17-
note: trait bound `T: Bar` was not satisfied
18-
--> $DIR/missing-trait-bounds-for-method-call.rs:10:19
19-
|
20-
LL | impl<T: Default + Bar> Bar for Foo<T> {}
21-
| ^^^ --- ------
22-
| |
23-
| unsatisfied trait bound introduced here
2420
help: consider restricting the type parameters to satisfy the trait bounds
2521
|
2622
LL | struct Foo<T> where T: Bar, T: Default {

tests/ui/suggestions/derive-trait-for-method-call.stderr

+22-44
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,18 @@ LL | struct Foo<X, Y> (X, Y);
1616
LL | let y = x.test();
1717
| ^^^^ method cannot be called on `Foo<Enum, CloneEnum>` due to unsatisfied trait bounds
1818
|
19-
note: trait bound `Enum: Clone` was not satisfied
19+
note: the following trait bounds were not satisfied:
20+
`CloneEnum: Default`
21+
`Enum: Clone`
22+
`Enum: Default`
2023
--> $DIR/derive-trait-for-method-call.rs:20:9
2124
|
2225
LL | impl<X: Clone + Default + , Y: Clone + Default> Foo<X, Y> {
23-
| ^^^^^ ---------
24-
| |
26+
| ^^^^^ ^^^^^^^ ^^^^^^^ ---------
27+
| | | |
28+
| | | unsatisfied trait bound introduced here
29+
| | unsatisfied trait bound introduced here
2530
| unsatisfied trait bound introduced here
26-
note: trait bound `Enum: Default` was not satisfied
27-
--> $DIR/derive-trait-for-method-call.rs:20:17
28-
|
29-
LL | impl<X: Clone + Default + , Y: Clone + Default> Foo<X, Y> {
30-
| ^^^^^^^ ---------
31-
| |
32-
| unsatisfied trait bound introduced here
33-
note: trait bound `CloneEnum: Default` was not satisfied
34-
--> $DIR/derive-trait-for-method-call.rs:20:40
35-
|
36-
LL | impl<X: Clone + Default + , Y: Clone + Default> Foo<X, Y> {
37-
| ^^^^^^^ ---------
38-
| |
39-
| unsatisfied trait bound introduced here
4031
note: the trait `Default` must be implemented
4132
--> $SRC_DIR/core/src/default.rs:LL:COL
4233
help: consider annotating `Enum` with `#[derive(Clone)]`
@@ -62,27 +53,18 @@ LL | struct Foo<X, Y> (X, Y);
6253
LL | let y = x.test();
6354
| ^^^^ method cannot be called on `Foo<Struct, CloneStruct>` due to unsatisfied trait bounds
6455
|
65-
note: trait bound `Struct: Clone` was not satisfied
56+
note: the following trait bounds were not satisfied:
57+
`CloneStruct: Default`
58+
`Struct: Clone`
59+
`Struct: Default`
6660
--> $DIR/derive-trait-for-method-call.rs:20:9
6761
|
6862
LL | impl<X: Clone + Default + , Y: Clone + Default> Foo<X, Y> {
69-
| ^^^^^ ---------
70-
| |
63+
| ^^^^^ ^^^^^^^ ^^^^^^^ ---------
64+
| | | |
65+
| | | unsatisfied trait bound introduced here
66+
| | unsatisfied trait bound introduced here
7167
| unsatisfied trait bound introduced here
72-
note: trait bound `Struct: Default` was not satisfied
73-
--> $DIR/derive-trait-for-method-call.rs:20:17
74-
|
75-
LL | impl<X: Clone + Default + , Y: Clone + Default> Foo<X, Y> {
76-
| ^^^^^^^ ---------
77-
| |
78-
| unsatisfied trait bound introduced here
79-
note: trait bound `CloneStruct: Default` was not satisfied
80-
--> $DIR/derive-trait-for-method-call.rs:20:40
81-
|
82-
LL | impl<X: Clone + Default + , Y: Clone + Default> Foo<X, Y> {
83-
| ^^^^^^^ ---------
84-
| |
85-
| unsatisfied trait bound introduced here
8668
help: consider annotating `CloneStruct` with `#[derive(Default)]`
8769
|
8870
LL | #[derive(Default)]
@@ -107,20 +89,16 @@ LL | let y = x.test();
10789
|
10890
= note: doesn't satisfy `Vec<Enum>: Clone`
10991
|
110-
note: trait bound `Vec<Enum>: Clone` was not satisfied
92+
note: the following trait bounds were not satisfied:
93+
`Instant: Default`
94+
`Vec<Enum>: Clone`
11195
--> $DIR/derive-trait-for-method-call.rs:20:9
11296
|
11397
LL | impl<X: Clone + Default + , Y: Clone + Default> Foo<X, Y> {
114-
| ^^^^^ ---------
115-
| |
98+
| ^^^^^ ^^^^^^^ ---------
99+
| | |
100+
| | unsatisfied trait bound introduced here
116101
| unsatisfied trait bound introduced here
117-
note: trait bound `Instant: Default` was not satisfied
118-
--> $DIR/derive-trait-for-method-call.rs:20:40
119-
|
120-
LL | impl<X: Clone + Default + , Y: Clone + Default> Foo<X, Y> {
121-
| ^^^^^^^ ---------
122-
| |
123-
| unsatisfied trait bound introduced here
124102

125103
error: aborting due to 3 previous errors
126104

tests/ui/union/union-derive-clone.mirunsafeck.stderr

-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ note: trait bound `CloneNoCopy: Copy` was not satisfied
3232
|
3333
LL | #[derive(Clone, Copy)]
3434
| ^^^^^ unsatisfied trait bound introduced in this `derive` macro
35-
= note: the following trait bounds were not satisfied:
36-
`CloneNoCopy: Copy`
37-
which is required by `U5<CloneNoCopy>: Clone`
3835
help: consider annotating `CloneNoCopy` with `#[derive(Clone, Copy)]`
3936
|
4037
LL | #[derive(Clone, Copy)]

tests/ui/union/union-derive-clone.thirunsafeck.stderr

-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ note: trait bound `CloneNoCopy: Copy` was not satisfied
3232
|
3333
LL | #[derive(Clone, Copy)]
3434
| ^^^^^ unsatisfied trait bound introduced in this `derive` macro
35-
= note: the following trait bounds were not satisfied:
36-
`CloneNoCopy: Copy`
37-
which is required by `U5<CloneNoCopy>: Clone`
3835
help: consider annotating `CloneNoCopy` with `#[derive(Clone, Copy)]`
3936
|
4037
LL | #[derive(Clone, Copy)]

0 commit comments

Comments
 (0)