Skip to content

Rename kw::Empty as sym::empty. #141376

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

Merged
merged 1 commit into from
May 23, 2025
Merged
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_ast_lowering/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use rustc_ast::*;
use rustc_data_structures::fx::FxIndexMap;
use rustc_hir as hir;
use rustc_session::config::FmtDebug;
use rustc_span::{Ident, Span, Symbol, kw, sym};
use rustc_span::{Ident, Span, Symbol, sym};

use super::LoweringContext;

Expand Down Expand Up @@ -418,7 +418,7 @@ fn expand_format_args<'hir>(
&FormatArgsPiece::Placeholder(_) => {
// Inject empty string before placeholders when not already preceded by a literal piece.
if i == 0 || matches!(fmt.template[i - 1], FormatArgsPiece::Placeholder(_)) {
Some(ctx.expr_str(fmt.span, kw::Empty))
Some(ctx.expr_str(fmt.span, sym::empty))
} else {
None
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_ssa/src/mir/debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
use rustc_middle::ty::{Instance, Ty};
use rustc_middle::{bug, mir, ty};
use rustc_session::config::DebugInfo;
use rustc_span::{BytePos, Span, Symbol, hygiene, kw};
use rustc_span::{BytePos, Span, Symbol, hygiene, sym};

use super::operand::{OperandRef, OperandValue};
use super::place::{PlaceRef, PlaceValue};
Expand Down Expand Up @@ -283,7 +283,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
// (after #67586 gets fixed).
None
} else {
let name = kw::Empty;
let name = sym::empty;
let decl = &self.mir.local_decls[local];
let dbg_var = if full_debug_info {
self.adjusted_span_and_dbg_scope(decl.source_info).map(
Expand Down Expand Up @@ -318,7 +318,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
None
} else {
Some(match whole_local_var.or(fallback_var.clone()) {
Some(var) if var.name != kw::Empty => var.name.to_string(),
Some(var) if var.name != sym::empty => var.name.to_string(),
_ => format!("{local:?}"),
})
};
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl From<Ident> for LifetimeSyntax {
fn from(ident: Ident) -> Self {
let name = ident.name;

if name == kw::Empty {
if name == sym::empty {
unreachable!("A lifetime name should never be empty");
} else if name == kw::UnderscoreLifetime {
LifetimeSyntax::Anonymous
Expand Down
6 changes: 3 additions & 3 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, kw, sym};
use rustc_span::{BytePos, DUMMY_SP, Span, Symbol, edition, 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 @@ -936,7 +936,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
let span = meta.name_value_literal_span().unwrap_or_else(|| meta.span());
let attr_str =
&format!("`#[doc(alias{})]`", if is_list { "(\"...\")" } else { " = \"...\"" });
if doc_alias == kw::Empty {
if doc_alias == sym::empty {
tcx.dcx().emit_err(errors::DocAliasEmpty { span, attr_str });
return;
}
Expand Down Expand Up @@ -1068,7 +1068,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
}

let doc_keyword = match meta.value_str() {
Some(value) if value != kw::Empty => value,
Some(value) if value != sym::empty => value,
_ => return self.doc_attr_str_error(meta, "keyword"),
};

Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_resolve/src/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::unord::UnordSet;
use rustc_middle::ty::TyCtxt;
use rustc_span::def_id::DefId;
use rustc_span::{DUMMY_SP, InnerSpan, Span, Symbol, kw, sym};
use rustc_span::{DUMMY_SP, InnerSpan, Span, Symbol, sym};
use thin_vec::ThinVec;
use tracing::{debug, trace};

Expand Down Expand Up @@ -157,7 +157,7 @@ pub fn unindent_doc_fragments(docs: &mut [DocFragment]) {
};

for fragment in docs {
if fragment.doc == kw::Empty {
if fragment.doc == sym::empty {
continue;
}

Expand All @@ -177,7 +177,7 @@ pub fn unindent_doc_fragments(docs: &mut [DocFragment]) {
///
/// Note: remove the trailing newline where appropriate
pub fn add_doc_fragment(out: &mut String, frag: &DocFragment) {
if frag.doc == kw::Empty {
if frag.doc == sym::empty {
out.push('\n');
return;
}
Expand Down
27 changes: 13 additions & 14 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,8 @@ symbols! {
// unnamed method parameters, crate root module, error recovery etc.
// Matching predicates: `is_special`/`is_reserved`
//
// Notes about `kw::Empty`:
// - Its use can blur the lines between "empty symbol" and "no symbol".
// Using `Option<Symbol>` is preferable, where possible, because that
// is unambiguous.
// - For dummy symbols that are never used and absolutely must be
// present, it's better to use `sym::dummy` than `kw::Empty`, because
// it's clearer that it's intended as a dummy value, and more likely
// to be detected if it accidentally does get used.
// tidy-alphabetical-start
DollarCrate: "$crate",
Empty: "",
PathRoot: "{{root}}",
Underscore: "_",
// tidy-alphabetical-end
Expand Down Expand Up @@ -864,7 +855,7 @@ symbols! {
drop_types_in_const,
dropck_eyepatch,
dropck_parametricity,
dummy: "<!dummy!>", // use this instead of `kw::Empty` for symbols that won't be used
dummy: "<!dummy!>", // use this instead of `sym::empty` for symbols that won't be used
dummy_cgu_name,
dylib,
dyn_compatible_for_dispatch,
Expand All @@ -883,6 +874,14 @@ symbols! {
emit_enum_variant_arg,
emit_struct,
emit_struct_field,
// Notes about `sym::empty`:
// - It should only be used when it genuinely means "empty symbol". Use
// `Option<Symbol>` when "no symbol" is a possibility.
// - For dummy symbols that are never used and absolutely must be
// present, it's better to use `sym::dummy` than `sym::empty`, because
// it's clearer that it's intended as a dummy value, and more likely
// to be detected if it accidentally does get used.
empty: "",
emscripten_wasm_eh,
enable,
encode,
Expand Down Expand Up @@ -2362,7 +2361,7 @@ impl Ident {
#[inline]
/// Constructs a new identifier from a symbol and a span.
pub fn new(name: Symbol, span: Span) -> Ident {
debug_assert_ne!(name, kw::Empty);
debug_assert_ne!(name, sym::empty);
Ident { name, span }
}

Expand Down Expand Up @@ -2584,7 +2583,7 @@ impl Symbol {
}

pub fn is_empty(self) -> bool {
self == kw::Empty
self == sym::empty
}

/// This method is supposed to be used in error messages, so it's expected to be
Expand All @@ -2593,7 +2592,7 @@ impl Symbol {
/// or edition, so we have to guess the rawness using the global edition.
pub fn to_ident_string(self) -> String {
// Avoid creating an empty identifier, because that asserts in debug builds.
if self == kw::Empty { String::new() } else { Ident::with_dummy_span(self).to_string() }
if self == sym::empty { String::new() } else { Ident::with_dummy_span(self).to_string() }
}
}

Expand Down Expand Up @@ -2773,7 +2772,7 @@ impl Symbol {

/// Returns `true` if this symbol can be a raw identifier.
pub fn can_be_raw(self) -> bool {
self != kw::Empty && self != kw::Underscore && !self.is_path_segment_keyword()
self != sym::empty && self != kw::Underscore && !self.is_path_segment_keyword()
}

/// Was this symbol predefined in the compiler's `symbols!` macro
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_symbol_mangling/src/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use rustc_middle::ty::{
self, FloatTy, GenericArg, GenericArgKind, Instance, IntTy, ReifyReason, Ty, TyCtxt,
TypeVisitable, TypeVisitableExt, UintTy,
};
use rustc_span::kw;
use rustc_span::sym;

pub(super) fn mangle<'tcx>(
tcx: TyCtxt<'tcx>,
Expand Down Expand Up @@ -902,7 +902,7 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
print_prefix,
ns,
disambiguated_data.disambiguator as u64,
name.unwrap_or(kw::Empty).as_str(),
name.unwrap_or(sym::empty).as_str(),
)
}

Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/clippy_lints/src/manual_string_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rustc_hir::{Expr, ExprKind, PathSegment, QPath, TyKind};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty;
use rustc_session::declare_lint_pass;
use rustc_span::{Span, sym, symbol};
use rustc_span::{Span, sym};

declare_clippy_lint! {
/// ### What it does
Expand Down Expand Up @@ -67,7 +67,7 @@ impl LateLintPass<'_> for ManualStringNew {
fn is_expr_kind_empty_str(expr_kind: &ExprKind<'_>) -> bool {
if let ExprKind::Lit(lit) = expr_kind
&& let LitKind::Str(value, _) = lit.node
&& value == symbol::kw::Empty
&& value == sym::empty
{
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/clippy_lints/src/methods/or_fun_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rustc_errors::Applicability;
use rustc_lint::LateContext;
use rustc_middle::ty;
use rustc_span::Span;
use rustc_span::symbol::{self, Symbol};
use rustc_span::Symbol;
use {rustc_ast as ast, rustc_hir as hir};

use super::{OR_FUN_CALL, UNWRAP_OR_DEFAULT};
Expand Down Expand Up @@ -265,7 +265,7 @@ fn closure_body_returns_empty_to_string(cx: &LateContext<'_>, e: &hir::Expr<'_>)
&& ident.name == sym::to_string
&& let hir::Expr { kind, .. } = self_arg
&& let hir::ExprKind::Lit(lit) = kind
&& let ast::LitKind::Str(symbol::kw::Empty, _) = lit.node
&& let ast::LitKind::Str(rustc_span::sym::empty, _) = lit.node
{
return true;
}
Expand Down
Loading