Store a LocalDefId in hir::Variant & hir::Field.
This commit is contained in:
parent
607d0c2a14
commit
9d20aca983
@ -307,8 +307,8 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
|
||||
}
|
||||
|
||||
fn visit_variant(&mut self, v: &'hir Variant<'hir>) {
|
||||
self.insert(v.span, v.id, Node::Variant(v));
|
||||
self.with_parent(v.id, |this| {
|
||||
self.insert(v.span, v.hir_id, Node::Variant(v));
|
||||
self.with_parent(v.hir_id, |this| {
|
||||
// Register the constructor of this variant.
|
||||
if let Some(ctor_hir_id) = v.data.ctor_hir_id() {
|
||||
this.insert(v.span, ctor_hir_id, Node::Ctor(&v.data));
|
||||
|
@ -709,11 +709,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
}
|
||||
|
||||
fn lower_variant(&mut self, v: &Variant) -> hir::Variant<'hir> {
|
||||
let id = self.lower_node_id(v.id);
|
||||
self.lower_attrs(id, &v.attrs);
|
||||
let hir_id = self.lower_node_id(v.id);
|
||||
self.lower_attrs(hir_id, &v.attrs);
|
||||
hir::Variant {
|
||||
id,
|
||||
data: self.lower_variant_data(id, &v.data),
|
||||
hir_id,
|
||||
def_id: self.local_def_id(v.id),
|
||||
data: self.lower_variant_data(hir_id, &v.data),
|
||||
disr_expr: v.disr_expr.as_ref().map(|e| self.lower_anon_const(e)),
|
||||
ident: self.lower_ident(v.ident),
|
||||
span: self.lower_span(v.span),
|
||||
@ -739,12 +740,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
fields.iter().enumerate().map(|f| self.lower_field_def(f)),
|
||||
),
|
||||
ctor_id,
|
||||
self.local_def_id(id),
|
||||
)
|
||||
}
|
||||
VariantData::Unit(id) => {
|
||||
let ctor_id = self.lower_node_id(id);
|
||||
self.alias_attrs(ctor_id, parent_id);
|
||||
hir::VariantData::Unit(ctor_id)
|
||||
hir::VariantData::Unit(ctor_id, self.local_def_id(id))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -767,6 +769,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
hir::FieldDef {
|
||||
span: self.lower_span(f.span),
|
||||
hir_id,
|
||||
def_id: self.local_def_id(f.id),
|
||||
ident: match f.ident {
|
||||
Some(ident) => self.lower_ident(ident),
|
||||
// FIXME(jseyfried): positional field hygiene.
|
||||
|
@ -2801,7 +2801,8 @@ pub struct Variant<'hir> {
|
||||
/// Name of the variant.
|
||||
pub ident: Ident,
|
||||
/// Id of the variant (not the constructor, see `VariantData::ctor_hir_id()`).
|
||||
pub id: HirId,
|
||||
pub hir_id: HirId,
|
||||
pub def_id: LocalDefId,
|
||||
/// Fields and constructor id of the variant.
|
||||
pub data: VariantData<'hir>,
|
||||
/// Explicit discriminant (e.g., `Foo = 1`).
|
||||
@ -2868,6 +2869,7 @@ pub struct FieldDef<'hir> {
|
||||
pub vis_span: Span,
|
||||
pub ident: Ident,
|
||||
pub hir_id: HirId,
|
||||
pub def_id: LocalDefId,
|
||||
pub ty: &'hir Ty<'hir>,
|
||||
}
|
||||
|
||||
@ -2889,11 +2891,11 @@ pub enum VariantData<'hir> {
|
||||
/// A tuple variant.
|
||||
///
|
||||
/// E.g., `Bar(..)` as in `enum Foo { Bar(..) }`.
|
||||
Tuple(&'hir [FieldDef<'hir>], HirId),
|
||||
Tuple(&'hir [FieldDef<'hir>], HirId, LocalDefId),
|
||||
/// A unit variant.
|
||||
///
|
||||
/// E.g., `Bar = ..` as in `enum Foo { Bar = .. }`.
|
||||
Unit(HirId),
|
||||
Unit(HirId, LocalDefId),
|
||||
}
|
||||
|
||||
impl<'hir> VariantData<'hir> {
|
||||
@ -2905,11 +2907,19 @@ impl<'hir> VariantData<'hir> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the `LocalDefId` of this variant's constructor, if it has one.
|
||||
pub fn ctor_def_id(&self) -> Option<LocalDefId> {
|
||||
match *self {
|
||||
VariantData::Struct(_, _) => None,
|
||||
VariantData::Tuple(_, _, def_id) | VariantData::Unit(_, def_id) => Some(def_id),
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the `HirId` of this variant's constructor, if it has one.
|
||||
pub fn ctor_hir_id(&self) -> Option<HirId> {
|
||||
match *self {
|
||||
VariantData::Struct(_, _) => None,
|
||||
VariantData::Tuple(_, hir_id) | VariantData::Unit(hir_id) => Some(hir_id),
|
||||
VariantData::Tuple(_, hir_id, _) | VariantData::Unit(hir_id, _) => Some(hir_id),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3535,7 +3545,7 @@ impl<'hir> Node<'hir> {
|
||||
/// Get the fields for the tuple-constructor,
|
||||
/// if this node is a tuple constructor, otherwise None
|
||||
pub fn tuple_fields(&self) -> Option<&'hir [FieldDef<'hir>]> {
|
||||
if let Node::Ctor(&VariantData::Tuple(fields, _)) = self { Some(fields) } else { None }
|
||||
if let Node::Ctor(&VariantData::Tuple(fields, _, _)) = self { Some(fields) } else { None }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1085,7 +1085,7 @@ pub fn walk_enum_def<'v, V: Visitor<'v>>(
|
||||
|
||||
pub fn walk_variant<'v, V: Visitor<'v>>(visitor: &mut V, variant: &'v Variant<'v>) {
|
||||
visitor.visit_ident(variant.ident);
|
||||
visitor.visit_id(variant.id);
|
||||
visitor.visit_id(variant.hir_id);
|
||||
visitor.visit_variant_data(&variant.data);
|
||||
walk_list!(visitor, visit_anon_const, &variant.disr_expr);
|
||||
}
|
||||
|
@ -633,14 +633,12 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
|
||||
tcx.ensure().predicates_of(def_id);
|
||||
|
||||
for f in struct_def.fields() {
|
||||
let def_id = tcx.hir().local_def_id(f.hir_id);
|
||||
tcx.ensure().generics_of(def_id);
|
||||
tcx.ensure().type_of(def_id);
|
||||
tcx.ensure().predicates_of(def_id);
|
||||
tcx.ensure().generics_of(f.def_id);
|
||||
tcx.ensure().type_of(f.def_id);
|
||||
tcx.ensure().predicates_of(f.def_id);
|
||||
}
|
||||
|
||||
if let Some(ctor_hir_id) = struct_def.ctor_hir_id() {
|
||||
let ctor_def_id = tcx.hir().local_def_id(ctor_hir_id);
|
||||
if let Some(ctor_def_id) = struct_def.ctor_def_id() {
|
||||
convert_variant_ctor(tcx, ctor_def_id);
|
||||
}
|
||||
}
|
||||
@ -817,7 +815,6 @@ fn convert_variant(
|
||||
.fields()
|
||||
.iter()
|
||||
.map(|f| {
|
||||
let fid = tcx.hir().local_def_id(f.hir_id);
|
||||
let dup_span = seen_fields.get(&f.ident.normalize_to_macros_2_0()).cloned();
|
||||
if let Some(prev_span) = dup_span {
|
||||
tcx.sess.emit_err(errors::FieldAlreadyDeclared {
|
||||
@ -829,7 +826,11 @@ fn convert_variant(
|
||||
seen_fields.insert(f.ident.normalize_to_macros_2_0(), f.span);
|
||||
}
|
||||
|
||||
ty::FieldDef { did: fid.to_def_id(), name: f.ident.name, vis: tcx.visibility(fid) }
|
||||
ty::FieldDef {
|
||||
did: f.def_id.to_def_id(),
|
||||
name: f.ident.name,
|
||||
vis: tcx.visibility(f.def_id),
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
let recovered = match def {
|
||||
@ -870,10 +871,6 @@ fn adt_def<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> ty::AdtDef<'tcx> {
|
||||
.variants
|
||||
.iter()
|
||||
.map(|v| {
|
||||
let variant_did = Some(tcx.hir().local_def_id(v.id));
|
||||
let ctor_did =
|
||||
v.data.ctor_hir_id().map(|hir_id| tcx.hir().local_def_id(hir_id));
|
||||
|
||||
let discr = if let Some(ref e) = v.disr_expr {
|
||||
distance_from_explicit = 0;
|
||||
ty::VariantDiscr::Explicit(e.def_id.to_def_id())
|
||||
@ -884,8 +881,8 @@ fn adt_def<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> ty::AdtDef<'tcx> {
|
||||
|
||||
convert_variant(
|
||||
tcx,
|
||||
variant_did,
|
||||
ctor_did,
|
||||
Some(v.def_id),
|
||||
v.data.ctor_def_id(),
|
||||
v.ident,
|
||||
discr,
|
||||
&v.data,
|
||||
@ -898,13 +895,10 @@ fn adt_def<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> ty::AdtDef<'tcx> {
|
||||
(AdtKind::Enum, variants)
|
||||
}
|
||||
ItemKind::Struct(ref def, _) => {
|
||||
let variant_did = None::<LocalDefId>;
|
||||
let ctor_did = def.ctor_hir_id().map(|hir_id| tcx.hir().local_def_id(hir_id));
|
||||
|
||||
let variants = std::iter::once(convert_variant(
|
||||
tcx,
|
||||
variant_did,
|
||||
ctor_did,
|
||||
None,
|
||||
def.ctor_def_id(),
|
||||
item.ident,
|
||||
ty::VariantDiscr::Relative(0),
|
||||
def,
|
||||
@ -916,13 +910,10 @@ fn adt_def<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> ty::AdtDef<'tcx> {
|
||||
(AdtKind::Struct, variants)
|
||||
}
|
||||
ItemKind::Union(ref def, _) => {
|
||||
let variant_did = None;
|
||||
let ctor_did = def.ctor_hir_id().map(|hir_id| tcx.hir().local_def_id(hir_id));
|
||||
|
||||
let variants = std::iter::once(convert_variant(
|
||||
tcx,
|
||||
variant_did,
|
||||
ctor_did,
|
||||
None,
|
||||
def.ctor_def_id(),
|
||||
item.ident,
|
||||
ty::VariantDiscr::Relative(0),
|
||||
def,
|
||||
@ -1182,8 +1173,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> {
|
||||
|
||||
Ctor(data) | Variant(hir::Variant { data, .. }) if data.ctor_hir_id().is_some() => {
|
||||
let ty = tcx.type_of(tcx.hir().get_parent_item(hir_id));
|
||||
let inputs =
|
||||
data.fields().iter().map(|f| tcx.type_of(tcx.hir().local_def_id(f.hir_id)));
|
||||
let inputs = data.fields().iter().map(|f| tcx.type_of(f.def_id));
|
||||
ty::Binder::dummy(tcx.mk_fn_sig(
|
||||
inputs,
|
||||
ty,
|
||||
|
@ -754,7 +754,7 @@ impl<'a> State<'a> {
|
||||
for v in variants {
|
||||
self.space_if_not_bol();
|
||||
self.maybe_print_comment(v.span.lo());
|
||||
self.print_outer_attributes(self.attrs(v.id));
|
||||
self.print_outer_attributes(self.attrs(v.hir_id));
|
||||
self.ibox(INDENT_UNIT);
|
||||
self.print_variant(v);
|
||||
self.word(",");
|
||||
|
@ -185,9 +185,8 @@ impl<'tcx> LateLintPass<'tcx> for BoxPointers {
|
||||
// If it's a struct, we also have to check the fields' types
|
||||
match it.kind {
|
||||
hir::ItemKind::Struct(ref struct_def, _) | hir::ItemKind::Union(ref struct_def, _) => {
|
||||
for struct_field in struct_def.fields() {
|
||||
let def_id = cx.tcx.hir().local_def_id(struct_field.hir_id);
|
||||
self.check_heap_type(cx, struct_field.span, cx.tcx.type_of(def_id));
|
||||
for field in struct_def.fields() {
|
||||
self.check_heap_type(cx, field.span, cx.tcx.type_of(field.def_id));
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
@ -673,13 +672,12 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
|
||||
|
||||
fn check_field_def(&mut self, cx: &LateContext<'_>, sf: &hir::FieldDef<'_>) {
|
||||
if !sf.is_positional() {
|
||||
let def_id = cx.tcx.hir().local_def_id(sf.hir_id);
|
||||
self.check_missing_docs_attrs(cx, def_id, "a", "struct field")
|
||||
self.check_missing_docs_attrs(cx, sf.def_id, "a", "struct field")
|
||||
}
|
||||
}
|
||||
|
||||
fn check_variant(&mut self, cx: &LateContext<'_>, v: &hir::Variant<'_>) {
|
||||
self.check_missing_docs_attrs(cx, cx.tcx.hir().local_def_id(v.id), "a", "variant");
|
||||
self.check_missing_docs_attrs(cx, v.def_id, "a", "variant");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1424,11 +1422,10 @@ impl<'tcx> LateLintPass<'tcx> for UnreachablePub {
|
||||
|
||||
fn check_field_def(&mut self, cx: &LateContext<'_>, field: &hir::FieldDef<'_>) {
|
||||
let map = cx.tcx.hir();
|
||||
let def_id = map.local_def_id(field.hir_id);
|
||||
if matches!(map.get(map.get_parent_node(field.hir_id)), Node::Variant(_)) {
|
||||
return;
|
||||
}
|
||||
self.perform_lint(cx, "field", def_id, field.vis_span, false);
|
||||
self.perform_lint(cx, "field", field.def_id, field.vis_span, false);
|
||||
}
|
||||
|
||||
fn check_impl_item(&mut self, cx: &LateContext<'_>, impl_item: &hir::ImplItem<'_>) {
|
||||
|
@ -205,7 +205,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
|
||||
}
|
||||
|
||||
fn visit_variant(&mut self, v: &'tcx hir::Variant<'tcx>) {
|
||||
self.with_lint_attrs(v.id, |cx| {
|
||||
self.with_lint_attrs(v.hir_id, |cx| {
|
||||
lint_callback!(cx, check_variant, v);
|
||||
hir_visit::walk_variant(cx, v);
|
||||
})
|
||||
|
@ -320,7 +320,7 @@ impl<'tcx> Visitor<'tcx> for LintLevelsBuilder<'_, LintLevelQueryMap<'tcx>> {
|
||||
}
|
||||
|
||||
fn visit_variant(&mut self, v: &'tcx hir::Variant<'tcx>) {
|
||||
self.add_id(v.id);
|
||||
self.add_id(v.hir_id);
|
||||
intravisit::walk_variant(self, v);
|
||||
}
|
||||
|
||||
@ -392,7 +392,7 @@ impl<'tcx> Visitor<'tcx> for LintLevelsBuilder<'_, QueryMapExpectationsWrapper<'
|
||||
}
|
||||
|
||||
fn visit_variant(&mut self, v: &'tcx hir::Variant<'tcx>) {
|
||||
self.add_id(v.id);
|
||||
self.add_id(v.hir_id);
|
||||
intravisit::walk_variant(self, v);
|
||||
}
|
||||
|
||||
|
@ -1558,9 +1558,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||
// Encode def_ids for each field and method
|
||||
// for methods, write all the stuff get_trait_method
|
||||
// needs to know
|
||||
let ctor = struct_def
|
||||
.ctor_hir_id()
|
||||
.map(|ctor_hir_id| self.tcx.hir().local_def_id(ctor_hir_id).local_def_index);
|
||||
let ctor = struct_def.ctor_def_id().map(|ctor_def_id| ctor_def_id.local_def_index);
|
||||
|
||||
let variant = adt_def.non_enum_variant();
|
||||
record!(self.tables.variant_data[def_id] <- VariantData {
|
||||
@ -1685,8 +1683,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||
hir::ItemKind::Struct(ref struct_def, _) => {
|
||||
let def = self.tcx.adt_def(item.owner_id.to_def_id());
|
||||
// If the struct has a constructor, encode it.
|
||||
if let Some(ctor_hir_id) = struct_def.ctor_hir_id() {
|
||||
let ctor_def_id = self.tcx.hir().local_def_id(ctor_hir_id);
|
||||
if let Some(ctor_def_id) = struct_def.ctor_def_id() {
|
||||
self.encode_struct_ctor(def, ctor_def_id.to_def_id());
|
||||
}
|
||||
}
|
||||
|
@ -217,19 +217,18 @@ fn mir_keys(tcx: TyCtxt<'_>, (): ()) -> FxIndexSet<LocalDefId> {
|
||||
|
||||
// Additionally, tuple struct/variant constructors have MIR, but
|
||||
// they don't have a BodyId, so we need to build them separately.
|
||||
struct GatherCtors<'a, 'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
struct GatherCtors<'a> {
|
||||
set: &'a mut FxIndexSet<LocalDefId>,
|
||||
}
|
||||
impl<'tcx> Visitor<'tcx> for GatherCtors<'_, 'tcx> {
|
||||
impl<'tcx> Visitor<'tcx> for GatherCtors<'_> {
|
||||
fn visit_variant_data(&mut self, v: &'tcx hir::VariantData<'tcx>) {
|
||||
if let hir::VariantData::Tuple(_, hir_id) = *v {
|
||||
self.set.insert(self.tcx.hir().local_def_id(hir_id));
|
||||
if let hir::VariantData::Tuple(_, _, def_id) = *v {
|
||||
self.set.insert(def_id);
|
||||
}
|
||||
intravisit::walk_struct_def(self, v)
|
||||
}
|
||||
}
|
||||
tcx.hir().visit_all_item_likes_in_crate(&mut GatherCtors { tcx, set: &mut set });
|
||||
tcx.hir().visit_all_item_likes_in_crate(&mut GatherCtors { set: &mut set });
|
||||
|
||||
set
|
||||
}
|
||||
|
@ -2137,7 +2137,7 @@ impl<'tcx> Visitor<'tcx> for CheckAttrVisitor<'tcx> {
|
||||
}
|
||||
|
||||
fn visit_variant(&mut self, variant: &'tcx hir::Variant<'tcx>) {
|
||||
self.check_attributes(variant.id, variant.span, Target::Variant, None);
|
||||
self.check_attributes(variant.hir_id, variant.span, Target::Variant, None);
|
||||
intravisit::walk_variant(self, variant)
|
||||
}
|
||||
|
||||
|
@ -362,7 +362,7 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
|
||||
let has_repr_c = self.repr_has_repr_c;
|
||||
let has_repr_simd = self.repr_has_repr_simd;
|
||||
let live_fields = def.fields().iter().filter_map(|f| {
|
||||
let def_id = tcx.hir().local_def_id(f.hir_id);
|
||||
let def_id = f.def_id;
|
||||
if has_repr_c || (f.is_positional() && has_repr_simd) {
|
||||
return Some(def_id);
|
||||
}
|
||||
@ -522,17 +522,13 @@ fn check_item<'tcx>(
|
||||
DefKind::Enum => {
|
||||
let item = tcx.hir().item(id);
|
||||
if let hir::ItemKind::Enum(ref enum_def, _) = item.kind {
|
||||
let hir = tcx.hir();
|
||||
if allow_dead_code {
|
||||
worklist.extend(
|
||||
enum_def.variants.iter().map(|variant| hir.local_def_id(variant.id)),
|
||||
);
|
||||
worklist.extend(enum_def.variants.iter().map(|variant| variant.def_id));
|
||||
}
|
||||
|
||||
for variant in enum_def.variants {
|
||||
if let Some(ctor_hir_id) = variant.data.ctor_hir_id() {
|
||||
struct_constructors
|
||||
.insert(hir.local_def_id(ctor_hir_id), hir.local_def_id(variant.id));
|
||||
if let Some(ctor_def_id) = variant.data.ctor_def_id() {
|
||||
struct_constructors.insert(ctor_def_id, variant.def_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -219,7 +219,7 @@ fn get_lang_items(tcx: TyCtxt<'_>, (): ()) -> LanguageItems {
|
||||
let item = tcx.hir().item(id);
|
||||
if let hir::ItemKind::Enum(def, ..) = &item.kind {
|
||||
for variant in def.variants {
|
||||
collector.check_for_lang(Target::Variant, variant.id);
|
||||
collector.check_for_lang(Target::Variant, variant.hir_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -358,9 +358,9 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
|
||||
const_stab_inherit = InheritConstStability::Yes;
|
||||
}
|
||||
hir::ItemKind::Struct(ref sd, _) => {
|
||||
if let Some(ctor_hir_id) = sd.ctor_hir_id() {
|
||||
if let Some(ctor_def_id) = sd.ctor_def_id() {
|
||||
self.annotate(
|
||||
self.tcx.hir().local_def_id(ctor_hir_id),
|
||||
ctor_def_id,
|
||||
i.span,
|
||||
None,
|
||||
AnnotationKind::Required,
|
||||
@ -435,7 +435,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
|
||||
|
||||
fn visit_variant(&mut self, var: &'tcx Variant<'tcx>) {
|
||||
self.annotate(
|
||||
self.tcx.hir().local_def_id(var.id),
|
||||
var.def_id,
|
||||
var.span,
|
||||
None,
|
||||
AnnotationKind::Required,
|
||||
@ -443,9 +443,9 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
|
||||
InheritConstStability::No,
|
||||
InheritStability::Yes,
|
||||
|v| {
|
||||
if let Some(ctor_hir_id) = var.data.ctor_hir_id() {
|
||||
if let Some(ctor_def_id) = var.data.ctor_def_id() {
|
||||
v.annotate(
|
||||
v.tcx.hir().local_def_id(ctor_hir_id),
|
||||
ctor_def_id,
|
||||
var.span,
|
||||
None,
|
||||
AnnotationKind::Required,
|
||||
@ -463,7 +463,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
|
||||
|
||||
fn visit_field_def(&mut self, s: &'tcx FieldDef<'tcx>) {
|
||||
self.annotate(
|
||||
self.tcx.hir().local_def_id(s.hir_id),
|
||||
s.def_id,
|
||||
s.span,
|
||||
None,
|
||||
AnnotationKind::Required,
|
||||
@ -593,15 +593,15 @@ impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'tcx> {
|
||||
}
|
||||
|
||||
fn visit_variant(&mut self, var: &'tcx Variant<'tcx>) {
|
||||
self.check_missing_stability(self.tcx.hir().local_def_id(var.id), var.span);
|
||||
if let Some(ctor_hir_id) = var.data.ctor_hir_id() {
|
||||
self.check_missing_stability(self.tcx.hir().local_def_id(ctor_hir_id), var.span);
|
||||
self.check_missing_stability(var.def_id, var.span);
|
||||
if let Some(ctor_def_id) = var.data.ctor_def_id() {
|
||||
self.check_missing_stability(ctor_def_id, var.span);
|
||||
}
|
||||
intravisit::walk_variant(self, var);
|
||||
}
|
||||
|
||||
fn visit_field_def(&mut self, s: &'tcx FieldDef<'tcx>) {
|
||||
self.check_missing_stability(self.tcx.hir().local_def_id(s.hir_id), s.span);
|
||||
self.check_missing_stability(s.def_id, s.span);
|
||||
intravisit::walk_field_def(self, s);
|
||||
}
|
||||
|
||||
|
@ -419,11 +419,6 @@ impl<'tcx> EmbargoVisitor<'tcx> {
|
||||
self.effective_visibilities.public_at_level(def_id)
|
||||
}
|
||||
|
||||
fn update_with_hir_id(&mut self, hir_id: hir::HirId, level: Option<Level>) -> Option<Level> {
|
||||
let def_id = self.tcx.hir().local_def_id(hir_id);
|
||||
self.update(def_id, level)
|
||||
}
|
||||
|
||||
/// Updates node level and returns the updated level.
|
||||
fn update(&mut self, def_id: LocalDefId, level: Option<Level>) -> Option<Level> {
|
||||
let old_level = self.get(def_id);
|
||||
@ -573,10 +568,9 @@ impl<'tcx> EmbargoVisitor<'tcx> {
|
||||
| hir::ItemKind::Union(ref struct_def, _) = item.kind
|
||||
{
|
||||
for field in struct_def.fields() {
|
||||
let def_id = self.tcx.hir().local_def_id(field.hir_id);
|
||||
let field_vis = self.tcx.local_visibility(def_id);
|
||||
let field_vis = self.tcx.local_visibility(field.def_id);
|
||||
if field_vis.is_accessible_from(module, self.tcx) {
|
||||
self.reach(def_id, level).ty();
|
||||
self.reach(field.def_id, level).ty();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -641,12 +635,12 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
|
||||
match item.kind {
|
||||
hir::ItemKind::Enum(ref def, _) => {
|
||||
for variant in def.variants {
|
||||
let variant_level = self.update_with_hir_id(variant.id, item_level);
|
||||
if let Some(ctor_hir_id) = variant.data.ctor_hir_id() {
|
||||
self.update_with_hir_id(ctor_hir_id, item_level);
|
||||
let variant_level = self.update(variant.def_id, item_level);
|
||||
if let Some(ctor_def_id) = variant.data.ctor_def_id() {
|
||||
self.update(ctor_def_id, item_level);
|
||||
}
|
||||
for field in variant.data.fields() {
|
||||
self.update_with_hir_id(field.hir_id, variant_level);
|
||||
self.update(field.def_id, variant_level);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -665,14 +659,13 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
|
||||
}
|
||||
}
|
||||
hir::ItemKind::Struct(ref def, _) | hir::ItemKind::Union(ref def, _) => {
|
||||
if let Some(ctor_hir_id) = def.ctor_hir_id() {
|
||||
self.update_with_hir_id(ctor_hir_id, item_level);
|
||||
if let Some(ctor_def_id) = def.ctor_def_id() {
|
||||
self.update(ctor_def_id, item_level);
|
||||
}
|
||||
for field in def.fields() {
|
||||
let def_id = self.tcx.hir().local_def_id(field.hir_id);
|
||||
let vis = self.tcx.visibility(def_id);
|
||||
let vis = self.tcx.visibility(field.def_id);
|
||||
if vis.is_public() {
|
||||
self.update_with_hir_id(field.hir_id, item_level);
|
||||
self.update(field.def_id, item_level);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -782,18 +775,16 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
|
||||
self.reach(item.owner_id.def_id, item_level).generics().predicates();
|
||||
}
|
||||
for variant in def.variants {
|
||||
let variant_level = self.get(self.tcx.hir().local_def_id(variant.id));
|
||||
let variant_level = self.get(variant.def_id);
|
||||
if variant_level.is_some() {
|
||||
for field in variant.data.fields() {
|
||||
self.reach(self.tcx.hir().local_def_id(field.hir_id), variant_level)
|
||||
.ty();
|
||||
self.reach(field.def_id, variant_level).ty();
|
||||
}
|
||||
// Corner case: if the variant is reachable, but its
|
||||
// enum is not, make the enum reachable as well.
|
||||
self.reach(item.owner_id.def_id, variant_level).ty();
|
||||
}
|
||||
if let Some(hir_id) = variant.data.ctor_hir_id() {
|
||||
let ctor_def_id = self.tcx.hir().local_def_id(hir_id);
|
||||
if let Some(ctor_def_id) = variant.data.ctor_def_id() {
|
||||
let ctor_level = self.get(ctor_def_id);
|
||||
if ctor_level.is_some() {
|
||||
self.reach(item.owner_id.def_id, ctor_level).ty();
|
||||
@ -818,15 +809,13 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
|
||||
if item_level.is_some() {
|
||||
self.reach(item.owner_id.def_id, item_level).generics().predicates();
|
||||
for field in struct_def.fields() {
|
||||
let def_id = self.tcx.hir().local_def_id(field.hir_id);
|
||||
let field_level = self.get(def_id);
|
||||
let field_level = self.get(field.def_id);
|
||||
if field_level.is_some() {
|
||||
self.reach(def_id, field_level).ty();
|
||||
self.reach(field.def_id, field_level).ty();
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(hir_id) = struct_def.ctor_hir_id() {
|
||||
let ctor_def_id = self.tcx.hir().local_def_id(hir_id);
|
||||
if let Some(ctor_def_id) = struct_def.ctor_def_id() {
|
||||
let ctor_level = self.get(ctor_def_id);
|
||||
if ctor_level.is_some() {
|
||||
self.reach(item.owner_id.def_id, ctor_level).ty();
|
||||
@ -957,26 +946,21 @@ impl<'tcx, 'a> Visitor<'tcx> for TestReachabilityVisitor<'tcx, 'a> {
|
||||
match item.kind {
|
||||
hir::ItemKind::Enum(ref def, _) => {
|
||||
for variant in def.variants.iter() {
|
||||
let variant_id = self.tcx.hir().local_def_id(variant.id);
|
||||
self.effective_visibility_diagnostic(variant_id);
|
||||
if let Some(ctor_hir_id) = variant.data.ctor_hir_id() {
|
||||
let ctor_def_id = self.tcx.hir().local_def_id(ctor_hir_id);
|
||||
self.effective_visibility_diagnostic(variant.def_id);
|
||||
if let Some(ctor_def_id) = variant.data.ctor_def_id() {
|
||||
self.effective_visibility_diagnostic(ctor_def_id);
|
||||
}
|
||||
for field in variant.data.fields() {
|
||||
let def_id = self.tcx.hir().local_def_id(field.hir_id);
|
||||
self.effective_visibility_diagnostic(def_id);
|
||||
self.effective_visibility_diagnostic(field.def_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
hir::ItemKind::Struct(ref def, _) | hir::ItemKind::Union(ref def, _) => {
|
||||
if let Some(ctor_hir_id) = def.ctor_hir_id() {
|
||||
let ctor_def_id = self.tcx.hir().local_def_id(ctor_hir_id);
|
||||
if let Some(ctor_def_id) = def.ctor_def_id() {
|
||||
self.effective_visibility_diagnostic(ctor_def_id);
|
||||
}
|
||||
for field in def.fields() {
|
||||
let def_id = self.tcx.hir().local_def_id(field.hir_id);
|
||||
self.effective_visibility_diagnostic(def_id);
|
||||
self.effective_visibility_diagnostic(field.def_id);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
@ -1719,7 +1703,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
|
||||
}
|
||||
|
||||
fn visit_variant(&mut self, v: &'tcx hir::Variant<'tcx>) {
|
||||
if self.effective_visibilities.is_reachable(self.tcx.hir().local_def_id(v.id)) {
|
||||
if self.effective_visibilities.is_reachable(v.def_id) {
|
||||
self.in_variant = true;
|
||||
intravisit::walk_variant(self, v);
|
||||
self.in_variant = false;
|
||||
@ -1727,8 +1711,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
|
||||
}
|
||||
|
||||
fn visit_field_def(&mut self, s: &'tcx hir::FieldDef<'tcx>) {
|
||||
let def_id = self.tcx.hir().local_def_id(s.hir_id);
|
||||
let vis = self.tcx.visibility(def_id);
|
||||
let vis = self.tcx.visibility(s.def_id);
|
||||
if vis.is_public() || self.in_variant {
|
||||
intravisit::walk_field_def(self, s);
|
||||
}
|
||||
@ -1982,8 +1965,7 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'tcx> {
|
||||
|
||||
for variant in def.variants {
|
||||
for field in variant.data.fields() {
|
||||
self.check(self.tcx.hir().local_def_id(field.hir_id), item_visibility)
|
||||
.ty();
|
||||
self.check(field.def_id, item_visibility).ty();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2010,9 +1992,8 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'tcx> {
|
||||
self.check(item.owner_id.def_id, item_visibility).generics().predicates();
|
||||
|
||||
for field in struct_def.fields() {
|
||||
let def_id = tcx.hir().local_def_id(field.hir_id);
|
||||
let field_visibility = tcx.local_visibility(def_id);
|
||||
self.check(def_id, min(item_visibility, field_visibility, tcx)).ty();
|
||||
let field_visibility = tcx.local_visibility(field.def_id);
|
||||
self.check(field.def_id, min(item_visibility, field_visibility, tcx)).ty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -527,9 +527,9 @@ impl<'tcx> DumpVisitor<'tcx> {
|
||||
let value = format!("{}::{} {{ {} }}", enum_data.name, name, fields_str);
|
||||
if !self.span.filter_generated(name_span) {
|
||||
let span = self.span_from_span(name_span);
|
||||
let id = id_from_hir_id(variant.id, &self.save_ctxt);
|
||||
let id = id_from_hir_id(variant.hir_id, &self.save_ctxt);
|
||||
let parent = Some(id_from_def_id(item.owner_id.to_def_id()));
|
||||
let attrs = self.tcx.hir().attrs(variant.id);
|
||||
let attrs = self.tcx.hir().attrs(variant.hir_id);
|
||||
|
||||
self.dumper.dump_def(
|
||||
&access,
|
||||
@ -552,7 +552,7 @@ impl<'tcx> DumpVisitor<'tcx> {
|
||||
}
|
||||
ref v => {
|
||||
let mut value = format!("{}::{}", enum_data.name, name);
|
||||
if let hir::VariantData::Tuple(fields, _) = v {
|
||||
if let hir::VariantData::Tuple(fields, _, _) = v {
|
||||
value.push('(');
|
||||
value.push_str(
|
||||
&fields
|
||||
@ -565,9 +565,9 @@ impl<'tcx> DumpVisitor<'tcx> {
|
||||
}
|
||||
if !self.span.filter_generated(name_span) {
|
||||
let span = self.span_from_span(name_span);
|
||||
let id = id_from_hir_id(variant.id, &self.save_ctxt);
|
||||
let id = id_from_hir_id(variant.hir_id, &self.save_ctxt);
|
||||
let parent = Some(id_from_def_id(item.owner_id.to_def_id()));
|
||||
let attrs = self.tcx.hir().attrs(variant.id);
|
||||
let attrs = self.tcx.hir().attrs(variant.hir_id);
|
||||
|
||||
self.dumper.dump_def(
|
||||
&access,
|
||||
@ -591,7 +591,7 @@ impl<'tcx> DumpVisitor<'tcx> {
|
||||
}
|
||||
|
||||
for field in variant.data.fields() {
|
||||
self.process_struct_field_def(field, variant.id);
|
||||
self.process_struct_field_def(field, variant.hir_id);
|
||||
self.visit_ty(field.ty);
|
||||
}
|
||||
}
|
||||
|
@ -319,7 +319,7 @@ impl<'tcx> SaveContext<'tcx> {
|
||||
qualname,
|
||||
value,
|
||||
parent: None,
|
||||
children: def.variants.iter().map(|v| id_from_hir_id(v.id, self)).collect(),
|
||||
children: def.variants.iter().map(|v| id_from_hir_id(v.hir_id, self)).collect(),
|
||||
decl_id: None,
|
||||
docs: self.docs_for_attrs(attrs),
|
||||
sig: sig::item_signature(item, self),
|
||||
|
@ -693,7 +693,7 @@ impl<'hir> Sig for hir::Variant<'hir> {
|
||||
text.push('}');
|
||||
Ok(Signature { text, defs, refs })
|
||||
}
|
||||
hir::VariantData::Tuple(fields, id) => {
|
||||
hir::VariantData::Tuple(fields, id, _) => {
|
||||
let name_def = SigElement {
|
||||
id: id_from_hir_id(id, scx),
|
||||
start: offset,
|
||||
@ -712,7 +712,7 @@ impl<'hir> Sig for hir::Variant<'hir> {
|
||||
text.push(')');
|
||||
Ok(Signature { text, defs, refs })
|
||||
}
|
||||
hir::VariantData::Unit(id) => {
|
||||
hir::VariantData::Unit(id, _) => {
|
||||
let name_def = SigElement {
|
||||
id: id_from_hir_id(id, scx),
|
||||
start: offset,
|
||||
|
@ -2045,7 +2045,7 @@ fn clean_maybe_renamed_item<'tcx>(
|
||||
|
||||
fn clean_variant<'tcx>(variant: &hir::Variant<'tcx>, cx: &mut DocContext<'tcx>) -> Item {
|
||||
let kind = VariantItem(clean_variant_data(&variant.data, &variant.disr_expr, cx));
|
||||
Item::from_hir_id_and_parts(variant.id, Some(variant.ident.name), kind, cx)
|
||||
Item::from_hir_id_and_parts(variant.hir_id, Some(variant.ident.name), kind, cx)
|
||||
}
|
||||
|
||||
fn clean_impl<'tcx>(
|
||||
|
@ -1293,7 +1293,7 @@ impl<'a, 'hir, 'tcx> intravisit::Visitor<'hir> for HirCollector<'a, 'hir, 'tcx>
|
||||
}
|
||||
|
||||
fn visit_variant(&mut self, v: &'hir hir::Variant<'_>) {
|
||||
self.visit_testable(v.ident.to_string(), v.id, v.span, |this| {
|
||||
self.visit_testable(v.ident.to_string(), v.hir_id, v.span, |this| {
|
||||
intravisit::walk_variant(this, v);
|
||||
});
|
||||
}
|
||||
|
@ -244,10 +244,10 @@ impl<'a, 'b> DocVisitor for CoverageCalculator<'a, 'b> {
|
||||
matches!(
|
||||
node,
|
||||
hir::Node::Variant(hir::Variant {
|
||||
data: hir::VariantData::Tuple(_, _),
|
||||
data: hir::VariantData::Tuple(_, _, _),
|
||||
..
|
||||
}) | hir::Node::Item(hir::Item {
|
||||
kind: hir::ItemKind::Struct(hir::VariantData::Tuple(_, _), _),
|
||||
kind: hir::ItemKind::Struct(hir::VariantData::Tuple(_, _, _), _),
|
||||
..
|
||||
})
|
||||
)
|
||||
|
@ -140,7 +140,7 @@ hir-stats GenericArg 128 ( 1.4%) 4 32
|
||||
hir-stats - Type 32 ( 0.3%) 1
|
||||
hir-stats - Lifetime 96 ( 1.0%) 3
|
||||
hir-stats GenericArgs 144 ( 1.6%) 3 48
|
||||
hir-stats Variant 160 ( 1.7%) 2 80
|
||||
hir-stats Variant 176 ( 1.9%) 2 88
|
||||
hir-stats GenericBound 192 ( 2.1%) 4 48
|
||||
hir-stats - Trait 192 ( 2.1%) 4
|
||||
hir-stats WherePredicate 192 ( 2.1%) 3 64
|
||||
@ -152,7 +152,7 @@ hir-stats - Struct 72 ( 0.8%) 1
|
||||
hir-stats - Binding 216 ( 2.4%) 3
|
||||
hir-stats GenericParam 400 ( 4.4%) 5 80
|
||||
hir-stats Generics 560 ( 6.1%) 10 56
|
||||
hir-stats Ty 720 ( 7.9%) 15 48
|
||||
hir-stats Ty 720 ( 7.8%) 15 48
|
||||
hir-stats - Ptr 48 ( 0.5%) 1
|
||||
hir-stats - Rptr 48 ( 0.5%) 1
|
||||
hir-stats - Path 624 ( 6.8%) 13
|
||||
@ -171,8 +171,8 @@ hir-stats - ForeignMod 80 ( 0.9%) 1
|
||||
hir-stats - Impl 80 ( 0.9%) 1
|
||||
hir-stats - Fn 160 ( 1.7%) 2
|
||||
hir-stats - Use 400 ( 4.4%) 5
|
||||
hir-stats Path 1_280 (14.0%) 32 40
|
||||
hir-stats PathSegment 1_920 (21.0%) 40 48
|
||||
hir-stats Path 1_280 (13.9%) 32 40
|
||||
hir-stats PathSegment 1_920 (20.9%) 40 48
|
||||
hir-stats ----------------------------------------------------------------
|
||||
hir-stats Total 9_160
|
||||
hir-stats Total 9_176
|
||||
hir-stats
|
||||
|
@ -157,10 +157,10 @@ impl<'tcx> LateLintPass<'tcx> for ManualNonExhaustiveEnum {
|
||||
&& def.variants.len() > 1
|
||||
{
|
||||
let mut iter = def.variants.iter().filter_map(|v| {
|
||||
let id = cx.tcx.hir().local_def_id(v.id);
|
||||
(matches!(v.data, hir::VariantData::Unit(_))
|
||||
let id = cx.tcx.hir().local_def_id(v.hir_id);
|
||||
(matches!(v.data, hir::VariantData::Unit(..))
|
||||
&& v.ident.as_str().starts_with('_')
|
||||
&& is_doc_hidden(cx.tcx.hir().attrs(v.id)))
|
||||
&& is_doc_hidden(cx.tcx.hir().attrs(v.hir_id)))
|
||||
.then_some((id, v.span))
|
||||
});
|
||||
if let Some((id, span)) = iter.next()
|
||||
|
@ -199,7 +199,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
|
||||
}
|
||||
|
||||
fn check_variant(&mut self, cx: &LateContext<'tcx>, v: &'tcx hir::Variant<'_>) {
|
||||
let attrs = cx.tcx.hir().attrs(v.id);
|
||||
let attrs = cx.tcx.hir().attrs(v.hir_id);
|
||||
if !is_from_proc_macro(cx, v) {
|
||||
self.check_missing_docs_attrs(cx, attrs, v.span, "a", "variant");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user