Skip to content

Commit e5ac087

Browse files
authored
Rollup merge of #93746 - cjgillot:nodefii, r=nikomatsakis
Remove defaultness from ImplItem. This information is not really used anywhere, except HIR pretty-printing. This makes ImplItem and TraitItem more similar.
2 parents 5609465 + 710662c commit e5ac087

File tree

8 files changed

+11
-21
lines changed

8 files changed

+11
-21
lines changed

Diff for: compiler/rustc_ast_lowering/src/item.rs

-4
Original file line numberDiff line numberDiff line change
@@ -894,17 +894,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
894894
AssocItemKind::MacCall(..) => panic!("`TyMac` should have been expanded by now"),
895895
};
896896

897-
// Since `default impl` is not yet implemented, this is always true in impls.
898-
let has_value = true;
899-
let (defaultness, _) = self.lower_defaultness(i.kind.defaultness(), has_value);
900897
let hir_id = self.lower_node_id(i.id);
901898
self.lower_attrs(hir_id, &i.attrs);
902899
let item = hir::ImplItem {
903900
def_id: hir_id.expect_owner(),
904901
ident: self.lower_ident(i.ident),
905902
generics,
906903
vis: self.lower_visibility(&i.vis),
907-
defaultness,
908904
kind,
909905
span: self.lower_span(i.span),
910906
};

Diff for: compiler/rustc_hir/src/hir.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2112,7 +2112,6 @@ pub struct ImplItem<'hir> {
21122112
pub ident: Ident,
21132113
pub def_id: LocalDefId,
21142114
pub vis: Visibility<'hir>,
2115-
pub defaultness: Defaultness,
21162115
pub generics: Generics<'hir>,
21172116
pub kind: ImplItemKind<'hir>,
21182117
pub span: Span,
@@ -3310,6 +3309,6 @@ mod size_asserts {
33103309

33113310
rustc_data_structures::static_assert_size!(super::Item<'static>, 184);
33123311
rustc_data_structures::static_assert_size!(super::TraitItem<'static>, 128);
3313-
rustc_data_structures::static_assert_size!(super::ImplItem<'static>, 152);
3312+
rustc_data_structures::static_assert_size!(super::ImplItem<'static>, 144);
33143313
rustc_data_structures::static_assert_size!(super::ForeignItem<'static>, 136);
33153314
}

Diff for: compiler/rustc_hir/src/intravisit.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1020,12 +1020,10 @@ pub fn walk_trait_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, trait_item_ref:
10201020

10211021
pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplItem<'v>) {
10221022
// N.B., deliberately force a compilation error if/when new fields are added.
1023-
let ImplItem { def_id: _, ident, ref vis, ref defaultness, ref generics, ref kind, span: _ } =
1024-
*impl_item;
1023+
let ImplItem { def_id: _, ident, ref vis, ref generics, ref kind, span: _ } = *impl_item;
10251024

10261025
visitor.visit_ident(ident);
10271026
visitor.visit_vis(vis);
1028-
visitor.visit_defaultness(defaultness);
10291027
visitor.visit_generics(generics);
10301028
match *kind {
10311029
ImplItemKind::Const(ref ty, body) => {

Diff for: compiler/rustc_hir/src/stable_hash_impls.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,11 @@ impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for TraitItem<'_> {
164164

165165
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for ImplItem<'_> {
166166
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
167-
let ImplItem { def_id: _, ident, ref vis, defaultness, ref generics, ref kind, span } =
168-
*self;
167+
let ImplItem { def_id: _, ident, ref vis, ref generics, ref kind, span } = *self;
169168

170169
hcx.hash_hir_item_like(|hcx| {
171170
ident.name.hash_stable(hcx, hasher);
172171
vis.hash_stable(hcx, hasher);
173-
defaultness.hash_stable(hcx, hasher);
174172
generics.hash_stable(hcx, hasher);
175173
kind.hash_stable(hcx, hasher);
176174
span.hash_stable(hcx, hasher);

Diff for: compiler/rustc_hir_pretty/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,6 @@ impl<'a> State<'a> {
923923
self.hardbreak_if_not_bol();
924924
self.maybe_print_comment(ii.span.lo());
925925
self.print_outer_attributes(self.attrs(ii.hir_id()));
926-
self.print_defaultness(ii.defaultness);
927926

928927
match ii.kind {
929928
hir::ImplItemKind::Const(ref ty, expr) => {

Diff for: src/librustdoc/clean/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,8 @@ impl Clean<Item> for hir::ImplItem<'_> {
10151015
{
10161016
m.header.constness = hir::Constness::NotConst;
10171017
}
1018-
MethodItem(m, Some(self.defaultness))
1018+
let defaultness = cx.tcx.associated_item(self.def_id).defaultness;
1019+
MethodItem(m, Some(defaultness))
10191020
}
10201021
hir::ImplItemKind::TyAlias(ref hir_ty) => {
10211022
let type_ = hir_ty.clean(cx);

Diff for: src/test/incremental/hashes/trait_impls.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,11 @@ pub trait AddDefaultTrait {
358358

359359
#[cfg(any(cfail1,cfail4))]
360360
impl AddDefaultTrait for Foo {
361-
// -------------------------------------------------------------------------------------------
361+
// ----------------------------------------------------
362362
// -------------------------
363-
fn method_name() { }
363+
// ----------------------------------------------------
364+
// -------------------------
365+
fn method_name() { }
364366
}
365367

366368
#[cfg(not(any(cfail1,cfail4)))]
@@ -369,9 +371,9 @@ impl AddDefaultTrait for Foo {
369371
#[rustc_clean(except="hir_owner,hir_owner_nodes", cfg="cfail5")]
370372
#[rustc_clean(cfg="cfail6")]
371373
impl AddDefaultTrait for Foo {
372-
#[rustc_clean(except="hir_owner,hir_owner_nodes,associated_item", cfg="cfail2")]
374+
#[rustc_clean(except="associated_item", cfg="cfail2")]
373375
#[rustc_clean(cfg="cfail3")]
374-
#[rustc_clean(except="hir_owner,hir_owner_nodes,associated_item,optimized_mir", cfg="cfail5")]
376+
#[rustc_clean(except="associated_item", cfg="cfail5")]
375377
#[rustc_clean(cfg="cfail6")]
376378
default fn method_name() { }
377379
}

Diff for: src/tools/clippy/clippy_lints/src/utils/inspector.rs

-3
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ impl<'tcx> LateLintPass<'tcx> for DeepCodeInspector {
5454
),
5555
hir::VisibilityKind::Inherited => println!("visibility inherited from outer item"),
5656
}
57-
if item.defaultness.is_default() {
58-
println!("default");
59-
}
6057
match item.kind {
6158
hir::ImplItemKind::Const(_, body_id) => {
6259
println!("associated constant");

0 commit comments

Comments
 (0)