Refactor FnKind variant to hold &Fn
This commit is contained in:
parent
2f348cb7ce
commit
c22a27130d
12 changed files with 93 additions and 91 deletions
|
|
@ -1,5 +1,5 @@
|
|||
use rustc_ast::visit::FnKind;
|
||||
use rustc_ast::{NodeId, WherePredicateKind};
|
||||
use rustc_ast::{Fn, NodeId, WherePredicateKind};
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_lint::{EarlyContext, EarlyLintPass};
|
||||
use rustc_session::declare_lint_pass;
|
||||
|
|
@ -39,7 +39,7 @@ declare_lint_pass!(MultipleBoundLocations => [MULTIPLE_BOUND_LOCATIONS]);
|
|||
|
||||
impl EarlyLintPass for MultipleBoundLocations {
|
||||
fn check_fn(&mut self, cx: &EarlyContext<'_>, kind: FnKind<'_>, _: Span, _: NodeId) {
|
||||
if let FnKind::Fn(_, _, _, _, generics, _) = kind
|
||||
if let FnKind::Fn(_, _, _, Fn { generics, .. }) = kind
|
||||
&& !generics.params.is_empty()
|
||||
&& !generics.where_clause.predicates.is_empty()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -333,19 +333,19 @@ impl<'a> FnSig<'a> {
|
|||
defaultness: ast::Defaultness,
|
||||
) -> FnSig<'a> {
|
||||
match *fn_kind {
|
||||
visit::FnKind::Fn(visit::FnCtxt::Assoc(..), _, fn_sig, vis, generics, _) => {
|
||||
let mut fn_sig = FnSig::from_method_sig(fn_sig, generics, vis);
|
||||
visit::FnKind::Fn(visit::FnCtxt::Assoc(..), _, vis, ast::Fn { sig, generics, .. }) => {
|
||||
let mut fn_sig = FnSig::from_method_sig(sig, generics, vis);
|
||||
fn_sig.defaultness = defaultness;
|
||||
fn_sig
|
||||
}
|
||||
visit::FnKind::Fn(_, _, fn_sig, vis, generics, _) => FnSig {
|
||||
visit::FnKind::Fn(_, _, vis, ast::Fn { sig, generics, .. }) => FnSig {
|
||||
decl,
|
||||
generics,
|
||||
ext: fn_sig.header.ext,
|
||||
constness: fn_sig.header.constness,
|
||||
coroutine_kind: Cow::Borrowed(&fn_sig.header.coroutine_kind),
|
||||
ext: sig.header.ext,
|
||||
constness: sig.header.constness,
|
||||
coroutine_kind: Cow::Borrowed(&sig.header.coroutine_kind),
|
||||
defaultness,
|
||||
safety: fn_sig.header.safety,
|
||||
safety: sig.header.safety,
|
||||
visibility: vis,
|
||||
},
|
||||
_ => unreachable!(),
|
||||
|
|
@ -3453,6 +3453,7 @@ impl Rewrite for ast::ForeignItem {
|
|||
ref sig,
|
||||
ref generics,
|
||||
ref body,
|
||||
..
|
||||
} = **fn_kind;
|
||||
if body.is_some() {
|
||||
let mut visitor = FmtVisitor::from_context(context);
|
||||
|
|
@ -3461,7 +3462,7 @@ impl Rewrite for ast::ForeignItem {
|
|||
let inner_attrs = inner_attributes(&self.attrs);
|
||||
let fn_ctxt = visit::FnCtxt::Foreign;
|
||||
visitor.visit_fn(
|
||||
visit::FnKind::Fn(fn_ctxt, &self.ident, sig, &self.vis, generics, body),
|
||||
visit::FnKind::Fn(fn_ctxt, &self.ident, &self.vis, fn_kind),
|
||||
&sig.decl,
|
||||
self.span,
|
||||
defaultness,
|
||||
|
|
|
|||
|
|
@ -386,7 +386,14 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
|
|||
let indent = self.block_indent;
|
||||
let block;
|
||||
let rewrite = match fk {
|
||||
visit::FnKind::Fn(_, ident, _, _, _, Some(ref b)) => {
|
||||
visit::FnKind::Fn(
|
||||
_,
|
||||
ident,
|
||||
_,
|
||||
ast::Fn {
|
||||
body: Some(ref b), ..
|
||||
},
|
||||
) => {
|
||||
block = b;
|
||||
self.rewrite_fn_before_block(
|
||||
indent,
|
||||
|
|
@ -539,6 +546,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
|
|||
ref sig,
|
||||
ref generics,
|
||||
ref body,
|
||||
..
|
||||
} = **fn_kind;
|
||||
if body.is_some() {
|
||||
let inner_attrs = inner_attributes(&item.attrs);
|
||||
|
|
@ -547,7 +555,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
|
|||
_ => visit::FnCtxt::Foreign,
|
||||
};
|
||||
self.visit_fn(
|
||||
visit::FnKind::Fn(fn_ctxt, &item.ident, sig, &item.vis, generics, body),
|
||||
visit::FnKind::Fn(fn_ctxt, &item.ident, &item.vis, fn_kind),
|
||||
&sig.decl,
|
||||
item.span,
|
||||
defaultness,
|
||||
|
|
@ -640,12 +648,13 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
|
|||
ref sig,
|
||||
ref generics,
|
||||
ref body,
|
||||
..
|
||||
} = **fn_kind;
|
||||
if body.is_some() {
|
||||
let inner_attrs = inner_attributes(&ai.attrs);
|
||||
let fn_ctxt = visit::FnCtxt::Assoc(assoc_ctxt);
|
||||
self.visit_fn(
|
||||
visit::FnKind::Fn(fn_ctxt, &ai.ident, sig, &ai.vis, generics, body),
|
||||
visit::FnKind::Fn(fn_ctxt, &ai.ident, &ai.vis, fn_kind),
|
||||
&sig.decl,
|
||||
ai.span,
|
||||
defaultness,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue