Skip to content

Commit 646fa9a

Browse files
Update HIR pretty printing
1 parent 338bfb7 commit 646fa9a

12 files changed

Lines changed: 29 additions & 22 deletions

File tree

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,10 +573,10 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
573573
},
574574
);
575575
hir::ItemKind::Trait(
576+
impl_restriction,
576577
constness,
577578
*is_auto,
578579
safety,
579-
impl_restriction,
580580
ident,
581581
generics,
582582
bounds,

compiler/rustc_hir/src/hir.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4323,17 +4323,17 @@ impl<'hir> Item<'hir> {
43234323

43244324
expect_trait,
43254325
(
4326+
&'hir ImplRestriction<'hir>,
43264327
Constness,
43274328
IsAuto,
43284329
Safety,
4329-
&'hir ImplRestriction<'hir>,
43304330
Ident,
43314331
&'hir Generics<'hir>,
43324332
GenericBounds<'hir>,
43334333
&'hir [TraitItemId]
43344334
),
4335-
ItemKind::Trait(constness, is_auto, safety, impl_restriction, ident, generics, bounds, items),
4336-
(*constness, *is_auto, *safety, impl_restriction, *ident, generics, bounds, items);
4335+
ItemKind::Trait(impl_restriction, constness, is_auto, safety, ident, generics, bounds, items),
4336+
(impl_restriction, *constness, *is_auto, *safety, *ident, generics, bounds, items);
43374337

43384338
expect_trait_alias, (Constness, Ident, &'hir Generics<'hir>, GenericBounds<'hir>),
43394339
ItemKind::TraitAlias(constness, ident, generics, bounds), (*constness, *ident, generics, bounds);
@@ -4525,10 +4525,10 @@ pub enum ItemKind<'hir> {
45254525
Union(Ident, &'hir Generics<'hir>, VariantData<'hir>),
45264526
/// A trait definition.
45274527
Trait(
4528+
&'hir ImplRestriction<'hir>,
45284529
Constness,
45294530
IsAuto,
45304531
Safety,
4531-
&'hir ImplRestriction<'hir>,
45324532
Ident,
45334533
&'hir Generics<'hir>,
45344534
GenericBounds<'hir>,

compiler/rustc_hir/src/intravisit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,10 +619,10 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) -> V::
619619
try_visit!(visitor.visit_variant_data(struct_definition));
620620
}
621621
ItemKind::Trait(
622+
ref impl_restriction,
622623
_constness,
623624
_is_auto,
624625
_safety,
625-
ref impl_restriction,
626626
ident,
627627
ref generics,
628628
bounds,

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
894894
let item = tcx.hir_expect_item(def_id);
895895

896896
let (constness, is_alias, is_auto, safety, impl_restriction) = match item.kind {
897-
hir::ItemKind::Trait(constness, is_auto, safety, impl_restriction, ..) => (
897+
hir::ItemKind::Trait(impl_restriction, constness, is_auto, safety, ..) => (
898898
constness,
899899
false,
900900
is_auto == hir::IsAuto::Yes,
@@ -958,9 +958,9 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
958958

959959
ty::TraitDef {
960960
def_id: def_id.to_def_id(),
961+
impl_restriction,
961962
safety,
962963
constness,
963-
impl_restriction,
964964
paren_sugar,
965965
has_auto_impl: is_auto,
966966
is_marker,

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -758,20 +758,20 @@ impl<'a> State<'a> {
758758
self.bclose(item.span, cb);
759759
}
760760
hir::ItemKind::Trait(
761+
impl_restriction,
761762
constness,
762763
is_auto,
763764
safety,
764-
impl_restriction,
765765
ident,
766766
generics,
767767
bounds,
768768
trait_items,
769769
) => {
770770
let (cb, ib) = self.head("");
771+
self.print_impl_restriction(impl_restriction);
771772
self.print_constness(constness);
772773
self.print_is_auto(is_auto);
773774
self.print_safety(safety);
774-
self.print_impl_restriction(impl_restriction);
775775
self.word_nbsp("trait");
776776
self.print_ident(ident);
777777
self.print_generic_params(generics.params);

compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1886,7 +1886,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18861886
entry.1.insert((self_ty.span, String::new()));
18871887
}
18881888
Some(Node::Item(hir::Item {
1889-
kind: hir::ItemKind::Trait(_, rustc_ast::ast::IsAuto::Yes, ..),
1889+
kind: hir::ItemKind::Trait(_, _, rustc_ast::ast::IsAuto::Yes, ..),
18901890
span: item_span,
18911891
..
18921892
})) => {

compiler/rustc_middle/src/ty/trait_def.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ use crate::ty::{Ident, Ty, TyCtxt};
2020
pub struct TraitDef {
2121
pub def_id: DefId,
2222

23+
/// Restrictions on trait implementations.
24+
pub impl_restriction: ImplRestrictionKind,
25+
2326
pub safety: hir::Safety,
2427

2528
/// Whether this trait is `const`.
2629
pub constness: hir::Constness,
2730

28-
/// Restrictions on trait implementations.
29-
pub impl_restriction: ImplRestrictionKind,
30-
3131
/// If `true`, then this trait had the `#[rustc_paren_sugar]`
3232
/// attribute, indicating that it should be used with `Foo()`
3333
/// sugar. This is a temporary thing -- eventually any trait will

compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3888,7 +3888,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
38883888
let mut is_auto_trait = false;
38893889
match tcx.hir_get_if_local(data.impl_or_alias_def_id) {
38903890
Some(Node::Item(hir::Item {
3891-
kind: hir::ItemKind::Trait(_, is_auto, _, _, ident, _, _, _),
3891+
kind: hir::ItemKind::Trait(_, _, is_auto, _, ident, _, _, _),
38923892
..
38933893
})) => {
38943894
// FIXME: we should do something else so that it works even on crate foreign

src/librustdoc/clean/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2915,7 +2915,7 @@ fn clean_maybe_renamed_item<'tcx>(
29152915
clean_fn_or_proc_macro(item, sig, generics, body_id, &mut name, cx)
29162916
}
29172917
// FIXME: rustdoc will need to handle `impl` restrictions at some point
2918-
ItemKind::Trait(_, _, _, _impl_restriction, _, generics, bounds, item_ids) => {
2918+
ItemKind::Trait(_impl_restriction, _, _, _, _, generics, bounds, item_ids) => {
29192919
let items = item_ids
29202920
.iter()
29212921
.map(|&ti| clean_trait_item(cx.tcx.hir_trait_item(ti), cx))

src/tools/clippy/clippy_lints/src/arbitrary_source_item_ordering.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,16 @@ impl<'tcx> LateLintPass<'tcx> for ArbitrarySourceItemOrdering {
306306
cur_f = Some(field);
307307
}
308308
},
309-
ItemKind::Trait(_constness, is_auto, _safety, _impl_restriction, _ident, _generics, _generic_bounds, item_ref)
310-
if self.enable_ordering_for_trait && *is_auto == IsAuto::No =>
311-
{
309+
ItemKind::Trait(
310+
_impl_restriction,
311+
_constness,
312+
is_auto,
313+
_safety,
314+
_ident,
315+
_generics,
316+
_generic_bounds,
317+
item_ref,
318+
) if self.enable_ordering_for_trait && *is_auto == IsAuto::No => {
312319
let mut cur_t: Option<(TraitItemId, Ident)> = None;
313320

314321
for &item in *item_ref {

0 commit comments

Comments
 (0)