Skip to content

Commit b499a88

Browse files
committed
Unify assoc item visitors more.
1 parent 51ccdeb commit b499a88

File tree

12 files changed

+56
-53
lines changed

12 files changed

+56
-53
lines changed

src/librustc/hir/lowering.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,19 +484,19 @@ impl<'a> LoweringContext<'a> {
484484
TraitItemKind::Method(_, None) => {
485485
// Ignore patterns in trait methods without bodies
486486
self.with_hir_id_owner(None, |this| {
487-
visit::walk_assoc_item(this, item)
487+
visit::walk_trait_item(this, item)
488488
});
489489
}
490490
_ => self.with_hir_id_owner(Some(item.id), |this| {
491-
visit::walk_assoc_item(this, item);
491+
visit::walk_trait_item(this, item);
492492
})
493493
}
494494
}
495495

496496
fn visit_impl_item(&mut self, item: &'tcx ImplItem) {
497497
self.lctx.allocate_hir_id_counter(item.id);
498498
self.with_hir_id_owner(Some(item.id), |this| {
499-
visit::walk_assoc_item(this, item);
499+
visit::walk_impl_item(this, item);
500500
});
501501
}
502502

src/librustc/lint/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,15 +1252,15 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
12521252
fn visit_trait_item(&mut self, trait_item: &'a ast::TraitItem) {
12531253
self.with_lint_attrs(trait_item.id, &trait_item.attrs, |cx| {
12541254
run_early_pass!(cx, check_trait_item, trait_item);
1255-
ast_visit::walk_assoc_item(cx, trait_item);
1255+
ast_visit::walk_trait_item(cx, trait_item);
12561256
run_early_pass!(cx, check_trait_item_post, trait_item);
12571257
});
12581258
}
12591259

12601260
fn visit_impl_item(&mut self, impl_item: &'a ast::ImplItem) {
12611261
self.with_lint_attrs(impl_item.id, &impl_item.attrs, |cx| {
12621262
run_early_pass!(cx, check_impl_item, impl_item);
1263-
ast_visit::walk_assoc_item(cx, impl_item);
1263+
ast_visit::walk_impl_item(cx, impl_item);
12641264
run_early_pass!(cx, check_impl_item_post, impl_item);
12651265
});
12661266
}

src/librustc_passes/ast_validation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -787,13 +787,13 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
787787
}
788788
_ => {}
789789
}
790-
visit::walk_assoc_item(self, ii);
790+
visit::walk_impl_item(self, ii);
791791
}
792792

793793
fn visit_trait_item(&mut self, ti: &'a AssocItem) {
794794
self.invalid_visibility(&ti.vis, None);
795795
self.check_defaultness(ti.span, ti.defaultness);
796-
visit::walk_assoc_item(self, ti);
796+
visit::walk_trait_item(self, ti);
797797
}
798798
}
799799

src/librustc_passes/hir_stats.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,12 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> {
316316

317317
fn visit_trait_item(&mut self, ti: &'v ast::TraitItem) {
318318
self.record("TraitItem", Id::None, ti);
319-
ast_visit::walk_assoc_item(self, ti)
319+
ast_visit::walk_trait_item(self, ti)
320320
}
321321

322322
fn visit_impl_item(&mut self, ii: &'v ast::ImplItem) {
323323
self.record("ImplItem", Id::None, ii);
324-
ast_visit::walk_assoc_item(self, ii)
324+
ast_visit::walk_impl_item(self, ii)
325325
}
326326

327327
fn visit_param_bound(&mut self, bounds: &'v ast::GenericBound) {

src/librustc_resolve/build_reduced_graph.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,15 +1190,15 @@ impl<'a, 'b> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b> {
11901190
let expansion = self.parent_scope.expansion;
11911191
self.r.define(parent, item.ident, ns, (res, vis, item.span, expansion));
11921192

1193-
visit::walk_assoc_item(self, item);
1193+
visit::walk_trait_item(self, item);
11941194
}
11951195

11961196
fn visit_impl_item(&mut self, item: &'b ast::ImplItem) {
11971197
if let ast::ImplItemKind::Macro(..) = item.kind {
11981198
self.visit_invoc(item.id);
11991199
} else {
12001200
self.resolve_visibility(&item.vis);
1201-
visit::walk_assoc_item(self, item);
1201+
visit::walk_impl_item(self, item);
12021202
}
12031203
}
12041204

src/librustc_resolve/def_collector.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
223223
};
224224

225225
let def = self.create_def(ti.id, def_data, ti.span);
226-
self.with_parent(def, |this| visit::walk_assoc_item(this, ti));
226+
self.with_parent(def, |this| visit::walk_trait_item(this, ti));
227227
}
228228

229229
fn visit_impl_item(&mut self, ii: &'a ImplItem) {
@@ -249,7 +249,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
249249
};
250250

251251
let def = self.create_def(ii.id, def_data, ii.span);
252-
self.with_parent(def, |this| visit::walk_assoc_item(this, ii));
252+
self.with_parent(def, |this| visit::walk_impl_item(this, ii));
253253
}
254254

255255
fn visit_pat(&mut self, pat: &'a Pat) {

src/libsyntax/feature_gate/check.rs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -577,42 +577,38 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
577577
if block.is_none() {
578578
self.check_extern(sig.header.ext);
579579
}
580-
if sig.decl.c_variadic() {
581-
gate_feature_post!(&self, c_variadic, ti.span,
582-
"C-variadic functions are unstable");
583-
}
584580
if sig.header.constness.node == ast::Constness::Const {
585581
gate_feature_post!(&self, const_fn, ti.span, "const fn is unstable");
586582
}
587583
}
588584
ast::TraitItemKind::TyAlias(_, ref default) => {
589-
if let Some(ty) = default {
590-
self.check_impl_trait(ty);
591-
gate_feature_post!(&self, associated_type_defaults, ti.span,
592-
"associated type defaults are unstable");
585+
if let Some(_) = default {
586+
gate_feature_post!(
587+
&self, associated_type_defaults, ti.span,
588+
"associated type defaults are unstable"
589+
);
593590
}
594-
self.check_gat(&ti.generics, ti.span);
595591
}
596592
_ => {}
597593
}
598-
visit::walk_assoc_item(self, ti)
594+
visit::walk_trait_item(self, ti)
599595
}
600596

601-
fn visit_impl_item(&mut self, ii: &'a ast::ImplItem) {
597+
fn visit_assoc_item(&mut self, ii: &'a ast::AssocItem) {
602598
if ii.defaultness == ast::Defaultness::Default {
603-
gate_feature_post!(&self, specialization,
604-
ii.span,
605-
"specialization is unstable");
599+
gate_feature_post!(&self, specialization, ii.span, "specialization is unstable");
606600
}
607601

608602
match ii.kind {
609-
ast::ImplItemKind::Method(ref sig, _) => {
603+
ast::AssocItemKind::Method(ref sig, _) => {
610604
if sig.decl.c_variadic() {
611-
gate_feature_post!(&self, c_variadic, ii.span,
612-
"C-variadic functions are unstable");
605+
gate_feature_post!(
606+
&self, c_variadic, ii.span,
607+
"C-variadic functions are unstable"
608+
);
613609
}
614610
}
615-
ast::ImplItemKind::TyAlias(_, ref ty) => {
611+
ast::AssocItemKind::TyAlias(_, ref ty) => {
616612
if let Some(ty) = ty {
617613
self.check_impl_trait(ty);
618614
}

src/libsyntax/util/node_count.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,10 @@ impl<'ast> Visitor<'ast> for NodeCounter {
7373
self.count += 1;
7474
walk_fn(self, fk, fd, s)
7575
}
76-
fn visit_trait_item(&mut self, ti: &TraitItem) {
76+
fn visit_assoc_item(&mut self, ti: &AssocItem) {
7777
self.count += 1;
7878
walk_assoc_item(self, ti)
7979
}
80-
fn visit_impl_item(&mut self, ii: &ImplItem) {
81-
self.count += 1;
82-
walk_assoc_item(self, ii)
83-
}
8480
fn visit_trait_ref(&mut self, t: &TraitRef) {
8581
self.count += 1;
8682
walk_trait_ref(self, t)

src/libsyntax/visit.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ pub trait Visitor<'ast>: Sized {
8383
fn visit_fn(&mut self, fk: FnKind<'ast>, fd: &'ast FnDecl, s: Span, _: NodeId) {
8484
walk_fn(self, fk, fd, s)
8585
}
86-
fn visit_trait_item(&mut self, i: &'ast AssocItem) { walk_assoc_item(self, i) }
87-
fn visit_impl_item(&mut self, i: &'ast AssocItem) { walk_assoc_item(self, i) }
86+
fn visit_trait_item(&mut self, i: &'ast AssocItem) { walk_trait_item(self, i) }
87+
fn visit_impl_item(&mut self, i: &'ast AssocItem) { walk_impl_item(self, i) }
88+
fn visit_assoc_item(&mut self, i: &'ast AssocItem) { walk_assoc_item(self, i) }
8889
fn visit_trait_ref(&mut self, t: &'ast TraitRef) { walk_trait_ref(self, t) }
8990
fn visit_param_bound(&mut self, bounds: &'ast GenericBound) {
9091
walk_param_bound(self, bounds)
@@ -581,6 +582,14 @@ pub fn walk_fn<'a, V>(visitor: &mut V, kind: FnKind<'a>, declaration: &'a FnDecl
581582
}
582583
}
583584

585+
pub fn walk_impl_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a AssocItem) {
586+
visitor.visit_assoc_item(item);
587+
}
588+
589+
pub fn walk_trait_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a AssocItem) {
590+
visitor.visit_assoc_item(item);
591+
}
592+
584593
pub fn walk_assoc_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a AssocItem) {
585594
visitor.visit_vis(&item.vis);
586595
visitor.visit_ident(item.ident);

src/test/ui/feature-gates/feature-gate-type_alias_impl_trait.stderr

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,6 @@ LL | type Baa = impl Debug;
1616
= note: for more information, see https://github.com/rust-lang/rust/issues/63063
1717
= help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable
1818

19-
error[E0658]: `impl Trait` in type aliases is unstable
20-
--> $DIR/feature-gate-type_alias_impl_trait.rs:18:18
21-
|
22-
LL | type Assoc = impl Debug;
23-
| ^^^^^^^^^^
24-
|
25-
= note: for more information, see https://github.com/rust-lang/rust/issues/63063
26-
= help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable
27-
2819
error[E0658]: associated type defaults are unstable
2920
--> $DIR/feature-gate-type_alias_impl_trait.rs:18:5
3021
|
@@ -34,6 +25,15 @@ LL | type Assoc = impl Debug;
3425
= note: for more information, see https://github.com/rust-lang/rust/issues/29661
3526
= help: add `#![feature(associated_type_defaults)]` to the crate attributes to enable
3627

28+
error[E0658]: `impl Trait` in type aliases is unstable
29+
--> $DIR/feature-gate-type_alias_impl_trait.rs:18:18
30+
|
31+
LL | type Assoc = impl Debug;
32+
| ^^^^^^^^^^
33+
|
34+
= note: for more information, see https://github.com/rust-lang/rust/issues/63063
35+
= help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable
36+
3737
error[E0658]: `impl Trait` in type aliases is unstable
3838
--> $DIR/feature-gate-type_alias_impl_trait.rs:24:24
3939
|

src/test/ui/parser/trait-item-with-defaultness-fail-semantic.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![feature(specialization)]
2+
13
fn main() {}
24

35
trait X {

src/test/ui/parser/trait-item-with-defaultness-fail-semantic.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
error: `default` is only allowed on items in `impl` definitions
2-
--> $DIR/trait-item-with-defaultness-fail-semantic.rs:4:5
2+
--> $DIR/trait-item-with-defaultness-fail-semantic.rs:6:5
33
|
44
LL | default const A: u8;
55
| ^^^^^^^^^^^^^^^^^^^^
66

77
error: `default` is only allowed on items in `impl` definitions
8-
--> $DIR/trait-item-with-defaultness-fail-semantic.rs:5:5
8+
--> $DIR/trait-item-with-defaultness-fail-semantic.rs:7:5
99
|
1010
LL | default const B: u8 = 0;
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^
1212

1313
error: `default` is only allowed on items in `impl` definitions
14-
--> $DIR/trait-item-with-defaultness-fail-semantic.rs:6:5
14+
--> $DIR/trait-item-with-defaultness-fail-semantic.rs:8:5
1515
|
1616
LL | default type D;
1717
| ^^^^^^^^^^^^^^^
1818

1919
error: `default` is only allowed on items in `impl` definitions
20-
--> $DIR/trait-item-with-defaultness-fail-semantic.rs:7:5
20+
--> $DIR/trait-item-with-defaultness-fail-semantic.rs:9:5
2121
|
2222
LL | default type C: Ord;
2323
| ^^^^^^^^^^^^^^^^^^^^
2424

2525
error: `default` is only allowed on items in `impl` definitions
26-
--> $DIR/trait-item-with-defaultness-fail-semantic.rs:8:5
26+
--> $DIR/trait-item-with-defaultness-fail-semantic.rs:10:5
2727
|
2828
LL | default fn f1();
2929
| ^^^^^^^^^^^^^^^^
3030

3131
error: `default` is only allowed on items in `impl` definitions
32-
--> $DIR/trait-item-with-defaultness-fail-semantic.rs:9:5
32+
--> $DIR/trait-item-with-defaultness-fail-semantic.rs:11:5
3333
|
3434
LL | default fn f2() {}
3535
| ^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)