Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4449,11 +4449,27 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
format!("required because it appears within the type `{ty_str}`")
};
match *ty.kind() {
ty::Adt(def, _) => {
ty::Adt(def, args) => {
let msg = msg();
match tcx.opt_item_ident(def.did()) {
Some(ident) => {
err.span_note(ident.span, msg);
let mut spans = MultiSpan::from(ident.span);
if def.did().is_local()
&& let Some(pred) = predicate.as_trait_clause()
{
let field_ty = self.deeply_resolve_ignoring_regions(
pred.skip_binder().self_ty(),
);
for field in def.all_fields() {
if field.ty(tcx, args).skip_norm_wip() == field_ty {
spans.push_span_label(
tcx.def_span(field.did),
"required by this field",
);
}
}
}
err.span_note(spans, msg);
}
None => {
err.note(msg);
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/associated-consts/issue-58022.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ note: required because it appears within the type `Bar<[u8]>`
--> $DIR/issue-58022.rs:8:12
|
LL | pub struct Bar<T: ?Sized>(T);
| ^^^
| ^^^ - required by this field
= note: the return type of a function must have a statically known size

error[E0790]: cannot refer to the associated constant on trait without specifying the corresponding `impl` type
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/async-await/issue-70935-complex-spans.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ note: required because it appears within the type `NotSync`
--> $DIR/issue-70935-complex-spans.rs:9:8
|
LL | struct NotSync(PhantomData<*mut ()>);
| ^^^^^^^
| ^^^^^^^ -------------------- required by this field
= note: required for `&NotSync` to implement `Send`
note: required because it's used within this closure
--> $DIR/issue-70935-complex-spans.rs:18:13
Expand Down
3 changes: 3 additions & 0 deletions tests/ui/async-await/issue-72590-type-error-sized.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ note: required because it appears within the type `Foo`
|
LL | struct Foo {
| ^^^
LL | foo: Nonexistent,
LL | other: str
| ---------- required by this field
= help: unsized fn params are gated as an unstable feature
help: function arguments must have a statically known size, borrowed types always have a known size
|
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/async-await/pin-needed-to-poll-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ note: required because it appears within the type `Sleep`
--> $DIR/pin-needed-to-poll-2.rs:8:8
|
LL | struct Sleep(std::marker::PhantomPinned);
| ^^^^^
| ^^^^^ -------------------------- required by this field
note: required by a bound in `Pin::<Ptr>::new`
--> $SRC_DIR/core/src/pin.rs:LL:COL

Expand Down
6 changes: 5 additions & 1 deletion tests/ui/auto-traits/auto-trait-phantom-data-bounds.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ note: required because it appears within the type `Guard<'_, T>`
|
LL | struct Guard<'a, T: 'a> {
| ^^^^^
LL | _marker: PhantomData<&'a T>,
| --------------------------- required by this field
note: required by a bound in `is_zen`
--> $DIR/auto-trait-phantom-data-bounds.rs:18:14
|
Expand Down Expand Up @@ -48,11 +50,13 @@ note: required because it appears within the type `Guard<'_, T>`
|
LL | struct Guard<'a, T: 'a> {
| ^^^^^
LL | _marker: PhantomData<&'a T>,
| --------------------------- required by this field
note: required because it appears within the type `Nested<Guard<'_, T>>`
--> $DIR/auto-trait-phantom-data-bounds.rs:16:8
|
LL | struct Nested<T>(T);
| ^^^^^^
| ^^^^^^ - required by this field
note: required by a bound in `is_zen`
--> $DIR/auto-trait-phantom-data-bounds.rs:18:14
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ note: required because it appears within the type `X<T>`
--> $DIR/builtin-superkinds-in-metadata.rs:9:8
|
LL | struct X<T>(T);
| ^
| ^ - required by this field
note: required by a bound in `RequiresRequiresShareAndSend`
--> $DIR/auxiliary/trait_superkinds_in_metadata.rs:7:58
|
Expand Down
1 change: 1 addition & 0 deletions tests/ui/coherence/deep-bad-copy-reason.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub struct ListS<T> {
len: usize,
data: [T; 0],
opaque: OpaqueListContents,
//~^ NOTE required by this field
}

pub struct Interned<'a, T>(&'a T);
Expand Down
11 changes: 7 additions & 4 deletions tests/ui/coherence/deep-bad-copy-reason.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0204]: the trait `Copy` cannot be implemented for this type
--> $DIR/deep-bad-copy-reason.rs:38:24
--> $DIR/deep-bad-copy-reason.rs:39:24
|
LL | pub struct List<'tcx, T>(Interned<'tcx, ListS<T>>);
| ------------------------ this field does not implement `Copy`
Expand All @@ -8,13 +8,13 @@ LL | impl<'tcx, T> Copy for List<'tcx, T> {}
| ^^^^^^^^^^^^^
|
note: the `Copy` impl for `Interned<'tcx, ListS<T>>` requires that `OpaqueListContents: Sized`
--> $DIR/deep-bad-copy-reason.rs:26:26
--> $DIR/deep-bad-copy-reason.rs:27:26
|
LL | pub struct List<'tcx, T>(Interned<'tcx, ListS<T>>);
| ^^^^^^^^^^^^^^^^^^^^^^^^

error[E0277]: the size for values of type `OpaqueListContents` cannot be known at compilation time
--> $DIR/deep-bad-copy-reason.rs:26:26
--> $DIR/deep-bad-copy-reason.rs:27:26
|
LL | pub struct List<'tcx, T>(Interned<'tcx, ListS<T>>);
| ^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
Expand All @@ -25,8 +25,11 @@ note: required because it appears within the type `ListS<T>`
|
LL | pub struct ListS<T> {
| ^^^^^
...
LL | opaque: OpaqueListContents,
| -------------------------- required by this field
note: required by an implicit `Sized` bound in `Interned`
--> $DIR/deep-bad-copy-reason.rs:14:25
--> $DIR/deep-bad-copy-reason.rs:15:25
|
LL | pub struct Interned<'a, T>(&'a T);
| ^ required by the implicit `Sized` requirement on this type parameter in `Interned`
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/deref/pin-impl-deref.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ note: required because it appears within the type `MyPinType`
--> $DIR/pin-impl-deref.rs:15:8
|
LL | struct MyPinType(core::marker::PhantomPinned);
| ^^^^^^^^^
| ^^^^^^^^^ --------------------------- required by this field
= note: required for `Pin<&MyPinType>` to implement `DerefMut`
note: required by a bound in `impl_deref_mut`
--> $DIR/pin-impl-deref.rs:22:27
Expand All @@ -66,7 +66,7 @@ note: required because it appears within the type `MyPinType`
--> $DIR/pin-impl-deref.rs:15:8
|
LL | struct MyPinType(core::marker::PhantomPinned);
| ^^^^^^^^^
| ^^^^^^^^^ --------------------------- required by this field
= note: required for `Pin<&mut MyPinType>` to implement `DerefMut`
note: required by a bound in `impl_deref_mut`
--> $DIR/pin-impl-deref.rs:22:27
Expand Down
27 changes: 27 additions & 0 deletions tests/ui/did_you_mean/recursion_limit.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,73 @@ LL | is_send::<A>();
note: required because it appears within the type `I`
--> $DIR/recursion_limit.rs:23:9
|
LL | enum $id { $id($t) }
| -- required by this field
...
LL | link! { I, J }
| ^
note: required because it appears within the type `H`
--> $DIR/recursion_limit.rs:22:9
|
LL | enum $id { $id($t) }
| -- required by this field
...
LL | link! { H, I }
| ^
note: required because it appears within the type `G`
--> $DIR/recursion_limit.rs:21:9
|
LL | enum $id { $id($t) }
| -- required by this field
...
LL | link! { G, H }
| ^
note: required because it appears within the type `F`
--> $DIR/recursion_limit.rs:20:9
|
LL | enum $id { $id($t) }
| -- required by this field
...
LL | link! { F, G }
| ^
note: required because it appears within the type `E`
--> $DIR/recursion_limit.rs:19:9
|
LL | enum $id { $id($t) }
| -- required by this field
...
LL | link! { E, F }
| ^
note: required because it appears within the type `D`
--> $DIR/recursion_limit.rs:18:9
|
LL | enum $id { $id($t) }
| -- required by this field
...
LL | link! { D, E }
| ^
note: required because it appears within the type `C`
--> $DIR/recursion_limit.rs:17:9
|
LL | enum $id { $id($t) }
| -- required by this field
...
LL | link! { C, D }
| ^
note: required because it appears within the type `B`
--> $DIR/recursion_limit.rs:16:9
|
LL | enum $id { $id($t) }
| -- required by this field
...
LL | link! { B, C }
| ^
note: required because it appears within the type `A`
--> $DIR/recursion_limit.rs:15:9
|
LL | enum $id { $id($t) }
| -- required by this field
...
LL | link! { A, B }
| ^
note: required by a bound in `is_send`
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/dst/dst-bad-deep-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ note: required because it appears within the type `Fat<[isize]>`
--> $DIR/dst-bad-deep-2.rs:6:8
|
LL | struct Fat<T: ?Sized>(T);
| ^^^
| ^^^ - required by this field
= note: all function arguments must have a statically known size
= help: unsized fn params are gated as an unstable feature

Expand Down
2 changes: 2 additions & 0 deletions tests/ui/dst/dst-bad-deep.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ note: required because it appears within the type `Fat<[isize]>`
|
LL | struct Fat<T: ?Sized> {
| ^^^
LL | ptr: T
| ------ required by this field
= note: structs must have a statically known size to be initialized

error: aborting due to 1 previous error
Expand Down
6 changes: 6 additions & 0 deletions tests/ui/error-codes/E0277-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,22 @@ note: required because it appears within the type `Baz`
|
LL | struct Baz {
| ^^^
LL | x: *const u8
| ------------ required by this field
note: required because it appears within the type `Bar`
--> $DIR/E0277-2.rs:5:8
|
LL | struct Bar {
| ^^^
LL | baz: Baz
| -------- required by this field
note: required because it appears within the type `Foo`
--> $DIR/E0277-2.rs:1:8
|
LL | struct Foo {
| ^^^
LL | bar: Bar
| -------- required by this field
note: required by a bound in `is_send`
--> $DIR/E0277-2.rs:13:15
|
Expand Down
9 changes: 9 additions & 0 deletions tests/ui/extern/extern-types-unsized.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ note: required because it appears within the type `Foo`
|
LL | struct Foo {
| ^^^
LL | x: u8,
LL | tail: A,
| ------- required by this field
note: required by an implicit `Sized` bound in `assert_sized`
--> $DIR/extern-types-unsized.rs:19:17
|
Expand All @@ -49,6 +52,9 @@ note: required because it appears within the type `Bar<A>`
|
LL | struct Bar<T: ?Sized> {
| ^^^
LL | x: u8,
LL | tail: T,
| ------- required by this field
note: required by an implicit `Sized` bound in `assert_sized`
--> $DIR/extern-types-unsized.rs:19:17
|
Expand Down Expand Up @@ -84,6 +90,9 @@ note: required because it appears within the type `Bar<A>`
|
LL | struct Bar<T: ?Sized> {
| ^^^
LL | x: u8,
LL | tail: T,
| ------- required by this field
note: required by an implicit `Sized` bound in `assert_sized`
--> $DIR/extern-types-unsized.rs:19:17
|
Expand Down
3 changes: 3 additions & 0 deletions tests/ui/feature-gates/feature-gate-offset-of-slice.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ note: required because it appears within the type `S`
|
LL | struct S {
| ^
...
LL | c: [i32],
| -------- required by this field

error[E0277]: the size for values of type `[i32]` cannot be known at compilation time
--> $DIR/feature-gate-offset-of-slice.rs:25:5
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/feature-gates/feature-gate-trivial_bounds.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ note: required because it appears within the type `Dst<(dyn A + 'static)>`
|
LL | struct Dst<X: ?Sized> {
| ^^^
LL | x: X,
| ---- required by this field
help: add `#![feature(trivial_bounds)]` to the crate attributes to enable
|
LL + #![feature(trivial_bounds)]
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/mut/mutable-enum-indirect.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ note: required because it appears within the type `Foo`
--> $DIR/mutable-enum-indirect.rs:11:6
|
LL | enum Foo { A(NoSync) }
| ^^^
| ^^^ ------ required by this field
= note: required because it appears within the type `&Foo`
note: required by a bound in `bar`
--> $DIR/mutable-enum-indirect.rs:13:11
Expand Down
3 changes: 3 additions & 0 deletions tests/ui/offset-of/offset-of-dst-field.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ note: required because it appears within the type `Alpha`
|
LL | struct Alpha {
| ^^^^^
...
LL | z: [u8],
| ------- required by this field

error[E0277]: the size for values of type `T` cannot be known at compilation time
--> $DIR/offset-of-dst-field.rs:51:5
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/pin-ergonomics/pin-pattern.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ note: required because it appears within the type `Foo<T>`
--> $DIR/pin-pattern.rs:11:8
|
LL | struct Foo<T>(T);
| ^^^
| ^^^ - required by this field
help: consider restricting type parameter `T` with trait `Unpin`
|
LL | fn tuple_ref_pin_mut_pat_and_mut_of_tuple_pin_mut_ty<'a, T: std::marker::Unpin>(
Expand Down
7 changes: 7 additions & 0 deletions tests/ui/recursion/recursive-requirements.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ note: required because it appears within the type `Foo`
|
LL | pub struct Foo {
| ^^^
LL | bar: *const Bar,
| --------------- required by this field
note: required by a bound in `AssertSync`
--> $DIR/recursive-requirements.rs:3:22
|
Expand All @@ -28,13 +30,18 @@ note: required because it appears within the type `Bar`
|
LL | pub struct Bar {
| ^^^
LL | foo: *const Foo,
| --------------- required by this field
note: required because it appears within the type `PhantomData<Bar>`
--> $SRC_DIR/core/src/marker.rs:LL:COL
note: required because it appears within the type `Foo`
--> $DIR/recursive-requirements.rs:5:12
|
LL | pub struct Foo {
| ^^^
LL | bar: *const Bar,
LL | phantom: PhantomData<Bar>,
| ------------------------- required by this field
note: required by a bound in `AssertSync`
--> $DIR/recursive-requirements.rs:3:22
|
Expand Down
Loading
Loading