diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index b64dcb0bbf03b..410058f49eea4 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -835,7 +835,13 @@ impl Visitor<'tcx> for Checker<'tcx> { let ty = self.tcx.type_of(item.def_id); let (adt_def, substs) = match ty.kind() { ty::Adt(adt_def, substs) => (adt_def, substs), - _ => bug!(), + _ => { + self.tcx.sess.delay_span_bug( + item.span, + &format!("unexpected type kind {:?} (`{:?}`)", ty, ty.kind()), + ); + return; + } }; // Non-`Copy` fields are unstable, except for `ManuallyDrop`. diff --git a/compiler/rustc_traits/src/normalize_erasing_regions.rs b/compiler/rustc_traits/src/normalize_erasing_regions.rs index 61ab5e28b6796..7139dc41fd2f0 100644 --- a/compiler/rustc_traits/src/normalize_erasing_regions.rs +++ b/compiler/rustc_traits/src/normalize_erasing_regions.rs @@ -2,6 +2,7 @@ use rustc_infer::infer::TyCtxtInferExt; use rustc_middle::traits::query::NoSolution; use rustc_middle::ty::query::Providers; use rustc_middle::ty::{self, ParamEnvAnd, TyCtxt, TypeFoldable}; +use rustc_span::DUMMY_SP; use rustc_trait_selection::traits::query::normalize::AtExt; use rustc_trait_selection::traits::{Normalized, ObligationCause}; use std::sync::atomic::Ordering; @@ -51,7 +52,13 @@ fn normalize_after_erasing_regions<'tcx, T: TypeFoldable<'tcx> + PartialEq + Cop debug_assert!(!erased.needs_infer(), "{:?}", erased); erased } - Err(NoSolution) => bug!("could not fully normalize `{:?}`", value), + Err(NoSolution) => { + infcx + .tcx + .sess + .delay_span_bug(DUMMY_SP, &format!("could not fully normalize `{:?}`", value)); + value + } } }) } diff --git a/src/test/ui/union/normalization-failure-issue-81199-autofix.fixed b/src/test/ui/union/normalization-failure-issue-81199-autofix.fixed new file mode 100644 index 0000000000000..45fdf74da836e --- /dev/null +++ b/src/test/ui/union/normalization-failure-issue-81199-autofix.fixed @@ -0,0 +1,21 @@ +// run-rustfix +#[allow(dead_code)] +#[repr(C)] +union PtrRepr { + const_ptr: *const T, + mut_ptr: *mut T, + components: std::mem::ManuallyDrop>, + //~^ ERROR the trait bound `T: Pointee` is not satisfied +} + +#[repr(C)] +struct PtrComponents { + data_address: *const (), + metadata: ::Metadata, +} + +pub trait Pointee { + type Metadata; +} + +fn main() {} diff --git a/src/test/ui/union/normalization-failure-issue-81199-autofix.rs b/src/test/ui/union/normalization-failure-issue-81199-autofix.rs new file mode 100644 index 0000000000000..5f73d7b952e26 --- /dev/null +++ b/src/test/ui/union/normalization-failure-issue-81199-autofix.rs @@ -0,0 +1,21 @@ +// run-rustfix +#[allow(dead_code)] +#[repr(C)] +union PtrRepr { + const_ptr: *const T, + mut_ptr: *mut T, + components: std::mem::ManuallyDrop>, + //~^ ERROR the trait bound `T: Pointee` is not satisfied +} + +#[repr(C)] +struct PtrComponents { + data_address: *const (), + metadata: ::Metadata, +} + +pub trait Pointee { + type Metadata; +} + +fn main() {} diff --git a/src/test/ui/union/normalization-failure-issue-81199-autofix.stderr b/src/test/ui/union/normalization-failure-issue-81199-autofix.stderr new file mode 100644 index 0000000000000..500f3bff92cf7 --- /dev/null +++ b/src/test/ui/union/normalization-failure-issue-81199-autofix.stderr @@ -0,0 +1,19 @@ +error[E0277]: the trait bound `T: Pointee` is not satisfied + --> $DIR/normalization-failure-issue-81199-autofix.rs:7:40 + | +LL | components: std::mem::ManuallyDrop>, + | ^^^^^^^^^^^^^^^^ the trait `Pointee` is not implemented for `T` + | +note: required by a bound in `PtrComponents` + --> $DIR/normalization-failure-issue-81199-autofix.rs:12:25 + | +LL | struct PtrComponents { + | ^^^^^^^ required by this bound in `PtrComponents` +help: consider further restricting this bound + | +LL | union PtrRepr { + | +++++++++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/union/normalization-failure-issue-81199-min.rs b/src/test/ui/union/normalization-failure-issue-81199-min.rs new file mode 100644 index 0000000000000..739e9d1b8ed0e --- /dev/null +++ b/src/test/ui/union/normalization-failure-issue-81199-min.rs @@ -0,0 +1,12 @@ +union PtrRepr { + const_ptr: *const T, + mut_ptr: *mut T, + components: ::Metadata + //~^ ERROR the trait bound `T: Pointee` is not satisfied +} + +pub trait Pointee { + type Metadata; +} + +fn main() {} diff --git a/src/test/ui/union/normalization-failure-issue-81199-min.stderr b/src/test/ui/union/normalization-failure-issue-81199-min.stderr new file mode 100644 index 0000000000000..a0d9b5866774e --- /dev/null +++ b/src/test/ui/union/normalization-failure-issue-81199-min.stderr @@ -0,0 +1,14 @@ +error[E0277]: the trait bound `T: Pointee` is not satisfied + --> $DIR/normalization-failure-issue-81199-min.rs:4:17 + | +LL | components: ::Metadata + | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Pointee` is not implemented for `T` + | +help: consider further restricting this bound + | +LL | union PtrRepr { + | +++++++++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/union/normalization-failure-issue-81199.rs b/src/test/ui/union/normalization-failure-issue-81199.rs new file mode 100644 index 0000000000000..e0b9107bcfa8e --- /dev/null +++ b/src/test/ui/union/normalization-failure-issue-81199.rs @@ -0,0 +1,19 @@ +#[repr(C)] +union PtrRepr { + const_ptr: *const T, + mut_ptr: *mut T, + components: PtrComponents, + //~^ ERROR the trait bound `T: Pointee` is not satisfied in `PtrComponents` +} + +#[repr(C)] +struct PtrComponents { + data_address: *const (), + metadata: ::Metadata, +} + +pub trait Pointee { + type Metadata; +} + +fn main() {} diff --git a/src/test/ui/union/normalization-failure-issue-81199.stderr b/src/test/ui/union/normalization-failure-issue-81199.stderr new file mode 100644 index 0000000000000..a41297d864c10 --- /dev/null +++ b/src/test/ui/union/normalization-failure-issue-81199.stderr @@ -0,0 +1,29 @@ +error[E0277]: the trait bound `T: Pointee` is not satisfied in `PtrComponents` + --> $DIR/normalization-failure-issue-81199.rs:5:17 + | +LL | components: PtrComponents, + | ^^^^^^^^^^^^^^^^ within `PtrComponents`, the trait `Pointee` is not implemented for `T` + | +note: required because it appears within the type `PtrComponents` + --> $DIR/normalization-failure-issue-81199.rs:10:8 + | +LL | struct PtrComponents { + | ^^^^^^^^^^^^^ + = note: no field of a union may have a dynamically sized type + = help: change the field's type to have a statically known size +help: consider further restricting this bound + | +LL | union PtrRepr { + | +++++++++ +help: borrowed types always have a statically known size + | +LL | components: &PtrComponents, + | + +help: the `Box` type always has a statically known size and allocates its contents in the heap + | +LL | components: Box>, + | ++++ + + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`.