diff --git a/src/librustc/traits/object_safety.rs b/src/librustc/traits/object_safety.rs index 31342c250e2bd..00967242bed0e 100644 --- a/src/librustc/traits/object_safety.rs +++ b/src/librustc/traits/object_safety.rs @@ -359,7 +359,15 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> { match abi_of_ty(unit_receiver_ty) { &Abi::Scalar(..) => (), - abi => bug!("Receiver when Self = () should have a Scalar ABI, found {:?}", abi) + abi => { + self.sess.delay_span_bug( + self.def_span(method.def_id), + &format!( + "Receiver when Self = () should have a Scalar ABI, found {:?}", + abi + ), + ); + } } let trait_object_ty = self.object_ty_for_trait( @@ -373,10 +381,15 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> { match abi_of_ty(trait_object_receiver) { &Abi::ScalarPair(..) => (), - abi => bug!( - "Receiver when Self = {} should have a ScalarPair ABI, found {:?}", - trait_object_ty, abi - ) + abi => { + self.sess.delay_span_bug( + self.def_span(method.def_id), + &format!( + "Receiver when Self = {} should have a ScalarPair ABI, found {:?}", + trait_object_ty, abi + ), + ); + } } } } diff --git a/src/test/ui/issues/issue-56806.rs b/src/test/ui/issues/issue-56806.rs new file mode 100644 index 0000000000000..b6454e578e6af --- /dev/null +++ b/src/test/ui/issues/issue-56806.rs @@ -0,0 +1,7 @@ +pub trait Trait { + fn dyn_instead_of_self(self: Box); + //~^ ERROR invalid method receiver type: std::boxed::Box<(dyn Trait + 'static)> +} + +pub fn main() { +} diff --git a/src/test/ui/issues/issue-56806.stderr b/src/test/ui/issues/issue-56806.stderr new file mode 100644 index 0000000000000..2dd3add8f60e6 --- /dev/null +++ b/src/test/ui/issues/issue-56806.stderr @@ -0,0 +1,12 @@ +error[E0307]: invalid method receiver type: std::boxed::Box<(dyn Trait + 'static)> + --> $DIR/issue-56806.rs:2:34 + | +LL | fn dyn_instead_of_self(self: Box); + | ^^^^^^^^^^^^^^ + | + = note: type must be `Self` or a type that dereferences to it + = help: consider changing to `self`, `&self`, `&mut self`, or `self: Box` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0307`.