From 66786fc407e79f013c6f0f256f36de7efcd96ae0 Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Mon, 2 Feb 2026 02:07:19 +0900 Subject: [PATCH 1/3] fix next-solver ICE on PointeeSized goals --- .../traits/fulfillment_errors.rs | 2 + .../pointee-sized-next-solver-ice.rs | 20 ++++ .../pointee-sized-next-solver-ice.stderr | 92 +++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 tests/ui/cycle-trait/pointee-sized-next-solver-ice.rs create mode 100644 tests/ui/cycle-trait/pointee-sized-next-solver-ice.stderr diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs index 4f51435290e49..ab02c6ce8b05a 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs @@ -2632,6 +2632,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { trait_def_id != def_id && trait_name == self.tcx.item_name(def_id) && trait_has_same_params(def_id) + // `PointeeSized` is removed during lowering. + && !self.tcx.is_lang_item(*def_id, LangItem::PointeeSized) && self.predicate_must_hold_modulo_regions(&Obligation::new( self.tcx, obligation.cause.clone(), diff --git a/tests/ui/cycle-trait/pointee-sized-next-solver-ice.rs b/tests/ui/cycle-trait/pointee-sized-next-solver-ice.rs new file mode 100644 index 0000000000000..3c8e0a797c52c --- /dev/null +++ b/tests/ui/cycle-trait/pointee-sized-next-solver-ice.rs @@ -0,0 +1,20 @@ +//@ compile-flags: -Znext-solver=globally + +// Regression test for #151957 + +trait PointeeSized { + type Undefined; +} + +struct T; + +impl PointeeSized for T +//~^ ERROR not all trait items implemented, missing: `Undefined` +//~| ERROR the trait bound `T: PointeeSized` is not satisfied +where + ::Undefined: PointeeSized, +//~^ ERROR the trait bound `T: PointeeSized` is not satisfied +//~| ERROR the trait bound `T: PointeeSized` is not satisfied +{} + +fn main() {} diff --git a/tests/ui/cycle-trait/pointee-sized-next-solver-ice.stderr b/tests/ui/cycle-trait/pointee-sized-next-solver-ice.stderr new file mode 100644 index 0000000000000..fd18f71606b11 --- /dev/null +++ b/tests/ui/cycle-trait/pointee-sized-next-solver-ice.stderr @@ -0,0 +1,92 @@ +error[E0046]: not all trait items implemented, missing: `Undefined` + --> $DIR/pointee-sized-next-solver-ice.rs:11:1 + | +LL | type Undefined; + | -------------- `Undefined` from trait +... +LL | / impl PointeeSized for T +LL | | +LL | | +LL | | where +LL | | ::Undefined: PointeeSized, + | |_________________________________________________^ missing `Undefined` in implementation + +error[E0277]: the trait bound `T: PointeeSized` is not satisfied + --> $DIR/pointee-sized-next-solver-ice.rs:15:5 + | +LL | ::Undefined: PointeeSized, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound + | +help: the trait `PointeeSized` is not implemented for `T` + --> $DIR/pointee-sized-next-solver-ice.rs:9:1 + | +LL | struct T; + | ^^^^^^^^ +help: the trait `PointeeSized` is implemented for `T` + --> $DIR/pointee-sized-next-solver-ice.rs:11:1 + | +LL | / impl PointeeSized for T +LL | | +LL | | +LL | | where +LL | | ::Undefined: PointeeSized, + | |_________________________________________________^ + = help: see issue #48214 +help: add `#![feature(trivial_bounds)]` to the crate attributes to enable + | +LL + #![feature(trivial_bounds)] + | + +error[E0277]: the trait bound `T: PointeeSized` is not satisfied + --> $DIR/pointee-sized-next-solver-ice.rs:11:23 + | +LL | impl PointeeSized for T + | ^ unsatisfied trait bound + | +help: the trait `PointeeSized` is not implemented for `T` + --> $DIR/pointee-sized-next-solver-ice.rs:9:1 + | +LL | struct T; + | ^^^^^^^^ +help: the trait `PointeeSized` is implemented for `T` + --> $DIR/pointee-sized-next-solver-ice.rs:11:1 + | +LL | / impl PointeeSized for T +LL | | +LL | | +LL | | where +LL | | ::Undefined: PointeeSized, + | |_________________________________________________^ + +error[E0277]: the trait bound `T: PointeeSized` is not satisfied + --> $DIR/pointee-sized-next-solver-ice.rs:15:37 + | +LL | ::Undefined: PointeeSized, + | ^^^^^^^^^^^^ unsatisfied trait bound + | +help: the trait `PointeeSized` is not implemented for `T` + --> $DIR/pointee-sized-next-solver-ice.rs:9:1 + | +LL | struct T; + | ^^^^^^^^ +help: the trait `PointeeSized` is implemented for `T` + --> $DIR/pointee-sized-next-solver-ice.rs:11:1 + | +LL | / impl PointeeSized for T +LL | | +LL | | +LL | | where +LL | | ::Undefined: PointeeSized, + | |_________________________________________________^ +note: required by a bound in `PointeeSized` + --> $DIR/pointee-sized-next-solver-ice.rs:5:1 + | +LL | / trait PointeeSized { +LL | | type Undefined; +LL | | } + | |_^ required by this bound in `PointeeSized` + +error: aborting due to 4 previous errors + +Some errors have detailed explanations: E0046, E0277. +For more information about an error, try `rustc --explain E0046`. From 6cda9bfafc16be357f94bfd03177c4a13622cbca Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Mon, 2 Feb 2026 03:21:51 +0900 Subject: [PATCH 2/3] replace issue number with link --- tests/ui/cycle-trait/pointee-sized-next-solver-ice.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/cycle-trait/pointee-sized-next-solver-ice.rs b/tests/ui/cycle-trait/pointee-sized-next-solver-ice.rs index 3c8e0a797c52c..b69382ebeccda 100644 --- a/tests/ui/cycle-trait/pointee-sized-next-solver-ice.rs +++ b/tests/ui/cycle-trait/pointee-sized-next-solver-ice.rs @@ -1,6 +1,6 @@ //@ compile-flags: -Znext-solver=globally -// Regression test for #151957 +// Regression test for https://github.com/rust-lang/rust/issues/151957 trait PointeeSized { type Undefined; From ca74063cea46d15b29c602be71ef8048c8aff63d Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Mon, 2 Mar 2026 17:41:36 +0900 Subject: [PATCH 3/3] simplify test case and add revisions for both solvers remove * --- .../traits/fulfillment_errors.rs | 2 +- ...intee-sized-next-solver-ice.current.stderr | 20 ++++ .../pointee-sized-next-solver-ice.next.stderr | 20 ++++ .../pointee-sized-next-solver-ice.rs | 31 ++++--- .../pointee-sized-next-solver-ice.stderr | 92 ------------------- 5 files changed, 57 insertions(+), 108 deletions(-) create mode 100644 tests/ui/cycle-trait/pointee-sized-next-solver-ice.current.stderr create mode 100644 tests/ui/cycle-trait/pointee-sized-next-solver-ice.next.stderr delete mode 100644 tests/ui/cycle-trait/pointee-sized-next-solver-ice.stderr diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs index ab02c6ce8b05a..364152475e94d 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs @@ -2633,7 +2633,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { && trait_name == self.tcx.item_name(def_id) && trait_has_same_params(def_id) // `PointeeSized` is removed during lowering. - && !self.tcx.is_lang_item(*def_id, LangItem::PointeeSized) + && !self.tcx.is_lang_item(def_id, LangItem::PointeeSized) && self.predicate_must_hold_modulo_regions(&Obligation::new( self.tcx, obligation.cause.clone(), diff --git a/tests/ui/cycle-trait/pointee-sized-next-solver-ice.current.stderr b/tests/ui/cycle-trait/pointee-sized-next-solver-ice.current.stderr new file mode 100644 index 0000000000000..39e815b9af4b5 --- /dev/null +++ b/tests/ui/cycle-trait/pointee-sized-next-solver-ice.current.stderr @@ -0,0 +1,20 @@ +error[E0277]: the trait bound `i32: PointeeSized` is not satisfied + --> $DIR/pointee-sized-next-solver-ice.rs:19:21 + | +LL | require_trait::(); + | ^^^ the trait `PointeeSized` is not implemented for `i32` + | +help: this trait has no implementations, consider adding one + --> $DIR/pointee-sized-next-solver-ice.rs:14:1 + | +LL | trait PointeeSized {} + | ^^^^^^^^^^^^^^^^^^ +note: required by a bound in `require_trait` + --> $DIR/pointee-sized-next-solver-ice.rs:16:21 + | +LL | fn require_trait() {} + | ^^^^^^^^^^^^ required by this bound in `require_trait` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/cycle-trait/pointee-sized-next-solver-ice.next.stderr b/tests/ui/cycle-trait/pointee-sized-next-solver-ice.next.stderr new file mode 100644 index 0000000000000..39e815b9af4b5 --- /dev/null +++ b/tests/ui/cycle-trait/pointee-sized-next-solver-ice.next.stderr @@ -0,0 +1,20 @@ +error[E0277]: the trait bound `i32: PointeeSized` is not satisfied + --> $DIR/pointee-sized-next-solver-ice.rs:19:21 + | +LL | require_trait::(); + | ^^^ the trait `PointeeSized` is not implemented for `i32` + | +help: this trait has no implementations, consider adding one + --> $DIR/pointee-sized-next-solver-ice.rs:14:1 + | +LL | trait PointeeSized {} + | ^^^^^^^^^^^^^^^^^^ +note: required by a bound in `require_trait` + --> $DIR/pointee-sized-next-solver-ice.rs:16:21 + | +LL | fn require_trait() {} + | ^^^^^^^^^^^^ required by this bound in `require_trait` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/cycle-trait/pointee-sized-next-solver-ice.rs b/tests/ui/cycle-trait/pointee-sized-next-solver-ice.rs index b69382ebeccda..20a11bf969184 100644 --- a/tests/ui/cycle-trait/pointee-sized-next-solver-ice.rs +++ b/tests/ui/cycle-trait/pointee-sized-next-solver-ice.rs @@ -1,20 +1,21 @@ -//@ compile-flags: -Znext-solver=globally +//@ revisions: current next +//@[next] compile-flags: -Znext-solver +//@ ignore-compare-mode-next-solver (explicit revisions) // Regression test for https://github.com/rust-lang/rust/issues/151957 +// +// When a user-defined trait shares the name `PointeeSized` with +// `core::marker::PointeeSized`, error reporting tries to check whether +// the type implements the lang-item `PointeeSized` trait via +// `predicate_must_hold_modulo_regions`. This creates a `PointeeSized` +// solver obligation which causes an ICE. We avoid this by skipping the +// `PointeeSized` lang item during the "similarly named trait" suggestion. -trait PointeeSized { - type Undefined; -} - -struct T; +trait PointeeSized {} -impl PointeeSized for T -//~^ ERROR not all trait items implemented, missing: `Undefined` -//~| ERROR the trait bound `T: PointeeSized` is not satisfied -where - ::Undefined: PointeeSized, -//~^ ERROR the trait bound `T: PointeeSized` is not satisfied -//~| ERROR the trait bound `T: PointeeSized` is not satisfied -{} +fn require_trait() {} -fn main() {} +fn main() { + require_trait::(); + //~^ ERROR the trait bound `i32: PointeeSized` is not satisfied +} diff --git a/tests/ui/cycle-trait/pointee-sized-next-solver-ice.stderr b/tests/ui/cycle-trait/pointee-sized-next-solver-ice.stderr deleted file mode 100644 index fd18f71606b11..0000000000000 --- a/tests/ui/cycle-trait/pointee-sized-next-solver-ice.stderr +++ /dev/null @@ -1,92 +0,0 @@ -error[E0046]: not all trait items implemented, missing: `Undefined` - --> $DIR/pointee-sized-next-solver-ice.rs:11:1 - | -LL | type Undefined; - | -------------- `Undefined` from trait -... -LL | / impl PointeeSized for T -LL | | -LL | | -LL | | where -LL | | ::Undefined: PointeeSized, - | |_________________________________________________^ missing `Undefined` in implementation - -error[E0277]: the trait bound `T: PointeeSized` is not satisfied - --> $DIR/pointee-sized-next-solver-ice.rs:15:5 - | -LL | ::Undefined: PointeeSized, - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound - | -help: the trait `PointeeSized` is not implemented for `T` - --> $DIR/pointee-sized-next-solver-ice.rs:9:1 - | -LL | struct T; - | ^^^^^^^^ -help: the trait `PointeeSized` is implemented for `T` - --> $DIR/pointee-sized-next-solver-ice.rs:11:1 - | -LL | / impl PointeeSized for T -LL | | -LL | | -LL | | where -LL | | ::Undefined: PointeeSized, - | |_________________________________________________^ - = help: see issue #48214 -help: add `#![feature(trivial_bounds)]` to the crate attributes to enable - | -LL + #![feature(trivial_bounds)] - | - -error[E0277]: the trait bound `T: PointeeSized` is not satisfied - --> $DIR/pointee-sized-next-solver-ice.rs:11:23 - | -LL | impl PointeeSized for T - | ^ unsatisfied trait bound - | -help: the trait `PointeeSized` is not implemented for `T` - --> $DIR/pointee-sized-next-solver-ice.rs:9:1 - | -LL | struct T; - | ^^^^^^^^ -help: the trait `PointeeSized` is implemented for `T` - --> $DIR/pointee-sized-next-solver-ice.rs:11:1 - | -LL | / impl PointeeSized for T -LL | | -LL | | -LL | | where -LL | | ::Undefined: PointeeSized, - | |_________________________________________________^ - -error[E0277]: the trait bound `T: PointeeSized` is not satisfied - --> $DIR/pointee-sized-next-solver-ice.rs:15:37 - | -LL | ::Undefined: PointeeSized, - | ^^^^^^^^^^^^ unsatisfied trait bound - | -help: the trait `PointeeSized` is not implemented for `T` - --> $DIR/pointee-sized-next-solver-ice.rs:9:1 - | -LL | struct T; - | ^^^^^^^^ -help: the trait `PointeeSized` is implemented for `T` - --> $DIR/pointee-sized-next-solver-ice.rs:11:1 - | -LL | / impl PointeeSized for T -LL | | -LL | | -LL | | where -LL | | ::Undefined: PointeeSized, - | |_________________________________________________^ -note: required by a bound in `PointeeSized` - --> $DIR/pointee-sized-next-solver-ice.rs:5:1 - | -LL | / trait PointeeSized { -LL | | type Undefined; -LL | | } - | |_^ required by this bound in `PointeeSized` - -error: aborting due to 4 previous errors - -Some errors have detailed explanations: E0046, E0277. -For more information about an error, try `rustc --explain E0046`.