Skip to content

Commit 78f2641

Browse files
authored
Unrolled build for rust-lang#128438
Rollup merge of rust-lang#128438 - Bryanskiy:empty-array-dropck, r=lcnr Add special-case for [T, 0] in dropck_outlives implements/fixes rust-lang#110288. r? `@lcnr`
2 parents 71b2116 + 34fcf92 commit 78f2641

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,15 @@ pub fn trivial_dropck_outlives<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
4242
| ty::Foreign(..)
4343
| ty::Error(_) => true,
4444

45-
// `T is PAT`, `[T; N]`, and `[T]` have same properties as T.
46-
ty::Pat(ty, _) | ty::Array(ty, _) | ty::Slice(ty) => trivial_dropck_outlives(tcx, *ty),
45+
// `T is PAT` and `[T]` have same properties as T.
46+
ty::Pat(ty, _) | ty::Slice(ty) => trivial_dropck_outlives(tcx, *ty),
47+
ty::Array(ty, size) => {
48+
// Empty array never has a dtor. See issue #110288.
49+
match size.try_to_target_usize(tcx) {
50+
Some(0) => true,
51+
_ => trivial_dropck_outlives(tcx, *ty),
52+
}
53+
}
4754

4855
// (T1..Tn) and closures have same properties as T1..Tn --
4956
// check if *all* of them are trivial.

tests/ui/dropck/dropck-empty-array.rs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//@ run-pass
2+
3+
#[allow(dead_code)]
4+
struct Struct<'s>(&'s str);
5+
6+
impl<'s> Drop for Struct<'s> {
7+
fn drop(&mut self) {}
8+
}
9+
10+
fn to_array_zero<T>(_: T) -> [T; 0] {
11+
[]
12+
}
13+
14+
pub fn array_zero_in_tuple() {
15+
let mut x = ([], String::new());
16+
{
17+
let s = String::from("temporary");
18+
let p = Struct(&s);
19+
x.0 = to_array_zero(p);
20+
}
21+
}
22+
23+
fn main() {}

0 commit comments

Comments
 (0)