Skip to content

Commit 225ed8b

Browse files
authored
Rollup merge of #141376 - nnethercote:rename-kw-Empty, r=petrochenkov
Rename `kw::Empty` as `sym::empty`. Because the empty string is not a keyword. r? `@petrochenkov`
2 parents 893494c + 849cabf commit 225ed8b

File tree

9 files changed

+31
-32
lines changed

9 files changed

+31
-32
lines changed

compiler/rustc_ast_lowering/src/format.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_ast::*;
66
use rustc_data_structures::fx::FxIndexMap;
77
use rustc_hir as hir;
88
use rustc_session::config::FmtDebug;
9-
use rustc_span::{Ident, Span, Symbol, kw, sym};
9+
use rustc_span::{Ident, Span, Symbol, sym};
1010

1111
use super::LoweringContext;
1212

@@ -418,7 +418,7 @@ fn expand_format_args<'hir>(
418418
&FormatArgsPiece::Placeholder(_) => {
419419
// Inject empty string before placeholders when not already preceded by a literal piece.
420420
if i == 0 || matches!(fmt.template[i - 1], FormatArgsPiece::Placeholder(_)) {
421-
Some(ctx.expr_str(fmt.span, kw::Empty))
421+
Some(ctx.expr_str(fmt.span, sym::empty))
422422
} else {
423423
None
424424
}

compiler/rustc_codegen_ssa/src/mir/debuginfo.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
1010
use rustc_middle::ty::{Instance, Ty};
1111
use rustc_middle::{bug, mir, ty};
1212
use rustc_session::config::DebugInfo;
13-
use rustc_span::{BytePos, Span, Symbol, hygiene, kw};
13+
use rustc_span::{BytePos, Span, Symbol, hygiene, sym};
1414

1515
use super::operand::{OperandRef, OperandValue};
1616
use super::place::{PlaceRef, PlaceValue};
@@ -283,7 +283,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
283283
// (after #67586 gets fixed).
284284
None
285285
} else {
286-
let name = kw::Empty;
286+
let name = sym::empty;
287287
let decl = &self.mir.local_decls[local];
288288
let dbg_var = if full_debug_info {
289289
self.adjusted_span_and_dbg_scope(decl.source_info).map(
@@ -318,7 +318,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
318318
None
319319
} else {
320320
Some(match whole_local_var.or(fallback_var.clone()) {
321-
Some(var) if var.name != kw::Empty => var.name.to_string(),
321+
Some(var) if var.name != sym::empty => var.name.to_string(),
322322
_ => format!("{local:?}"),
323323
})
324324
};

compiler/rustc_hir/src/hir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl From<Ident> for LifetimeSyntax {
8585
fn from(ident: Ident) -> Self {
8686
let name = ident.name;
8787

88-
if name == kw::Empty {
88+
if name == sym::empty {
8989
unreachable!("A lifetime name should never be empty");
9090
} else if name == kw::UnderscoreLifetime {
9191
LifetimeSyntax::Anonymous

compiler/rustc_passes/src/check_attr.rs

Lines changed: 3 additions & 3 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, kw, sym};
38+
use rustc_span::{BytePos, DUMMY_SP, Span, Symbol, edition, sym};
3939
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
4040
use rustc_trait_selection::infer::{TyCtxtInferExt, ValuePairs};
4141
use rustc_trait_selection::traits::ObligationCtxt;
@@ -936,7 +936,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
936936
let span = meta.name_value_literal_span().unwrap_or_else(|| meta.span());
937937
let attr_str =
938938
&format!("`#[doc(alias{})]`", if is_list { "(\"...\")" } else { " = \"...\"" });
939-
if doc_alias == kw::Empty {
939+
if doc_alias == sym::empty {
940940
tcx.dcx().emit_err(errors::DocAliasEmpty { span, attr_str });
941941
return;
942942
}
@@ -1068,7 +1068,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
10681068
}
10691069

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

compiler/rustc_resolve/src/rustdoc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_data_structures::fx::FxIndexMap;
1212
use rustc_data_structures::unord::UnordSet;
1313
use rustc_middle::ty::TyCtxt;
1414
use rustc_span::def_id::DefId;
15-
use rustc_span::{DUMMY_SP, InnerSpan, Span, Symbol, kw, sym};
15+
use rustc_span::{DUMMY_SP, InnerSpan, Span, Symbol, sym};
1616
use thin_vec::ThinVec;
1717
use tracing::{debug, trace};
1818

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

159159
for fragment in docs {
160-
if fragment.doc == kw::Empty {
160+
if fragment.doc == sym::empty {
161161
continue;
162162
}
163163

@@ -177,7 +177,7 @@ pub fn unindent_doc_fragments(docs: &mut [DocFragment]) {
177177
///
178178
/// Note: remove the trailing newline where appropriate
179179
pub fn add_doc_fragment(out: &mut String, frag: &DocFragment) {
180-
if frag.doc == kw::Empty {
180+
if frag.doc == sym::empty {
181181
out.push('\n');
182182
return;
183183
}

compiler/rustc_span/src/symbol.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,8 @@ symbols! {
3434
// unnamed method parameters, crate root module, error recovery etc.
3535
// Matching predicates: `is_special`/`is_reserved`
3636
//
37-
// Notes about `kw::Empty`:
38-
// - Its use can blur the lines between "empty symbol" and "no symbol".
39-
// Using `Option<Symbol>` is preferable, where possible, because that
40-
// is unambiguous.
41-
// - For dummy symbols that are never used and absolutely must be
42-
// present, it's better to use `sym::dummy` than `kw::Empty`, because
43-
// it's clearer that it's intended as a dummy value, and more likely
44-
// to be detected if it accidentally does get used.
4537
// tidy-alphabetical-start
4638
DollarCrate: "$crate",
47-
Empty: "",
4839
PathRoot: "{{root}}",
4940
Underscore: "_",
5041
// tidy-alphabetical-end
@@ -863,7 +854,7 @@ symbols! {
863854
drop_types_in_const,
864855
dropck_eyepatch,
865856
dropck_parametricity,
866-
dummy: "<!dummy!>", // use this instead of `kw::Empty` for symbols that won't be used
857+
dummy: "<!dummy!>", // use this instead of `sym::empty` for symbols that won't be used
867858
dummy_cgu_name,
868859
dylib,
869860
dyn_compatible_for_dispatch,
@@ -882,6 +873,14 @@ symbols! {
882873
emit_enum_variant_arg,
883874
emit_struct,
884875
emit_struct_field,
876+
// Notes about `sym::empty`:
877+
// - It should only be used when it genuinely means "empty symbol". Use
878+
// `Option<Symbol>` when "no symbol" is a possibility.
879+
// - For dummy symbols that are never used and absolutely must be
880+
// present, it's better to use `sym::dummy` than `sym::empty`, because
881+
// it's clearer that it's intended as a dummy value, and more likely
882+
// to be detected if it accidentally does get used.
883+
empty: "",
885884
emscripten_wasm_eh,
886885
enable,
887886
encode,
@@ -2361,7 +2360,7 @@ impl Ident {
23612360
#[inline]
23622361
/// Constructs a new identifier from a symbol and a span.
23632362
pub fn new(name: Symbol, span: Span) -> Ident {
2364-
debug_assert_ne!(name, kw::Empty);
2363+
debug_assert_ne!(name, sym::empty);
23652364
Ident { name, span }
23662365
}
23672366

@@ -2583,7 +2582,7 @@ impl Symbol {
25832582
}
25842583

25852584
pub fn is_empty(self) -> bool {
2586-
self == kw::Empty
2585+
self == sym::empty
25872586
}
25882587

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

@@ -2772,7 +2771,7 @@ impl Symbol {
27722771

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

27782777
/// Was this symbol predefined in the compiler's `symbols!` macro

compiler/rustc_symbol_mangling/src/v0.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc_middle::ty::{
2020
self, FloatTy, GenericArg, GenericArgKind, Instance, IntTy, ReifyReason, Ty, TyCtxt,
2121
TypeVisitable, TypeVisitableExt, UintTy,
2222
};
23-
use rustc_span::kw;
23+
use rustc_span::sym;
2424

2525
pub(super) fn mangle<'tcx>(
2626
tcx: TyCtxt<'tcx>,
@@ -902,7 +902,7 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
902902
print_prefix,
903903
ns,
904904
disambiguated_data.disambiguator as u64,
905-
name.unwrap_or(kw::Empty).as_str(),
905+
name.unwrap_or(sym::empty).as_str(),
906906
)
907907
}
908908

src/tools/clippy/clippy_lints/src/manual_string_new.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_hir::{Expr, ExprKind, PathSegment, QPath, TyKind};
55
use rustc_lint::{LateContext, LateLintPass};
66
use rustc_middle::ty;
77
use rustc_session::declare_lint_pass;
8-
use rustc_span::{Span, sym, symbol};
8+
use rustc_span::{Span, sym};
99

1010
declare_clippy_lint! {
1111
/// ### What it does
@@ -67,7 +67,7 @@ impl LateLintPass<'_> for ManualStringNew {
6767
fn is_expr_kind_empty_str(expr_kind: &ExprKind<'_>) -> bool {
6868
if let ExprKind::Lit(lit) = expr_kind
6969
&& let LitKind::Str(value, _) = lit.node
70-
&& value == symbol::kw::Empty
70+
&& value == sym::empty
7171
{
7272
return true;
7373
}

src/tools/clippy/clippy_lints/src/methods/or_fun_call.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_errors::Applicability;
1212
use rustc_lint::LateContext;
1313
use rustc_middle::ty;
1414
use rustc_span::Span;
15-
use rustc_span::symbol::{self, Symbol};
15+
use rustc_span::Symbol;
1616
use {rustc_ast as ast, rustc_hir as hir};
1717

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

0 commit comments

Comments
 (0)