mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
AssocImplKind::{Method -> Fn}
.
This commit is contained in:
parent
abf2e7aa95
commit
e52f902a8a
@ -481,7 +481,7 @@ impl<'a> LoweringContext<'a> {
|
|||||||
self.lctx.allocate_hir_id_counter(item.id);
|
self.lctx.allocate_hir_id_counter(item.id);
|
||||||
|
|
||||||
match item.kind {
|
match item.kind {
|
||||||
AssocItemKind::Method(_, None) => {
|
AssocItemKind::Fn(_, None) => {
|
||||||
// Ignore patterns in trait methods without bodies
|
// Ignore patterns in trait methods without bodies
|
||||||
self.with_hir_id_owner(None, |this| {
|
self.with_hir_id_owner(None, |this| {
|
||||||
visit::walk_trait_item(this, item)
|
visit::walk_trait_item(this, item)
|
||||||
|
@ -826,7 +826,7 @@ impl LoweringContext<'_> {
|
|||||||
.map(|x| self.lower_const_body(i.span, Some(x))),
|
.map(|x| self.lower_const_body(i.span, Some(x))),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
AssocItemKind::Method(ref sig, None) => {
|
AssocItemKind::Fn(ref sig, None) => {
|
||||||
let names = self.lower_fn_params_to_names(&sig.decl);
|
let names = self.lower_fn_params_to_names(&sig.decl);
|
||||||
let (generics, sig) = self.lower_method_sig(
|
let (generics, sig) = self.lower_method_sig(
|
||||||
&i.generics,
|
&i.generics,
|
||||||
@ -837,7 +837,7 @@ impl LoweringContext<'_> {
|
|||||||
);
|
);
|
||||||
(generics, hir::TraitItemKind::Method(sig, hir::TraitMethod::Required(names)))
|
(generics, hir::TraitItemKind::Method(sig, hir::TraitMethod::Required(names)))
|
||||||
}
|
}
|
||||||
AssocItemKind::Method(ref sig, Some(ref body)) => {
|
AssocItemKind::Fn(ref sig, Some(ref body)) => {
|
||||||
let body_id = self.lower_fn_body_block(i.span, &sig.decl, Some(body));
|
let body_id = self.lower_fn_body_block(i.span, &sig.decl, Some(body));
|
||||||
let (generics, sig) = self.lower_method_sig(
|
let (generics, sig) = self.lower_method_sig(
|
||||||
&i.generics,
|
&i.generics,
|
||||||
@ -880,7 +880,7 @@ impl LoweringContext<'_> {
|
|||||||
AssocItemKind::TyAlias(_, ref default) => {
|
AssocItemKind::TyAlias(_, ref default) => {
|
||||||
(hir::AssocItemKind::Type, default.is_some())
|
(hir::AssocItemKind::Type, default.is_some())
|
||||||
}
|
}
|
||||||
AssocItemKind::Method(ref sig, ref default) => (
|
AssocItemKind::Fn(ref sig, ref default) => (
|
||||||
hir::AssocItemKind::Method {
|
hir::AssocItemKind::Method {
|
||||||
has_self: sig.decl.has_self(),
|
has_self: sig.decl.has_self(),
|
||||||
},
|
},
|
||||||
@ -913,7 +913,7 @@ impl LoweringContext<'_> {
|
|||||||
self.lower_const_body(i.span, expr.as_deref()),
|
self.lower_const_body(i.span, expr.as_deref()),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
AssocItemKind::Method(ref sig, ref body) => {
|
AssocItemKind::Fn(ref sig, ref body) => {
|
||||||
self.current_item = Some(i.span);
|
self.current_item = Some(i.span);
|
||||||
let body_id = self.lower_maybe_async_body(
|
let body_id = self.lower_maybe_async_body(
|
||||||
i.span,
|
i.span,
|
||||||
@ -984,7 +984,7 @@ impl LoweringContext<'_> {
|
|||||||
None => hir::AssocItemKind::Type,
|
None => hir::AssocItemKind::Type,
|
||||||
Some(_) => hir::AssocItemKind::OpaqueTy,
|
Some(_) => hir::AssocItemKind::OpaqueTy,
|
||||||
},
|
},
|
||||||
AssocItemKind::Method(sig, _) => hir::AssocItemKind::Method {
|
AssocItemKind::Fn(sig, _) => hir::AssocItemKind::Method {
|
||||||
has_self: sig.decl.has_self(),
|
has_self: sig.decl.has_self(),
|
||||||
},
|
},
|
||||||
AssocItemKind::Macro(..) => unimplemented!(),
|
AssocItemKind::Macro(..) => unimplemented!(),
|
||||||
|
@ -779,7 +779,7 @@ impl<'a> MutVisitor for ReplaceBodyWithLoop<'a, '_> {
|
|||||||
fn flat_map_trait_item(&mut self, i: ast::AssocItem) -> SmallVec<[ast::AssocItem; 1]> {
|
fn flat_map_trait_item(&mut self, i: ast::AssocItem) -> SmallVec<[ast::AssocItem; 1]> {
|
||||||
let is_const = match i.kind {
|
let is_const = match i.kind {
|
||||||
ast::AssocItemKind::Const(..) => true,
|
ast::AssocItemKind::Const(..) => true,
|
||||||
ast::AssocItemKind::Method(ref sig, _) => Self::is_sig_const(sig),
|
ast::AssocItemKind::Fn(ref sig, _) => Self::is_sig_const(sig),
|
||||||
_ => false,
|
_ => false,
|
||||||
};
|
};
|
||||||
self.run(is_const, |s| noop_flat_map_assoc_item(i, s))
|
self.run(is_const, |s| noop_flat_map_assoc_item(i, s))
|
||||||
|
@ -269,7 +269,7 @@ impl EarlyLintPass for UnsafeCode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn check_trait_item(&mut self, cx: &EarlyContext<'_>, item: &ast::AssocItem) {
|
fn check_trait_item(&mut self, cx: &EarlyContext<'_>, item: &ast::AssocItem) {
|
||||||
if let ast::AssocItemKind::Method(ref sig, None) = item.kind {
|
if let ast::AssocItemKind::Fn(ref sig, None) = item.kind {
|
||||||
if sig.header.unsafety == ast::Unsafety::Unsafe {
|
if sig.header.unsafety == ast::Unsafety::Unsafe {
|
||||||
self.report_unsafe(cx, item.span, "declaration of an `unsafe` method")
|
self.report_unsafe(cx, item.span, "declaration of an `unsafe` method")
|
||||||
}
|
}
|
||||||
@ -617,7 +617,7 @@ declare_lint_pass!(
|
|||||||
impl EarlyLintPass for AnonymousParameters {
|
impl EarlyLintPass for AnonymousParameters {
|
||||||
fn check_trait_item(&mut self, cx: &EarlyContext<'_>, it: &ast::AssocItem) {
|
fn check_trait_item(&mut self, cx: &EarlyContext<'_>, it: &ast::AssocItem) {
|
||||||
match it.kind {
|
match it.kind {
|
||||||
ast::AssocItemKind::Method(ref sig, _) => {
|
ast::AssocItemKind::Fn(ref sig, _) => {
|
||||||
for arg in sig.decl.inputs.iter() {
|
for arg in sig.decl.inputs.iter() {
|
||||||
match arg.pat.kind {
|
match arg.pat.kind {
|
||||||
ast::PatKind::Ident(_, ident, None) => {
|
ast::PatKind::Ident(_, ident, None) => {
|
||||||
|
@ -1790,7 +1790,7 @@ impl<'a> Parser<'a> {
|
|||||||
})?;
|
})?;
|
||||||
let sig = FnSig { header, decl };
|
let sig = FnSig { header, decl };
|
||||||
let body = self.parse_assoc_fn_body(at_end, attrs)?;
|
let body = self.parse_assoc_fn_body(at_end, attrs)?;
|
||||||
Ok((ident, AssocItemKind::Method(sig, body), generics))
|
Ok((ident, AssocItemKind::Fn(sig, body), generics))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse the "body" of a method in an associated item definition.
|
/// Parse the "body" of a method in an associated item definition.
|
||||||
|
@ -544,7 +544,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
|||||||
}
|
}
|
||||||
for impl_item in impl_items {
|
for impl_item in impl_items {
|
||||||
self.invalid_visibility(&impl_item.vis, None);
|
self.invalid_visibility(&impl_item.vis, None);
|
||||||
if let AssocItemKind::Method(ref sig, _) = impl_item.kind {
|
if let AssocItemKind::Fn(ref sig, _) = impl_item.kind {
|
||||||
self.check_trait_fn_not_const(sig.header.constness);
|
self.check_trait_fn_not_const(sig.header.constness);
|
||||||
self.check_trait_fn_not_async(impl_item.span, sig.header.asyncness.node);
|
self.check_trait_fn_not_async(impl_item.span, sig.header.asyncness.node);
|
||||||
}
|
}
|
||||||
@ -795,7 +795,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
|||||||
AssocItemKind::Const(_, body) => {
|
AssocItemKind::Const(_, body) => {
|
||||||
self.check_impl_item_provided(ii.span, body, "constant", " = <expr>;");
|
self.check_impl_item_provided(ii.span, body, "constant", " = <expr>;");
|
||||||
}
|
}
|
||||||
AssocItemKind::Method(sig, body) => {
|
AssocItemKind::Fn(sig, body) => {
|
||||||
self.check_impl_item_provided(ii.span, body, "function", " { <body> }");
|
self.check_impl_item_provided(ii.span, body, "function", " { <body> }");
|
||||||
self.check_fn_decl(&sig.decl);
|
self.check_fn_decl(&sig.decl);
|
||||||
}
|
}
|
||||||
@ -812,7 +812,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
|||||||
self.invalid_visibility(&ti.vis, None);
|
self.invalid_visibility(&ti.vis, None);
|
||||||
self.check_defaultness(ti.span, ti.defaultness);
|
self.check_defaultness(ti.span, ti.defaultness);
|
||||||
|
|
||||||
if let AssocItemKind::Method(sig, block) = &ti.kind {
|
if let AssocItemKind::Fn(sig, block) = &ti.kind {
|
||||||
self.check_fn_decl(&sig.decl);
|
self.check_fn_decl(&sig.decl);
|
||||||
self.check_trait_fn_not_async(ti.span, sig.header.asyncness.node);
|
self.check_trait_fn_not_async(ti.span, sig.header.asyncness.node);
|
||||||
self.check_trait_fn_not_const(sig.header.constness);
|
self.check_trait_fn_not_const(sig.header.constness);
|
||||||
@ -838,7 +838,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn visit_assoc_item(&mut self, item: &'a AssocItem) {
|
fn visit_assoc_item(&mut self, item: &'a AssocItem) {
|
||||||
if let AssocItemKind::Method(sig, _) = &item.kind {
|
if let AssocItemKind::Fn(sig, _) = &item.kind {
|
||||||
self.check_c_varadic_type(&sig.decl);
|
self.check_c_varadic_type(&sig.decl);
|
||||||
}
|
}
|
||||||
visit::walk_assoc_item(self, item);
|
visit::walk_assoc_item(self, item);
|
||||||
|
@ -1176,7 +1176,7 @@ impl<'a, 'b> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b> {
|
|||||||
let item_def_id = self.r.definitions.local_def_id(item.id);
|
let item_def_id = self.r.definitions.local_def_id(item.id);
|
||||||
let (res, ns) = match item.kind {
|
let (res, ns) = match item.kind {
|
||||||
AssocItemKind::Const(..) => (Res::Def(DefKind::AssocConst, item_def_id), ValueNS),
|
AssocItemKind::Const(..) => (Res::Def(DefKind::AssocConst, item_def_id), ValueNS),
|
||||||
AssocItemKind::Method(ref sig, _) => {
|
AssocItemKind::Fn(ref sig, _) => {
|
||||||
if sig.decl.has_self() {
|
if sig.decl.has_self() {
|
||||||
self.r.has_self.insert(item_def_id);
|
self.r.has_self.insert(item_def_id);
|
||||||
}
|
}
|
||||||
|
@ -214,11 +214,8 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
|
|||||||
|
|
||||||
fn visit_trait_item(&mut self, ti: &'a AssocItem) {
|
fn visit_trait_item(&mut self, ti: &'a AssocItem) {
|
||||||
let def_data = match ti.kind {
|
let def_data = match ti.kind {
|
||||||
AssocItemKind::Method(..) | AssocItemKind::Const(..) =>
|
AssocItemKind::Fn(..) | AssocItemKind::Const(..) => DefPathData::ValueNs(ti.ident.name),
|
||||||
DefPathData::ValueNs(ti.ident.name),
|
AssocItemKind::TyAlias(..) => DefPathData::TypeNs(ti.ident.name),
|
||||||
AssocItemKind::TyAlias(..) => {
|
|
||||||
DefPathData::TypeNs(ti.ident.name)
|
|
||||||
},
|
|
||||||
AssocItemKind::Macro(..) => return self.visit_macro_invoc(ti.id),
|
AssocItemKind::Macro(..) => return self.visit_macro_invoc(ti.id),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -228,7 +225,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
|
|||||||
|
|
||||||
fn visit_impl_item(&mut self, ii: &'a AssocItem) {
|
fn visit_impl_item(&mut self, ii: &'a AssocItem) {
|
||||||
let def_data = match ii.kind {
|
let def_data = match ii.kind {
|
||||||
AssocItemKind::Method(FnSig {
|
AssocItemKind::Fn(FnSig {
|
||||||
ref header,
|
ref header,
|
||||||
ref decl,
|
ref decl,
|
||||||
}, ref body) if header.asyncness.node.is_async() => {
|
}, ref body) if header.asyncness.node.is_async() => {
|
||||||
@ -242,7 +239,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
|
|||||||
body.as_deref(),
|
body.as_deref(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
AssocItemKind::Method(..) |
|
AssocItemKind::Fn(..) |
|
||||||
AssocItemKind::Const(..) => DefPathData::ValueNs(ii.ident.name),
|
AssocItemKind::Const(..) => DefPathData::ValueNs(ii.ident.name),
|
||||||
AssocItemKind::TyAlias(..) => DefPathData::TypeNs(ii.ident.name),
|
AssocItemKind::TyAlias(..) => DefPathData::TypeNs(ii.ident.name),
|
||||||
AssocItemKind::Macro(..) => return self.visit_macro_invoc(ii.id),
|
AssocItemKind::Macro(..) => return self.visit_macro_invoc(ii.id),
|
||||||
|
@ -818,7 +818,7 @@ impl<'a, 'b> LateResolutionVisitor<'a, '_> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AssocItemKind::Method(_, _) => {
|
AssocItemKind::Fn(_, _) => {
|
||||||
visit::walk_assoc_item(this, trait_item)
|
visit::walk_assoc_item(this, trait_item)
|
||||||
}
|
}
|
||||||
AssocItemKind::TyAlias(..) => {
|
AssocItemKind::TyAlias(..) => {
|
||||||
@ -1109,7 +1109,7 @@ impl<'a, 'b> LateResolutionVisitor<'a, '_> {
|
|||||||
visit::walk_assoc_item(this, impl_item)
|
visit::walk_assoc_item(this, impl_item)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
AssocItemKind::Method(..) => {
|
AssocItemKind::Fn(..) => {
|
||||||
// If this is a trait impl, ensure the method
|
// If this is a trait impl, ensure the method
|
||||||
// exists in trait
|
// exists in trait
|
||||||
this.check_trait_item(impl_item.ident,
|
this.check_trait_item(impl_item.ident,
|
||||||
|
@ -1044,7 +1044,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
|
|||||||
&trait_item.attrs,
|
&trait_item.attrs,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
ast::AssocItemKind::Method(ref sig, ref body) => {
|
ast::AssocItemKind::Fn(ref sig, ref body) => {
|
||||||
self.process_method(
|
self.process_method(
|
||||||
sig,
|
sig,
|
||||||
body.as_ref().map(|x| &**x),
|
body.as_ref().map(|x| &**x),
|
||||||
@ -1115,7 +1115,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
|
|||||||
&impl_item.attrs,
|
&impl_item.attrs,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
ast::AssocItemKind::Method(ref sig, ref body) => {
|
ast::AssocItemKind::Fn(ref sig, ref body) => {
|
||||||
self.process_method(
|
self.process_method(
|
||||||
sig,
|
sig,
|
||||||
body.as_deref(),
|
body.as_deref(),
|
||||||
|
@ -1634,8 +1634,7 @@ pub enum AssocItemKind {
|
|||||||
Const(P<Ty>, Option<P<Expr>>),
|
Const(P<Ty>, Option<P<Expr>>),
|
||||||
|
|
||||||
/// An associated function.
|
/// An associated function.
|
||||||
/// FIXME(Centril): Rename to `Fn`.
|
Fn(FnSig, Option<P<Block>>),
|
||||||
Method(FnSig, Option<P<Block>>),
|
|
||||||
|
|
||||||
/// An associated type.
|
/// An associated type.
|
||||||
TyAlias(GenericBounds, Option<P<Ty>>),
|
TyAlias(GenericBounds, Option<P<Ty>>),
|
||||||
|
@ -573,7 +573,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
|
|||||||
|
|
||||||
fn visit_trait_item(&mut self, ti: &'a ast::AssocItem) {
|
fn visit_trait_item(&mut self, ti: &'a ast::AssocItem) {
|
||||||
match ti.kind {
|
match ti.kind {
|
||||||
ast::AssocItemKind::Method(ref sig, ref block) => {
|
ast::AssocItemKind::Fn(ref sig, ref block) => {
|
||||||
if block.is_none() {
|
if block.is_none() {
|
||||||
self.check_extern(sig.header.ext);
|
self.check_extern(sig.header.ext);
|
||||||
}
|
}
|
||||||
@ -600,7 +600,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
match ii.kind {
|
match ii.kind {
|
||||||
ast::AssocItemKind::Method(ref sig, _) => {
|
ast::AssocItemKind::Fn(ref sig, _) => {
|
||||||
if sig.decl.c_variadic() {
|
if sig.decl.c_variadic() {
|
||||||
gate_feature_post!(
|
gate_feature_post!(
|
||||||
&self, c_variadic, ii.span,
|
&self, c_variadic, ii.span,
|
||||||
|
@ -955,7 +955,7 @@ pub fn noop_flat_map_assoc_item<T: MutVisitor>(mut item: AssocItem, visitor: &mu
|
|||||||
visitor.visit_ty(ty);
|
visitor.visit_ty(ty);
|
||||||
visit_opt(expr, |expr| visitor.visit_expr(expr));
|
visit_opt(expr, |expr| visitor.visit_expr(expr));
|
||||||
}
|
}
|
||||||
AssocItemKind::Method(sig, body) => {
|
AssocItemKind::Fn(sig, body) => {
|
||||||
visit_fn_sig(sig, visitor);
|
visit_fn_sig(sig, visitor);
|
||||||
visit_opt(body, |body| visitor.visit_block(body));
|
visit_opt(body, |body| visitor.visit_block(body));
|
||||||
}
|
}
|
||||||
|
@ -1528,7 +1528,7 @@ impl<'a> State<'a> {
|
|||||||
ast::AssocItemKind::Const(ty, expr) => {
|
ast::AssocItemKind::Const(ty, expr) => {
|
||||||
self.print_associated_const(item.ident, ty, expr.as_deref(), &item.vis);
|
self.print_associated_const(item.ident, ty, expr.as_deref(), &item.vis);
|
||||||
}
|
}
|
||||||
ast::AssocItemKind::Method(sig, body) => {
|
ast::AssocItemKind::Fn(sig, body) => {
|
||||||
if body.is_some() {
|
if body.is_some() {
|
||||||
self.head("");
|
self.head("");
|
||||||
}
|
}
|
||||||
|
@ -600,11 +600,11 @@ pub fn walk_assoc_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a AssocItem)
|
|||||||
visitor.visit_ty(ty);
|
visitor.visit_ty(ty);
|
||||||
walk_list!(visitor, visit_expr, expr);
|
walk_list!(visitor, visit_expr, expr);
|
||||||
}
|
}
|
||||||
AssocItemKind::Method(ref sig, None) => {
|
AssocItemKind::Fn(ref sig, None) => {
|
||||||
visitor.visit_fn_header(&sig.header);
|
visitor.visit_fn_header(&sig.header);
|
||||||
walk_fn_decl(visitor, &sig.decl);
|
walk_fn_decl(visitor, &sig.decl);
|
||||||
}
|
}
|
||||||
AssocItemKind::Method(ref sig, Some(ref body)) => {
|
AssocItemKind::Fn(ref sig, Some(ref body)) => {
|
||||||
visitor.visit_fn(FnKind::Method(item.ident, sig, &item.vis, body),
|
visitor.visit_fn(FnKind::Method(item.ident, sig, &item.vis, body),
|
||||||
&sig.decl, item.span, item.id);
|
&sig.decl, item.span, item.id);
|
||||||
}
|
}
|
||||||
|
@ -958,7 +958,7 @@ impl<'a> MethodDef<'a> {
|
|||||||
vis: respan(trait_lo_sp, ast::VisibilityKind::Inherited),
|
vis: respan(trait_lo_sp, ast::VisibilityKind::Inherited),
|
||||||
defaultness: ast::Defaultness::Final,
|
defaultness: ast::Defaultness::Final,
|
||||||
ident: method_ident,
|
ident: method_ident,
|
||||||
kind: ast::AssocItemKind::Method(sig, Some(body_block)),
|
kind: ast::AssocItemKind::Fn(sig, Some(body_block)),
|
||||||
tokens: None,
|
tokens: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user