Unify assoc item visitors more.
This commit is contained in:
parent
51ccdebe0b
commit
b499a88dfc
12 changed files with 56 additions and 53 deletions
|
@ -484,11 +484,11 @@ impl<'a> LoweringContext<'a> {
|
|||
TraitItemKind::Method(_, None) => {
|
||||
// Ignore patterns in trait methods without bodies
|
||||
self.with_hir_id_owner(None, |this| {
|
||||
visit::walk_assoc_item(this, item)
|
||||
visit::walk_trait_item(this, item)
|
||||
});
|
||||
}
|
||||
_ => self.with_hir_id_owner(Some(item.id), |this| {
|
||||
visit::walk_assoc_item(this, item);
|
||||
visit::walk_trait_item(this, item);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -496,7 +496,7 @@ impl<'a> LoweringContext<'a> {
|
|||
fn visit_impl_item(&mut self, item: &'tcx ImplItem) {
|
||||
self.lctx.allocate_hir_id_counter(item.id);
|
||||
self.with_hir_id_owner(Some(item.id), |this| {
|
||||
visit::walk_assoc_item(this, item);
|
||||
visit::walk_impl_item(this, item);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -1252,7 +1252,7 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
|
|||
fn visit_trait_item(&mut self, trait_item: &'a ast::TraitItem) {
|
||||
self.with_lint_attrs(trait_item.id, &trait_item.attrs, |cx| {
|
||||
run_early_pass!(cx, check_trait_item, trait_item);
|
||||
ast_visit::walk_assoc_item(cx, trait_item);
|
||||
ast_visit::walk_trait_item(cx, trait_item);
|
||||
run_early_pass!(cx, check_trait_item_post, trait_item);
|
||||
});
|
||||
}
|
||||
|
@ -1260,7 +1260,7 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
|
|||
fn visit_impl_item(&mut self, impl_item: &'a ast::ImplItem) {
|
||||
self.with_lint_attrs(impl_item.id, &impl_item.attrs, |cx| {
|
||||
run_early_pass!(cx, check_impl_item, impl_item);
|
||||
ast_visit::walk_assoc_item(cx, impl_item);
|
||||
ast_visit::walk_impl_item(cx, impl_item);
|
||||
run_early_pass!(cx, check_impl_item_post, impl_item);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -787,13 +787,13 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
|||
}
|
||||
_ => {}
|
||||
}
|
||||
visit::walk_assoc_item(self, ii);
|
||||
visit::walk_impl_item(self, ii);
|
||||
}
|
||||
|
||||
fn visit_trait_item(&mut self, ti: &'a AssocItem) {
|
||||
self.invalid_visibility(&ti.vis, None);
|
||||
self.check_defaultness(ti.span, ti.defaultness);
|
||||
visit::walk_assoc_item(self, ti);
|
||||
visit::walk_trait_item(self, ti);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -316,12 +316,12 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> {
|
|||
|
||||
fn visit_trait_item(&mut self, ti: &'v ast::TraitItem) {
|
||||
self.record("TraitItem", Id::None, ti);
|
||||
ast_visit::walk_assoc_item(self, ti)
|
||||
ast_visit::walk_trait_item(self, ti)
|
||||
}
|
||||
|
||||
fn visit_impl_item(&mut self, ii: &'v ast::ImplItem) {
|
||||
self.record("ImplItem", Id::None, ii);
|
||||
ast_visit::walk_assoc_item(self, ii)
|
||||
ast_visit::walk_impl_item(self, ii)
|
||||
}
|
||||
|
||||
fn visit_param_bound(&mut self, bounds: &'v ast::GenericBound) {
|
||||
|
|
|
@ -1190,7 +1190,7 @@ impl<'a, 'b> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b> {
|
|||
let expansion = self.parent_scope.expansion;
|
||||
self.r.define(parent, item.ident, ns, (res, vis, item.span, expansion));
|
||||
|
||||
visit::walk_assoc_item(self, item);
|
||||
visit::walk_trait_item(self, item);
|
||||
}
|
||||
|
||||
fn visit_impl_item(&mut self, item: &'b ast::ImplItem) {
|
||||
|
@ -1198,7 +1198,7 @@ impl<'a, 'b> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b> {
|
|||
self.visit_invoc(item.id);
|
||||
} else {
|
||||
self.resolve_visibility(&item.vis);
|
||||
visit::walk_assoc_item(self, item);
|
||||
visit::walk_impl_item(self, item);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -223,7 +223,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
|
|||
};
|
||||
|
||||
let def = self.create_def(ti.id, def_data, ti.span);
|
||||
self.with_parent(def, |this| visit::walk_assoc_item(this, ti));
|
||||
self.with_parent(def, |this| visit::walk_trait_item(this, ti));
|
||||
}
|
||||
|
||||
fn visit_impl_item(&mut self, ii: &'a ImplItem) {
|
||||
|
@ -249,7 +249,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
|
|||
};
|
||||
|
||||
let def = self.create_def(ii.id, def_data, ii.span);
|
||||
self.with_parent(def, |this| visit::walk_assoc_item(this, ii));
|
||||
self.with_parent(def, |this| visit::walk_impl_item(this, ii));
|
||||
}
|
||||
|
||||
fn visit_pat(&mut self, pat: &'a Pat) {
|
||||
|
|
|
@ -577,42 +577,38 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
|
|||
if block.is_none() {
|
||||
self.check_extern(sig.header.ext);
|
||||
}
|
||||
if sig.decl.c_variadic() {
|
||||
gate_feature_post!(&self, c_variadic, ti.span,
|
||||
"C-variadic functions are unstable");
|
||||
}
|
||||
if sig.header.constness.node == ast::Constness::Const {
|
||||
gate_feature_post!(&self, const_fn, ti.span, "const fn is unstable");
|
||||
}
|
||||
}
|
||||
ast::TraitItemKind::TyAlias(_, ref default) => {
|
||||
if let Some(ty) = default {
|
||||
self.check_impl_trait(ty);
|
||||
gate_feature_post!(&self, associated_type_defaults, ti.span,
|
||||
"associated type defaults are unstable");
|
||||
if let Some(_) = default {
|
||||
gate_feature_post!(
|
||||
&self, associated_type_defaults, ti.span,
|
||||
"associated type defaults are unstable"
|
||||
);
|
||||
}
|
||||
self.check_gat(&ti.generics, ti.span);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
visit::walk_assoc_item(self, ti)
|
||||
visit::walk_trait_item(self, ti)
|
||||
}
|
||||
|
||||
fn visit_impl_item(&mut self, ii: &'a ast::ImplItem) {
|
||||
fn visit_assoc_item(&mut self, ii: &'a ast::AssocItem) {
|
||||
if ii.defaultness == ast::Defaultness::Default {
|
||||
gate_feature_post!(&self, specialization,
|
||||
ii.span,
|
||||
"specialization is unstable");
|
||||
gate_feature_post!(&self, specialization, ii.span, "specialization is unstable");
|
||||
}
|
||||
|
||||
match ii.kind {
|
||||
ast::ImplItemKind::Method(ref sig, _) => {
|
||||
ast::AssocItemKind::Method(ref sig, _) => {
|
||||
if sig.decl.c_variadic() {
|
||||
gate_feature_post!(&self, c_variadic, ii.span,
|
||||
"C-variadic functions are unstable");
|
||||
gate_feature_post!(
|
||||
&self, c_variadic, ii.span,
|
||||
"C-variadic functions are unstable"
|
||||
);
|
||||
}
|
||||
}
|
||||
ast::ImplItemKind::TyAlias(_, ref ty) => {
|
||||
ast::AssocItemKind::TyAlias(_, ref ty) => {
|
||||
if let Some(ty) = ty {
|
||||
self.check_impl_trait(ty);
|
||||
}
|
||||
|
|
|
@ -73,14 +73,10 @@ impl<'ast> Visitor<'ast> for NodeCounter {
|
|||
self.count += 1;
|
||||
walk_fn(self, fk, fd, s)
|
||||
}
|
||||
fn visit_trait_item(&mut self, ti: &TraitItem) {
|
||||
fn visit_assoc_item(&mut self, ti: &AssocItem) {
|
||||
self.count += 1;
|
||||
walk_assoc_item(self, ti)
|
||||
}
|
||||
fn visit_impl_item(&mut self, ii: &ImplItem) {
|
||||
self.count += 1;
|
||||
walk_assoc_item(self, ii)
|
||||
}
|
||||
fn visit_trait_ref(&mut self, t: &TraitRef) {
|
||||
self.count += 1;
|
||||
walk_trait_ref(self, t)
|
||||
|
|
|
@ -83,8 +83,9 @@ pub trait Visitor<'ast>: Sized {
|
|||
fn visit_fn(&mut self, fk: FnKind<'ast>, fd: &'ast FnDecl, s: Span, _: NodeId) {
|
||||
walk_fn(self, fk, fd, s)
|
||||
}
|
||||
fn visit_trait_item(&mut self, i: &'ast AssocItem) { walk_assoc_item(self, i) }
|
||||
fn visit_impl_item(&mut self, i: &'ast AssocItem) { walk_assoc_item(self, i) }
|
||||
fn visit_trait_item(&mut self, i: &'ast AssocItem) { walk_trait_item(self, i) }
|
||||
fn visit_impl_item(&mut self, i: &'ast AssocItem) { walk_impl_item(self, i) }
|
||||
fn visit_assoc_item(&mut self, i: &'ast AssocItem) { walk_assoc_item(self, i) }
|
||||
fn visit_trait_ref(&mut self, t: &'ast TraitRef) { walk_trait_ref(self, t) }
|
||||
fn visit_param_bound(&mut self, bounds: &'ast GenericBound) {
|
||||
walk_param_bound(self, bounds)
|
||||
|
@ -581,6 +582,14 @@ pub fn walk_fn<'a, V>(visitor: &mut V, kind: FnKind<'a>, declaration: &'a FnDecl
|
|||
}
|
||||
}
|
||||
|
||||
pub fn walk_impl_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a AssocItem) {
|
||||
visitor.visit_assoc_item(item);
|
||||
}
|
||||
|
||||
pub fn walk_trait_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a AssocItem) {
|
||||
visitor.visit_assoc_item(item);
|
||||
}
|
||||
|
||||
pub fn walk_assoc_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a AssocItem) {
|
||||
visitor.visit_vis(&item.vis);
|
||||
visitor.visit_ident(item.ident);
|
||||
|
|
|
@ -16,15 +16,6 @@ LL | type Baa = impl Debug;
|
|||
= note: for more information, see https://github.com/rust-lang/rust/issues/63063
|
||||
= help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: `impl Trait` in type aliases is unstable
|
||||
--> $DIR/feature-gate-type_alias_impl_trait.rs:18:18
|
||||
|
|
||||
LL | type Assoc = impl Debug;
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
= note: for more information, see https://github.com/rust-lang/rust/issues/63063
|
||||
= help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: associated type defaults are unstable
|
||||
--> $DIR/feature-gate-type_alias_impl_trait.rs:18:5
|
||||
|
|
||||
|
@ -34,6 +25,15 @@ LL | type Assoc = impl Debug;
|
|||
= note: for more information, see https://github.com/rust-lang/rust/issues/29661
|
||||
= help: add `#![feature(associated_type_defaults)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: `impl Trait` in type aliases is unstable
|
||||
--> $DIR/feature-gate-type_alias_impl_trait.rs:18:18
|
||||
|
|
||||
LL | type Assoc = impl Debug;
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
= note: for more information, see https://github.com/rust-lang/rust/issues/63063
|
||||
= help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: `impl Trait` in type aliases is unstable
|
||||
--> $DIR/feature-gate-type_alias_impl_trait.rs:24:24
|
||||
|
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
#![feature(specialization)]
|
||||
|
||||
fn main() {}
|
||||
|
||||
trait X {
|
||||
|
|
|
@ -1,35 +1,35 @@
|
|||
error: `default` is only allowed on items in `impl` definitions
|
||||
--> $DIR/trait-item-with-defaultness-fail-semantic.rs:4:5
|
||||
--> $DIR/trait-item-with-defaultness-fail-semantic.rs:6:5
|
||||
|
|
||||
LL | default const A: u8;
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: `default` is only allowed on items in `impl` definitions
|
||||
--> $DIR/trait-item-with-defaultness-fail-semantic.rs:5:5
|
||||
--> $DIR/trait-item-with-defaultness-fail-semantic.rs:7:5
|
||||
|
|
||||
LL | default const B: u8 = 0;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: `default` is only allowed on items in `impl` definitions
|
||||
--> $DIR/trait-item-with-defaultness-fail-semantic.rs:6:5
|
||||
--> $DIR/trait-item-with-defaultness-fail-semantic.rs:8:5
|
||||
|
|
||||
LL | default type D;
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
||||
error: `default` is only allowed on items in `impl` definitions
|
||||
--> $DIR/trait-item-with-defaultness-fail-semantic.rs:7:5
|
||||
--> $DIR/trait-item-with-defaultness-fail-semantic.rs:9:5
|
||||
|
|
||||
LL | default type C: Ord;
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: `default` is only allowed on items in `impl` definitions
|
||||
--> $DIR/trait-item-with-defaultness-fail-semantic.rs:8:5
|
||||
--> $DIR/trait-item-with-defaultness-fail-semantic.rs:10:5
|
||||
|
|
||||
LL | default fn f1();
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
error: `default` is only allowed on items in `impl` definitions
|
||||
--> $DIR/trait-item-with-defaultness-fail-semantic.rs:9:5
|
||||
--> $DIR/trait-item-with-defaultness-fail-semantic.rs:11:5
|
||||
|
|
||||
LL | default fn f2() {}
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue