Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #56806 by using delay_span_bug in object safety layout sanity checks #57229

Merged
merged 1 commit into from
Jan 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions src/librustc/traits/object_safety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,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(
Expand All @@ -383,10 +391,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
),
);
}
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/test/ui/issues/issue-56806.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pub trait Trait {
fn dyn_instead_of_self(self: Box<dyn Trait>);
//~^ ERROR invalid method receiver type: std::boxed::Box<(dyn Trait + 'static)>
}

pub fn main() {
}
12 changes: 12 additions & 0 deletions src/test/ui/issues/issue-56806.stderr
Original file line number Diff line number Diff line change
@@ -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<dyn Trait>);
| ^^^^^^^^^^^^^^
|
= note: type must be `Self` or a type that dereferences to it
= help: consider changing to `self`, `&self`, `&mut self`, or `self: Box<Self>`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0307`.