Skip to content
/ rust Public
forked from rust-lang/rust

Commit 70534c9

Browse files
authored
Rollup merge of rust-lang#157330 - josetorrs:remove-is-type-const, r=BoxyUwU
remove `IsTypeConst` from `hir::TraitItemKind` Fixes rust-lang#152940 following up on rust-lang#152940 (comment) r? @BoxyUwU
2 parents 0f203df + 0b4a6f8 commit 70534c9

15 files changed

Lines changed: 27 additions & 51 deletions

File tree

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
10001000
} else {
10011001
None
10021002
};
1003-
hir::TraitItemKind::Const(ty, rhs, rhs_kind.is_type_const().into())
1003+
hir::TraitItemKind::Const(ty, rhs)
10041004
},
10051005
);
10061006

compiler/rustc_hir/src/hir.rs

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3320,7 +3320,7 @@ impl<'hir> TraitItem<'hir> {
33203320

33213321
expect_methods_self_kind! {
33223322
expect_const, (&'hir Ty<'hir>, Option<ConstItemRhs<'hir>>),
3323-
TraitItemKind::Const(ty, rhs, _), (ty, *rhs);
3323+
TraitItemKind::Const(ty, rhs), (ty, *rhs);
33243324

33253325
expect_fn, (&FnSig<'hir>, &TraitFn<'hir>),
33263326
TraitItemKind::Fn(ty, trfn), (ty, trfn);
@@ -3340,32 +3340,11 @@ pub enum TraitFn<'hir> {
33403340
Provided(BodyId),
33413341
}
33423342

3343-
#[derive(Debug, Clone, Copy, PartialEq, Eq, StableHash)]
3344-
pub enum IsTypeConst {
3345-
No,
3346-
Yes,
3347-
}
3348-
3349-
impl From<bool> for IsTypeConst {
3350-
fn from(value: bool) -> Self {
3351-
if value { Self::Yes } else { Self::No }
3352-
}
3353-
}
3354-
3355-
impl From<IsTypeConst> for bool {
3356-
fn from(value: IsTypeConst) -> Self {
3357-
matches!(value, IsTypeConst::Yes)
3358-
}
3359-
}
3360-
33613343
/// Represents a trait method or associated constant or type
33623344
#[derive(Debug, Clone, Copy, StableHash)]
33633345
pub enum TraitItemKind<'hir> {
3364-
// FIXME(mgca) eventually want to move the option that is around `ConstItemRhs<'hir>`
3365-
// into `ConstItemRhs`, much like `ast::ConstItemRhsKind`, but for now mark whether
3366-
// this node is a TypeConst with a flag.
33673346
/// An associated constant with an optional value (otherwise `impl`s must contain a value).
3368-
Const(&'hir Ty<'hir>, Option<ConstItemRhs<'hir>>, IsTypeConst),
3347+
Const(&'hir Ty<'hir>, Option<ConstItemRhs<'hir>>),
33693348
/// An associated function with an optional body.
33703349
Fn(FnSig<'hir>, TraitFn<'hir>),
33713350
/// An associated type with (possibly empty) bounds and optional concrete
@@ -5011,7 +4990,7 @@ impl<'hir> OwnerNode<'hir> {
50114990
| OwnerNode::TraitItem(TraitItem {
50124991
kind:
50134992
TraitItemKind::Fn(_, TraitFn::Provided(body))
5014-
| TraitItemKind::Const(_, Some(ConstItemRhs::Body(body)), _),
4993+
| TraitItemKind::Const(_, Some(ConstItemRhs::Body(body))),
50154994
..
50164995
})
50174996
| OwnerNode::ImplItem(ImplItem {
@@ -5238,7 +5217,7 @@ impl<'hir> Node<'hir> {
52385217
_ => None,
52395218
},
52405219
Node::TraitItem(it) => match it.kind {
5241-
TraitItemKind::Const(ty, _, _) => Some(ty),
5220+
TraitItemKind::Const(ty, _) => Some(ty),
52425221
TraitItemKind::Type(_, ty) => ty,
52435222
_ => None,
52445223
},
@@ -5282,7 +5261,7 @@ impl<'hir> Node<'hir> {
52825261
| Node::TraitItem(TraitItem {
52835262
owner_id,
52845263
kind:
5285-
TraitItemKind::Const(_, Some(ConstItemRhs::Body(body)), _)
5264+
TraitItemKind::Const(_, Some(ConstItemRhs::Body(body)))
52865265
| TraitItemKind::Fn(_, TraitFn::Provided(body)),
52875266
..
52885267
})

compiler/rustc_hir/src/intravisit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,7 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(
12731273
try_visit!(visitor.visit_defaultness(&defaultness));
12741274
try_visit!(visitor.visit_id(hir_id));
12751275
match *kind {
1276-
TraitItemKind::Const(ref ty, default, _) => {
1276+
TraitItemKind::Const(ref ty, default) => {
12771277
try_visit!(visitor.visit_ty_unambig(ty));
12781278
visit_opt!(visitor, visit_const_item_rhs, default);
12791279
}

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,8 +1673,7 @@ fn is_anon_const_rhs_of_const_item<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId)
16731673
let (Node::Item(hir::Item { kind: hir::ItemKind::Const(_, _, _, ct_rhs), .. })
16741674
| Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Const(_, ct_rhs), .. })
16751675
| Node::TraitItem(hir::TraitItem {
1676-
kind: hir::TraitItemKind::Const(_, Some(ct_rhs), _),
1677-
..
1676+
kind: hir::TraitItemKind::Const(_, Some(ct_rhs)), ..
16781677
})) = grandparent_node
16791678
else {
16801679
return false;
@@ -1718,9 +1717,9 @@ fn const_of_item<'tcx>(
17181717
) -> ty::EarlyBinder<'tcx, Const<'tcx>> {
17191718
let ct_rhs = match tcx.hir_node_by_def_id(def_id) {
17201719
hir::Node::Item(hir::Item { kind: hir::ItemKind::Const(.., ct), .. }) => *ct,
1721-
hir::Node::TraitItem(hir::TraitItem {
1722-
kind: hir::TraitItemKind::Const(_, ct, _), ..
1723-
}) => ct.expect("no default value for trait assoc const"),
1720+
hir::Node::TraitItem(hir::TraitItem { kind: hir::TraitItemKind::Const(_, ct), .. }) => {
1721+
ct.expect("no default value for trait assoc const")
1722+
}
17241723
hir::Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Const(.., ct), .. }) => *ct,
17251724
_ => {
17261725
span_bug!(tcx.def_span(def_id), "`const_of_item` expected a const or assoc const item")

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
860860
}
861861
})
862862
}
863-
Const(_, _, _) => self.visit_early(trait_item.hir_id(), trait_item.generics, |this| {
863+
Const(_, _) => self.visit_early(trait_item.hir_id(), trait_item.generics, |this| {
864864
intravisit::walk_trait_item(this, trait_item)
865865
}),
866866
}

compiler/rustc_hir_analysis/src/collect/type_of.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_
6262
let args = ty::GenericArgs::identity_for_item(tcx, def_id);
6363
Ty::new_fn_def(tcx, def_id.to_def_id(), args)
6464
}
65-
TraitItemKind::Const(ty, rhs, _) => rhs
65+
TraitItemKind::Const(ty, rhs) => rhs
6666
.and_then(|rhs| {
6767
ty.is_suggestable_infer_ty().then(|| {
6868
infer_placeholder_type(

compiler/rustc_hir_analysis/src/hir_wf_check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ pub(super) fn diagnostic_hir_wf_check<'tcx>(
139139
},
140140
hir::Node::TraitItem(item) => match item.kind {
141141
hir::TraitItemKind::Type(_, ty) => ty.into_iter().collect(),
142-
hir::TraitItemKind::Const(ty, _, _) => vec![ty],
142+
hir::TraitItemKind::Const(ty, _) => vec![ty],
143143
ref item => bug!("Unexpected TraitItem {:?}", item),
144144
},
145145
hir::Node::Item(item) => match item.kind {

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ impl<'a> State<'a> {
951951
self.maybe_print_comment(ti.span.lo());
952952
self.print_attrs(self.attrs(ti.hir_id()));
953953
match ti.kind {
954-
hir::TraitItemKind::Const(ty, default, _) => {
954+
hir::TraitItemKind::Const(ty, default) => {
955955
self.print_associated_const(ti.ident, ti.generics, ty, default);
956956
}
957957
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Required(arg_idents)) => {

compiler/rustc_hir_typeck/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,7 @@ fn extend_err_with_const_context(
286286
) {
287287
match node {
288288
hir::Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Const(ty, _), .. })
289-
| hir::Node::TraitItem(hir::TraitItem {
290-
kind: hir::TraitItemKind::Const(ty, _, _), ..
291-
}) => {
289+
| hir::Node::TraitItem(hir::TraitItem { kind: hir::TraitItemKind::Const(ty, _), .. }) => {
292290
// Point at the `Type` in `const NAME: Type = value;`.
293291
err.span_label(ty.span, "expected because of the type of the associated constant");
294292
}

compiler/rustc_mir_build/src/builder/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ fn construct_const<'a, 'tcx>(
577577
})
578578
| Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Const(ty, _), span, .. })
579579
| Node::TraitItem(hir::TraitItem {
580-
kind: hir::TraitItemKind::Const(ty, Some(_), _),
580+
kind: hir::TraitItemKind::Const(ty, Some(_)),
581581
span,
582582
..
583583
}) => (*span, ty.span),

0 commit comments

Comments
 (0)