Skip to content

Commit

Permalink
Unrolled build for rust-lang#137977
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#137977 - nnethercote:less-kw-Empty-1, r=spastorino

Reduce `kw::Empty` usage, part 1

This PR fixes some confusing `kw::Empty` usage, fixing a crash test along the way.

r? ```@spastorino```
  • Loading branch information
rust-timer authored Mar 7, 2025
2 parents c53af1c + af92a33 commit 0b6c069
Show file tree
Hide file tree
Showing 19 changed files with 125 additions and 83 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use rustc_middle::span_bug;
use rustc_middle::ty::TyCtxt;
use rustc_session::errors::report_lit_error;
use rustc_span::source_map::{Spanned, respan};
use rustc_span::{DUMMY_SP, DesugaringKind, Ident, Span, Symbol, kw, sym};
use rustc_span::{DUMMY_SP, DesugaringKind, Ident, Span, Symbol, sym};
use thin_vec::{ThinVec, thin_vec};
use visit::{Visitor, walk_expr};

Expand Down Expand Up @@ -483,7 +483,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
if legacy_args_idx.contains(&idx) {
let parent_def_id = self.current_hir_id_owner.def_id;
let node_id = self.next_node_id();
self.create_def(parent_def_id, node_id, kw::Empty, DefKind::AnonConst, f.span);
self.create_def(parent_def_id, node_id, None, DefKind::AnonConst, f.span);
let mut visitor = WillCreateDefIdsVisitor {};
let const_value = if let ControlFlow::Break(span) = visitor.visit_expr(&arg) {
AstP(Expr {
Expand Down
7 changes: 3 additions & 4 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
&mut self,
parent: LocalDefId,
node_id: ast::NodeId,
name: Symbol,
name: Option<Symbol>,
def_kind: DefKind,
span: Span,
) -> LocalDefId {
Expand Down Expand Up @@ -774,7 +774,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let _def_id = self.create_def(
self.current_hir_id_owner.def_id,
param,
kw::UnderscoreLifetime,
Some(kw::UnderscoreLifetime),
DefKind::LifetimeParam,
ident.span,
);
Expand Down Expand Up @@ -2089,8 +2089,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// We're lowering a const argument that was originally thought to be a type argument,
// so the def collector didn't create the def ahead of time. That's why we have to do
// it here.
let def_id =
self.create_def(parent_def_id, node_id, kw::Empty, DefKind::AnonConst, span);
let def_id = self.create_def(parent_def_id, node_id, None, DefKind::AnonConst, span);
let hir_id = self.lower_node_id(node_id);

let path_expr = Expr {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_lowering/src/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use rustc_hir::def::{DefKind, Res};
use rustc_hir::{self as hir, LangItem};
use rustc_middle::span_bug;
use rustc_span::source_map::{Spanned, respan};
use rustc_span::{DesugaringKind, Ident, Span, kw};
use rustc_span::{DesugaringKind, Ident, Span};

use super::errors::{
ArbitraryExpressionInPattern, ExtraDoubleDot, MisplacedDoubleDot, SubTupleBinding,
Expand Down Expand Up @@ -523,7 +523,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// We're generating a range end that didn't exist in the AST,
// so the def collector didn't create the def ahead of time. That's why we have to do
// it here.
let def_id = self.create_def(parent_def_id, node_id, kw::Empty, DefKind::AnonConst, span);
let def_id = self.create_def(parent_def_id, node_id, None, DefKind::AnonConst, span);
let hir_id = self.lower_node_id(node_id);

let unstable_span = self.mark_span_with_reason(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/interpret/intern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ fn intern_as_new_static<'tcx>(
) {
let feed = tcx.create_def(
static_id,
sym::nested,
Some(sym::nested),
DefKind::Static { safety: hir::Safety::Safe, mutability: alloc.0.mutability, nested: true },
);
tcx.set_nested_alloc_id_static(alloc_id, feed.def_id());
Expand Down
18 changes: 12 additions & 6 deletions compiler/rustc_hir/src/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,9 @@ impl DefKind {
}
}

pub fn def_path_data(self, name: Symbol) -> DefPathData {
// Some `DefKind`s require a name, some don't. Panics if one is needed but
// not provided. (`AssocTy` is an exception, see below.)
pub fn def_path_data(self, name: Option<Symbol>) -> DefPathData {
match self {
DefKind::Mod
| DefKind::Struct
Expand All @@ -264,9 +266,13 @@ impl DefKind {
| DefKind::TyAlias
| DefKind::ForeignTy
| DefKind::TraitAlias
| DefKind::AssocTy
| DefKind::TyParam
| DefKind::ExternCrate => DefPathData::TypeNs(name),
| DefKind::ExternCrate => DefPathData::TypeNs(Some(name.unwrap())),

// An associated type names will be missing for an RPITIT. It will
// later be given a name with `synthetic` in it, if necessary.
DefKind::AssocTy => DefPathData::TypeNs(name),

// It's not exactly an anon const, but wrt DefPathData, there
// is no difference.
DefKind::Static { nested: true, .. } => DefPathData::AnonConst,
Expand All @@ -276,9 +282,9 @@ impl DefKind {
| DefKind::Static { .. }
| DefKind::AssocFn
| DefKind::AssocConst
| DefKind::Field => DefPathData::ValueNs(name),
DefKind::Macro(..) => DefPathData::MacroNs(name),
DefKind::LifetimeParam => DefPathData::LifetimeNs(name),
| DefKind::Field => DefPathData::ValueNs(name.unwrap()),
DefKind::Macro(..) => DefPathData::MacroNs(name.unwrap()),
DefKind::LifetimeParam => DefPathData::LifetimeNs(name.unwrap()),
DefKind::Ctor(..) => DefPathData::Ctor,
DefKind::Use => DefPathData::Use,
DefKind::ForeignMod => DefPathData::ForeignMod,
Expand Down
22 changes: 13 additions & 9 deletions compiler/rustc_hir/src/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,9 @@ pub enum DefPathData {
Use,
/// A global asm item.
GlobalAsm,
/// Something in the type namespace.
TypeNs(Symbol),
/// Something in the type namespace. Will be empty for RPITIT associated
/// types, which are given a synthetic name later, if necessary.
TypeNs(Option<Symbol>),
/// Something in the value namespace.
ValueNs(Symbol),
/// Something in the macro namespace.
Expand Down Expand Up @@ -410,8 +411,9 @@ impl DefPathData {
pub fn get_opt_name(&self) -> Option<Symbol> {
use self::DefPathData::*;
match *self {
TypeNs(name) if name == kw::Empty => None,
TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) => Some(name),
TypeNs(name) => name,

ValueNs(name) | MacroNs(name) | LifetimeNs(name) => Some(name),

Impl | ForeignMod | CrateRoot | Use | GlobalAsm | Closure | Ctor | AnonConst
| OpaqueTy => None,
Expand All @@ -421,12 +423,14 @@ impl DefPathData {
pub fn name(&self) -> DefPathDataName {
use self::DefPathData::*;
match *self {
TypeNs(name) if name == kw::Empty => {
DefPathDataName::Anon { namespace: sym::synthetic }
}
TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) => {
DefPathDataName::Named(name)
TypeNs(name) => {
if let Some(name) = name {
DefPathDataName::Named(name)
} else {
DefPathDataName::Anon { namespace: sym::synthetic }
}
}
ValueNs(name) | MacroNs(name) | LifetimeNs(name) => DefPathDataName::Named(name),
// Note that this does not show up in user print-outs.
CrateRoot => DefPathDataName::Anon { namespace: kw::Crate },
Impl => DefPathDataName::Anon { namespace: kw::Impl },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1462,7 +1462,8 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
for &(opaque_def_id, captures) in opaque_capture_scopes.iter().rev() {
let mut captures = captures.borrow_mut();
let remapped = *captures.entry(lifetime).or_insert_with(|| {
let feed = self.tcx.create_def(opaque_def_id, ident.name, DefKind::LifetimeParam);
let feed =
self.tcx.create_def(opaque_def_id, Some(ident.name), DefKind::LifetimeParam);
feed.def_span(ident.span);
feed.def_ident_span(Some(ident.span));
feed.def_id()
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1890,7 +1890,7 @@ impl<'tcx> TyCtxtAt<'tcx> {
pub fn create_def(
self,
parent: LocalDefId,
name: Symbol,
name: Option<Symbol>,
def_kind: DefKind,
) -> TyCtxtFeed<'tcx, LocalDefId> {
let feed = self.tcx.create_def(parent, name, def_kind);
Expand All @@ -1905,7 +1905,7 @@ impl<'tcx> TyCtxt<'tcx> {
pub fn create_def(
self,
parent: LocalDefId,
name: Symbol,
name: Option<Symbol>,
def_kind: DefKind,
) -> TyCtxtFeed<'tcx, LocalDefId> {
let data = def_kind.def_path_data(name);
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
// the children of the visible parent (as was done when computing
// `visible_parent_map`), looking for the specific child we currently have and then
// have access to the re-exported name.
DefPathData::TypeNs(ref mut name) if Some(visible_parent) != actual_parent => {
DefPathData::TypeNs(Some(ref mut name)) if Some(visible_parent) != actual_parent => {
// Item might be re-exported several times, but filter for the one
// that's public and whose identifier isn't `_`.
let reexport = self
Expand All @@ -590,7 +590,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
}
// Re-exported `extern crate` (#43189).
DefPathData::CrateRoot => {
data = DefPathData::TypeNs(self.tcx().crate_name(def_id.krate));
data = DefPathData::TypeNs(Some(self.tcx().crate_name(def_id.krate)));
}
_ => {}
}
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_middle/src/ty/significant_drop_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ fn true_significant_drop_ty<'tcx>(

match key.disambiguated_data.data {
rustc_hir::definitions::DefPathData::CrateRoot => {
name_rev.push(tcx.crate_name(did.krate))
name_rev.push(tcx.crate_name(did.krate));
}
rustc_hir::definitions::DefPathData::TypeNs(symbol) => {
name_rev.push(symbol.unwrap());
}
rustc_hir::definitions::DefPathData::TypeNs(symbol) => name_rev.push(symbol),
_ => return None,
}
if let Some(parent) = key.parent {
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_mir_transform/src/coroutine/by_move_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ use rustc_middle::hir::place::{Projection, ProjectionKind};
use rustc_middle::mir::visit::MutVisitor;
use rustc_middle::mir::{self, dump_mir};
use rustc_middle::ty::{self, InstanceKind, Ty, TyCtxt, TypeVisitableExt};
use rustc_span::kw;

pub(crate) fn coroutine_by_move_body_def_id<'tcx>(
tcx: TyCtxt<'tcx>,
Expand Down Expand Up @@ -214,7 +213,7 @@ pub(crate) fn coroutine_by_move_body_def_id<'tcx>(
MakeByMoveBody { tcx, field_remapping, by_move_coroutine_ty }.visit_body(&mut by_move_body);

// This will always be `{closure#1}`, since the original coroutine is `{closure#0}`.
let body_def = tcx.create_def(parent_def_id, kw::Empty, DefKind::SyntheticCoroutineBody);
let body_def = tcx.create_def(parent_def_id, None, DefKind::SyntheticCoroutineBody);
by_move_body.source =
mir::MirSource::from_instance(InstanceKind::Item(body_def.def_id().to_def_id()));
dump_mir(tcx, false, "built", &"after", &by_move_body, |_, _| Ok(()));
Expand Down
Loading

0 comments on commit 0b6c069

Please sign in to comment.