Skip to content

Commit 569a8d2

Browse files
committed
Use span context to point at item of field that introduced bound requirement
``` note: required because it appears within the type `ListS<T>` --> $DIR/deep-bad-copy-reason.rs:10:5 | LL | pub struct ListS<T> { ... LL | opaque: OpaqueListContents, | ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this field ```
1 parent f7575a9 commit 569a8d2

46 files changed

Lines changed: 201 additions & 241 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4456,7 +4456,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
44564456
let msg = msg();
44574457
match tcx.opt_item_ident(def.did()) {
44584458
Some(ident) => {
4459-
let mut spans = MultiSpan::from(ident.span);
4459+
let mut spans = MultiSpan::new();
44604460
if def.did().is_local()
44614461
&& let Some(pred) = predicate.as_trait_clause()
44624462
{
@@ -4465,13 +4465,18 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
44654465
);
44664466
for field in def.all_fields() {
44674467
if field.ty(tcx, args).skip_norm_wip() == field_ty {
4468-
spans.push_span_label(
4469-
tcx.def_span(field.did),
4470-
"required by this field",
4471-
);
4468+
let sp = tcx.def_span(field.did);
4469+
spans.push_primary_span(sp);
4470+
spans.push_span_label(sp, "required by this field");
44724471
}
44734472
}
44744473
}
4474+
if spans.has_primary_spans() {
4475+
spans.push_span_context(ident.span);
4476+
} else {
4477+
spans.push_primary_span(ident.span);
4478+
spans.push_span_label(ident.span, "");
4479+
}
44754480
err.span_note(spans, msg);
44764481
}
44774482
None => {

‎tests/ui/associated-consts/issue-58022.stderr‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ LL | fn new(slice: &[u8; Self::SIZE]) -> Self {
66
|
77
= help: within `Bar<[u8]>`, the trait `Sized` is not implemented for `[u8]`
88
note: required because it appears within the type `Bar<[u8]>`
9-
--> $DIR/issue-58022.rs:8:12
9+
--> $DIR/issue-58022.rs:8:27
1010
|
1111
LL | pub struct Bar<T: ?Sized>(T);
12-
| ^^^ - required by this field
12+
| ^ required by this field
1313
= note: the return type of a function must have a statically known size
1414

1515
error[E0790]: cannot refer to the associated constant on trait without specifying the corresponding `impl` type

‎tests/ui/async-await/issue-70935-complex-spans.stderr‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ LL | fn foo(x: NotSync) -> impl Future + Send {
88
note: required because it appears within the type `PhantomData<*mut ()>`
99
--> $SRC_DIR/core/src/marker.rs:LL:COL
1010
note: required because it appears within the type `NotSync`
11-
--> $DIR/issue-70935-complex-spans.rs:9:8
11+
--> $DIR/issue-70935-complex-spans.rs:9:16
1212
|
1313
LL | struct NotSync(PhantomData<*mut ()>);
14-
| ^^^^^^^ -------------------- required by this field
14+
| ^^^^^^^^^^^^^^^^^^^^ required by this field
1515
= note: required for `&NotSync` to implement `Send`
1616
note: required because it's used within this closure
1717
--> $DIR/issue-70935-complex-spans.rs:18:13

‎tests/ui/async-await/issue-72590-type-error-sized.stderr‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@ LL | async fn frob(self) {}
1818
|
1919
= help: within `Foo`, the trait `Sized` is not implemented for `str`
2020
note: required because it appears within the type `Foo`
21-
--> $DIR/issue-72590-type-error-sized.rs:5:8
21+
--> $DIR/issue-72590-type-error-sized.rs:7:5
2222
|
2323
LL | struct Foo {
24-
| ^^^
2524
LL | foo: Nonexistent,
2625
LL | other: str
27-
| ---------- required by this field
26+
| ^^^^^^^^^^ required by this field
2827
= help: unsized fn params are gated as an unstable feature
2928
help: function arguments must have a statically known size, borrowed types always have a known size
3029
|

‎tests/ui/async-await/pin-needed-to-poll-2.stderr‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ LL | Pin::new(&mut self.sleep).poll(cx)
99
= note: consider using the `pin!` macro
1010
consider using `Box::pin` if you need to access the pinned value outside of the current scope
1111
note: required because it appears within the type `Sleep`
12-
--> $DIR/pin-needed-to-poll-2.rs:8:8
12+
--> $DIR/pin-needed-to-poll-2.rs:8:14
1313
|
1414
LL | struct Sleep(std::marker::PhantomPinned);
15-
| ^^^^^ -------------------------- required by this field
15+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this field
1616
note: required by a bound in `Pin::<Ptr>::new`
1717
--> $SRC_DIR/core/src/pin.rs:LL:COL
1818

‎tests/ui/auto-traits/auto-trait-phantom-data-bounds.stderr‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ LL | unsafe impl<'a, T: 'a> Zen for &'a T where T: Sync {}
1414
note: required because it appears within the type `PhantomData<&T>`
1515
--> $SRC_DIR/core/src/marker.rs:LL:COL
1616
note: required because it appears within the type `Guard<'_, T>`
17-
--> $DIR/auto-trait-phantom-data-bounds.rs:12:8
17+
--> $DIR/auto-trait-phantom-data-bounds.rs:13:5
1818
|
1919
LL | struct Guard<'a, T: 'a> {
20-
| ^^^^^
2120
LL | _marker: PhantomData<&'a T>,
22-
| --------------------------- required by this field
21+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this field
2322
note: required by a bound in `is_zen`
2423
--> $DIR/auto-trait-phantom-data-bounds.rs:18:14
2524
|
@@ -46,17 +45,16 @@ LL | unsafe impl<'a, T: 'a> Zen for &'a T where T: Sync {}
4645
note: required because it appears within the type `PhantomData<&T>`
4746
--> $SRC_DIR/core/src/marker.rs:LL:COL
4847
note: required because it appears within the type `Guard<'_, T>`
49-
--> $DIR/auto-trait-phantom-data-bounds.rs:12:8
48+
--> $DIR/auto-trait-phantom-data-bounds.rs:13:5
5049
|
5150
LL | struct Guard<'a, T: 'a> {
52-
| ^^^^^
5351
LL | _marker: PhantomData<&'a T>,
54-
| --------------------------- required by this field
52+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this field
5553
note: required because it appears within the type `Nested<Guard<'_, T>>`
56-
--> $DIR/auto-trait-phantom-data-bounds.rs:16:8
54+
--> $DIR/auto-trait-phantom-data-bounds.rs:16:18
5755
|
5856
LL | struct Nested<T>(T);
59-
| ^^^^^^ - required by this field
57+
| ^ required by this field
6058
note: required by a bound in `is_zen`
6159
--> $DIR/auto-trait-phantom-data-bounds.rs:18:14
6260
|

‎tests/ui/builtin-superkinds/builtin-superkinds-in-metadata.stderr‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ LL | impl <T:Sync+'static> RequiresRequiresShareAndSend for X<T> { }
55
| ^^^^ `T` cannot be sent between threads safely
66
|
77
note: required because it appears within the type `X<T>`
8-
--> $DIR/builtin-superkinds-in-metadata.rs:9:8
8+
--> $DIR/builtin-superkinds-in-metadata.rs:9:13
99
|
1010
LL | struct X<T>(T);
11-
| ^ - required by this field
11+
| ^ required by this field
1212
note: required by a bound in `RequiresRequiresShareAndSend`
1313
--> $DIR/auxiliary/trait_superkinds_in_metadata.rs:7:58
1414
|

‎tests/ui/coherence/deep-bad-copy-reason.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ extern "Rust" {
55
}
66

77
pub struct ListS<T> {
8-
//~^ NOTE: required because it appears within the type
98
len: usize,
109
data: [T; 0],
1110
opaque: OpaqueListContents,
12-
//~^ NOTE required by this field
11+
//~^ NOTE: required because it appears within the type
12+
//~| NOTE: required by this field
1313
}
1414

1515
pub struct Interned<'a, T>(&'a T);

‎tests/ui/coherence/deep-bad-copy-reason.stderr‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@ LL | pub struct List<'tcx, T>(Interned<'tcx, ListS<T>>);
2121
|
2222
= help: within `ListS<T>`, the trait `Sized` is not implemented for `OpaqueListContents`
2323
note: required because it appears within the type `ListS<T>`
24-
--> $DIR/deep-bad-copy-reason.rs:7:12
24+
--> $DIR/deep-bad-copy-reason.rs:10:5
2525
|
2626
LL | pub struct ListS<T> {
27-
| ^^^^^
2827
...
2928
LL | opaque: OpaqueListContents,
30-
| -------------------------- required by this field
29+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this field
3130
note: required by an implicit `Sized` bound in `Interned`
3231
--> $DIR/deep-bad-copy-reason.rs:15:25
3332
|

‎tests/ui/deref/pin-impl-deref.stderr‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ LL | impl_deref_mut(r_pin)
4141
= note: consider using the `pin!` macro
4242
consider using `Box::pin` if you need to access the pinned value outside of the current scope
4343
note: required because it appears within the type `MyPinType`
44-
--> $DIR/pin-impl-deref.rs:15:8
44+
--> $DIR/pin-impl-deref.rs:15:18
4545
|
4646
LL | struct MyPinType(core::marker::PhantomPinned);
47-
| ^^^^^^^^^ --------------------------- required by this field
47+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this field
4848
= note: required for `Pin<&MyPinType>` to implement `DerefMut`
4949
note: required by a bound in `impl_deref_mut`
5050
--> $DIR/pin-impl-deref.rs:22:27
@@ -63,10 +63,10 @@ LL | impl_deref_mut(r_pin)
6363
= note: consider using the `pin!` macro
6464
consider using `Box::pin` if you need to access the pinned value outside of the current scope
6565
note: required because it appears within the type `MyPinType`
66-
--> $DIR/pin-impl-deref.rs:15:8
66+
--> $DIR/pin-impl-deref.rs:15:18
6767
|
6868
LL | struct MyPinType(core::marker::PhantomPinned);
69-
| ^^^^^^^^^ --------------------------- required by this field
69+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this field
7070
= note: required for `Pin<&mut MyPinType>` to implement `DerefMut`
7171
note: required by a bound in `impl_deref_mut`
7272
--> $DIR/pin-impl-deref.rs:22:27

0 commit comments

Comments
 (0)