Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0defc4f

Browse files
authoredMar 7, 2025
Rollup merge of #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```
2 parents 63c548d + af92a33 commit 0defc4f

File tree

19 files changed

+125
-83
lines changed

19 files changed

+125
-83
lines changed
 

‎compiler/rustc_ast_lowering/src/expr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_middle::span_bug;
1313
use rustc_middle::ty::TyCtxt;
1414
use rustc_session::errors::report_lit_error;
1515
use rustc_span::source_map::{Spanned, respan};
16-
use rustc_span::{DUMMY_SP, DesugaringKind, Ident, Span, Symbol, kw, sym};
16+
use rustc_span::{DUMMY_SP, DesugaringKind, Ident, Span, Symbol, sym};
1717
use thin_vec::{ThinVec, thin_vec};
1818
use visit::{Visitor, walk_expr};
1919

@@ -484,7 +484,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
484484
if legacy_args_idx.contains(&idx) {
485485
let parent_def_id = self.current_hir_id_owner.def_id;
486486
let node_id = self.next_node_id();
487-
self.create_def(parent_def_id, node_id, kw::Empty, DefKind::AnonConst, f.span);
487+
self.create_def(parent_def_id, node_id, None, DefKind::AnonConst, f.span);
488488
let mut visitor = WillCreateDefIdsVisitor {};
489489
let const_value = if let ControlFlow::Break(span) = visitor.visit_expr(&arg) {
490490
AstP(Expr {

‎compiler/rustc_ast_lowering/src/lib.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
494494
&mut self,
495495
parent: LocalDefId,
496496
node_id: ast::NodeId,
497-
name: Symbol,
497+
name: Option<Symbol>,
498498
def_kind: DefKind,
499499
span: Span,
500500
) -> LocalDefId {
@@ -774,7 +774,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
774774
let _def_id = self.create_def(
775775
self.current_hir_id_owner.def_id,
776776
param,
777-
kw::UnderscoreLifetime,
777+
Some(kw::UnderscoreLifetime),
778778
DefKind::LifetimeParam,
779779
ident.span,
780780
);
@@ -2089,8 +2089,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20892089
// We're lowering a const argument that was originally thought to be a type argument,
20902090
// so the def collector didn't create the def ahead of time. That's why we have to do
20912091
// it here.
2092-
let def_id =
2093-
self.create_def(parent_def_id, node_id, kw::Empty, DefKind::AnonConst, span);
2092+
let def_id = self.create_def(parent_def_id, node_id, None, DefKind::AnonConst, span);
20942093
let hir_id = self.lower_node_id(node_id);
20952094

20962095
let path_expr = Expr {

‎compiler/rustc_ast_lowering/src/pat.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_hir::def::{DefKind, Res};
77
use rustc_hir::{self as hir, LangItem};
88
use rustc_middle::span_bug;
99
use rustc_span::source_map::{Spanned, respan};
10-
use rustc_span::{DesugaringKind, Ident, Span, kw};
10+
use rustc_span::{DesugaringKind, Ident, Span};
1111

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

529529
let unstable_span = self.mark_span_with_reason(

‎compiler/rustc_const_eval/src/interpret/intern.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ fn intern_as_new_static<'tcx>(
104104
) {
105105
let feed = tcx.create_def(
106106
static_id,
107-
sym::nested,
107+
Some(sym::nested),
108108
DefKind::Static { safety: hir::Safety::Safe, mutability: alloc.0.mutability, nested: true },
109109
);
110110
tcx.set_nested_alloc_id_static(alloc_id, feed.def_id());

‎compiler/rustc_hir/src/def.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,9 @@ impl DefKind {
253253
}
254254
}
255255

256-
pub fn def_path_data(self, name: Symbol) -> DefPathData {
256+
// Some `DefKind`s require a name, some don't. Panics if one is needed but
257+
// not provided. (`AssocTy` is an exception, see below.)
258+
pub fn def_path_data(self, name: Option<Symbol>) -> DefPathData {
257259
match self {
258260
DefKind::Mod
259261
| DefKind::Struct
@@ -264,9 +266,13 @@ impl DefKind {
264266
| DefKind::TyAlias
265267
| DefKind::ForeignTy
266268
| DefKind::TraitAlias
267-
| DefKind::AssocTy
268269
| DefKind::TyParam
269-
| DefKind::ExternCrate => DefPathData::TypeNs(name),
270+
| DefKind::ExternCrate => DefPathData::TypeNs(Some(name.unwrap())),
271+
272+
// An associated type names will be missing for an RPITIT. It will
273+
// later be given a name with `synthetic` in it, if necessary.
274+
DefKind::AssocTy => DefPathData::TypeNs(name),
275+
270276
// It's not exactly an anon const, but wrt DefPathData, there
271277
// is no difference.
272278
DefKind::Static { nested: true, .. } => DefPathData::AnonConst,
@@ -276,9 +282,9 @@ impl DefKind {
276282
| DefKind::Static { .. }
277283
| DefKind::AssocFn
278284
| DefKind::AssocConst
279-
| DefKind::Field => DefPathData::ValueNs(name),
280-
DefKind::Macro(..) => DefPathData::MacroNs(name),
281-
DefKind::LifetimeParam => DefPathData::LifetimeNs(name),
285+
| DefKind::Field => DefPathData::ValueNs(name.unwrap()),
286+
DefKind::Macro(..) => DefPathData::MacroNs(name.unwrap()),
287+
DefKind::LifetimeParam => DefPathData::LifetimeNs(name.unwrap()),
282288
DefKind::Ctor(..) => DefPathData::Ctor,
283289
DefKind::Use => DefPathData::Use,
284290
DefKind::ForeignMod => DefPathData::ForeignMod,

‎compiler/rustc_hir/src/definitions.rs

+13-9
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,9 @@ pub enum DefPathData {
271271
Use,
272272
/// A global asm item.
273273
GlobalAsm,
274-
/// Something in the type namespace.
275-
TypeNs(Symbol),
274+
/// Something in the type namespace. Will be empty for RPITIT associated
275+
/// types, which are given a synthetic name later, if necessary.
276+
TypeNs(Option<Symbol>),
276277
/// Something in the value namespace.
277278
ValueNs(Symbol),
278279
/// Something in the macro namespace.
@@ -410,8 +411,9 @@ impl DefPathData {
410411
pub fn get_opt_name(&self) -> Option<Symbol> {
411412
use self::DefPathData::*;
412413
match *self {
413-
TypeNs(name) if name == kw::Empty => None,
414-
TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) => Some(name),
414+
TypeNs(name) => name,
415+
416+
ValueNs(name) | MacroNs(name) | LifetimeNs(name) => Some(name),
415417

416418
Impl | ForeignMod | CrateRoot | Use | GlobalAsm | Closure | Ctor | AnonConst
417419
| OpaqueTy => None,
@@ -421,12 +423,14 @@ impl DefPathData {
421423
pub fn name(&self) -> DefPathDataName {
422424
use self::DefPathData::*;
423425
match *self {
424-
TypeNs(name) if name == kw::Empty => {
425-
DefPathDataName::Anon { namespace: sym::synthetic }
426-
}
427-
TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) => {
428-
DefPathDataName::Named(name)
426+
TypeNs(name) => {
427+
if let Some(name) = name {
428+
DefPathDataName::Named(name)
429+
} else {
430+
DefPathDataName::Anon { namespace: sym::synthetic }
431+
}
429432
}
433+
ValueNs(name) | MacroNs(name) | LifetimeNs(name) => DefPathDataName::Named(name),
430434
// Note that this does not show up in user print-outs.
431435
CrateRoot => DefPathDataName::Anon { namespace: kw::Crate },
432436
Impl => DefPathDataName::Anon { namespace: kw::Impl },

‎compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1462,7 +1462,8 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
14621462
for &(opaque_def_id, captures) in opaque_capture_scopes.iter().rev() {
14631463
let mut captures = captures.borrow_mut();
14641464
let remapped = *captures.entry(lifetime).or_insert_with(|| {
1465-
let feed = self.tcx.create_def(opaque_def_id, ident.name, DefKind::LifetimeParam);
1465+
let feed =
1466+
self.tcx.create_def(opaque_def_id, Some(ident.name), DefKind::LifetimeParam);
14661467
feed.def_span(ident.span);
14671468
feed.def_ident_span(Some(ident.span));
14681469
feed.def_id()

‎compiler/rustc_middle/src/ty/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1890,7 +1890,7 @@ impl<'tcx> TyCtxtAt<'tcx> {
18901890
pub fn create_def(
18911891
self,
18921892
parent: LocalDefId,
1893-
name: Symbol,
1893+
name: Option<Symbol>,
18941894
def_kind: DefKind,
18951895
) -> TyCtxtFeed<'tcx, LocalDefId> {
18961896
let feed = self.tcx.create_def(parent, name, def_kind);
@@ -1905,7 +1905,7 @@ impl<'tcx> TyCtxt<'tcx> {
19051905
pub fn create_def(
19061906
self,
19071907
parent: LocalDefId,
1908-
name: Symbol,
1908+
name: Option<Symbol>,
19091909
def_kind: DefKind,
19101910
) -> TyCtxtFeed<'tcx, LocalDefId> {
19111911
let data = def_kind.def_path_data(name);

‎compiler/rustc_middle/src/ty/print/pretty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
569569
// the children of the visible parent (as was done when computing
570570
// `visible_parent_map`), looking for the specific child we currently have and then
571571
// have access to the re-exported name.
572-
DefPathData::TypeNs(ref mut name) if Some(visible_parent) != actual_parent => {
572+
DefPathData::TypeNs(Some(ref mut name)) if Some(visible_parent) != actual_parent => {
573573
// Item might be re-exported several times, but filter for the one
574574
// that's public and whose identifier isn't `_`.
575575
let reexport = self
@@ -590,7 +590,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
590590
}
591591
// Re-exported `extern crate` (#43189).
592592
DefPathData::CrateRoot => {
593-
data = DefPathData::TypeNs(self.tcx().crate_name(def_id.krate));
593+
data = DefPathData::TypeNs(Some(self.tcx().crate_name(def_id.krate)));
594594
}
595595
_ => {}
596596
}

‎compiler/rustc_middle/src/ty/significant_drop_order.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ fn true_significant_drop_ty<'tcx>(
2323

2424
match key.disambiguated_data.data {
2525
rustc_hir::definitions::DefPathData::CrateRoot => {
26-
name_rev.push(tcx.crate_name(did.krate))
26+
name_rev.push(tcx.crate_name(did.krate));
27+
}
28+
rustc_hir::definitions::DefPathData::TypeNs(symbol) => {
29+
name_rev.push(symbol.unwrap());
2730
}
28-
rustc_hir::definitions::DefPathData::TypeNs(symbol) => name_rev.push(symbol),
2931
_ => return None,
3032
}
3133
if let Some(parent) = key.parent {

‎compiler/rustc_mir_transform/src/coroutine/by_move_body.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ use rustc_middle::hir::place::{Projection, ProjectionKind};
7878
use rustc_middle::mir::visit::MutVisitor;
7979
use rustc_middle::mir::{self, dump_mir};
8080
use rustc_middle::ty::{self, InstanceKind, Ty, TyCtxt, TypeVisitableExt};
81-
use rustc_span::kw;
8281

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

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

‎compiler/rustc_resolve/src/def_collector.rs

+21-31
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_hir as hir;
99
use rustc_hir::def::{CtorKind, CtorOf, DefKind};
1010
use rustc_hir::def_id::LocalDefId;
1111
use rustc_span::hygiene::LocalExpnId;
12-
use rustc_span::{Span, Symbol, kw, sym};
12+
use rustc_span::{Span, Symbol, sym};
1313
use tracing::debug;
1414

1515
use crate::{ImplTraitContext, InvocationParent, Resolver};
@@ -38,7 +38,7 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> {
3838
fn create_def(
3939
&mut self,
4040
node_id: NodeId,
41-
name: Symbol,
41+
name: Option<Symbol>,
4242
def_kind: DefKind,
4343
span: Span,
4444
) -> LocalDefId {
@@ -89,7 +89,7 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> {
8989
self.visit_macro_invoc(field.id);
9090
} else {
9191
let name = field.ident.map_or_else(|| sym::integer(index(self)), |ident| ident.name);
92-
let def = self.create_def(field.id, name, DefKind::Field, field.span);
92+
let def = self.create_def(field.id, Some(name), DefKind::Field, field.span);
9393
self.with_parent(def, |this| visit::walk_field_def(this, field));
9494
}
9595
}
@@ -161,7 +161,7 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
161161
return self.visit_macro_invoc(i.id);
162162
}
163163
};
164-
let def_id = self.create_def(i.id, i.ident.name, def_kind, i.span);
164+
let def_id = self.create_def(i.id, Some(i.ident.name), def_kind, i.span);
165165

166166
if let Some(macro_data) = opt_macro_data {
167167
self.resolver.macro_map.insert(def_id.to_def_id(), macro_data);
@@ -175,7 +175,7 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
175175
if let Some((ctor_kind, ctor_node_id)) = CtorKind::from_ast(struct_def) {
176176
this.create_def(
177177
ctor_node_id,
178-
kw::Empty,
178+
None,
179179
DefKind::Ctor(CtorOf::Struct, ctor_kind),
180180
i.span,
181181
);
@@ -211,20 +211,15 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
211211
}
212212

213213
let (return_id, return_span) = coroutine_kind.return_id();
214-
let return_def =
215-
self.create_def(return_id, kw::Empty, DefKind::OpaqueTy, return_span);
214+
let return_def = self.create_def(return_id, None, DefKind::OpaqueTy, return_span);
216215
self.with_parent(return_def, |this| this.visit_fn_ret_ty(output));
217216

218217
// If this async fn has no body (i.e. it's an async fn signature in a trait)
219218
// then the closure_def will never be used, and we should avoid generating a
220219
// def-id for it.
221220
if let Some(body) = body {
222-
let closure_def = self.create_def(
223-
coroutine_kind.closure_id(),
224-
kw::Empty,
225-
DefKind::Closure,
226-
span,
227-
);
221+
let closure_def =
222+
self.create_def(coroutine_kind.closure_id(), None, DefKind::Closure, span);
228223
self.with_parent(closure_def, |this| this.visit_block(body));
229224
}
230225
}
@@ -235,15 +230,15 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
235230
// Async closures desugar to closures inside of closures, so
236231
// we must create two defs.
237232
let coroutine_def =
238-
self.create_def(coroutine_kind.closure_id(), kw::Empty, DefKind::Closure, span);
233+
self.create_def(coroutine_kind.closure_id(), None, DefKind::Closure, span);
239234
self.with_parent(coroutine_def, |this| this.visit_expr(body));
240235
}
241236
_ => visit::walk_fn(self, fn_kind),
242237
}
243238
}
244239

245240
fn visit_use_tree(&mut self, use_tree: &'a UseTree, id: NodeId, _nested: bool) {
246-
self.create_def(id, kw::Empty, DefKind::Use, use_tree.span);
241+
self.create_def(id, None, DefKind::Use, use_tree.span);
247242
visit::walk_use_tree(self, use_tree, id);
248243
}
249244

@@ -262,7 +257,7 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
262257
ForeignItemKind::MacCall(_) => return self.visit_macro_invoc(fi.id),
263258
};
264259

265-
let def = self.create_def(fi.id, fi.ident.name, def_kind, fi.span);
260+
let def = self.create_def(fi.id, Some(fi.ident.name), def_kind, fi.span);
266261

267262
self.with_parent(def, |this| visit::walk_item(this, fi));
268263
}
@@ -271,12 +266,12 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
271266
if v.is_placeholder {
272267
return self.visit_macro_invoc(v.id);
273268
}
274-
let def = self.create_def(v.id, v.ident.name, DefKind::Variant, v.span);
269+
let def = self.create_def(v.id, Some(v.ident.name), DefKind::Variant, v.span);
275270
self.with_parent(def, |this| {
276271
if let Some((ctor_kind, ctor_node_id)) = CtorKind::from_ast(&v.data) {
277272
this.create_def(
278273
ctor_node_id,
279-
kw::Empty,
274+
None,
280275
DefKind::Ctor(CtorOf::Variant, ctor_kind),
281276
v.span,
282277
);
@@ -312,7 +307,7 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
312307
GenericParamKind::Type { .. } => DefKind::TyParam,
313308
GenericParamKind::Const { .. } => DefKind::ConstParam,
314309
};
315-
self.create_def(param.id, param.ident.name, def_kind, param.ident.span);
310+
self.create_def(param.id, Some(param.ident.name), def_kind, param.ident.span);
316311

317312
// impl-Trait can happen inside generic parameters, like
318313
// ```
@@ -335,7 +330,7 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
335330
}
336331
};
337332

338-
let def = self.create_def(i.id, i.ident.name, def_kind, i.span);
333+
let def = self.create_def(i.id, Some(i.ident.name), def_kind, i.span);
339334
self.with_parent(def, |this| visit::walk_assoc_item(this, i, ctxt));
340335
}
341336

@@ -347,27 +342,22 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
347342
}
348343

349344
fn visit_anon_const(&mut self, constant: &'a AnonConst) {
350-
let parent =
351-
self.create_def(constant.id, kw::Empty, DefKind::AnonConst, constant.value.span);
345+
let parent = self.create_def(constant.id, None, DefKind::AnonConst, constant.value.span);
352346
self.with_parent(parent, |this| visit::walk_anon_const(this, constant));
353347
}
354348

355349
fn visit_expr(&mut self, expr: &'a Expr) {
356350
let parent_def = match expr.kind {
357351
ExprKind::MacCall(..) => return self.visit_macro_invoc(expr.id),
358352
ExprKind::Closure(..) | ExprKind::Gen(..) => {
359-
self.create_def(expr.id, kw::Empty, DefKind::Closure, expr.span)
353+
self.create_def(expr.id, None, DefKind::Closure, expr.span)
360354
}
361355
ExprKind::ConstBlock(ref constant) => {
362356
for attr in &expr.attrs {
363357
visit::walk_attribute(self, attr);
364358
}
365-
let def = self.create_def(
366-
constant.id,
367-
kw::Empty,
368-
DefKind::InlineConst,
369-
constant.value.span,
370-
);
359+
let def =
360+
self.create_def(constant.id, None, DefKind::InlineConst, constant.value.span);
371361
self.with_parent(def, |this| visit::walk_anon_const(this, constant));
372362
return;
373363
}
@@ -391,7 +381,7 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
391381
ImplTraitContext::Existential => DefKind::OpaqueTy,
392382
ImplTraitContext::InBinding => return visit::walk_ty(self, ty),
393383
};
394-
let id = self.create_def(*id, name, kind, ty.span);
384+
let id = self.create_def(*id, Some(name), kind, ty.span);
395385
match self.impl_trait_context {
396386
// Do not nest APIT, as we desugar them as `impl_trait: bounds`,
397387
// so the `impl_trait` node is not a parent to `bounds`.
@@ -495,7 +485,7 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
495485
InlineAsmOperand::Const { anon_const } => {
496486
let def = self.create_def(
497487
anon_const.id,
498-
kw::Empty,
488+
None,
499489
DefKind::InlineConst,
500490
anon_const.value.span,
501491
);

‎compiler/rustc_resolve/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1340,7 +1340,7 @@ impl<'tcx> Resolver<'_, 'tcx> {
13401340
&mut self,
13411341
parent: LocalDefId,
13421342
node_id: ast::NodeId,
1343-
name: Symbol,
1343+
name: Option<Symbol>,
13441344
def_kind: DefKind,
13451345
expn_id: ExpnId,
13461346
span: Span,

‎compiler/rustc_ty_utils/src/assoc.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ fn associated_type_for_impl_trait_in_trait(
252252
assert_eq!(tcx.def_kind(trait_def_id), DefKind::Trait);
253253

254254
let span = tcx.def_span(opaque_ty_def_id);
255-
let trait_assoc_ty = tcx.at(span).create_def(trait_def_id, kw::Empty, DefKind::AssocTy);
255+
// No name because this is a synthetic associated type.
256+
let trait_assoc_ty = tcx.at(span).create_def(trait_def_id, None, DefKind::AssocTy);
256257

257258
let local_def_id = trait_assoc_ty.def_id();
258259
let def_id = local_def_id.to_def_id();
@@ -304,7 +305,8 @@ fn associated_type_for_impl_trait_in_impl(
304305
hir::FnRetTy::DefaultReturn(_) => tcx.def_span(impl_fn_def_id),
305306
hir::FnRetTy::Return(ty) => ty.span,
306307
};
307-
let impl_assoc_ty = tcx.at(span).create_def(impl_local_def_id, kw::Empty, DefKind::AssocTy);
308+
// No name because this is a synthetic associated type.
309+
let impl_assoc_ty = tcx.at(span).create_def(impl_local_def_id, None, DefKind::AssocTy);
308310

309311
let local_def_id = impl_assoc_ty.def_id();
310312
let def_id = local_def_id.to_def_id();

‎src/tools/clippy/clippy_utils/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3492,7 +3492,7 @@ fn maybe_get_relative_path(from: &DefPath, to: &DefPath, max_super: usize) -> St
34923492
// a::b::c ::d::sym refers to
34933493
// e::f::sym:: ::
34943494
// result should be super::super::super::super::e::f
3495-
if let DefPathData::TypeNs(s) = l {
3495+
if let DefPathData::TypeNs(Some(s)) = l {
34963496
path.push(s.to_string());
34973497
}
34983498
if let DefPathData::TypeNs(_) = r {
@@ -3503,7 +3503,7 @@ fn maybe_get_relative_path(from: &DefPath, to: &DefPath, max_super: usize) -> St
35033503
// a::b::sym:: :: refers to
35043504
// c::d::e ::f::sym
35053505
// when looking at `f`
3506-
Left(DefPathData::TypeNs(sym)) => path.push(sym.to_string()),
3506+
Left(DefPathData::TypeNs(Some(sym))) => path.push(sym.to_string()),
35073507
// consider:
35083508
// a::b::c ::d::sym refers to
35093509
// e::f::sym:: ::
@@ -3517,7 +3517,7 @@ fn maybe_get_relative_path(from: &DefPath, to: &DefPath, max_super: usize) -> St
35173517
// `super` chain would be too long, just use the absolute path instead
35183518
once(String::from("crate"))
35193519
.chain(to.data.iter().filter_map(|el| {
3520-
if let DefPathData::TypeNs(sym) = el.data {
3520+
if let DefPathData::TypeNs(Some(sym)) = el.data {
35213521
Some(sym.to_string())
35223522
} else {
35233523
None

‎src/tools/compiletest/src/runtest/crashes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ impl TestCx<'_> {
1515
// if a test does not crash, consider it an error
1616
if proc_res.status.success() || matches!(proc_res.status.code(), Some(1 | 0)) {
1717
self.fatal(&format!(
18-
"crashtest no longer crashes/triggers ICE, horray! Please give it a meaningful \
18+
"crashtest no longer crashes/triggers ICE, hooray! Please give it a meaningful \
1919
name, add a doc-comment to the start of the test explaining why it exists and \
2020
move it to tests/ui or wherever you see fit. Adding 'Fixes #<issueNr>' to your PR \
2121
description ensures that the corresponding ticket is auto-closed upon merge. \

‎tests/crashes/133426.rs

-12
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//! Test for the crash in #133426, caused by an empty symbol being used for a
2+
//! type name.
3+
4+
#![allow(incomplete_features)]
5+
#![feature(never_patterns)]
6+
7+
fn a(
8+
_: impl Iterator<
9+
Item = [(); {
10+
match *todo!() { ! }; //~ ERROR type `!` cannot be dereferenced
11+
}],
12+
>,
13+
) {
14+
}
15+
16+
fn b(_: impl Iterator<Item = { match 0 { ! } }>) {}
17+
//~^ ERROR associated const equality is incomplete
18+
//~| ERROR expected type, found constant
19+
20+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
error[E0658]: associated const equality is incomplete
2+
--> $DIR/no-name-for-DefPath-issue-133426.rs:16:23
3+
|
4+
LL | fn b(_: impl Iterator<Item = { match 0 { ! } }>) {}
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #92827 <https://github.com/rust-lang/rust/issues/92827> for more information
8+
= help: add `#![feature(associated_const_equality)]` to the crate attributes to enable
9+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10+
11+
error[E0614]: type `!` cannot be dereferenced
12+
--> $DIR/no-name-for-DefPath-issue-133426.rs:10:19
13+
|
14+
LL | match *todo!() { ! };
15+
| ^^^^^^^^ can't be dereferenced
16+
17+
error: expected type, found constant
18+
--> $DIR/no-name-for-DefPath-issue-133426.rs:16:30
19+
|
20+
LL | fn b(_: impl Iterator<Item = { match 0 { ! } }>) {}
21+
| ---- ^^^^^^^^^^^^^^^^^ unexpected constant
22+
| |
23+
| expected a type because of this associated type
24+
|
25+
note: the associated type is defined here
26+
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
27+
28+
error: aborting due to 3 previous errors
29+
30+
Some errors have detailed explanations: E0614, E0658.
31+
For more information about an error, try `rustc --explain E0614`.

0 commit comments

Comments
 (0)
Please sign in to comment.