Get rid of GenericsArg wrapper type
`GenericsArg` is basically identical to `ast::GenericParam`. Just use the latter.
This commit is contained in:
parent
1ef6bccea3
commit
939a6c5820
57
src/items.rs
57
src/items.rs
@ -30,9 +30,9 @@ use rewrite::{Rewrite, RewriteContext};
|
||||
use shape::{Indent, Shape};
|
||||
use spanned::Spanned;
|
||||
use types::join_bounds;
|
||||
use utils::{colon_spaces, contains_skip, end_typaram, first_line_width, format_abi,
|
||||
format_constness, format_defaultness, format_mutability, format_unsafety,
|
||||
format_visibility, is_attributes_extendable, last_line_contains_single_line_comment,
|
||||
use utils::{colon_spaces, contains_skip, first_line_width, format_abi, format_constness,
|
||||
format_defaultness, format_mutability, format_unsafety, format_visibility,
|
||||
is_attributes_extendable, last_line_contains_single_line_comment,
|
||||
last_line_used_width, last_line_width, mk_sp, semicolon_for_expr, starts_with_newline,
|
||||
stmt_expr, trim_newlines, trimmed_last_line_width};
|
||||
use vertical::rewrite_with_alignment;
|
||||
@ -1871,12 +1871,8 @@ fn rewrite_fn_base(
|
||||
.generics
|
||||
.params
|
||||
.iter()
|
||||
.filter_map(|p| match p {
|
||||
&ast::GenericParam::Type(ref t) => Some(t),
|
||||
_ => None,
|
||||
})
|
||||
.last()
|
||||
.map_or(lo_after_visibility, |tp| end_typaram(tp));
|
||||
.map_or(lo_after_visibility, |param| param.span().hi());
|
||||
let args_end = if fd.inputs.is_empty() {
|
||||
context
|
||||
.codemap
|
||||
@ -2346,47 +2342,13 @@ fn rewrite_generics_inner(
|
||||
// FIXME: convert bounds to where clauses where they get too big or if
|
||||
// there is a where clause at all.
|
||||
|
||||
// Wrapper type
|
||||
enum GenericsArg<'a> {
|
||||
Lifetime(&'a ast::LifetimeDef),
|
||||
TyParam(&'a ast::TyParam),
|
||||
}
|
||||
impl<'a> Rewrite for GenericsArg<'a> {
|
||||
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
|
||||
match *self {
|
||||
GenericsArg::Lifetime(lifetime) => lifetime.rewrite(context, shape),
|
||||
GenericsArg::TyParam(ty) => ty.rewrite(context, shape),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<'a> Spanned for GenericsArg<'a> {
|
||||
fn span(&self) -> Span {
|
||||
match *self {
|
||||
GenericsArg::Lifetime(lifetime) => lifetime.span(),
|
||||
GenericsArg::TyParam(ty) => ty.span(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if generics.params.is_empty() {
|
||||
return Some(String::new());
|
||||
}
|
||||
|
||||
let generics_args = generics
|
||||
.params
|
||||
.iter()
|
||||
.filter_map(|p| match p {
|
||||
&ast::GenericParam::Lifetime(ref l) => Some(l),
|
||||
_ => None,
|
||||
})
|
||||
.map(|lt| GenericsArg::Lifetime(lt))
|
||||
.chain(generics.params.iter().filter_map(|ty| match ty {
|
||||
&ast::GenericParam::Type(ref ty) => Some(GenericsArg::TyParam(ty)),
|
||||
_ => None,
|
||||
}));
|
||||
let items = itemize_list(
|
||||
context.codemap,
|
||||
generics_args,
|
||||
generics.params.iter(),
|
||||
">",
|
||||
",",
|
||||
|arg| arg.span().lo(),
|
||||
@ -2868,3 +2830,12 @@ impl Rewrite for ast::ForeignItem {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl Rewrite for ast::GenericParam {
|
||||
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
|
||||
match *self {
|
||||
ast::GenericParam::Lifetime(ref lifetime_def) => lifetime_def.rewrite(context, shape),
|
||||
ast::GenericParam::Type(ref ty) => ty.rewrite(context, shape),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -105,6 +105,15 @@ impl Spanned for ast::Arg {
|
||||
}
|
||||
}
|
||||
|
||||
impl Spanned for ast::GenericParam {
|
||||
fn span(&self) -> Span {
|
||||
match *self {
|
||||
ast::GenericParam::Lifetime(ref lifetime_def) => lifetime_def.span(),
|
||||
ast::GenericParam::Type(ref ty) => ty.span(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Spanned for ast::StructField {
|
||||
fn span(&self) -> Span {
|
||||
span_with_attrs_lo_hi!(self, self.span.lo(), self.ty.span.hi())
|
||||
|
13
src/utils.rs
13
src/utils.rs
@ -213,19 +213,6 @@ pub fn contains_skip(attrs: &[Attribute]) -> bool {
|
||||
.any(|a| a.meta().map_or(false, |a| is_skip(&a)))
|
||||
}
|
||||
|
||||
// Find the end of a TyParam
|
||||
#[inline]
|
||||
pub fn end_typaram(typaram: &ast::TyParam) -> BytePos {
|
||||
typaram
|
||||
.bounds
|
||||
.last()
|
||||
.map_or(typaram.span, |bound| match *bound {
|
||||
ast::RegionTyParamBound(ref lt) => lt.span,
|
||||
ast::TraitTyParamBound(ref prt, _) => prt.span,
|
||||
})
|
||||
.hi()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn semicolon_for_expr(context: &RewriteContext, expr: &ast::Expr) -> bool {
|
||||
match expr.node {
|
||||
|
Loading…
x
Reference in New Issue
Block a user