1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
use crate::infer::at::At;
use crate::infer::canonical::OriginalQueryValues;
use crate::infer::InferOk;
use rustc_middle::ty::subst::GenericArg;
use rustc_middle::ty::{self, Ty, TyCtxt};
pub use rustc_middle::traits::query::{DropckOutlivesResult, DtorckConstraint};
pub trait AtExt<'tcx> {
fn dropck_outlives(&self, ty: Ty<'tcx>) -> InferOk<'tcx, Vec<GenericArg<'tcx>>>;
}
impl<'cx, 'tcx> AtExt<'tcx> for At<'cx, 'tcx> {
fn dropck_outlives(&self, ty: Ty<'tcx>) -> InferOk<'tcx, Vec<GenericArg<'tcx>>> {
debug!("dropck_outlives(ty={:?}, param_env={:?})", ty, self.param_env,);
let tcx = self.infcx.tcx;
if trivial_dropck_outlives(tcx, ty) {
return InferOk { value: vec![], obligations: vec![] };
}
let mut orig_values = OriginalQueryValues::default();
let c_ty = self.infcx.canonicalize_query(self.param_env.and(ty), &mut orig_values);
let span = self.cause.span;
debug!("c_ty = {:?}", c_ty);
if let Ok(result) = tcx.dropck_outlives(c_ty) {
if result.is_proven() {
if let Ok(InferOk { value, obligations }) =
self.infcx.instantiate_query_response_and_region_obligations(
self.cause,
self.param_env,
&orig_values,
result,
)
{
let ty = self.infcx.resolve_vars_if_possible(ty);
let kinds = value.into_kinds_reporting_overflows(tcx, span, ty);
return InferOk { value: kinds, obligations };
}
}
}
tcx.sess.delay_span_bug(span, "dtorck encountered internal error");
InferOk { value: vec![], obligations: vec![] }
}
}
pub fn trivial_dropck_outlives<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
match ty.kind() {
ty::Infer(ty::FreshIntTy(_))
| ty::Infer(ty::FreshFloatTy(_))
| ty::Bool
| ty::Int(_)
| ty::Uint(_)
| ty::Float(_)
| ty::Never
| ty::FnDef(..)
| ty::FnPtr(_)
| ty::Char
| ty::GeneratorWitness(..)
| ty::RawPtr(_)
| ty::Ref(..)
| ty::Str
| ty::Foreign(..)
| ty::Error(_) => true,
ty::Array(ty, _) | ty::Slice(ty) => trivial_dropck_outlives(tcx, ty),
ty::Tuple(ref tys) => tys.iter().all(|t| trivial_dropck_outlives(tcx, t.expect_ty())),
ty::Closure(_, ref substs) => {
trivial_dropck_outlives(tcx, substs.as_closure().tupled_upvars_ty())
}
ty::Adt(def, _) => {
if Some(def.did) == tcx.lang_items().manually_drop() {
true
} else {
false
}
}
ty::Dynamic(..)
| ty::Projection(..)
| ty::Param(_)
| ty::Opaque(..)
| ty::Placeholder(..)
| ty::Infer(_)
| ty::Bound(..)
| ty::Generator(..) => false,
}
}