Skip to content

Commit 5606653

Browse files
authored
Rollup merge of rust-lang#110465 - WaffleLapkin:assure_everyone_that_has_type_flags_is_fast, r=oli-obk
Assure everyone that `has_type_flags` is fast `number_of_people_who_tripped_on_this += 1` r? ``@oli-obk``
2 parents d97b39d + c960a04 commit 5606653

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)