Skip to content

Commit

Permalink
Merge pull request #2043 from sunjay/lift_generics
Browse files Browse the repository at this point in the history
Lifted generics to account for changes in rust-lang/rust#44766
  • Loading branch information
nrc authored Oct 28, 2017
2 parents 4022b09 + 3f11c4b commit e2a5c78
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
15 changes: 10 additions & 5 deletions src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,25 +184,29 @@ impl<'a> FnSig<'a> {
}
}

pub fn from_method_sig(method_sig: &'a ast::MethodSig) -> FnSig {
pub fn from_method_sig(
method_sig: &'a ast::MethodSig,
generics: &'a ast::Generics,
) -> FnSig<'a> {
FnSig {
unsafety: method_sig.unsafety,
constness: method_sig.constness.node,
defaultness: ast::Defaultness::Final,
abi: method_sig.abi,
decl: &*method_sig.decl,
generics: &method_sig.generics,
generics: generics,
visibility: ast::Visibility::Inherited,
}
}

pub fn from_fn_kind(
fn_kind: &'a visit::FnKind,
generics: &'a ast::Generics,
decl: &'a ast::FnDecl,
defualtness: ast::Defaultness,
) -> FnSig<'a> {
match *fn_kind {
visit::FnKind::ItemFn(_, generics, unsafety, constness, abi, visibility, _) => FnSig {
visit::FnKind::ItemFn(_, unsafety, constness, abi, visibility, _) => FnSig {
decl: decl,
generics: generics,
abi: abi,
Expand All @@ -212,7 +216,7 @@ impl<'a> FnSig<'a> {
visibility: visibility.clone(),
},
visit::FnKind::Method(_, ref method_sig, vis, _) => {
let mut fn_sig = FnSig::from_method_sig(method_sig);
let mut fn_sig = FnSig::from_method_sig(method_sig, generics);
fn_sig.defaultness = defualtness;
if let Some(vis) = vis {
fn_sig.visibility = vis.clone();
Expand Down Expand Up @@ -338,6 +342,7 @@ impl<'a> FmtVisitor<'a> {
indent: Indent,
ident: ast::Ident,
sig: &ast::MethodSig,
generics: &ast::Generics,
span: Span,
) -> Option<String> {
// Drop semicolon or it will be interpreted as comment.
Expand All @@ -348,7 +353,7 @@ impl<'a> FmtVisitor<'a> {
&context,
indent,
ident,
&FnSig::from_method_sig(sig),
&FnSig::from_method_sig(sig, generics),
span,
false,
false,
Expand Down
23 changes: 10 additions & 13 deletions src/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ impl<'a> FmtVisitor<'a> {
fn visit_fn(
&mut self,
fk: visit::FnKind,
generics: &ast::Generics,
fd: &ast::FnDecl,
s: Span,
_: ast::NodeId,
Expand All @@ -247,12 +248,12 @@ impl<'a> FmtVisitor<'a> {
let indent = self.block_indent;
let block;
let rewrite = match fk {
visit::FnKind::ItemFn(ident, _, _, _, _, _, b) => {
visit::FnKind::ItemFn(ident, _, _, _, _, b) => {
block = b;
self.rewrite_fn(
indent,
ident,
&FnSig::from_fn_kind(&fk, fd, defaultness),
&FnSig::from_fn_kind(&fk, generics, fd, defaultness),
mk_sp(s.lo(), b.span.lo()),
b,
)
Expand All @@ -262,7 +263,7 @@ impl<'a> FmtVisitor<'a> {
self.rewrite_fn(
indent,
ident,
&FnSig::from_fn_kind(&fk, fd, defaultness),
&FnSig::from_fn_kind(&fk, generics, fd, defaultness),
mk_sp(s.lo(), b.span.lo()),
b,
)
Expand Down Expand Up @@ -420,15 +421,8 @@ impl<'a> FmtVisitor<'a> {
}
ast::ItemKind::Fn(ref decl, unsafety, constness, abi, ref generics, ref body) => {
self.visit_fn(
visit::FnKind::ItemFn(
item.ident,
generics,
unsafety,
constness,
abi,
&item.vis,
body,
),
visit::FnKind::ItemFn(item.ident, unsafety, constness, abi, &item.vis, body),
generics,
decl,
item.span,
item.id,
Expand Down Expand Up @@ -499,12 +493,14 @@ impl<'a> FmtVisitor<'a> {
}
ast::TraitItemKind::Method(ref sig, None) => {
let indent = self.block_indent;
let rewrite = self.rewrite_required_fn(indent, ti.ident, sig, ti.span);
let rewrite =
self.rewrite_required_fn(indent, ti.ident, sig, &ti.generics, ti.span);
self.push_rewrite(ti.span, rewrite);
}
ast::TraitItemKind::Method(ref sig, Some(ref body)) => {
self.visit_fn(
visit::FnKind::Method(ti.ident, sig, None, body),
&ti.generics,
&sig.decl,
ti.span,
ti.id,
Expand Down Expand Up @@ -540,6 +536,7 @@ impl<'a> FmtVisitor<'a> {
ast::ImplItemKind::Method(ref sig, ref body) => {
self.visit_fn(
visit::FnKind::Method(ii.ident, sig, Some(&ii.vis), body),
&ii.generics,
&sig.decl,
ii.span,
ii.id,
Expand Down

0 comments on commit e2a5c78

Please sign in to comment.