From e7d308cba05c27c06bd1fc0bd0c78fe14ee6272e Mon Sep 17 00:00:00 2001 From: David Wood Date: Tue, 17 Jun 2025 07:05:00 +0000 Subject: [PATCH] trait_sel: delay bug for removed pointeesized This code path isn't hit during normal compilation, only in error reporting, so delaying the bug is sufficient. It might be possible to trigger this with `dyn PointeeSized` and code that doesn't error but no such example could be found at the time of writing. --- .../src/traits/select/candidate_assembly.rs | 2 +- .../dyn-pointeesized-issue-142652.rs | 9 +++++++++ .../dyn-pointeesized-issue-142652.stderr | 14 ++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 tests/ui/sized-hierarchy/dyn-pointeesized-issue-142652.rs create mode 100644 tests/ui/sized-hierarchy/dyn-pointeesized-issue-142652.stderr diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs index 81ce58a93fa9d..9d777d4121d73 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -101,7 +101,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { ); } Some(LangItem::PointeeSized) => { - bug!("`PointeeSized` is removed during lowering"); + tcx.dcx().delayed_bug("`PointeeSized` is removed during lowering"); } Some(LangItem::Unsize) => { self.assemble_candidates_for_unsizing(obligation, &mut candidates); diff --git a/tests/ui/sized-hierarchy/dyn-pointeesized-issue-142652.rs b/tests/ui/sized-hierarchy/dyn-pointeesized-issue-142652.rs new file mode 100644 index 0000000000000..31f3287601cac --- /dev/null +++ b/tests/ui/sized-hierarchy/dyn-pointeesized-issue-142652.rs @@ -0,0 +1,9 @@ +#![feature(sized_hierarchy)] + +use std::marker::PointeeSized; + +fn main() { + let x = main; + let y: Box = x; +//~^ ERROR mismatched types +} diff --git a/tests/ui/sized-hierarchy/dyn-pointeesized-issue-142652.stderr b/tests/ui/sized-hierarchy/dyn-pointeesized-issue-142652.stderr new file mode 100644 index 0000000000000..77b4fdb6af580 --- /dev/null +++ b/tests/ui/sized-hierarchy/dyn-pointeesized-issue-142652.stderr @@ -0,0 +1,14 @@ +error[E0308]: mismatched types + --> $DIR/dyn-pointeesized-issue-142652.rs:7:38 + | +LL | let y: Box = x; + | --------------------- ^ expected `Box`, found fn item + | | + | expected due to this + | + = note: expected struct `Box` + found fn item `fn() {main}` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0308`.