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```
This commit is contained in:
commit
0defc4f27f
19 changed files with 125 additions and 83 deletions
|
@ -13,7 +13,7 @@ use rustc_middle::span_bug;
|
||||||
use rustc_middle::ty::TyCtxt;
|
use rustc_middle::ty::TyCtxt;
|
||||||
use rustc_session::errors::report_lit_error;
|
use rustc_session::errors::report_lit_error;
|
||||||
use rustc_span::source_map::{Spanned, respan};
|
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 thin_vec::{ThinVec, thin_vec};
|
||||||
use visit::{Visitor, walk_expr};
|
use visit::{Visitor, walk_expr};
|
||||||
|
|
||||||
|
@ -484,7 +484,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
if legacy_args_idx.contains(&idx) {
|
if legacy_args_idx.contains(&idx) {
|
||||||
let parent_def_id = self.current_hir_id_owner.def_id;
|
let parent_def_id = self.current_hir_id_owner.def_id;
|
||||||
let node_id = self.next_node_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 mut visitor = WillCreateDefIdsVisitor {};
|
||||||
let const_value = if let ControlFlow::Break(span) = visitor.visit_expr(&arg) {
|
let const_value = if let ControlFlow::Break(span) = visitor.visit_expr(&arg) {
|
||||||
AstP(Expr {
|
AstP(Expr {
|
||||||
|
|
|
@ -494,7 +494,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
&mut self,
|
&mut self,
|
||||||
parent: LocalDefId,
|
parent: LocalDefId,
|
||||||
node_id: ast::NodeId,
|
node_id: ast::NodeId,
|
||||||
name: Symbol,
|
name: Option<Symbol>,
|
||||||
def_kind: DefKind,
|
def_kind: DefKind,
|
||||||
span: Span,
|
span: Span,
|
||||||
) -> LocalDefId {
|
) -> LocalDefId {
|
||||||
|
@ -774,7 +774,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
let _def_id = self.create_def(
|
let _def_id = self.create_def(
|
||||||
self.current_hir_id_owner.def_id,
|
self.current_hir_id_owner.def_id,
|
||||||
param,
|
param,
|
||||||
kw::UnderscoreLifetime,
|
Some(kw::UnderscoreLifetime),
|
||||||
DefKind::LifetimeParam,
|
DefKind::LifetimeParam,
|
||||||
ident.span,
|
ident.span,
|
||||||
);
|
);
|
||||||
|
@ -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,
|
// 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
|
// so the def collector didn't create the def ahead of time. That's why we have to do
|
||||||
// it here.
|
// it here.
|
||||||
let def_id =
|
let def_id = self.create_def(parent_def_id, node_id, None, DefKind::AnonConst, span);
|
||||||
self.create_def(parent_def_id, node_id, kw::Empty, DefKind::AnonConst, span);
|
|
||||||
let hir_id = self.lower_node_id(node_id);
|
let hir_id = self.lower_node_id(node_id);
|
||||||
|
|
||||||
let path_expr = Expr {
|
let path_expr = Expr {
|
||||||
|
|
|
@ -7,7 +7,7 @@ use rustc_hir::def::{DefKind, Res};
|
||||||
use rustc_hir::{self as hir, LangItem};
|
use rustc_hir::{self as hir, LangItem};
|
||||||
use rustc_middle::span_bug;
|
use rustc_middle::span_bug;
|
||||||
use rustc_span::source_map::{Spanned, respan};
|
use rustc_span::source_map::{Spanned, respan};
|
||||||
use rustc_span::{DesugaringKind, Ident, Span, kw};
|
use rustc_span::{DesugaringKind, Ident, Span};
|
||||||
|
|
||||||
use super::errors::{
|
use super::errors::{
|
||||||
ArbitraryExpressionInPattern, ExtraDoubleDot, MisplacedDoubleDot, SubTupleBinding,
|
ArbitraryExpressionInPattern, ExtraDoubleDot, MisplacedDoubleDot, SubTupleBinding,
|
||||||
|
@ -523,7 +523,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
// We're generating a range end that didn't exist in the AST,
|
// 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
|
// so the def collector didn't create the def ahead of time. That's why we have to do
|
||||||
// it here.
|
// 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 hir_id = self.lower_node_id(node_id);
|
||||||
|
|
||||||
let unstable_span = self.mark_span_with_reason(
|
let unstable_span = self.mark_span_with_reason(
|
||||||
|
|
|
@ -104,7 +104,7 @@ fn intern_as_new_static<'tcx>(
|
||||||
) {
|
) {
|
||||||
let feed = tcx.create_def(
|
let feed = tcx.create_def(
|
||||||
static_id,
|
static_id,
|
||||||
sym::nested,
|
Some(sym::nested),
|
||||||
DefKind::Static { safety: hir::Safety::Safe, mutability: alloc.0.mutability, nested: true },
|
DefKind::Static { safety: hir::Safety::Safe, mutability: alloc.0.mutability, nested: true },
|
||||||
);
|
);
|
||||||
tcx.set_nested_alloc_id_static(alloc_id, feed.def_id());
|
tcx.set_nested_alloc_id_static(alloc_id, feed.def_id());
|
||||||
|
|
|
@ -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 {
|
match self {
|
||||||
DefKind::Mod
|
DefKind::Mod
|
||||||
| DefKind::Struct
|
| DefKind::Struct
|
||||||
|
@ -264,9 +266,13 @@ impl DefKind {
|
||||||
| DefKind::TyAlias
|
| DefKind::TyAlias
|
||||||
| DefKind::ForeignTy
|
| DefKind::ForeignTy
|
||||||
| DefKind::TraitAlias
|
| DefKind::TraitAlias
|
||||||
| DefKind::AssocTy
|
|
||||||
| DefKind::TyParam
|
| 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
|
// It's not exactly an anon const, but wrt DefPathData, there
|
||||||
// is no difference.
|
// is no difference.
|
||||||
DefKind::Static { nested: true, .. } => DefPathData::AnonConst,
|
DefKind::Static { nested: true, .. } => DefPathData::AnonConst,
|
||||||
|
@ -276,9 +282,9 @@ impl DefKind {
|
||||||
| DefKind::Static { .. }
|
| DefKind::Static { .. }
|
||||||
| DefKind::AssocFn
|
| DefKind::AssocFn
|
||||||
| DefKind::AssocConst
|
| DefKind::AssocConst
|
||||||
| DefKind::Field => DefPathData::ValueNs(name),
|
| DefKind::Field => DefPathData::ValueNs(name.unwrap()),
|
||||||
DefKind::Macro(..) => DefPathData::MacroNs(name),
|
DefKind::Macro(..) => DefPathData::MacroNs(name.unwrap()),
|
||||||
DefKind::LifetimeParam => DefPathData::LifetimeNs(name),
|
DefKind::LifetimeParam => DefPathData::LifetimeNs(name.unwrap()),
|
||||||
DefKind::Ctor(..) => DefPathData::Ctor,
|
DefKind::Ctor(..) => DefPathData::Ctor,
|
||||||
DefKind::Use => DefPathData::Use,
|
DefKind::Use => DefPathData::Use,
|
||||||
DefKind::ForeignMod => DefPathData::ForeignMod,
|
DefKind::ForeignMod => DefPathData::ForeignMod,
|
||||||
|
|
|
@ -271,8 +271,9 @@ pub enum DefPathData {
|
||||||
Use,
|
Use,
|
||||||
/// A global asm item.
|
/// A global asm item.
|
||||||
GlobalAsm,
|
GlobalAsm,
|
||||||
/// Something in the type namespace.
|
/// Something in the type namespace. Will be empty for RPITIT associated
|
||||||
TypeNs(Symbol),
|
/// types, which are given a synthetic name later, if necessary.
|
||||||
|
TypeNs(Option<Symbol>),
|
||||||
/// Something in the value namespace.
|
/// Something in the value namespace.
|
||||||
ValueNs(Symbol),
|
ValueNs(Symbol),
|
||||||
/// Something in the macro namespace.
|
/// Something in the macro namespace.
|
||||||
|
@ -410,8 +411,9 @@ impl DefPathData {
|
||||||
pub fn get_opt_name(&self) -> Option<Symbol> {
|
pub fn get_opt_name(&self) -> Option<Symbol> {
|
||||||
use self::DefPathData::*;
|
use self::DefPathData::*;
|
||||||
match *self {
|
match *self {
|
||||||
TypeNs(name) if name == kw::Empty => None,
|
TypeNs(name) => name,
|
||||||
TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) => Some(name),
|
|
||||||
|
ValueNs(name) | MacroNs(name) | LifetimeNs(name) => Some(name),
|
||||||
|
|
||||||
Impl | ForeignMod | CrateRoot | Use | GlobalAsm | Closure | Ctor | AnonConst
|
Impl | ForeignMod | CrateRoot | Use | GlobalAsm | Closure | Ctor | AnonConst
|
||||||
| OpaqueTy => None,
|
| OpaqueTy => None,
|
||||||
|
@ -421,12 +423,14 @@ impl DefPathData {
|
||||||
pub fn name(&self) -> DefPathDataName {
|
pub fn name(&self) -> DefPathDataName {
|
||||||
use self::DefPathData::*;
|
use self::DefPathData::*;
|
||||||
match *self {
|
match *self {
|
||||||
TypeNs(name) if name == kw::Empty => {
|
TypeNs(name) => {
|
||||||
|
if let Some(name) = name {
|
||||||
|
DefPathDataName::Named(name)
|
||||||
|
} else {
|
||||||
DefPathDataName::Anon { namespace: sym::synthetic }
|
DefPathDataName::Anon { namespace: sym::synthetic }
|
||||||
}
|
}
|
||||||
TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) => {
|
|
||||||
DefPathDataName::Named(name)
|
|
||||||
}
|
}
|
||||||
|
ValueNs(name) | MacroNs(name) | LifetimeNs(name) => DefPathDataName::Named(name),
|
||||||
// Note that this does not show up in user print-outs.
|
// Note that this does not show up in user print-outs.
|
||||||
CrateRoot => DefPathDataName::Anon { namespace: kw::Crate },
|
CrateRoot => DefPathDataName::Anon { namespace: kw::Crate },
|
||||||
Impl => DefPathDataName::Anon { namespace: kw::Impl },
|
Impl => DefPathDataName::Anon { namespace: kw::Impl },
|
||||||
|
|
|
@ -1462,7 +1462,8 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
|
||||||
for &(opaque_def_id, captures) in opaque_capture_scopes.iter().rev() {
|
for &(opaque_def_id, captures) in opaque_capture_scopes.iter().rev() {
|
||||||
let mut captures = captures.borrow_mut();
|
let mut captures = captures.borrow_mut();
|
||||||
let remapped = *captures.entry(lifetime).or_insert_with(|| {
|
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_span(ident.span);
|
||||||
feed.def_ident_span(Some(ident.span));
|
feed.def_ident_span(Some(ident.span));
|
||||||
feed.def_id()
|
feed.def_id()
|
||||||
|
|
|
@ -1890,7 +1890,7 @@ impl<'tcx> TyCtxtAt<'tcx> {
|
||||||
pub fn create_def(
|
pub fn create_def(
|
||||||
self,
|
self,
|
||||||
parent: LocalDefId,
|
parent: LocalDefId,
|
||||||
name: Symbol,
|
name: Option<Symbol>,
|
||||||
def_kind: DefKind,
|
def_kind: DefKind,
|
||||||
) -> TyCtxtFeed<'tcx, LocalDefId> {
|
) -> TyCtxtFeed<'tcx, LocalDefId> {
|
||||||
let feed = self.tcx.create_def(parent, name, def_kind);
|
let feed = self.tcx.create_def(parent, name, def_kind);
|
||||||
|
@ -1905,7 +1905,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
pub fn create_def(
|
pub fn create_def(
|
||||||
self,
|
self,
|
||||||
parent: LocalDefId,
|
parent: LocalDefId,
|
||||||
name: Symbol,
|
name: Option<Symbol>,
|
||||||
def_kind: DefKind,
|
def_kind: DefKind,
|
||||||
) -> TyCtxtFeed<'tcx, LocalDefId> {
|
) -> TyCtxtFeed<'tcx, LocalDefId> {
|
||||||
let data = def_kind.def_path_data(name);
|
let data = def_kind.def_path_data(name);
|
||||||
|
|
|
@ -569,7 +569,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
|
||||||
// the children of the visible parent (as was done when computing
|
// the children of the visible parent (as was done when computing
|
||||||
// `visible_parent_map`), looking for the specific child we currently have and then
|
// `visible_parent_map`), looking for the specific child we currently have and then
|
||||||
// have access to the re-exported name.
|
// 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
|
// Item might be re-exported several times, but filter for the one
|
||||||
// that's public and whose identifier isn't `_`.
|
// that's public and whose identifier isn't `_`.
|
||||||
let reexport = self
|
let reexport = self
|
||||||
|
@ -590,7 +590,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
|
||||||
}
|
}
|
||||||
// Re-exported `extern crate` (#43189).
|
// Re-exported `extern crate` (#43189).
|
||||||
DefPathData::CrateRoot => {
|
DefPathData::CrateRoot => {
|
||||||
data = DefPathData::TypeNs(self.tcx().crate_name(def_id.krate));
|
data = DefPathData::TypeNs(Some(self.tcx().crate_name(def_id.krate)));
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,9 +23,11 @@ fn true_significant_drop_ty<'tcx>(
|
||||||
|
|
||||||
match key.disambiguated_data.data {
|
match key.disambiguated_data.data {
|
||||||
rustc_hir::definitions::DefPathData::CrateRoot => {
|
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,
|
_ => return None,
|
||||||
}
|
}
|
||||||
if let Some(parent) = key.parent {
|
if let Some(parent) = key.parent {
|
||||||
|
|
|
@ -78,7 +78,6 @@ use rustc_middle::hir::place::{Projection, ProjectionKind};
|
||||||
use rustc_middle::mir::visit::MutVisitor;
|
use rustc_middle::mir::visit::MutVisitor;
|
||||||
use rustc_middle::mir::{self, dump_mir};
|
use rustc_middle::mir::{self, dump_mir};
|
||||||
use rustc_middle::ty::{self, InstanceKind, Ty, TyCtxt, TypeVisitableExt};
|
use rustc_middle::ty::{self, InstanceKind, Ty, TyCtxt, TypeVisitableExt};
|
||||||
use rustc_span::kw;
|
|
||||||
|
|
||||||
pub(crate) fn coroutine_by_move_body_def_id<'tcx>(
|
pub(crate) fn coroutine_by_move_body_def_id<'tcx>(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
|
@ -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);
|
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}`.
|
// 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 =
|
by_move_body.source =
|
||||||
mir::MirSource::from_instance(InstanceKind::Item(body_def.def_id().to_def_id()));
|
mir::MirSource::from_instance(InstanceKind::Item(body_def.def_id().to_def_id()));
|
||||||
dump_mir(tcx, false, "built", &"after", &by_move_body, |_, _| Ok(()));
|
dump_mir(tcx, false, "built", &"after", &by_move_body, |_, _| Ok(()));
|
||||||
|
|
|
@ -9,7 +9,7 @@ use rustc_hir as hir;
|
||||||
use rustc_hir::def::{CtorKind, CtorOf, DefKind};
|
use rustc_hir::def::{CtorKind, CtorOf, DefKind};
|
||||||
use rustc_hir::def_id::LocalDefId;
|
use rustc_hir::def_id::LocalDefId;
|
||||||
use rustc_span::hygiene::LocalExpnId;
|
use rustc_span::hygiene::LocalExpnId;
|
||||||
use rustc_span::{Span, Symbol, kw, sym};
|
use rustc_span::{Span, Symbol, sym};
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
|
||||||
use crate::{ImplTraitContext, InvocationParent, Resolver};
|
use crate::{ImplTraitContext, InvocationParent, Resolver};
|
||||||
|
@ -38,7 +38,7 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> {
|
||||||
fn create_def(
|
fn create_def(
|
||||||
&mut self,
|
&mut self,
|
||||||
node_id: NodeId,
|
node_id: NodeId,
|
||||||
name: Symbol,
|
name: Option<Symbol>,
|
||||||
def_kind: DefKind,
|
def_kind: DefKind,
|
||||||
span: Span,
|
span: Span,
|
||||||
) -> LocalDefId {
|
) -> LocalDefId {
|
||||||
|
@ -89,7 +89,7 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> {
|
||||||
self.visit_macro_invoc(field.id);
|
self.visit_macro_invoc(field.id);
|
||||||
} else {
|
} else {
|
||||||
let name = field.ident.map_or_else(|| sym::integer(index(self)), |ident| ident.name);
|
let name = field.ident.map_or_else(|| sym::integer(index(self)), |ident| ident.name);
|
||||||
let def = self.create_def(field.id, name, DefKind::Field, field.span);
|
let def = self.create_def(field.id, Some(name), DefKind::Field, field.span);
|
||||||
self.with_parent(def, |this| visit::walk_field_def(this, field));
|
self.with_parent(def, |this| visit::walk_field_def(this, field));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -161,7 +161,7 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
|
||||||
return self.visit_macro_invoc(i.id);
|
return self.visit_macro_invoc(i.id);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let def_id = self.create_def(i.id, i.ident.name, def_kind, i.span);
|
let def_id = self.create_def(i.id, Some(i.ident.name), def_kind, i.span);
|
||||||
|
|
||||||
if let Some(macro_data) = opt_macro_data {
|
if let Some(macro_data) = opt_macro_data {
|
||||||
self.resolver.macro_map.insert(def_id.to_def_id(), macro_data);
|
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> {
|
||||||
if let Some((ctor_kind, ctor_node_id)) = CtorKind::from_ast(struct_def) {
|
if let Some((ctor_kind, ctor_node_id)) = CtorKind::from_ast(struct_def) {
|
||||||
this.create_def(
|
this.create_def(
|
||||||
ctor_node_id,
|
ctor_node_id,
|
||||||
kw::Empty,
|
None,
|
||||||
DefKind::Ctor(CtorOf::Struct, ctor_kind),
|
DefKind::Ctor(CtorOf::Struct, ctor_kind),
|
||||||
i.span,
|
i.span,
|
||||||
);
|
);
|
||||||
|
@ -211,20 +211,15 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let (return_id, return_span) = coroutine_kind.return_id();
|
let (return_id, return_span) = coroutine_kind.return_id();
|
||||||
let return_def =
|
let return_def = self.create_def(return_id, None, DefKind::OpaqueTy, return_span);
|
||||||
self.create_def(return_id, kw::Empty, DefKind::OpaqueTy, return_span);
|
|
||||||
self.with_parent(return_def, |this| this.visit_fn_ret_ty(output));
|
self.with_parent(return_def, |this| this.visit_fn_ret_ty(output));
|
||||||
|
|
||||||
// If this async fn has no body (i.e. it's an async fn signature in a trait)
|
// If this async fn has no body (i.e. it's an async fn signature in a trait)
|
||||||
// then the closure_def will never be used, and we should avoid generating a
|
// then the closure_def will never be used, and we should avoid generating a
|
||||||
// def-id for it.
|
// def-id for it.
|
||||||
if let Some(body) = body {
|
if let Some(body) = body {
|
||||||
let closure_def = self.create_def(
|
let closure_def =
|
||||||
coroutine_kind.closure_id(),
|
self.create_def(coroutine_kind.closure_id(), None, DefKind::Closure, span);
|
||||||
kw::Empty,
|
|
||||||
DefKind::Closure,
|
|
||||||
span,
|
|
||||||
);
|
|
||||||
self.with_parent(closure_def, |this| this.visit_block(body));
|
self.with_parent(closure_def, |this| this.visit_block(body));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -235,7 +230,7 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
|
||||||
// Async closures desugar to closures inside of closures, so
|
// Async closures desugar to closures inside of closures, so
|
||||||
// we must create two defs.
|
// we must create two defs.
|
||||||
let coroutine_def =
|
let coroutine_def =
|
||||||
self.create_def(coroutine_kind.closure_id(), kw::Empty, DefKind::Closure, span);
|
self.create_def(coroutine_kind.closure_id(), None, DefKind::Closure, span);
|
||||||
self.with_parent(coroutine_def, |this| this.visit_expr(body));
|
self.with_parent(coroutine_def, |this| this.visit_expr(body));
|
||||||
}
|
}
|
||||||
_ => visit::walk_fn(self, fn_kind),
|
_ => visit::walk_fn(self, fn_kind),
|
||||||
|
@ -243,7 +238,7 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_use_tree(&mut self, use_tree: &'a UseTree, id: NodeId, _nested: bool) {
|
fn visit_use_tree(&mut self, use_tree: &'a UseTree, id: NodeId, _nested: bool) {
|
||||||
self.create_def(id, kw::Empty, DefKind::Use, use_tree.span);
|
self.create_def(id, None, DefKind::Use, use_tree.span);
|
||||||
visit::walk_use_tree(self, use_tree, id);
|
visit::walk_use_tree(self, use_tree, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -262,7 +257,7 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
|
||||||
ForeignItemKind::MacCall(_) => return self.visit_macro_invoc(fi.id),
|
ForeignItemKind::MacCall(_) => return self.visit_macro_invoc(fi.id),
|
||||||
};
|
};
|
||||||
|
|
||||||
let def = self.create_def(fi.id, fi.ident.name, def_kind, fi.span);
|
let def = self.create_def(fi.id, Some(fi.ident.name), def_kind, fi.span);
|
||||||
|
|
||||||
self.with_parent(def, |this| visit::walk_item(this, fi));
|
self.with_parent(def, |this| visit::walk_item(this, fi));
|
||||||
}
|
}
|
||||||
|
@ -271,12 +266,12 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
|
||||||
if v.is_placeholder {
|
if v.is_placeholder {
|
||||||
return self.visit_macro_invoc(v.id);
|
return self.visit_macro_invoc(v.id);
|
||||||
}
|
}
|
||||||
let def = self.create_def(v.id, v.ident.name, DefKind::Variant, v.span);
|
let def = self.create_def(v.id, Some(v.ident.name), DefKind::Variant, v.span);
|
||||||
self.with_parent(def, |this| {
|
self.with_parent(def, |this| {
|
||||||
if let Some((ctor_kind, ctor_node_id)) = CtorKind::from_ast(&v.data) {
|
if let Some((ctor_kind, ctor_node_id)) = CtorKind::from_ast(&v.data) {
|
||||||
this.create_def(
|
this.create_def(
|
||||||
ctor_node_id,
|
ctor_node_id,
|
||||||
kw::Empty,
|
None,
|
||||||
DefKind::Ctor(CtorOf::Variant, ctor_kind),
|
DefKind::Ctor(CtorOf::Variant, ctor_kind),
|
||||||
v.span,
|
v.span,
|
||||||
);
|
);
|
||||||
|
@ -312,7 +307,7 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
|
||||||
GenericParamKind::Type { .. } => DefKind::TyParam,
|
GenericParamKind::Type { .. } => DefKind::TyParam,
|
||||||
GenericParamKind::Const { .. } => DefKind::ConstParam,
|
GenericParamKind::Const { .. } => DefKind::ConstParam,
|
||||||
};
|
};
|
||||||
self.create_def(param.id, param.ident.name, def_kind, param.ident.span);
|
self.create_def(param.id, Some(param.ident.name), def_kind, param.ident.span);
|
||||||
|
|
||||||
// impl-Trait can happen inside generic parameters, like
|
// impl-Trait can happen inside generic parameters, like
|
||||||
// ```
|
// ```
|
||||||
|
@ -335,7 +330,7 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let def = self.create_def(i.id, i.ident.name, def_kind, i.span);
|
let def = self.create_def(i.id, Some(i.ident.name), def_kind, i.span);
|
||||||
self.with_parent(def, |this| visit::walk_assoc_item(this, i, ctxt));
|
self.with_parent(def, |this| visit::walk_assoc_item(this, i, ctxt));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -347,8 +342,7 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_anon_const(&mut self, constant: &'a AnonConst) {
|
fn visit_anon_const(&mut self, constant: &'a AnonConst) {
|
||||||
let parent =
|
let parent = self.create_def(constant.id, None, DefKind::AnonConst, constant.value.span);
|
||||||
self.create_def(constant.id, kw::Empty, DefKind::AnonConst, constant.value.span);
|
|
||||||
self.with_parent(parent, |this| visit::walk_anon_const(this, constant));
|
self.with_parent(parent, |this| visit::walk_anon_const(this, constant));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -356,18 +350,14 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
|
||||||
let parent_def = match expr.kind {
|
let parent_def = match expr.kind {
|
||||||
ExprKind::MacCall(..) => return self.visit_macro_invoc(expr.id),
|
ExprKind::MacCall(..) => return self.visit_macro_invoc(expr.id),
|
||||||
ExprKind::Closure(..) | ExprKind::Gen(..) => {
|
ExprKind::Closure(..) | ExprKind::Gen(..) => {
|
||||||
self.create_def(expr.id, kw::Empty, DefKind::Closure, expr.span)
|
self.create_def(expr.id, None, DefKind::Closure, expr.span)
|
||||||
}
|
}
|
||||||
ExprKind::ConstBlock(ref constant) => {
|
ExprKind::ConstBlock(ref constant) => {
|
||||||
for attr in &expr.attrs {
|
for attr in &expr.attrs {
|
||||||
visit::walk_attribute(self, attr);
|
visit::walk_attribute(self, attr);
|
||||||
}
|
}
|
||||||
let def = self.create_def(
|
let def =
|
||||||
constant.id,
|
self.create_def(constant.id, None, DefKind::InlineConst, constant.value.span);
|
||||||
kw::Empty,
|
|
||||||
DefKind::InlineConst,
|
|
||||||
constant.value.span,
|
|
||||||
);
|
|
||||||
self.with_parent(def, |this| visit::walk_anon_const(this, constant));
|
self.with_parent(def, |this| visit::walk_anon_const(this, constant));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -391,7 +381,7 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
|
||||||
ImplTraitContext::Existential => DefKind::OpaqueTy,
|
ImplTraitContext::Existential => DefKind::OpaqueTy,
|
||||||
ImplTraitContext::InBinding => return visit::walk_ty(self, ty),
|
ImplTraitContext::InBinding => return visit::walk_ty(self, ty),
|
||||||
};
|
};
|
||||||
let id = self.create_def(*id, name, kind, ty.span);
|
let id = self.create_def(*id, Some(name), kind, ty.span);
|
||||||
match self.impl_trait_context {
|
match self.impl_trait_context {
|
||||||
// Do not nest APIT, as we desugar them as `impl_trait: bounds`,
|
// Do not nest APIT, as we desugar them as `impl_trait: bounds`,
|
||||||
// so the `impl_trait` node is not a parent to `bounds`.
|
// 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> {
|
||||||
InlineAsmOperand::Const { anon_const } => {
|
InlineAsmOperand::Const { anon_const } => {
|
||||||
let def = self.create_def(
|
let def = self.create_def(
|
||||||
anon_const.id,
|
anon_const.id,
|
||||||
kw::Empty,
|
None,
|
||||||
DefKind::InlineConst,
|
DefKind::InlineConst,
|
||||||
anon_const.value.span,
|
anon_const.value.span,
|
||||||
);
|
);
|
||||||
|
|
|
@ -1340,7 +1340,7 @@ impl<'tcx> Resolver<'_, 'tcx> {
|
||||||
&mut self,
|
&mut self,
|
||||||
parent: LocalDefId,
|
parent: LocalDefId,
|
||||||
node_id: ast::NodeId,
|
node_id: ast::NodeId,
|
||||||
name: Symbol,
|
name: Option<Symbol>,
|
||||||
def_kind: DefKind,
|
def_kind: DefKind,
|
||||||
expn_id: ExpnId,
|
expn_id: ExpnId,
|
||||||
span: Span,
|
span: Span,
|
||||||
|
|
|
@ -252,7 +252,8 @@ fn associated_type_for_impl_trait_in_trait(
|
||||||
assert_eq!(tcx.def_kind(trait_def_id), DefKind::Trait);
|
assert_eq!(tcx.def_kind(trait_def_id), DefKind::Trait);
|
||||||
|
|
||||||
let span = tcx.def_span(opaque_ty_def_id);
|
let span = tcx.def_span(opaque_ty_def_id);
|
||||||
let trait_assoc_ty = tcx.at(span).create_def(trait_def_id, kw::Empty, DefKind::AssocTy);
|
// No name because this is a synthetic associated type.
|
||||||
|
let trait_assoc_ty = tcx.at(span).create_def(trait_def_id, None, DefKind::AssocTy);
|
||||||
|
|
||||||
let local_def_id = trait_assoc_ty.def_id();
|
let local_def_id = trait_assoc_ty.def_id();
|
||||||
let def_id = local_def_id.to_def_id();
|
let def_id = local_def_id.to_def_id();
|
||||||
|
@ -304,7 +305,8 @@ fn associated_type_for_impl_trait_in_impl(
|
||||||
hir::FnRetTy::DefaultReturn(_) => tcx.def_span(impl_fn_def_id),
|
hir::FnRetTy::DefaultReturn(_) => tcx.def_span(impl_fn_def_id),
|
||||||
hir::FnRetTy::Return(ty) => ty.span,
|
hir::FnRetTy::Return(ty) => ty.span,
|
||||||
};
|
};
|
||||||
let impl_assoc_ty = tcx.at(span).create_def(impl_local_def_id, kw::Empty, DefKind::AssocTy);
|
// No name because this is a synthetic associated type.
|
||||||
|
let impl_assoc_ty = tcx.at(span).create_def(impl_local_def_id, None, DefKind::AssocTy);
|
||||||
|
|
||||||
let local_def_id = impl_assoc_ty.def_id();
|
let local_def_id = impl_assoc_ty.def_id();
|
||||||
let def_id = local_def_id.to_def_id();
|
let def_id = local_def_id.to_def_id();
|
||||||
|
|
|
@ -3492,7 +3492,7 @@ fn maybe_get_relative_path(from: &DefPath, to: &DefPath, max_super: usize) -> St
|
||||||
// a::b::c ::d::sym refers to
|
// a::b::c ::d::sym refers to
|
||||||
// e::f::sym:: ::
|
// e::f::sym:: ::
|
||||||
// result should be super::super::super::super::e::f
|
// result should be super::super::super::super::e::f
|
||||||
if let DefPathData::TypeNs(s) = l {
|
if let DefPathData::TypeNs(Some(s)) = l {
|
||||||
path.push(s.to_string());
|
path.push(s.to_string());
|
||||||
}
|
}
|
||||||
if let DefPathData::TypeNs(_) = r {
|
if let DefPathData::TypeNs(_) = r {
|
||||||
|
@ -3503,7 +3503,7 @@ fn maybe_get_relative_path(from: &DefPath, to: &DefPath, max_super: usize) -> St
|
||||||
// a::b::sym:: :: refers to
|
// a::b::sym:: :: refers to
|
||||||
// c::d::e ::f::sym
|
// c::d::e ::f::sym
|
||||||
// when looking at `f`
|
// when looking at `f`
|
||||||
Left(DefPathData::TypeNs(sym)) => path.push(sym.to_string()),
|
Left(DefPathData::TypeNs(Some(sym))) => path.push(sym.to_string()),
|
||||||
// consider:
|
// consider:
|
||||||
// a::b::c ::d::sym refers to
|
// a::b::c ::d::sym refers to
|
||||||
// e::f::sym:: ::
|
// e::f::sym:: ::
|
||||||
|
@ -3517,7 +3517,7 @@ fn maybe_get_relative_path(from: &DefPath, to: &DefPath, max_super: usize) -> St
|
||||||
// `super` chain would be too long, just use the absolute path instead
|
// `super` chain would be too long, just use the absolute path instead
|
||||||
once(String::from("crate"))
|
once(String::from("crate"))
|
||||||
.chain(to.data.iter().filter_map(|el| {
|
.chain(to.data.iter().filter_map(|el| {
|
||||||
if let DefPathData::TypeNs(sym) = el.data {
|
if let DefPathData::TypeNs(Some(sym)) = el.data {
|
||||||
Some(sym.to_string())
|
Some(sym.to_string())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
|
@ -15,7 +15,7 @@ impl TestCx<'_> {
|
||||||
// if a test does not crash, consider it an error
|
// if a test does not crash, consider it an error
|
||||||
if proc_res.status.success() || matches!(proc_res.status.code(), Some(1 | 0)) {
|
if proc_res.status.success() || matches!(proc_res.status.code(), Some(1 | 0)) {
|
||||||
self.fatal(&format!(
|
self.fatal(&format!(
|
||||||
"crashtest no longer crashes/triggers ICE, horray! Please give it a meaningful \
|
"crashtest no longer crashes/triggers ICE, hooray! Please give it a meaningful \
|
||||||
name, add a doc-comment to the start of the test explaining why it exists and \
|
name, add a doc-comment to the start of the test explaining why it exists and \
|
||||||
move it to tests/ui or wherever you see fit. Adding 'Fixes #<issueNr>' to your PR \
|
move it to tests/ui or wherever you see fit. Adding 'Fixes #<issueNr>' to your PR \
|
||||||
description ensures that the corresponding ticket is auto-closed upon merge. \
|
description ensures that the corresponding ticket is auto-closed upon merge. \
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
//@ known-bug: #133426
|
|
||||||
|
|
||||||
fn a(
|
|
||||||
_: impl Iterator<
|
|
||||||
Item = [(); {
|
|
||||||
match *todo!() { ! };
|
|
||||||
}],
|
|
||||||
>,
|
|
||||||
) {
|
|
||||||
}
|
|
||||||
|
|
||||||
fn b(_: impl Iterator<Item = { match 0 { ! } }>) {}
|
|
20
tests/ui/lowering/no-name-for-DefPath-issue-133426.rs
Normal file
20
tests/ui/lowering/no-name-for-DefPath-issue-133426.rs
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
//! Test for the crash in #133426, caused by an empty symbol being used for a
|
||||||
|
//! type name.
|
||||||
|
|
||||||
|
#![allow(incomplete_features)]
|
||||||
|
#![feature(never_patterns)]
|
||||||
|
|
||||||
|
fn a(
|
||||||
|
_: impl Iterator<
|
||||||
|
Item = [(); {
|
||||||
|
match *todo!() { ! }; //~ ERROR type `!` cannot be dereferenced
|
||||||
|
}],
|
||||||
|
>,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
fn b(_: impl Iterator<Item = { match 0 { ! } }>) {}
|
||||||
|
//~^ ERROR associated const equality is incomplete
|
||||||
|
//~| ERROR expected type, found constant
|
||||||
|
|
||||||
|
fn main() {}
|
31
tests/ui/lowering/no-name-for-DefPath-issue-133426.stderr
Normal file
31
tests/ui/lowering/no-name-for-DefPath-issue-133426.stderr
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
error[E0658]: associated const equality is incomplete
|
||||||
|
--> $DIR/no-name-for-DefPath-issue-133426.rs:16:23
|
||||||
|
|
|
||||||
|
LL | fn b(_: impl Iterator<Item = { match 0 { ! } }>) {}
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= note: see issue #92827 <https://github.com/rust-lang/rust/issues/92827> for more information
|
||||||
|
= help: add `#![feature(associated_const_equality)]` to the crate attributes to enable
|
||||||
|
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||||
|
|
||||||
|
error[E0614]: type `!` cannot be dereferenced
|
||||||
|
--> $DIR/no-name-for-DefPath-issue-133426.rs:10:19
|
||||||
|
|
|
||||||
|
LL | match *todo!() { ! };
|
||||||
|
| ^^^^^^^^ can't be dereferenced
|
||||||
|
|
||||||
|
error: expected type, found constant
|
||||||
|
--> $DIR/no-name-for-DefPath-issue-133426.rs:16:30
|
||||||
|
|
|
||||||
|
LL | fn b(_: impl Iterator<Item = { match 0 { ! } }>) {}
|
||||||
|
| ---- ^^^^^^^^^^^^^^^^^ unexpected constant
|
||||||
|
| |
|
||||||
|
| expected a type because of this associated type
|
||||||
|
|
|
||||||
|
note: the associated type is defined here
|
||||||
|
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
|
||||||
|
|
||||||
|
error: aborting due to 3 previous errors
|
||||||
|
|
||||||
|
Some errors have detailed explanations: E0614, E0658.
|
||||||
|
For more information about an error, try `rustc --explain E0614`.
|
Loading…
Add table
Add a link
Reference in a new issue