From 180aa923c5f2629046e8cd1cb2a7bed7f873536f Mon Sep 17 00:00:00 2001 From: Amirhossein Akhlaghpour Date: Sat, 5 Sep 2026 16:03:17 +0330 Subject: [PATCH 1/3] preserve overflow in builtin Field candidates Signed-off-by: Amirhossein Akhlaghpour --- .../src/solve/trait_goals.rs | 82 ++++++++++--------- .../field-projection-overflow-coherence.rs | 55 +++++++++++++ ...field-projection-overflow-coherence.stderr | 18 ++++ .../not-field-if-unsized.next.stderr | 24 +++++- .../not-field-if-unsized.old.stderr | 8 +- .../not-field-if-unsized.rs | 8 +- .../sized.next.stderr | 61 ++++++++++++-- .../field_representing_types/sized.old.stderr | 12 +-- tests/ui/field_representing_types/sized.rs | 16 ++-- 9 files changed, 210 insertions(+), 74 deletions(-) create mode 100644 tests/ui/field_representing_types/field-projection-overflow-coherence.rs create mode 100644 tests/ui/field_representing_types/field-projection-overflow-coherence.stderr diff --git a/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs b/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs index 19a09e99c7d64..35d51fde8224a 100644 --- a/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs +++ b/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs @@ -903,47 +903,49 @@ where if goal.predicate.polarity != ty::ClausePolarity::Positive { return Err(NoSolution.into()); } - if let ty::Adt(def, args) = goal.predicate.self_ty().kind() - && let Some(FieldInfo { base, ty, .. }) = - def.field_representing_type_info(ecx.cx(), args) - && { - let sized_trait = ecx.cx().require_trait_lang_item(SolverTraitLangItem::Sized); - // FIXME: add better support for builtin impls of traits that check for the bounds - // on the trait definition in std. - - // NOTE: these bounds have to be kept in sync with the definition of the `Field` - // trait in `library/core/src/field.rs` as well as the old trait solver `fn - // assemble_candidates_for_field_trait` in - // `compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs`. - ecx.add_goal( - GoalSource::ImplWhereBound, - Goal { - param_env: goal.param_env, - predicate: TraitRef::new(ecx.cx(), sized_trait, [base]).upcast(ecx.cx()), - }, - )?; - ecx.add_goal( - GoalSource::ImplWhereBound, - Goal { - param_env: goal.param_env, - predicate: TraitRef::new(ecx.cx(), sized_trait, [ty]).upcast(ecx.cx()), - }, - )?; - // FIXME(field_projections): This function does some questionable incomplete stuff by - // returning `Err(NoSolution)` on ambiguity. - ecx.try_evaluate_added_goals()? == Certainty::Yes - } - && match base.kind() { - ty::Adt(def, _) => def.is_struct() && !def.is_packed(), - ty::Tuple(..) => true, - _ => false, - } - { - ecx.probe_builtin_trait_candidate(BuiltinImplSource::Misc) - .enter(|ecx| ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)) - } else { - Err(NoSolution.into()) + + let ty::Adt(def, args) = goal.predicate.self_ty().kind() else { + return Err(NoSolution.into()); + }; + + let Some(FieldInfo { base, ty, .. }) = def.field_representing_type_info(ecx.cx(), args) + else { + return Err(NoSolution.into()); + }; + + match base.kind() { + ty::Adt(def, _) if def.is_struct() && !def.is_packed() => {} + ty::Tuple(..) => {} + _ => return Err(NoSolution.into()), } + + ecx.probe_builtin_trait_candidate(BuiltinImplSource::Misc).enter(|ecx| { + let sized_trait = ecx.cx().require_trait_lang_item(SolverTraitLangItem::Sized); + + // FIXME: add better support for builtin impls of traits that check for the bounds + // on the trait definition in std. + // + // NOTE: these bounds have to be kept in sync with the definition of the `Field` + // trait in `library/core/src/field.rs` as well as the old trait solver `fn + // assemble_candidates_for_field_trait` in + // `compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs`. + ecx.add_goal( + GoalSource::ImplWhereBound, + Goal { + param_env: goal.param_env, + predicate: TraitRef::new(ecx.cx(), sized_trait, [base]).upcast(ecx.cx()), + }, + )?; + ecx.add_goal( + GoalSource::ImplWhereBound, + Goal { + param_env: goal.param_env, + predicate: TraitRef::new(ecx.cx(), sized_trait, [ty]).upcast(ecx.cx()), + }, + )?; + + ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) + }) } } diff --git a/tests/ui/field_representing_types/field-projection-overflow-coherence.rs b/tests/ui/field_representing_types/field-projection-overflow-coherence.rs new file mode 100644 index 0000000000000..ea95e12a6d4bf --- /dev/null +++ b/tests/ui/field_representing_types/field-projection-overflow-coherence.rs @@ -0,0 +1,55 @@ +//@ edition: 2021 +//@ compile-flags: -Znext-solver -Arecursion_depth_exceeding_limit + +#![forbid(unsafe_code)] +#![feature(field_projections)] +#![allow(incomplete_features)] + +use core::field::{Field, field_of}; + +trait Chain { + type A; +} + +impl Chain for () { + type A = u8; +} + +struct Link(T); + +impl Chain for Link { + type A = ::A; +} + +type L4 = Link>>>; +type L16 = L4>>>; +type L64 = L16>>>; +type Deep = L64>>; // 192 links + +struct S { + f: ::A, +} + +trait Tr { + type Out; +} + +impl Tr for S +where + field_of!(S, f): Field, +{ + type Out = u8; +} + +impl Tr for S { //~ ERROR conflicting implementations of trait `Tr` + type Out = [u8; 16]; +} + +fn poly() -> as Tr>::Out { + 0 +} + +fn main() { + let v = poly::(); + println!("{:?}", v); +} diff --git a/tests/ui/field_representing_types/field-projection-overflow-coherence.stderr b/tests/ui/field_representing_types/field-projection-overflow-coherence.stderr new file mode 100644 index 0000000000000..d53819445a083 --- /dev/null +++ b/tests/ui/field_representing_types/field-projection-overflow-coherence.stderr @@ -0,0 +1,18 @@ +error[E0119]: conflicting implementations of trait `Tr` for type `S>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>` + --> $DIR/field-projection-overflow-coherence.rs:44:1 + | +LL | / impl Tr for S +LL | | where +LL | | field_of!(S, f): Field, + | |______________________________- first implementation here +... +LL | impl Tr for S { + | ^^^^^^^^^^^^^^^^^^^ conflicting implementation for `S>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>` + | + = note: overflow evaluating the requirement `Link>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>: Chain` + = note: overflow evaluating the requirement `field_of!(S>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>, f): Field` + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`field_projection_overflow_coherence`) + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0119`. diff --git a/tests/ui/field_representing_types/not-field-if-unsized.next.stderr b/tests/ui/field_representing_types/not-field-if-unsized.next.stderr index 967f6115c1ac1..be6c49ceb6242 100644 --- a/tests/ui/field_representing_types/not-field-if-unsized.next.stderr +++ b/tests/ui/field_representing_types/not-field-if-unsized.next.stderr @@ -1,21 +1,37 @@ -error[E0277]: the trait bound `field_of!(MyStruct, 0): Field` is not satisfied +error[E0277]: the size for values of type `(dyn Trait + 'static)` cannot be known at compilation time --> $DIR/not-field-if-unsized.rs:17:20 | LL | assert_field::(); - | ^^^^^^^^^^^^^^^^^^^^^^ the nightly-only, unstable trait `Field` is not implemented for `field_of!(MyStruct, 0)` + | ^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | + = help: within `field_of!(MyStruct, 0)`, the trait `Sized` is not implemented for `(dyn Trait + 'static)` +note: required because it appears within the type `MyStruct` + --> $DIR/not-field-if-unsized.rs:10:12 + | +LL | pub struct MyStruct(usize, dyn Trait); + | ^^^^^^^^ +note: required because it appears within the type `field_of!(MyStruct, 0)` + --> $SRC_DIR/core/src/field.rs:LL:COL note: required by a bound in `assert_field` --> $DIR/not-field-if-unsized.rs:12:20 | LL | fn assert_field() {} | ^^^^^ required by this bound in `assert_field` -error[E0277]: the trait bound `field_of!(MyStruct, 1): Field` is not satisfied +error[E0277]: the size for values of type `(dyn Trait + 'static)` cannot be known at compilation time --> $DIR/not-field-if-unsized.rs:21:20 | LL | assert_field::(); - | ^^^^^^^^^^^^^^^^^^^^^^ the nightly-only, unstable trait `Field` is not implemented for `field_of!(MyStruct, 1)` + | ^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time + | + = help: within `field_of!(MyStruct, 1)`, the trait `Sized` is not implemented for `(dyn Trait + 'static)` +note: required because it appears within the type `MyStruct` + --> $DIR/not-field-if-unsized.rs:10:12 | +LL | pub struct MyStruct(usize, dyn Trait); + | ^^^^^^^^ +note: required because it appears within the type `field_of!(MyStruct, 1)` + --> $SRC_DIR/core/src/field.rs:LL:COL note: required by a bound in `assert_field` --> $DIR/not-field-if-unsized.rs:12:20 | diff --git a/tests/ui/field_representing_types/not-field-if-unsized.old.stderr b/tests/ui/field_representing_types/not-field-if-unsized.old.stderr index 967f6115c1ac1..693f1353253bd 100644 --- a/tests/ui/field_representing_types/not-field-if-unsized.old.stderr +++ b/tests/ui/field_representing_types/not-field-if-unsized.old.stderr @@ -1,8 +1,8 @@ error[E0277]: the trait bound `field_of!(MyStruct, 0): Field` is not satisfied --> $DIR/not-field-if-unsized.rs:17:20 | -LL | assert_field::(); - | ^^^^^^^^^^^^^^^^^^^^^^ the nightly-only, unstable trait `Field` is not implemented for `field_of!(MyStruct, 0)` +LL | ..._field::(); + | ^^^^^^^^^^^^^^^^^^^^^^ the nightly-only, unstable trait `Field` is not implemented for `field_of!(MyStruct, 0)` | note: required by a bound in `assert_field` --> $DIR/not-field-if-unsized.rs:12:20 @@ -13,8 +13,8 @@ LL | fn assert_field() {} error[E0277]: the trait bound `field_of!(MyStruct, 1): Field` is not satisfied --> $DIR/not-field-if-unsized.rs:21:20 | -LL | assert_field::(); - | ^^^^^^^^^^^^^^^^^^^^^^ the nightly-only, unstable trait `Field` is not implemented for `field_of!(MyStruct, 1)` +LL | ..._field::(); + | ^^^^^^^^^^^^^^^^^^^^^^ the nightly-only, unstable trait `Field` is not implemented for `field_of!(MyStruct, 1)` | note: required by a bound in `assert_field` --> $DIR/not-field-if-unsized.rs:12:20 diff --git a/tests/ui/field_representing_types/not-field-if-unsized.rs b/tests/ui/field_representing_types/not-field-if-unsized.rs index 8f28443d7968c..82a3c385cb799 100644 --- a/tests/ui/field_representing_types/not-field-if-unsized.rs +++ b/tests/ui/field_representing_types/not-field-if-unsized.rs @@ -14,10 +14,10 @@ fn assert_field() {} fn main() { // FIXME(FRTs): this requires relaxing the `Base: ?Sized` bound in the // `Field` trait & compiler changes. - assert_field::(); - //~^ ERROR: the trait bound `field_of!(MyStruct, 0): Field` is not satisfied [E0277] + assert_field::(); //[next]~ ERROR: the size for values of type `(dyn Trait + 'static)` cannot be known at compilation time [E0277] + //[old]~^ ERROR: the trait bound `field_of!(MyStruct, 0): Field` is not satisfied [E0277] // FIXME(FRTs): improve this error message, point to the `dyn Trait` span. - assert_field::(); - //~^ ERROR: the trait bound `field_of!(MyStruct, 1): Field` is not satisfied [E0277] + assert_field::(); //[next]~ ERROR: the size for values of type `(dyn Trait + 'static)` cannot be known at compilation time [E0277] + //[old]~^ ERROR: the trait bound `field_of!(MyStruct, 1): Field` is not satisfied [E0277] } diff --git a/tests/ui/field_representing_types/sized.next.stderr b/tests/ui/field_representing_types/sized.next.stderr index ed7e6955c0762..a39538e4bc6c1 100644 --- a/tests/ui/field_representing_types/sized.next.stderr +++ b/tests/ui/field_representing_types/sized.next.stderr @@ -1,45 +1,90 @@ -error[E0277]: the trait bound `field_of!(Generic, count): Field` is not satisfied +error[E0277]: the size for values of type `T` cannot be known at compilation time --> $DIR/sized.rs:20:19 | +LL | fn generic() { + | - this type parameter needs to be `Sized` LL | impls_field::, count)>(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the nightly-only, unstable trait `Field` is not implemented for `field_of!(Generic, count)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | +note: required because it appears within the type `Generic` + --> $DIR/sized.rs:14:12 + | +LL | pub struct Generic { + | ^^^^^^^ +note: required because it appears within the type `field_of!(Generic, count)` + --> $SRC_DIR/core/src/field.rs:LL:COL note: required by a bound in `impls_field` --> $DIR/sized.rs:38:19 | LL | fn impls_field() {} | ^^^^^ required by this bound in `impls_field` +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL - fn generic() { +LL + fn generic() { + | -error[E0277]: the trait bound `field_of!(Generic, last): Field` is not satisfied +error[E0277]: the size for values of type `T` cannot be known at compilation time --> $DIR/sized.rs:22:19 | +LL | fn generic() { + | - this type parameter needs to be `Sized` +... LL | impls_field::, last)>(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the nightly-only, unstable trait `Field` is not implemented for `field_of!(Generic, last)` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time + | +note: required because it appears within the type `Generic` + --> $DIR/sized.rs:14:12 | +LL | pub struct Generic { + | ^^^^^^^ +note: required because it appears within the type `field_of!(Generic, last)` + --> $SRC_DIR/core/src/field.rs:LL:COL note: required by a bound in `impls_field` --> $DIR/sized.rs:38:19 | LL | fn impls_field() {} | ^^^^^ required by this bound in `impls_field` +help: consider removing the `?Sized` bound to make the type parameter `Sized` + | +LL - fn generic() { +LL + fn generic() { + | -error[E0277]: the trait bound `field_of!(MyDST, count): Field` is not satisfied +error[E0277]: the size for values of type `(dyn Debug + 'static)` cannot be known at compilation time --> $DIR/sized.rs:32:19 | LL | impls_field::(); - | ^^^^^^^^^^^^^^^^^^^^^^^ the nightly-only, unstable trait `Field` is not implemented for `field_of!(MyDST, count)` + | ^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | + = help: within `field_of!(MyDST, count)`, the trait `Sized` is not implemented for `(dyn Debug + 'static)` +note: required because it appears within the type `MyDST` + --> $DIR/sized.rs:9:12 + | +LL | pub struct MyDST { + | ^^^^^ +note: required because it appears within the type `field_of!(MyDST, count)` + --> $SRC_DIR/core/src/field.rs:LL:COL note: required by a bound in `impls_field` --> $DIR/sized.rs:38:19 | LL | fn impls_field() {} | ^^^^^ required by this bound in `impls_field` -error[E0277]: the trait bound `field_of!(MyDST, last): Field` is not satisfied +error[E0277]: the size for values of type `(dyn Debug + 'static)` cannot be known at compilation time --> $DIR/sized.rs:34:19 | LL | impls_field::(); - | ^^^^^^^^^^^^^^^^^^^^^^ the nightly-only, unstable trait `Field` is not implemented for `field_of!(MyDST, last)` + | ^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time + | + = help: within `field_of!(MyDST, last)`, the trait `Sized` is not implemented for `(dyn Debug + 'static)` +note: required because it appears within the type `MyDST` + --> $DIR/sized.rs:9:12 | +LL | pub struct MyDST { + | ^^^^^ +note: required because it appears within the type `field_of!(MyDST, last)` + --> $SRC_DIR/core/src/field.rs:LL:COL note: required by a bound in `impls_field` --> $DIR/sized.rs:38:19 | diff --git a/tests/ui/field_representing_types/sized.old.stderr b/tests/ui/field_representing_types/sized.old.stderr index ed7e6955c0762..f86bf6ddd53ee 100644 --- a/tests/ui/field_representing_types/sized.old.stderr +++ b/tests/ui/field_representing_types/sized.old.stderr @@ -1,8 +1,8 @@ error[E0277]: the trait bound `field_of!(Generic, count): Field` is not satisfied --> $DIR/sized.rs:20:19 | -LL | impls_field::, count)>(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the nightly-only, unstable trait `Field` is not implemented for `field_of!(Generic, count)` +LL | ...::, count)>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the nightly-only, unstable trait `Field` is not implemented for `field_of!(Generic, count)` | note: required by a bound in `impls_field` --> $DIR/sized.rs:38:19 @@ -13,8 +13,8 @@ LL | fn impls_field() {} error[E0277]: the trait bound `field_of!(Generic, last): Field` is not satisfied --> $DIR/sized.rs:22:19 | -LL | impls_field::, last)>(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the nightly-only, unstable trait `Field` is not implemented for `field_of!(Generic, last)` +LL | ...d::, last)>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the nightly-only, unstable trait `Field` is not implemented for `field_of!(Generic, last)` | note: required by a bound in `impls_field` --> $DIR/sized.rs:38:19 @@ -25,8 +25,8 @@ LL | fn impls_field() {} error[E0277]: the trait bound `field_of!(MyDST, count): Field` is not satisfied --> $DIR/sized.rs:32:19 | -LL | impls_field::(); - | ^^^^^^^^^^^^^^^^^^^^^^^ the nightly-only, unstable trait `Field` is not implemented for `field_of!(MyDST, count)` +LL | ...field::(); + | ^^^^^^^^^^^^^^^^^^^^^^^ the nightly-only, unstable trait `Field` is not implemented for `field_of!(MyDST, count)` | note: required by a bound in `impls_field` --> $DIR/sized.rs:38:19 diff --git a/tests/ui/field_representing_types/sized.rs b/tests/ui/field_representing_types/sized.rs index 22499e32f33b2..658dd5f24a131 100644 --- a/tests/ui/field_representing_types/sized.rs +++ b/tests/ui/field_representing_types/sized.rs @@ -17,10 +17,10 @@ pub struct Generic { } fn generic() { - impls_field::, count)>(); - //~^ ERROR: the trait bound `field_of!(Generic, count): Field` is not satisfied [E0277] - impls_field::, last)>(); - //~^ ERROR: the trait bound `field_of!(Generic, last): Field` is not satisfied [E0277] + impls_field::, count)>(); //[next]~ ERROR: the size for values of type `T` cannot be known at compilation time [E0277] + //[old]~^ ERROR: the trait bound `field_of!(Generic, count): Field` is not satisfied [E0277] + impls_field::, last)>(); //[next]~ ERROR: the size for values of type `T` cannot be known at compilation time [E0277] + //[old]~^ ERROR: the trait bound `field_of!(Generic, last): Field` is not satisfied [E0277] } fn ok() { @@ -29,10 +29,10 @@ fn ok() { } fn main() { - impls_field::(); - //~^ ERROR: the trait bound `field_of!(MyDST, count): Field` is not satisfied [E0277] - impls_field::(); - //~^ ERROR: the trait bound `field_of!(MyDST, last): Field` is not satisfied [E0277] + impls_field::(); //[next]~ ERROR: the size for values of type `(dyn Debug + 'static)` cannot be known at compilation time [E0277] + //[old]~^ ERROR: the trait bound `field_of!(MyDST, count): Field` is not satisfied [E0277] + impls_field::(); //[next]~ ERROR: the size for values of type `(dyn Debug + 'static)` cannot be known at compilation time [E0277] + //[old]~^ ERROR: the trait bound `field_of!(MyDST, last): Field` is not satisfied [E0277] } fn impls_field() {} From a785a9fbc1e5d0eaad7ed85ad8d769399a5d49f9 Mon Sep 17 00:00:00 2001 From: Amirhossein Akhlaghpour Date: Fri, 2 Oct 2026 17:09:40 +0330 Subject: [PATCH 2/3] make Field base kind invariant explicit Signed-off-by: Amirhossein Akhlaghpour --- compiler/rustc_next_trait_solver/src/solve/trait_goals.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs b/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs index 35d51fde8224a..32eecd4e44b38 100644 --- a/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs +++ b/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs @@ -915,8 +915,9 @@ where match base.kind() { ty::Adt(def, _) if def.is_struct() && !def.is_packed() => {} + ty::Adt(..) => return Err(NoSolution.into()), ty::Tuple(..) => {} - _ => return Err(NoSolution.into()), + _ => unreachable!(), } ecx.probe_builtin_trait_candidate(BuiltinImplSource::Misc).enter(|ecx| { From 01ad9b75b12127613f2616ff9569950cd54dbc8b Mon Sep 17 00:00:00 2001 From: Amirhossein Akhlaghpour Date: Fri, 2 Oct 2026 18:45:48 +0330 Subject: [PATCH 3/3] update Field UI stderr after diagnostic change Signed-off-by: Amirhossein Akhlaghpour --- .../not-field-if-unsized.next.stderr | 8 +++---- .../sized.next.stderr | 24 ++++++++++++------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/tests/ui/field_representing_types/not-field-if-unsized.next.stderr b/tests/ui/field_representing_types/not-field-if-unsized.next.stderr index be6c49ceb6242..e639d01dc176a 100644 --- a/tests/ui/field_representing_types/not-field-if-unsized.next.stderr +++ b/tests/ui/field_representing_types/not-field-if-unsized.next.stderr @@ -6,10 +6,10 @@ LL | assert_field::(); | = help: within `field_of!(MyStruct, 0)`, the trait `Sized` is not implemented for `(dyn Trait + 'static)` note: required because it appears within the type `MyStruct` - --> $DIR/not-field-if-unsized.rs:10:12 + --> $DIR/not-field-if-unsized.rs:10:28 | LL | pub struct MyStruct(usize, dyn Trait); - | ^^^^^^^^ + | ^^^^^^^^^ required by this field note: required because it appears within the type `field_of!(MyStruct, 0)` --> $SRC_DIR/core/src/field.rs:LL:COL note: required by a bound in `assert_field` @@ -26,10 +26,10 @@ LL | assert_field::(); | = help: within `field_of!(MyStruct, 1)`, the trait `Sized` is not implemented for `(dyn Trait + 'static)` note: required because it appears within the type `MyStruct` - --> $DIR/not-field-if-unsized.rs:10:12 + --> $DIR/not-field-if-unsized.rs:10:28 | LL | pub struct MyStruct(usize, dyn Trait); - | ^^^^^^^^ + | ^^^^^^^^^ required by this field note: required because it appears within the type `field_of!(MyStruct, 1)` --> $SRC_DIR/core/src/field.rs:LL:COL note: required by a bound in `assert_field` diff --git a/tests/ui/field_representing_types/sized.next.stderr b/tests/ui/field_representing_types/sized.next.stderr index a39538e4bc6c1..254603f09b960 100644 --- a/tests/ui/field_representing_types/sized.next.stderr +++ b/tests/ui/field_representing_types/sized.next.stderr @@ -7,10 +7,12 @@ LL | impls_field::, count)>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | note: required because it appears within the type `Generic` - --> $DIR/sized.rs:14:12 + --> $DIR/sized.rs:16:5 | LL | pub struct Generic { - | ^^^^^^^ +LL | count: usize, +LL | last: T, + | ^^^^^^^ required by this field note: required because it appears within the type `field_of!(Generic, count)` --> $SRC_DIR/core/src/field.rs:LL:COL note: required by a bound in `impls_field` @@ -34,10 +36,12 @@ LL | impls_field::, last)>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | note: required because it appears within the type `Generic` - --> $DIR/sized.rs:14:12 + --> $DIR/sized.rs:16:5 | LL | pub struct Generic { - | ^^^^^^^ +LL | count: usize, +LL | last: T, + | ^^^^^^^ required by this field note: required because it appears within the type `field_of!(Generic, last)` --> $SRC_DIR/core/src/field.rs:LL:COL note: required by a bound in `impls_field` @@ -59,10 +63,12 @@ LL | impls_field::(); | = help: within `field_of!(MyDST, count)`, the trait `Sized` is not implemented for `(dyn Debug + 'static)` note: required because it appears within the type `MyDST` - --> $DIR/sized.rs:9:12 + --> $DIR/sized.rs:11:5 | LL | pub struct MyDST { - | ^^^^^ +LL | count: usize, +LL | last: dyn Debug, + | ^^^^^^^^^^^^^^^ required by this field note: required because it appears within the type `field_of!(MyDST, count)` --> $SRC_DIR/core/src/field.rs:LL:COL note: required by a bound in `impls_field` @@ -79,10 +85,12 @@ LL | impls_field::(); | = help: within `field_of!(MyDST, last)`, the trait `Sized` is not implemented for `(dyn Debug + 'static)` note: required because it appears within the type `MyDST` - --> $DIR/sized.rs:9:12 + --> $DIR/sized.rs:11:5 | LL | pub struct MyDST { - | ^^^^^ +LL | count: usize, +LL | last: dyn Debug, + | ^^^^^^^^^^^^^^^ required by this field note: required because it appears within the type `field_of!(MyDST, last)` --> $SRC_DIR/core/src/field.rs:LL:COL note: required by a bound in `impls_field`