Skip to content

Commit 1833298

Browse files
committed
privacy: Do not use DefIdVisitorSkeleton ty cache for primitives
1 parent 934563f commit 1833298

File tree

1 file changed

+24
-9
lines changed
  • compiler/rustc_privacy/src

1 file changed

+24
-9
lines changed

compiler/rustc_privacy/src/lib.rs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,6 @@ where
182182
}
183183

184184
fn visit_ty(&mut self, ty: Ty<'tcx>) -> Self::Result {
185-
if !self.visited_tys.insert(ty) {
186-
return V::Result::output();
187-
}
188185
let tcx = self.def_id_visitor.tcx();
189186
// GenericArgs are not visited here because they are visited below
190187
// in `super_visit_with`.
@@ -195,6 +192,9 @@ where
195192
| ty::Closure(def_id, ..)
196193
| ty::CoroutineClosure(def_id, ..)
197194
| ty::Coroutine(def_id, ..) => {
195+
if !self.visited_tys.insert(ty) {
196+
return V::Result::output();
197+
}
198198
try_visit!(self.def_id_visitor.visit_def_id(def_id, "type", &ty));
199199
if V::SHALLOW {
200200
return V::Result::output();
@@ -217,6 +217,9 @@ where
217217
}
218218
}
219219
ty::Alias(kind @ (ty::Inherent | ty::Free | ty::Projection), data) => {
220+
if !self.visited_tys.insert(ty) {
221+
return V::Result::output();
222+
}
220223
if self.def_id_visitor.skip_assoc_tys() {
221224
// Visitors searching for minimal visibility/reachability want to
222225
// conservatively approximate associated types like `Type::Alias`
@@ -248,6 +251,9 @@ where
248251
};
249252
}
250253
ty::Dynamic(predicates, ..) => {
254+
if !self.visited_tys.insert(ty) {
255+
return V::Result::output();
256+
}
251257
// All traits in the list are considered the "primary" part of the type
252258
// and are visited by shallow visitors.
253259
for predicate in predicates {
@@ -263,6 +269,9 @@ where
263269
}
264270
}
265271
ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) => {
272+
if !self.visited_tys.insert(ty) {
273+
return V::Result::output();
274+
}
266275
// The intent is to treat `impl Trait1 + Trait2` identically to
267276
// `dyn Trait1 + Trait2`. Therefore we ignore def-id of the opaque type itself
268277
// (it either has no visibility, or its visibility is insignificant, like
@@ -272,27 +281,33 @@ where
272281
// and are visited by shallow visitors.
273282
try_visit!(self.visit_clauses(tcx.explicit_item_bounds(def_id).skip_binder()));
274283
}
275-
// These types don't have their own def-ids (but may have subcomponents
276-
// with def-ids that should be visited recursively).
284+
// These types have neither their own def-ids nor subcomponents.
277285
ty::Bool
278286
| ty::Char
279287
| ty::Int(..)
280288
| ty::Uint(..)
281289
| ty::Float(..)
282290
| ty::Str
283291
| ty::Never
284-
| ty::Array(..)
292+
| ty::Bound(..)
293+
| ty::Param(..) => return V::Result::output(),
294+
295+
// These types don't have their own def-ids (but may have subcomponents
296+
// with def-ids that should be visited recursively).
297+
ty::Array(..)
285298
| ty::Slice(..)
286299
| ty::Tuple(..)
287300
| ty::RawPtr(..)
288301
| ty::Ref(..)
289302
| ty::Pat(..)
290303
| ty::FnPtr(..)
291304
| ty::UnsafeBinder(_)
292-
| ty::Param(..)
293-
| ty::Bound(..)
294305
| ty::Error(_)
295-
| ty::CoroutineWitness(..) => {}
306+
| ty::CoroutineWitness(..) => {
307+
if !self.visited_tys.insert(ty) {
308+
return V::Result::output();
309+
}
310+
}
296311
ty::Placeholder(..) | ty::Infer(..) => {
297312
bug!("unexpected type: {:?}", ty)
298313
}

0 commit comments

Comments
 (0)