mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Add special-case for [T, 0] in dropck
This commit is contained in:
parent
595316b400
commit
34fcf92ea0
@ -42,8 +42,15 @@ pub fn trivial_dropck_outlives<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
|
|||||||
| ty::Foreign(..)
|
| ty::Foreign(..)
|
||||||
| ty::Error(_) => true,
|
| ty::Error(_) => true,
|
||||||
|
|
||||||
// `T is PAT`, `[T; N]`, and `[T]` have same properties as T.
|
// `T is PAT` and `[T]` have same properties as T.
|
||||||
ty::Pat(ty, _) | ty::Array(ty, _) | ty::Slice(ty) => trivial_dropck_outlives(tcx, *ty),
|
ty::Pat(ty, _) | ty::Slice(ty) => trivial_dropck_outlives(tcx, *ty),
|
||||||
|
ty::Array(ty, size) => {
|
||||||
|
// Empty array never has a dtor. See issue #110288.
|
||||||
|
match size.try_to_target_usize(tcx) {
|
||||||
|
Some(0) => true,
|
||||||
|
_ => trivial_dropck_outlives(tcx, *ty),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// (T1..Tn) and closures have same properties as T1..Tn --
|
// (T1..Tn) and closures have same properties as T1..Tn --
|
||||||
// check if *all* of them are trivial.
|
// check if *all* of them are trivial.
|
||||||
|
23
tests/ui/dropck/dropck-empty-array.rs
Normal file
23
tests/ui/dropck/dropck-empty-array.rs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
//@ run-pass
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
struct Struct<'s>(&'s str);
|
||||||
|
|
||||||
|
impl<'s> Drop for Struct<'s> {
|
||||||
|
fn drop(&mut self) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn to_array_zero<T>(_: T) -> [T; 0] {
|
||||||
|
[]
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn array_zero_in_tuple() {
|
||||||
|
let mut x = ([], String::new());
|
||||||
|
{
|
||||||
|
let s = String::from("temporary");
|
||||||
|
let p = Struct(&s);
|
||||||
|
x.0 = to_array_zero(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
Loading…
Reference in New Issue
Block a user