Skip to content

Commit 31663db

Browse files
authored
Rollup merge of #142767 - nnethercote:symbol-cleanups, r=petrochenkov
Some symbol and PathRoot cleanups I'm looking into unifying how we join and print paths. Here are some preliminary cleanups. r? ``@petrochenkov``
2 parents 74cea63 + b95d39d commit 31663db

File tree

14 files changed

+29
-24
lines changed

14 files changed

+29
-24
lines changed

compiler/rustc_builtin_macros/src/alloc_error_handler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ pub(crate) fn expand(
6262
fn generate_handler(cx: &ExtCtxt<'_>, handler: Ident, span: Span, sig_span: Span) -> Stmt {
6363
let usize = cx.path_ident(span, Ident::new(sym::usize, span));
6464
let ty_usize = cx.ty_path(usize);
65-
let size = Ident::from_str_and_span("size", span);
66-
let align = Ident::from_str_and_span("align", span);
65+
let size = Ident::new(sym::size, span);
66+
let align = Ident::new(sym::align, span);
6767

6868
let layout_new = cx.std_path(&[sym::alloc, sym::Layout, sym::from_size_align_unchecked]);
6969
let layout_new = cx.expr_path(cx.path(span, layout_new));

compiler/rustc_builtin_macros/src/autodiff.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -652,8 +652,10 @@ mod llvm_enzyme {
652652
exprs = ecx.expr_call(new_decl_span, bb_call_expr, thin_vec![exprs]);
653653
} else {
654654
let q = QSelf { ty: d_ret_ty, path_span: span, position: 0 };
655-
let y =
656-
ExprKind::Path(Some(P(q)), ecx.path_ident(span, Ident::from_str("default")));
655+
let y = ExprKind::Path(
656+
Some(P(q)),
657+
ecx.path_ident(span, Ident::with_dummy_span(kw::Default)),
658+
);
657659
let default_call_expr = ecx.expr(span, y);
658660
let default_call_expr =
659661
ecx.expr_call(new_decl_span, default_call_expr, thin_vec![]);

compiler/rustc_builtin_macros/src/proc_macro_harness.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub fn inject(
5656
is_test_crate: bool,
5757
dcx: DiagCtxtHandle<'_>,
5858
) {
59-
let ecfg = ExpansionConfig::default("proc_macro".to_string(), features);
59+
let ecfg = ExpansionConfig::default(sym::proc_macro, features);
6060
let mut cx = ExtCtxt::new(sess, ecfg, resolver, None);
6161

6262
let mut collect = CollectProcMacros {

compiler/rustc_builtin_macros/src/standard_library_imports.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub fn inject(
3636
let span = DUMMY_SP.with_def_site_ctxt(expn_id.to_expn_id());
3737
let call_site = DUMMY_SP.with_call_site_ctxt(expn_id.to_expn_id());
3838

39-
let ecfg = ExpansionConfig::default("std_lib_injection".to_string(), features);
39+
let ecfg = ExpansionConfig::default(sym::std_lib_injection, features);
4040
let cx = ExtCtxt::new(sess, ecfg, resolver, None);
4141

4242
let ident_span = if edition >= Edition2018 { span } else { call_site };

compiler/rustc_builtin_macros/src/test_harness.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ fn generate_test_harness(
227227
panic_strategy: PanicStrategy,
228228
test_runner: Option<ast::Path>,
229229
) {
230-
let econfig = ExpansionConfig::default("test".to_string(), features);
230+
let econfig = ExpansionConfig::default(sym::test, features);
231231
let ext_cx = ExtCtxt::new(sess, econfig, resolver, None);
232232

233233
let expn_id = ext_cx.resolver.expansion_for_ast_pass(

compiler/rustc_expand/src/errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,12 @@ pub(crate) struct FeatureNotAllowed {
183183
#[derive(Diagnostic)]
184184
#[diag(expand_recursion_limit_reached)]
185185
#[help]
186-
pub(crate) struct RecursionLimitReached<'a> {
186+
pub(crate) struct RecursionLimitReached {
187187
#[primary_span]
188188
pub span: Span,
189189
pub descr: String,
190190
pub suggested_limit: Limit,
191-
pub crate_name: &'a str,
191+
pub crate_name: Symbol,
192192
}
193193

194194
#[derive(Diagnostic)]

compiler/rustc_expand/src/expand.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use rustc_session::lint::builtin::{UNUSED_ATTRIBUTES, UNUSED_DOC_COMMENTS};
2626
use rustc_session::parse::feature_err;
2727
use rustc_session::{Limit, Session};
2828
use rustc_span::hygiene::SyntaxContext;
29-
use rustc_span::{ErrorGuaranteed, FileName, Ident, LocalExpnId, Span, sym};
29+
use rustc_span::{ErrorGuaranteed, FileName, Ident, LocalExpnId, Span, Symbol, sym};
3030
use smallvec::SmallVec;
3131

3232
use crate::base::*;
@@ -473,7 +473,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
473473
let dir_path = file_path.parent().unwrap_or(&file_path).to_owned();
474474
self.cx.root_path = dir_path.clone();
475475
self.cx.current_expansion.module = Rc::new(ModuleData {
476-
mod_path: vec![Ident::from_str(&self.cx.ecfg.crate_name)],
476+
mod_path: vec![Ident::with_dummy_span(self.cx.ecfg.crate_name)],
477477
file_path_stack: vec![file_path],
478478
dir_path,
479479
});
@@ -689,7 +689,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
689689
span: expn_data.call_site,
690690
descr: expn_data.kind.descr(),
691691
suggested_limit,
692-
crate_name: &self.cx.ecfg.crate_name,
692+
crate_name: self.cx.ecfg.crate_name,
693693
});
694694

695695
self.cx.trace_macros_diag();
@@ -2458,7 +2458,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
24582458
}
24592459

24602460
pub struct ExpansionConfig<'feat> {
2461-
pub crate_name: String,
2461+
pub crate_name: Symbol,
24622462
pub features: &'feat Features,
24632463
pub recursion_limit: Limit,
24642464
pub trace_mac: bool,
@@ -2471,7 +2471,7 @@ pub struct ExpansionConfig<'feat> {
24712471
}
24722472

24732473
impl ExpansionConfig<'_> {
2474-
pub fn default(crate_name: String, features: &Features) -> ExpansionConfig<'_> {
2474+
pub fn default(crate_name: Symbol, features: &Features) -> ExpansionConfig<'_> {
24752475
ExpansionConfig {
24762476
crate_name,
24772477
features,

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use rustc_hir::{
2222
TyPatKind,
2323
};
2424
use rustc_span::source_map::SourceMap;
25-
use rustc_span::{FileName, Ident, Span, Symbol, kw};
25+
use rustc_span::{FileName, Ident, Span, Symbol, kw, sym};
2626
use {rustc_ast as ast, rustc_hir as hir};
2727

2828
pub fn id_to_string(cx: &dyn rustc_hir::intravisit::HirTyCtxt<'_>, hir_id: HirId) -> String {
@@ -1517,7 +1517,7 @@ impl<'a> State<'a> {
15171517
self.bopen(ib);
15181518

15191519
// Print `let _t = $init;`:
1520-
let temp = Ident::from_str("_t");
1520+
let temp = Ident::with_dummy_span(sym::_t);
15211521
self.print_local(false, Some(init), None, |this| this.print_ident(temp));
15221522
self.word(";");
15231523

compiler/rustc_interface/src/passes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ fn configure_and_expand(
192192
// Create the config for macro expansion
193193
let recursion_limit = get_recursion_limit(pre_configured_attrs, sess);
194194
let cfg = rustc_expand::expand::ExpansionConfig {
195-
crate_name: crate_name.to_string(),
195+
crate_name,
196196
features,
197197
recursion_limit,
198198
trace_mac: sess.opts.unstable_opts.trace_macros,

compiler/rustc_passes/src/check_attr.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use rustc_session::lint::builtin::{
3535
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES, UNUSED_ATTRIBUTES,
3636
};
3737
use rustc_session::parse::feature_err;
38-
use rustc_span::{BytePos, DUMMY_SP, Span, Symbol, edition, sym};
38+
use rustc_span::{BytePos, DUMMY_SP, Span, Symbol, edition, kw, sym};
3939
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
4040
use rustc_trait_selection::infer::{TyCtxtInferExt, ValuePairs};
4141
use rustc_trait_selection::traits::ObligationCtxt;
@@ -724,7 +724,10 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
724724
&& !matches!(other_attr.path().as_slice(), [sym::rustfmt, ..])
725725
{
726726
let path = other_attr.path();
727-
let path: Vec<_> = path.iter().map(|s| s.as_str()).collect();
727+
let path: Vec<_> = path
728+
.iter()
729+
.map(|s| if *s == kw::PathRoot { "" } else { s.as_str() })
730+
.collect();
728731
let other_attr_name = path.join("::");
729732

730733
self.dcx().emit_err(errors::NakedFunctionIncompatibleAttribute {

compiler/rustc_span/src/symbol.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,7 @@ symbols! {
396396
__S,
397397
__awaitee,
398398
__try_var,
399-
_d,
400-
_e,
399+
_t,
401400
_task_context,
402401
a32,
403402
aarch64_target_feature,
@@ -2052,6 +2051,7 @@ symbols! {
20522051
static_recursion,
20532052
staticlib,
20542053
std,
2054+
std_lib_injection,
20552055
std_panic,
20562056
std_panic_2015_macro,
20572057
std_panic_macro,

src/tools/clippy/clippy_lints/src/bool_assert_comparison.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fn is_impl_not_trait_with_bool_out<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -
5656
.and_then(|trait_id| {
5757
cx.tcx.associated_items(trait_id).find_by_ident_and_kind(
5858
cx.tcx,
59-
Ident::from_str("Output"),
59+
Ident::with_dummy_span(sym::Output),
6060
ty::AssocTag::Type,
6161
trait_id,
6262
)

src/tools/rustfmt/src/imports.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ impl UseSegment {
184184
modsep: bool,
185185
) -> Option<UseSegment> {
186186
let name = rewrite_ident(context, path_seg.ident);
187-
if name.is_empty() || name == "{{root}}" {
187+
if name.is_empty() {
188188
return None;
189189
}
190190
let kind = match name {

tests/ui/asm/naked-invalid-attr.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ error[E0736]: attribute incompatible with `#[unsafe(naked)]`
3737
--> $DIR/naked-invalid-attr.rs:56:1
3838
|
3939
LL | #[::a]
40-
| ^^^^^^ the `{{root}}::a` attribute is incompatible with `#[unsafe(naked)]`
40+
| ^^^^^^ the `::a` attribute is incompatible with `#[unsafe(naked)]`
4141
...
4242
LL | #[unsafe(naked)]
4343
| ---------------- function marked with `#[unsafe(naked)]` here

0 commit comments

Comments
 (0)