Skip to content

Commit c960a04

Browse files
committed
Assure everyone that has_type_flags is fast
1 parent e49122f commit c960a04

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

compiler/rustc_middle/src/ty/visit.rs

+8
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ pub trait TypeVisitableExt<'tcx>: TypeVisitable<TyCtxt<'tcx>> {
3333
}
3434

3535
fn has_type_flags(&self, flags: TypeFlags) -> bool {
36+
// N.B. Even though this uses a visitor, the visitor does not actually
37+
// recurse through the whole `TypeVisitable` implementor type.
38+
//
39+
// Instead it stops on the first "level", visiting types, regions,
40+
// consts and predicates just fetches their type flags.
41+
//
42+
// Thus this is a lot faster than it might seem and should be
43+
// optimized to a simple field access.
3644
let res =
3745
self.visit_with(&mut HasTypeFlagsVisitor { flags }).break_value() == Some(FoundFlags);
3846
trace!(?self, ?flags, ?res, "has_type_flags");

0 commit comments

Comments
 (0)