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..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 @@ -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.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 new file mode 100644 index 0000000000000..20a11bf969184 --- /dev/null +++ b/tests/ui/cycle-trait/pointee-sized-next-solver-ice.rs @@ -0,0 +1,21 @@ +//@ 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 {} + +fn require_trait() {} + +fn main() { + require_trait::(); + //~^ ERROR the trait bound `i32: PointeeSized` is not satisfied +}