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`
This commit is contained in:
@@ -6,7 +6,7 @@ use rustc_ast::*;
|
|||||||
use rustc_data_structures::fx::FxIndexMap;
|
use rustc_data_structures::fx::FxIndexMap;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_session::config::FmtDebug;
|
use rustc_session::config::FmtDebug;
|
||||||
use rustc_span::{Ident, Span, Symbol, kw, sym};
|
use rustc_span::{Ident, Span, Symbol, sym};
|
||||||
|
|
||||||
use super::LoweringContext;
|
use super::LoweringContext;
|
||||||
|
|
||||||
@@ -418,7 +418,7 @@ fn expand_format_args<'hir>(
|
|||||||
&FormatArgsPiece::Placeholder(_) => {
|
&FormatArgsPiece::Placeholder(_) => {
|
||||||
// Inject empty string before placeholders when not already preceded by a literal piece.
|
// Inject empty string before placeholders when not already preceded by a literal piece.
|
||||||
if i == 0 || matches!(fmt.template[i - 1], FormatArgsPiece::Placeholder(_)) {
|
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 {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
|
|||||||
use rustc_middle::ty::{Instance, Ty};
|
use rustc_middle::ty::{Instance, Ty};
|
||||||
use rustc_middle::{bug, mir, ty};
|
use rustc_middle::{bug, mir, ty};
|
||||||
use rustc_session::config::DebugInfo;
|
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::operand::{OperandRef, OperandValue};
|
||||||
use super::place::{PlaceRef, PlaceValue};
|
use super::place::{PlaceRef, PlaceValue};
|
||||||
@@ -283,7 +283,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
|||||||
// (after #67586 gets fixed).
|
// (after #67586 gets fixed).
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
let name = kw::Empty;
|
let name = sym::empty;
|
||||||
let decl = &self.mir.local_decls[local];
|
let decl = &self.mir.local_decls[local];
|
||||||
let dbg_var = if full_debug_info {
|
let dbg_var = if full_debug_info {
|
||||||
self.adjusted_span_and_dbg_scope(decl.source_info).map(
|
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> {
|
|||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(match whole_local_var.or(fallback_var.clone()) {
|
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:?}"),
|
_ => format!("{local:?}"),
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ impl From<Ident> for LifetimeSyntax {
|
|||||||
fn from(ident: Ident) -> Self {
|
fn from(ident: Ident) -> Self {
|
||||||
let name = ident.name;
|
let name = ident.name;
|
||||||
|
|
||||||
if name == kw::Empty {
|
if name == sym::empty {
|
||||||
unreachable!("A lifetime name should never be empty");
|
unreachable!("A lifetime name should never be empty");
|
||||||
} else if name == kw::UnderscoreLifetime {
|
} else if name == kw::UnderscoreLifetime {
|
||||||
LifetimeSyntax::Anonymous
|
LifetimeSyntax::Anonymous
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ use rustc_session::lint::builtin::{
|
|||||||
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES, UNUSED_ATTRIBUTES,
|
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES, UNUSED_ATTRIBUTES,
|
||||||
};
|
};
|
||||||
use rustc_session::parse::feature_err;
|
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::error_reporting::InferCtxtErrorExt;
|
||||||
use rustc_trait_selection::infer::{TyCtxtInferExt, ValuePairs};
|
use rustc_trait_selection::infer::{TyCtxtInferExt, ValuePairs};
|
||||||
use rustc_trait_selection::traits::ObligationCtxt;
|
use rustc_trait_selection::traits::ObligationCtxt;
|
||||||
@@ -936,7 +936,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
|||||||
let span = meta.name_value_literal_span().unwrap_or_else(|| meta.span());
|
let span = meta.name_value_literal_span().unwrap_or_else(|| meta.span());
|
||||||
let attr_str =
|
let attr_str =
|
||||||
&format!("`#[doc(alias{})]`", if is_list { "(\"...\")" } else { " = \"...\"" });
|
&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 });
|
tcx.dcx().emit_err(errors::DocAliasEmpty { span, attr_str });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1068,7 +1068,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let doc_keyword = match meta.value_str() {
|
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"),
|
_ => return self.doc_attr_str_error(meta, "keyword"),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ use rustc_data_structures::fx::FxIndexMap;
|
|||||||
use rustc_data_structures::unord::UnordSet;
|
use rustc_data_structures::unord::UnordSet;
|
||||||
use rustc_middle::ty::TyCtxt;
|
use rustc_middle::ty::TyCtxt;
|
||||||
use rustc_span::def_id::DefId;
|
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 thin_vec::ThinVec;
|
||||||
use tracing::{debug, trace};
|
use tracing::{debug, trace};
|
||||||
|
|
||||||
@@ -157,7 +157,7 @@ pub fn unindent_doc_fragments(docs: &mut [DocFragment]) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
for fragment in docs {
|
for fragment in docs {
|
||||||
if fragment.doc == kw::Empty {
|
if fragment.doc == sym::empty {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,7 +177,7 @@ pub fn unindent_doc_fragments(docs: &mut [DocFragment]) {
|
|||||||
///
|
///
|
||||||
/// Note: remove the trailing newline where appropriate
|
/// Note: remove the trailing newline where appropriate
|
||||||
pub fn add_doc_fragment(out: &mut String, frag: &DocFragment) {
|
pub fn add_doc_fragment(out: &mut String, frag: &DocFragment) {
|
||||||
if frag.doc == kw::Empty {
|
if frag.doc == sym::empty {
|
||||||
out.push('\n');
|
out.push('\n');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,17 +34,8 @@ symbols! {
|
|||||||
// unnamed method parameters, crate root module, error recovery etc.
|
// unnamed method parameters, crate root module, error recovery etc.
|
||||||
// Matching predicates: `is_special`/`is_reserved`
|
// 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
|
// tidy-alphabetical-start
|
||||||
DollarCrate: "$crate",
|
DollarCrate: "$crate",
|
||||||
Empty: "",
|
|
||||||
PathRoot: "{{root}}",
|
PathRoot: "{{root}}",
|
||||||
Underscore: "_",
|
Underscore: "_",
|
||||||
// tidy-alphabetical-end
|
// tidy-alphabetical-end
|
||||||
@@ -863,7 +854,7 @@ symbols! {
|
|||||||
drop_types_in_const,
|
drop_types_in_const,
|
||||||
dropck_eyepatch,
|
dropck_eyepatch,
|
||||||
dropck_parametricity,
|
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,
|
dummy_cgu_name,
|
||||||
dylib,
|
dylib,
|
||||||
dyn_compatible_for_dispatch,
|
dyn_compatible_for_dispatch,
|
||||||
@@ -882,6 +873,14 @@ symbols! {
|
|||||||
emit_enum_variant_arg,
|
emit_enum_variant_arg,
|
||||||
emit_struct,
|
emit_struct,
|
||||||
emit_struct_field,
|
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,
|
emscripten_wasm_eh,
|
||||||
enable,
|
enable,
|
||||||
encode,
|
encode,
|
||||||
@@ -2361,7 +2360,7 @@ impl Ident {
|
|||||||
#[inline]
|
#[inline]
|
||||||
/// Constructs a new identifier from a symbol and a span.
|
/// Constructs a new identifier from a symbol and a span.
|
||||||
pub fn new(name: Symbol, span: Span) -> Ident {
|
pub fn new(name: Symbol, span: Span) -> Ident {
|
||||||
debug_assert_ne!(name, kw::Empty);
|
debug_assert_ne!(name, sym::empty);
|
||||||
Ident { name, span }
|
Ident { name, span }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2583,7 +2582,7 @@ impl Symbol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_empty(self) -> bool {
|
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
|
/// This method is supposed to be used in error messages, so it's expected to be
|
||||||
@@ -2592,7 +2591,7 @@ impl Symbol {
|
|||||||
/// or edition, so we have to guess the rawness using the global edition.
|
/// or edition, so we have to guess the rawness using the global edition.
|
||||||
pub fn to_ident_string(self) -> String {
|
pub fn to_ident_string(self) -> String {
|
||||||
// Avoid creating an empty identifier, because that asserts in debug builds.
|
// 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() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2772,7 +2771,7 @@ impl Symbol {
|
|||||||
|
|
||||||
/// Returns `true` if this symbol can be a raw identifier.
|
/// Returns `true` if this symbol can be a raw identifier.
|
||||||
pub fn can_be_raw(self) -> bool {
|
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
|
/// Was this symbol predefined in the compiler's `symbols!` macro
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ use rustc_middle::ty::{
|
|||||||
self, FloatTy, GenericArg, GenericArgKind, Instance, IntTy, ReifyReason, Ty, TyCtxt,
|
self, FloatTy, GenericArg, GenericArgKind, Instance, IntTy, ReifyReason, Ty, TyCtxt,
|
||||||
TypeVisitable, TypeVisitableExt, UintTy,
|
TypeVisitable, TypeVisitableExt, UintTy,
|
||||||
};
|
};
|
||||||
use rustc_span::kw;
|
use rustc_span::sym;
|
||||||
|
|
||||||
pub(super) fn mangle<'tcx>(
|
pub(super) fn mangle<'tcx>(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
@@ -902,7 +902,7 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
|
|||||||
print_prefix,
|
print_prefix,
|
||||||
ns,
|
ns,
|
||||||
disambiguated_data.disambiguator as u64,
|
disambiguated_data.disambiguator as u64,
|
||||||
name.unwrap_or(kw::Empty).as_str(),
|
name.unwrap_or(sym::empty).as_str(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use rustc_hir::{Expr, ExprKind, PathSegment, QPath, TyKind};
|
|||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_middle::ty;
|
use rustc_middle::ty;
|
||||||
use rustc_session::declare_lint_pass;
|
use rustc_session::declare_lint_pass;
|
||||||
use rustc_span::{Span, sym, symbol};
|
use rustc_span::{Span, sym};
|
||||||
|
|
||||||
declare_clippy_lint! {
|
declare_clippy_lint! {
|
||||||
/// ### What it does
|
/// ### What it does
|
||||||
@@ -67,7 +67,7 @@ impl LateLintPass<'_> for ManualStringNew {
|
|||||||
fn is_expr_kind_empty_str(expr_kind: &ExprKind<'_>) -> bool {
|
fn is_expr_kind_empty_str(expr_kind: &ExprKind<'_>) -> bool {
|
||||||
if let ExprKind::Lit(lit) = expr_kind
|
if let ExprKind::Lit(lit) = expr_kind
|
||||||
&& let LitKind::Str(value, _) = lit.node
|
&& let LitKind::Str(value, _) = lit.node
|
||||||
&& value == symbol::kw::Empty
|
&& value == sym::empty
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ use rustc_errors::Applicability;
|
|||||||
use rustc_lint::LateContext;
|
use rustc_lint::LateContext;
|
||||||
use rustc_middle::ty;
|
use rustc_middle::ty;
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
use rustc_span::symbol::{self, Symbol};
|
use rustc_span::Symbol;
|
||||||
use {rustc_ast as ast, rustc_hir as hir};
|
use {rustc_ast as ast, rustc_hir as hir};
|
||||||
|
|
||||||
use super::{OR_FUN_CALL, UNWRAP_OR_DEFAULT};
|
use super::{OR_FUN_CALL, UNWRAP_OR_DEFAULT};
|
||||||
@@ -265,7 +265,7 @@ fn closure_body_returns_empty_to_string(cx: &LateContext<'_>, e: &hir::Expr<'_>)
|
|||||||
&& ident.name == sym::to_string
|
&& ident.name == sym::to_string
|
||||||
&& let hir::Expr { kind, .. } = self_arg
|
&& let hir::Expr { kind, .. } = self_arg
|
||||||
&& let hir::ExprKind::Lit(lit) = kind
|
&& 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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user