Skip to content

Commit cbebdd8

Browse files
authored
Rollup merge of #89991 - petrochenkov:visitok2, r=jackh726
rustc_ast: Turn `MutVisitor::token_visiting_enabled` into a constant It's a visitor property rather than something that needs to be determined at runtime
2 parents 8b7adf6 + d2470e7 commit cbebdd8

File tree

3 files changed

+8
-13
lines changed

3 files changed

+8
-13
lines changed

compiler/rustc_ast/src/mut_visit.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ pub trait MutVisitor: Sized {
3737
/// Mutable token visiting only exists for the `macro_rules` token marker and should not be
3838
/// used otherwise. Token visitor would be entirely separate from the regular visitor if
3939
/// the marker didn't have to visit AST fragments in nonterminal tokens.
40-
fn token_visiting_enabled(&self) -> bool {
41-
false
42-
}
40+
const VISIT_TOKENS: bool = false;
4341

4442
// Methods in this trait have one of three forms:
4543
//
@@ -363,7 +361,7 @@ pub fn visit_mac_args<T: MutVisitor>(args: &mut MacArgs, vis: &mut T) {
363361
}
364362
MacArgs::Eq(eq_span, token) => {
365363
vis.visit_span(eq_span);
366-
if vis.token_visiting_enabled() {
364+
if T::VISIT_TOKENS {
367365
visit_token(token, vis);
368366
} else {
369367
// The value in `#[key = VALUE]` must be visited as an expression for backward
@@ -682,7 +680,7 @@ pub fn visit_tt<T: MutVisitor>(tt: &mut TokenTree, vis: &mut T) {
682680

683681
// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
684682
pub fn visit_tts<T: MutVisitor>(TokenStream(tts): &mut TokenStream, vis: &mut T) {
685-
if vis.token_visiting_enabled() && !tts.is_empty() {
683+
if T::VISIT_TOKENS && !tts.is_empty() {
686684
let tts = Lrc::make_mut(tts);
687685
visit_vec(tts, |(tree, _is_joint)| visit_tt(tree, vis));
688686
}
@@ -692,14 +690,14 @@ pub fn visit_attr_annotated_tts<T: MutVisitor>(
692690
AttrAnnotatedTokenStream(tts): &mut AttrAnnotatedTokenStream,
693691
vis: &mut T,
694692
) {
695-
if vis.token_visiting_enabled() && !tts.is_empty() {
693+
if T::VISIT_TOKENS && !tts.is_empty() {
696694
let tts = Lrc::make_mut(tts);
697695
visit_vec(tts, |(tree, _is_joint)| visit_attr_annotated_tt(tree, vis));
698696
}
699697
}
700698

701699
pub fn visit_lazy_tts_opt_mut<T: MutVisitor>(lazy_tts: Option<&mut LazyTokenStream>, vis: &mut T) {
702-
if vis.token_visiting_enabled() {
700+
if T::VISIT_TOKENS {
703701
if let Some(lazy_tts) = lazy_tts {
704702
let mut tts = lazy_tts.create_token_stream();
705703
visit_attr_annotated_tts(&mut tts, vis);

compiler/rustc_expand/src/mbe/transcribe.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ use std::mem;
1919
struct Marker(LocalExpnId, Transparency);
2020

2121
impl MutVisitor for Marker {
22-
fn token_visiting_enabled(&self) -> bool {
23-
true
24-
}
22+
const VISIT_TOKENS: bool = true;
2523

2624
fn visit_span(&mut self, span: &mut Span) {
2725
*span = span.apply_mark(self.0.to_expn_id(), self.1)

compiler/rustc_expand/src/mut_visit/tests.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ fn print_crate_items(krate: &ast::Crate) -> String {
1515
struct ToZzIdentMutVisitor;
1616

1717
impl MutVisitor for ToZzIdentMutVisitor {
18-
fn token_visiting_enabled(&self) -> bool {
19-
true
20-
}
18+
const VISIT_TOKENS: bool = true;
19+
2120
fn visit_ident(&mut self, ident: &mut Ident) {
2221
*ident = Ident::from_str("zz");
2322
}

0 commit comments

Comments
 (0)