Skip to content

Commit 4925e4a

Browse files
committed
wfcheck: just assume needs-drop on unresolved type expression
for last-field, rather than even a delayed ICE. Fix rust-lang#61402.
1 parent bcc568f commit 4925e4a

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

src/librustc_typeck/check/wfcheck.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,7 @@ fn check_type_defn<'tcx, F>(
270270
let ty = variant.fields.last().unwrap().ty;
271271
fcx.tcx.erase_regions(&ty).lift_to_tcx(fcx_tcx)
272272
.map(|ty| ty.needs_drop(fcx_tcx, fcx_tcx.param_env(def_id)))
273-
.unwrap_or_else(|| {
274-
fcx_tcx.sess.delay_span_bug(
275-
item.span, &format!("inference variables in {:?}", ty));
276-
// Just treat unresolved type expression as if it needs drop.
277-
true
278-
})
273+
.unwrap_or(true) // #61402 treat unresolved type expression as needs-drop
279274
}
280275
};
281276
let all_sized =
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// rust-lang/rust#61402: if a struct is packed and the last
2+
// field of the struct needs drop glue, then the compiler's well-formedness check
3+
// will put a Sized bound on that last field.
4+
//
5+
// However, we do not want to ICE the compiler in our attempt to
6+
// avoid adding that Sized bound; it is better to just let a
7+
// potentially unneeded constraint through.
8+
9+
#![allow(unused_imports, dead_code)]
10+
11+
pub struct S;
12+
13+
pub trait Trait<R> { type Assoc; }
14+
15+
impl<X> Trait<X> for S { type Assoc = X; }
16+
17+
#[repr(C, packed)]
18+
struct PackedAssocSized {
19+
pos: Box<<S as Trait<usize>>::Assoc>,
20+
}
21+
22+
fn main() { println!("Hello, world!"); }

0 commit comments

Comments
 (0)