Skip to content

Commit e6b6ba9

Browse files
committed
XXX: DollarCrate
1 parent 03ee0b8 commit e6b6ba9

File tree

10 files changed

+24
-25
lines changed

10 files changed

+24
-25
lines changed

compiler/rustc_builtin_macros/src/deriving/generic/ty.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_ast::ptr::P;
66
use rustc_ast::{self as ast, Expr, GenericArg, GenericParamKind, Generics, SelfKind};
77
use rustc_expand::base::ExtCtxt;
88
use rustc_span::source_map::respan;
9-
use rustc_span::symbol::{Ident, Symbol, kw};
9+
use rustc_span::symbol::{Ident, Symbol, sym};
1010
use rustc_span::{DUMMY_SP, Span};
1111
use thin_vec::ThinVec;
1212

@@ -62,7 +62,7 @@ impl Path {
6262
PathKind::Local => cx.path_all(span, false, idents, params),
6363
PathKind::Std => {
6464
let def_site = cx.with_def_site_ctxt(DUMMY_SP);
65-
idents.insert(0, Ident::new(kw::DollarCrate, def_site));
65+
idents.insert(0, Ident::new(sym::dollar_crate, def_site));
6666
cx.path_all(span, false, idents, params)
6767
}
6868
}

compiler/rustc_expand/src/base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use rustc_span::def_id::{CrateNum, DefId, LocalDefId};
2525
use rustc_span::edition::Edition;
2626
use rustc_span::hygiene::{AstPass, ExpnData, ExpnKind, LocalExpnId, MacroKind};
2727
use rustc_span::source_map::SourceMap;
28-
use rustc_span::symbol::{Ident, Symbol, kw, sym};
28+
use rustc_span::symbol::{Ident, Symbol, sym};
2929
use rustc_span::{DUMMY_SP, FileName, Span};
3030
use smallvec::{SmallVec, smallvec};
3131
use thin_vec::ThinVec;
@@ -1257,7 +1257,7 @@ impl<'a> ExtCtxt<'a> {
12571257
}
12581258
pub fn std_path(&self, components: &[Symbol]) -> Vec<Ident> {
12591259
let def_site = self.with_def_site_ctxt(DUMMY_SP);
1260-
iter::once(Ident::new(kw::DollarCrate, def_site))
1260+
iter::once(Ident::new(sym::dollar_crate, def_site))
12611261
.chain(components.iter().map(|&s| Ident::with_dummy_span(s)))
12621262
.collect()
12631263
}

compiler/rustc_expand/src/mbe/quoted.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ fn parse_tree<'a>(
248248
let (ident, is_raw) = token.ident().unwrap();
249249
let span = ident.span.with_lo(dollar_span.lo());
250250
if ident.name == kw::Crate && matches!(is_raw, IdentIsRaw::No) {
251-
TokenTree::token(token::Ident(kw::DollarCrate, is_raw), span)
251+
TokenTree::token(token::Ident(sym::dollar_crate, is_raw), span)
252252
} else {
253253
TokenTree::MetaVar(span, ident)
254254
}

compiler/rustc_resolve/src/build_reduced_graph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
583583
}
584584

585585
// Disallow `use $crate;`
586-
if source.ident.name == kw::DollarCrate && module_path.is_empty() {
586+
if source.ident.name == sym::dollar_crate && module_path.is_empty() {
587587
let crate_root = self.r.resolve_crate_root(source.ident);
588588
let crate_name = match crate_root.kind {
589589
ModuleKind::Def(.., name) => name,

compiler/rustc_resolve/src/ident.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
850850
ModuleOrUniformRoot::CurrentScope => {
851851
assert_eq!(shadowing, Shadowing::Unrestricted);
852852
if ns == TypeNS {
853-
if ident.name == kw::Crate || ident.name == kw::DollarCrate {
853+
if ident.name == kw::Crate || ident.name == sym::dollar_crate {
854854
let module = self.resolve_crate_root(ident);
855855
return Ok(self.module_self_bindings[&module]);
856856
} else if ident.name == kw::Super || ident.name == kw::SelfLower {
@@ -1497,7 +1497,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
14971497
module = Some(ModuleOrUniformRoot::CrateRootAndExternPrelude);
14981498
continue;
14991499
}
1500-
if name == sym::path_root || name == kw::Crate || name == kw::DollarCrate {
1500+
if name == sym::path_root || name == kw::Crate || name == sym::dollar_crate {
15011501
// `::a::b`, `crate::a::b` or `$crate::a::b`
15021502
let crate_root = self.resolve_crate_root(ident);
15031503
if let Some(res) = crate_root.res() {

compiler/rustc_resolve/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1941,7 +1941,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
19411941
fn resolve_crate_root(&mut self, ident: Ident) -> Module<'ra> {
19421942
debug!("resolve_crate_root({:?})", ident);
19431943
let mut ctxt = ident.span.ctxt();
1944-
let mark = if ident.name == kw::DollarCrate {
1944+
let mark = if ident.name == sym::dollar_crate {
19451945
// When resolving `$crate` from a `macro_rules!` invoked in a `macro`,
19461946
// we don't want to pretend that the `macro_rules!` definition is in the `macro`
19471947
// as described in `SyntaxContext::apply_mark`, so we ignore prepended opaque marks.

compiler/rustc_resolve/src/macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ impl<'ra, 'tcx> ResolverExpand for Resolver<'ra, 'tcx> {
188188

189189
fn resolve_dollar_crates(&mut self) {
190190
hygiene::update_dollar_crate_names(|ctxt| {
191-
let ident = Ident::new(kw::DollarCrate, DUMMY_SP.with_ctxt(ctxt));
191+
let ident = Ident::new(sym::dollar_crate, DUMMY_SP.with_ctxt(ctxt));
192192
match self.resolve_crate_root(ident).kind {
193193
ModuleKind::Def(.., name) if name != sym::empty => name,
194194
_ => kw::Crate,
@@ -749,7 +749,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
749749
&& let [segment] = path.as_slice()
750750
&& segment.ident.span.ctxt().outer_expn_data().local_inner_macros
751751
{
752-
let root = Ident::new(kw::DollarCrate, segment.ident.span);
752+
let root = Ident::new(sym::dollar_crate, segment.ident.span);
753753
path.insert(0, Segment::from_ident(root));
754754
}
755755

compiler/rustc_span/src/hygiene.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use tracing::{debug, trace};
4242

4343
use crate::def_id::{CRATE_DEF_ID, CrateNum, DefId, LOCAL_CRATE, StableCrateId};
4444
use crate::edition::Edition;
45-
use crate::symbol::{Symbol, kw, sym};
45+
use crate::symbol::{Symbol, sym};
4646
use crate::{DUMMY_SP, HashStableContext, Span, SpanDecoder, SpanEncoder, with_session_globals};
4747

4848
/// A `SyntaxContext` represents a chain of pairs `(ExpnId, Transparency)` named "marks".
@@ -366,7 +366,7 @@ impl HygieneData {
366366
parent: SyntaxContext(0),
367367
opaque: SyntaxContext(0),
368368
opaque_and_semitransparent: SyntaxContext(0),
369-
dollar_crate_name: kw::DollarCrate,
369+
dollar_crate_name: sym::dollar_crate,
370370
}],
371371
syntax_context_map: FxHashMap::default(),
372372
expn_data_disambiguators: UnhashMap::default(),
@@ -560,7 +560,7 @@ impl HygieneData {
560560
parent,
561561
opaque: new_opaque,
562562
opaque_and_semitransparent: new_opaque,
563-
dollar_crate_name: kw::DollarCrate,
563+
dollar_crate_name: sym::dollar_crate,
564564
});
565565
new_opaque
566566
});
@@ -580,7 +580,7 @@ impl HygieneData {
580580
parent,
581581
opaque,
582582
opaque_and_semitransparent: new_opaque_and_semitransparent,
583-
dollar_crate_name: kw::DollarCrate,
583+
dollar_crate_name: sym::dollar_crate,
584584
});
585585
new_opaque_and_semitransparent
586586
});
@@ -596,7 +596,7 @@ impl HygieneData {
596596
parent,
597597
opaque,
598598
opaque_and_semitransparent,
599-
dollar_crate_name: kw::DollarCrate,
599+
dollar_crate_name: sym::dollar_crate,
600600
});
601601
new_opaque_and_semitransparent_and_transparent
602602
})
@@ -624,7 +624,7 @@ pub fn update_dollar_crate_names(mut get_name: impl FnMut(SyntaxContext) -> Symb
624624
data.syntax_context_data
625625
.iter()
626626
.rev()
627-
.take_while(|scdata| scdata.dollar_crate_name == kw::DollarCrate)
627+
.take_while(|scdata| scdata.dollar_crate_name == sym::dollar_crate)
628628
.count(),
629629
)
630630
});
@@ -1411,7 +1411,7 @@ pub fn decode_syntax_context<D: Decoder, F: FnOnce(&mut D, u32) -> SyntaxContext
14111411
// Reset `dollar_crate_name` so that it will be updated by `update_dollar_crate_names`
14121412
// We don't care what the encoding crate set this to - we want to resolve it
14131413
// from the perspective of the current compilation session
1414-
ctxt_data.dollar_crate_name = kw::DollarCrate;
1414+
ctxt_data.dollar_crate_name = sym::dollar_crate;
14151415

14161416
// Overwrite the dummy data with our decoded SyntaxContextData
14171417
HygieneData::with(|hygiene_data| {

compiler/rustc_span/src/symbol.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ symbols! {
2626
Keywords {
2727
// Special reserved identifiers used internally for elided lifetimes,
2828
// unnamed method parameters, error recovery etc.
29-
DollarCrate: "$crate",
3029
Underscore: "_",
3130

3231
// Keywords that are used in stable Rust.
@@ -771,6 +770,7 @@ symbols! {
771770
doc_spotlight,
772771
doctest,
773772
document_private_items,
773+
dollar_crate: "$crate",
774774
dotdot: "..",
775775
dotdot_in_tuple_patterns,
776776
dotdoteq_in_patterns,
@@ -2354,7 +2354,7 @@ impl fmt::Display for IdentPrinter {
23542354
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23552355
if self.is_raw {
23562356
f.write_str("r#")?;
2357-
} else if self.symbol == kw::DollarCrate {
2357+
} else if self.symbol == sym::dollar_crate {
23582358
if let Some(span) = self.convert_dollar_crate {
23592359
let converted = span.ctxt().dollar_crate_name();
23602360
if !converted.is_path_segment_keyword() {
@@ -2588,7 +2588,7 @@ pub mod sym {
25882588

25892589
impl Symbol {
25902590
fn is_special(self) -> bool {
2591-
self <= kw::Underscore
2591+
self == sym::dollar_crate || self == kw::Underscore
25922592
}
25932593

25942594
fn is_used_keyword_always(self) -> bool {
@@ -2623,7 +2623,7 @@ impl Symbol {
26232623
|| self == kw::SelfUpper
26242624
|| self == kw::Crate
26252625
|| self == sym::path_root
2626-
|| self == kw::DollarCrate
2626+
|| self == sym::dollar_crate
26272627
}
26282628

26292629
/// Returns `true` if the symbol is `true` or `false`.
@@ -2694,7 +2694,7 @@ impl AllKeywords {
26942694
/// *Note:* Please update this if a new keyword is added beyond the current
26952695
/// range.
26962696
pub fn new() -> Self {
2697-
AllKeywords { curr_idx: kw::DollarCrate.as_u32(), end_idx: kw::Yeet.as_u32() }
2697+
AllKeywords { curr_idx: kw::Underscore.as_u32(), end_idx: kw::Yeet.as_u32() }
26982698
}
26992699

27002700
/// Collect all the keywords in a given edition into a vector.

src/tools/rustfmt/src/parse/macros/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,7 @@ pub(crate) fn parse_expr(
170170
parser.parse_expr().ok()
171171
}
172172

173-
const RUST_KW: [Symbol; 65] = [
174-
kw::DollarCrate,
173+
const RUST_KW: [Symbol; 64] = [
175174
kw::Underscore,
176175
kw::As,
177176
kw::Break,

0 commit comments

Comments
 (0)