Skip to content

Some symbol and PathRoot cleanups #142767

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/rustc_builtin_macros/src/alloc_error_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ pub(crate) fn expand(
fn generate_handler(cx: &ExtCtxt<'_>, handler: Ident, span: Span, sig_span: Span) -> Stmt {
let usize = cx.path_ident(span, Ident::new(sym::usize, span));
let ty_usize = cx.ty_path(usize);
let size = Ident::from_str_and_span("size", span);
let align = Ident::from_str_and_span("align", span);
let size = Ident::new(sym::size, span);
let align = Ident::new(sym::align, span);

let layout_new = cx.std_path(&[sym::alloc, sym::Layout, sym::from_size_align_unchecked]);
let layout_new = cx.expr_path(cx.path(span, layout_new));
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_builtin_macros/src/autodiff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,8 +652,10 @@ mod llvm_enzyme {
exprs = ecx.expr_call(new_decl_span, bb_call_expr, thin_vec![exprs]);
} else {
let q = QSelf { ty: d_ret_ty, path_span: span, position: 0 };
let y =
ExprKind::Path(Some(P(q)), ecx.path_ident(span, Ident::from_str("default")));
let y = ExprKind::Path(
Some(P(q)),
ecx.path_ident(span, Ident::with_dummy_span(kw::Default)),
);
let default_call_expr = ecx.expr(span, y);
let default_call_expr =
ecx.expr_call(new_decl_span, default_call_expr, thin_vec![]);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/proc_macro_harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub fn inject(
is_test_crate: bool,
dcx: DiagCtxtHandle<'_>,
) {
let ecfg = ExpansionConfig::default("proc_macro".to_string(), features);
let ecfg = ExpansionConfig::default(sym::proc_macro, features);
let mut cx = ExtCtxt::new(sess, ecfg, resolver, None);

let mut collect = CollectProcMacros {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn inject(
let span = DUMMY_SP.with_def_site_ctxt(expn_id.to_expn_id());
let call_site = DUMMY_SP.with_call_site_ctxt(expn_id.to_expn_id());

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

let ident_span = if edition >= Edition2018 { span } else { call_site };
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/test_harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ fn generate_test_harness(
panic_strategy: PanicStrategy,
test_runner: Option<ast::Path>,
) {
let econfig = ExpansionConfig::default("test".to_string(), features);
let econfig = ExpansionConfig::default(sym::test, features);
let ext_cx = ExtCtxt::new(sess, econfig, resolver, None);

let expn_id = ext_cx.resolver.expansion_for_ast_pass(
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_expand/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,12 @@ pub(crate) struct FeatureNotAllowed {
#[derive(Diagnostic)]
#[diag(expand_recursion_limit_reached)]
#[help]
pub(crate) struct RecursionLimitReached<'a> {
pub(crate) struct RecursionLimitReached {
#[primary_span]
pub span: Span,
pub descr: String,
pub suggested_limit: Limit,
pub crate_name: &'a str,
pub crate_name: Symbol,
}

#[derive(Diagnostic)]
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use rustc_session::lint::builtin::{UNUSED_ATTRIBUTES, UNUSED_DOC_COMMENTS};
use rustc_session::parse::feature_err;
use rustc_session::{Limit, Session};
use rustc_span::hygiene::SyntaxContext;
use rustc_span::{ErrorGuaranteed, FileName, Ident, LocalExpnId, Span, sym};
use rustc_span::{ErrorGuaranteed, FileName, Ident, LocalExpnId, Span, Symbol, sym};
use smallvec::SmallVec;

use crate::base::*;
Expand Down Expand Up @@ -473,7 +473,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
let dir_path = file_path.parent().unwrap_or(&file_path).to_owned();
self.cx.root_path = dir_path.clone();
self.cx.current_expansion.module = Rc::new(ModuleData {
mod_path: vec![Ident::from_str(&self.cx.ecfg.crate_name)],
mod_path: vec![Ident::with_dummy_span(self.cx.ecfg.crate_name)],
file_path_stack: vec![file_path],
dir_path,
});
Expand Down Expand Up @@ -689,7 +689,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
span: expn_data.call_site,
descr: expn_data.kind.descr(),
suggested_limit,
crate_name: &self.cx.ecfg.crate_name,
crate_name: self.cx.ecfg.crate_name,
});

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

pub struct ExpansionConfig<'feat> {
pub crate_name: String,
pub crate_name: Symbol,
pub features: &'feat Features,
pub recursion_limit: Limit,
pub trace_mac: bool,
Expand All @@ -2471,7 +2471,7 @@ pub struct ExpansionConfig<'feat> {
}

impl ExpansionConfig<'_> {
pub fn default(crate_name: String, features: &Features) -> ExpansionConfig<'_> {
pub fn default(crate_name: Symbol, features: &Features) -> ExpansionConfig<'_> {
ExpansionConfig {
crate_name,
features,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_pretty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use rustc_hir::{
TyPatKind,
};
use rustc_span::source_map::SourceMap;
use rustc_span::{FileName, Ident, Span, Symbol, kw};
use rustc_span::{FileName, Ident, Span, Symbol, kw, sym};
use {rustc_ast as ast, rustc_hir as hir};

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

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

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ fn configure_and_expand(
// Create the config for macro expansion
let recursion_limit = get_recursion_limit(pre_configured_attrs, sess);
let cfg = rustc_expand::expand::ExpansionConfig {
crate_name: crate_name.to_string(),
crate_name,
features,
recursion_limit,
trace_mac: sess.opts.unstable_opts.trace_macros,
Expand Down
7 changes: 5 additions & 2 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use rustc_session::lint::builtin::{
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES, UNUSED_ATTRIBUTES,
};
use rustc_session::parse::feature_err;
use rustc_span::{BytePos, DUMMY_SP, Span, Symbol, edition, sym};
use rustc_span::{BytePos, DUMMY_SP, Span, Symbol, edition, kw, sym};
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
use rustc_trait_selection::infer::{TyCtxtInferExt, ValuePairs};
use rustc_trait_selection::traits::ObligationCtxt;
Expand Down Expand Up @@ -715,7 +715,10 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
&& !matches!(other_attr.path().as_slice(), [sym::rustfmt, ..])
{
let path = other_attr.path();
let path: Vec<_> = path.iter().map(|s| s.as_str()).collect();
let path: Vec<_> = path
.iter()
.map(|s| if *s == kw::PathRoot { "" } else { s.as_str() })
.collect();
let other_attr_name = path.join("::");

self.dcx().emit_err(errors::NakedFunctionIncompatibleAttribute {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,7 @@ symbols! {
__S,
__awaitee,
__try_var,
_d,
_e,
_t,
_task_context,
a32,
aarch64_target_feature,
Expand Down Expand Up @@ -2052,6 +2051,7 @@ symbols! {
static_recursion,
staticlib,
std,
std_lib_injection,
std_panic,
std_panic_2015_macro,
std_panic_macro,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn is_impl_not_trait_with_bool_out<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -
.and_then(|trait_id| {
cx.tcx.associated_items(trait_id).find_by_ident_and_kind(
cx.tcx,
Ident::from_str("Output"),
Ident::with_dummy_span(sym::Output),
ty::AssocTag::Type,
trait_id,
)
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rustfmt/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl UseSegment {
modsep: bool,
) -> Option<UseSegment> {
let name = rewrite_ident(context, path_seg.ident);
if name.is_empty() || name == "{{root}}" {
if name.is_empty() {
return None;
}
let kind = match name {
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/asm/naked-invalid-attr.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ error[E0736]: attribute incompatible with `#[unsafe(naked)]`
--> $DIR/naked-invalid-attr.rs:56:1
|
LL | #[::a]
| ^^^^^^ the `{{root}}::a` attribute is incompatible with `#[unsafe(naked)]`
| ^^^^^^ the `::a` attribute is incompatible with `#[unsafe(naked)]`
...
LL | #[unsafe(naked)]
| ---------------- function marked with `#[unsafe(naked)]` here
Expand Down
Loading