Skip to content

Commit 15adeea

Browse files
committed
Remove IsAuto from hir::ItemKind::Trait
1 parent cfda2a3 commit 15adeea

File tree

13 files changed

+36
-52
lines changed

13 files changed

+36
-52
lines changed

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
149149
hir::ItemKind::Impl(impl_) => {
150150
lctx.is_in_trait_impl = impl_.of_trait.is_some();
151151
}
152-
hir::ItemKind::Trait(_, _, generics, _, _) if lctx.tcx.features().effects => {
152+
hir::ItemKind::Trait(_, generics, _, _) if lctx.tcx.features().effects => {
153153
lctx.host_param_id = generics
154154
.params
155155
.iter()
@@ -445,14 +445,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
445445
}
446446
// We intentionally ignore `is_auto` since `auto trait` is now meaningless.
447447
ItemKind::Trait(box Trait { is_auto: _, unsafety, generics, bounds, items }) => {
448-
let attrs = attrs.unwrap_or(&[]);
449-
let is_auto = if attrs.iter().any(|attr| attr.has_name(sym::rustc_auto_trait)) {
450-
IsAuto::Yes
451-
} else {
452-
IsAuto::No
453-
};
454448
// FIXME(const_trait_impl, effects, fee1-dead) this should be simplified if possible
455449
let constness = attrs
450+
.unwrap_or(&[])
456451
.iter()
457452
.find(|x| x.has_name(sym::const_trait))
458453
.map_or(Const::No, |x| Const::Yes(x.span));
@@ -473,7 +468,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
473468
(unsafety, items, bounds)
474469
},
475470
);
476-
hir::ItemKind::Trait(is_auto, unsafety, generics, bounds, items)
471+
hir::ItemKind::Trait(unsafety, generics, bounds, items)
477472
}
478473
ItemKind::TraitAlias(generics, bounds) => {
479474
let (generics, bounds) = self.lower_generics(

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -672,8 +672,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
672672
true,
673673
td.as_local().and_then(|tld| match hir_map.find_by_def_id(tld) {
674674
Some(Node::Item(hir::Item {
675-
kind: hir::ItemKind::Trait(_, _, _, _, items),
676-
..
675+
kind: hir::ItemKind::Trait(_, _, _, items), ..
677676
})) => {
678677
let mut f_in_trait_opt = None;
679678
for hir::TraitItemRef { id: fi, kind: k, .. } in *items {

compiler/rustc_hir/src/hir.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::LangItem;
77
use rustc_ast as ast;
88
use rustc_ast::util::parser::ExprPrecedence;
99
use rustc_ast::{Attribute, FloatTy, IntTy, Label, LitKind, TraitObjectSyntax, UintTy};
10-
pub use rustc_ast::{BindingAnnotation, BorrowKind, ByRef, ImplPolarity, IsAuto};
10+
pub use rustc_ast::{BindingAnnotation, BorrowKind, ByRef, ImplPolarity};
1111
pub use rustc_ast::{CaptureBy, Movability, Mutability};
1212
use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
1313
use rustc_data_structures::fingerprint::Fingerprint;
@@ -3216,11 +3216,11 @@ impl<'hir> Item<'hir> {
32163216
#[track_caller]
32173217
pub fn expect_trait(
32183218
self,
3219-
) -> (IsAuto, Unsafety, &'hir Generics<'hir>, GenericBounds<'hir>, &'hir [TraitItemRef]) {
3220-
let ItemKind::Trait(is_auto, unsafety, gen, bounds, items) = self.kind else {
3219+
) -> (Unsafety, &'hir Generics<'hir>, GenericBounds<'hir>, &'hir [TraitItemRef]) {
3220+
let ItemKind::Trait(unsafety, gen, bounds, items) = self.kind else {
32213221
self.expect_failed("a trait")
32223222
};
3223-
(is_auto, unsafety, gen, bounds, items)
3223+
(unsafety, gen, bounds, items)
32243224
}
32253225

32263226
/// Expect an [`ItemKind::TraitAlias`] or panic.
@@ -3347,7 +3347,7 @@ pub enum ItemKind<'hir> {
33473347
/// A union definition, e.g., `union Foo<A, B> {x: A, y: B}`.
33483348
Union(VariantData<'hir>, &'hir Generics<'hir>),
33493349
/// A trait definition.
3350-
Trait(IsAuto, Unsafety, &'hir Generics<'hir>, GenericBounds<'hir>, &'hir [TraitItemRef]),
3350+
Trait(Unsafety, &'hir Generics<'hir>, GenericBounds<'hir>, &'hir [TraitItemRef]),
33513351
/// A trait alias.
33523352
TraitAlias(&'hir Generics<'hir>, GenericBounds<'hir>),
33533353

@@ -3382,7 +3382,7 @@ impl ItemKind<'_> {
33823382
| ItemKind::Enum(_, ref generics)
33833383
| ItemKind::Struct(_, ref generics)
33843384
| ItemKind::Union(_, ref generics)
3385-
| ItemKind::Trait(_, _, ref generics, _, _)
3385+
| ItemKind::Trait(_, ref generics, _, _)
33863386
| ItemKind::TraitAlias(ref generics, _)
33873387
| ItemKind::Impl(Impl { ref generics, .. }) => generics,
33883388
_ => return None,

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1091,7 +1091,7 @@ fn check_trait(tcx: TyCtxt<'_>, item: &hir::Item<'_>) {
10911091
});
10921092

10931093
// Only check traits, don't check trait aliases
1094-
if let hir::ItemKind::Trait(_, _, _, _, items) = item.kind {
1094+
if let hir::ItemKind::Trait(_, _, _, items) = item.kind {
10951095
check_gat_where_clauses(tcx, items);
10961096
}
10971097
}

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ fn reject_placeholder_type_signatures_in_item<'tcx>(
252252
hir::ItemKind::Union(_, generics)
253253
| hir::ItemKind::Enum(_, generics)
254254
| hir::ItemKind::TraitAlias(generics, _)
255-
| hir::ItemKind::Trait(_, _, generics, ..)
255+
| hir::ItemKind::Trait(_, generics, ..)
256256
| hir::ItemKind::Impl(hir::Impl { generics, .. })
257257
| hir::ItemKind::Struct(_, generics) => (generics, true),
258258
hir::ItemKind::OpaqueTy(hir::OpaqueTy { generics, .. })
@@ -893,10 +893,9 @@ fn adt_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::AdtDef<'_> {
893893
fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
894894
let item = tcx.hir().expect_item(def_id);
895895

896-
// FIXME: Maybe check `tcx.has_attr(def_id, sym::rustc_auto_trait)` **here**!
897896
let (is_auto, unsafety, items) = match item.kind {
898-
hir::ItemKind::Trait(is_auto, unsafety, .., items) => {
899-
(is_auto == hir::IsAuto::Yes, unsafety, items)
897+
hir::ItemKind::Trait(unsafety, .., items) => {
898+
(tcx.has_attr(def_id, sym::rustc_auto_trait), unsafety, items)
900899
}
901900
hir::ItemKind::TraitAlias(..) => (false, hir::Unsafety::Normal, &[][..]),
902901
_ => span_bug!(item.span, "trait_def_of_item invoked on non-trait"),

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
143143
| ItemKind::Struct(_, generics)
144144
| ItemKind::Union(_, generics) => generics,
145145

146-
ItemKind::Trait(_, _, generics, self_bounds, ..)
146+
ItemKind::Trait(_, generics, self_bounds, ..)
147147
| ItemKind::TraitAlias(generics, self_bounds) => {
148148
is_trait = Some(self_bounds);
149149
generics
@@ -703,7 +703,7 @@ pub(super) fn type_param_predicates(
703703
| ItemKind::Enum(_, generics)
704704
| ItemKind::Struct(_, generics)
705705
| ItemKind::Union(_, generics) => generics,
706-
ItemKind::Trait(_, _, generics, ..) => {
706+
ItemKind::Trait(_, generics, ..) => {
707707
// Implied `Self: Trait` and supertrait bounds.
708708
if param_id == item_hir_id {
709709
let identity_trait_ref =

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
589589
| hir::ItemKind::Enum(_, generics)
590590
| hir::ItemKind::Struct(_, generics)
591591
| hir::ItemKind::Union(_, generics)
592-
| hir::ItemKind::Trait(_, _, generics, ..)
592+
| hir::ItemKind::Trait(_, generics, ..)
593593
| hir::ItemKind::TraitAlias(generics, ..)
594594
| hir::ItemKind::Impl(&hir::Impl { generics, .. }) => {
595595
// These kinds of items have only early-bound lifetime parameters.

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -663,9 +663,8 @@ impl<'a> State<'a> {
663663
}
664664
self.bclose(item.span);
665665
}
666-
hir::ItemKind::Trait(is_auto, unsafety, generics, bounds, trait_items) => {
666+
hir::ItemKind::Trait(unsafety, generics, bounds, trait_items) => {
667667
self.head("");
668-
self.print_is_auto(is_auto);
669668
self.print_unsafety(unsafety);
670669
self.word_nbsp("trait");
671670
self.print_ident(item.ident);
@@ -2330,13 +2329,6 @@ impl<'a> State<'a> {
23302329
hir::Unsafety::Unsafe => self.word_nbsp("unsafe"),
23312330
}
23322331
}
2333-
2334-
pub fn print_is_auto(&mut self, s: hir::IsAuto) {
2335-
match s {
2336-
hir::IsAuto::Yes => self.word_nbsp("auto"),
2337-
hir::IsAuto::No => {}
2338-
}
2339-
}
23402332
}
23412333

23422334
/// Does this expression require a semicolon to be treated

compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -804,21 +804,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
804804
}
805805
entry.1.insert((self_ty.span, ""));
806806
}
807-
Some(Node::Item(hir::Item {
808-
kind: hir::ItemKind::Trait(rustc_hir::IsAuto::Yes, ..),
809-
span: item_span,
810-
..
811-
})) => {
812-
tcx.sess.delay_span_bug(
813-
*item_span,
814-
"auto trait is invoked with no method error, but no error reported?",
815-
);
816-
}
817807
Some(Node::Item(hir::Item {
818808
ident,
819809
kind: hir::ItemKind::Trait(..) | hir::ItemKind::TraitAlias(..),
810+
span: item_span,
820811
..
821812
})) => {
813+
if tcx.has_attr(item_def_id, sym::rustc_auto_trait) {
814+
tcx.sess.delay_span_bug(
815+
*item_span,
816+
"auto trait is invoked with no method error, but no error reported?",
817+
);
818+
continue;
819+
}
820+
822821
skip_list.insert(p);
823822
let entry = spanned_predicates.entry(ident.span);
824823
let entry = entry.or_insert_with(|| {

compiler/rustc_lint/src/multiple_supertrait_upcastable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl<'tcx> LateLintPass<'tcx> for MultipleSupertraitUpcastable {
3939
let def_id = item.owner_id.to_def_id();
4040
// NOTE(nbdd0121): use `object_safety_violations` instead of `check_is_object_safe` because
4141
// the latter will report `where_clause_object_safety` lint.
42-
if let hir::ItemKind::Trait(_, _, _, _, _) = item.kind
42+
if let hir::ItemKind::Trait(_, _, _, _) = item.kind
4343
&& cx.tcx.object_safety_violations(def_id).is_empty()
4444
{
4545
let direct_super_traits_iter = cx.tcx

0 commit comments

Comments
 (0)