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

delay_span_bug in wfcheck's ty.lift_to_tcx unwrap #58970

Merged
merged 2 commits into from
Mar 9, 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
11 changes: 7 additions & 4 deletions src/librustc_typeck/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,14 @@ fn check_type_defn<'a, 'tcx, F>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
let needs_drop_copy = || {
packed && {
let ty = variant.fields.last().unwrap().ty;
let ty = fcx.tcx.erase_regions(&ty).lift_to_tcx(fcx_tcx)
fcx.tcx.erase_regions(&ty).lift_to_tcx(fcx_tcx)
.map(|ty| ty.needs_drop(fcx_tcx, fcx_tcx.param_env(def_id)))
.unwrap_or_else(|| {
span_bug!(item.span, "inference variables in {:?}", ty)
});
ty.needs_drop(fcx_tcx, fcx_tcx.param_env(def_id))
fcx_tcx.sess.delay_span_bug(
item.span, &format!("inference variables in {:?}", ty));
// Just treat unresolved type expression as if it needs drop.
true
})
}
};
let all_sized =
Expand Down
31 changes: 31 additions & 0 deletions src/test/ui/wf/wf-packed-on-proj-of-type-as-unimpl-trait.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// rust-lang/rust#58158: We have special-case code to deal with case
// when a type is both packed and needs drop glue, (we move the fields
// out of their potentially unaligned locations before dropping them,
// which requires they be Sized; see PR #44884).
//
// So, we need to check if a given type needs drop-glue. That requires
// that we actually know that the concrete type, and we guard against
// the type having unknown parts (i.e. type variables) by ICE'ing in
// that scenario.
//
// But in a case where we have a projection (`Type as Trait::Assoc`)
// where `Type` does not actually implement `Trait`, we of course
// cannot have a concrete type, because there is no impl to look up
// the concrete type for the associated type `Assoc`.
//
// So, this test is just making sure that in such a case that we do
// not immediately ICE, and instead allow the underlying type error to
// surface.

pub struct Matrix<S>(S);
pub struct DefaultAllocator;

pub trait Allocator { type Buffer; }

// impl Allocator for DefaultAllocator { type Buffer = (); }

#[repr(packed)]
struct Foo(Matrix<<DefaultAllocator as Allocator>::Buffer>);
//~^ ERROR the trait bound `DefaultAllocator: Allocator` is not satisfied

fn main() { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0277]: the trait bound `DefaultAllocator: Allocator` is not satisfied
--> $DIR/wf-packed-on-proj-of-type-as-unimpl-trait.rs:28:12
|
LL | struct Foo(Matrix<<DefaultAllocator as Allocator>::Buffer>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Allocator` is not implemented for `DefaultAllocator`

error: aborting due to previous error

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