Skip to content

Commit 939a6c5

Browse files
committed
Get rid of GenericsArg wrapper type
`GenericsArg` is basically identical to `ast::GenericParam`. Just use the latter.
1 parent 1ef6bcc commit 939a6c5

File tree

3 files changed

+23
-56
lines changed

3 files changed

+23
-56
lines changed

src/items.rs

Lines changed: 14 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ use rewrite::{Rewrite, RewriteContext};
3030
use shape::{Indent, Shape};
3131
use spanned::Spanned;
3232
use types::join_bounds;
33-
use utils::{colon_spaces, contains_skip, end_typaram, first_line_width, format_abi,
34-
format_constness, format_defaultness, format_mutability, format_unsafety,
35-
format_visibility, is_attributes_extendable, last_line_contains_single_line_comment,
33+
use utils::{colon_spaces, contains_skip, first_line_width, format_abi, format_constness,
34+
format_defaultness, format_mutability, format_unsafety, format_visibility,
35+
is_attributes_extendable, last_line_contains_single_line_comment,
3636
last_line_used_width, last_line_width, mk_sp, semicolon_for_expr, starts_with_newline,
3737
stmt_expr, trim_newlines, trimmed_last_line_width};
3838
use vertical::rewrite_with_alignment;
@@ -1871,12 +1871,8 @@ fn rewrite_fn_base(
18711871
.generics
18721872
.params
18731873
.iter()
1874-
.filter_map(|p| match p {
1875-
&ast::GenericParam::Type(ref t) => Some(t),
1876-
_ => None,
1877-
})
18781874
.last()
1879-
.map_or(lo_after_visibility, |tp| end_typaram(tp));
1875+
.map_or(lo_after_visibility, |param| param.span().hi());
18801876
let args_end = if fd.inputs.is_empty() {
18811877
context
18821878
.codemap
@@ -2346,47 +2342,13 @@ fn rewrite_generics_inner(
23462342
// FIXME: convert bounds to where clauses where they get too big or if
23472343
// there is a where clause at all.
23482344

2349-
// Wrapper type
2350-
enum GenericsArg<'a> {
2351-
Lifetime(&'a ast::LifetimeDef),
2352-
TyParam(&'a ast::TyParam),
2353-
}
2354-
impl<'a> Rewrite for GenericsArg<'a> {
2355-
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
2356-
match *self {
2357-
GenericsArg::Lifetime(lifetime) => lifetime.rewrite(context, shape),
2358-
GenericsArg::TyParam(ty) => ty.rewrite(context, shape),
2359-
}
2360-
}
2361-
}
2362-
impl<'a> Spanned for GenericsArg<'a> {
2363-
fn span(&self) -> Span {
2364-
match *self {
2365-
GenericsArg::Lifetime(lifetime) => lifetime.span(),
2366-
GenericsArg::TyParam(ty) => ty.span(),
2367-
}
2368-
}
2369-
}
2370-
23712345
if generics.params.is_empty() {
23722346
return Some(String::new());
23732347
}
23742348

2375-
let generics_args = generics
2376-
.params
2377-
.iter()
2378-
.filter_map(|p| match p {
2379-
&ast::GenericParam::Lifetime(ref l) => Some(l),
2380-
_ => None,
2381-
})
2382-
.map(|lt| GenericsArg::Lifetime(lt))
2383-
.chain(generics.params.iter().filter_map(|ty| match ty {
2384-
&ast::GenericParam::Type(ref ty) => Some(GenericsArg::TyParam(ty)),
2385-
_ => None,
2386-
}));
23872349
let items = itemize_list(
23882350
context.codemap,
2389-
generics_args,
2351+
generics.params.iter(),
23902352
">",
23912353
",",
23922354
|arg| arg.span().lo(),
@@ -2868,3 +2830,12 @@ impl Rewrite for ast::ForeignItem {
28682830
)
28692831
}
28702832
}
2833+
2834+
impl Rewrite for ast::GenericParam {
2835+
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
2836+
match *self {
2837+
ast::GenericParam::Lifetime(ref lifetime_def) => lifetime_def.rewrite(context, shape),
2838+
ast::GenericParam::Type(ref ty) => ty.rewrite(context, shape),
2839+
}
2840+
}
2841+
}

src/spanned.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,15 @@ impl Spanned for ast::Arg {
105105
}
106106
}
107107

108+
impl Spanned for ast::GenericParam {
109+
fn span(&self) -> Span {
110+
match *self {
111+
ast::GenericParam::Lifetime(ref lifetime_def) => lifetime_def.span(),
112+
ast::GenericParam::Type(ref ty) => ty.span(),
113+
}
114+
}
115+
}
116+
108117
impl Spanned for ast::StructField {
109118
fn span(&self) -> Span {
110119
span_with_attrs_lo_hi!(self, self.span.lo(), self.ty.span.hi())

src/utils.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -213,19 +213,6 @@ pub fn contains_skip(attrs: &[Attribute]) -> bool {
213213
.any(|a| a.meta().map_or(false, |a| is_skip(&a)))
214214
}
215215

216-
// Find the end of a TyParam
217-
#[inline]
218-
pub fn end_typaram(typaram: &ast::TyParam) -> BytePos {
219-
typaram
220-
.bounds
221-
.last()
222-
.map_or(typaram.span, |bound| match *bound {
223-
ast::RegionTyParamBound(ref lt) => lt.span,
224-
ast::TraitTyParamBound(ref prt, _) => prt.span,
225-
})
226-
.hi()
227-
}
228-
229216
#[inline]
230217
pub fn semicolon_for_expr(context: &RewriteContext, expr: &ast::Expr) -> bool {
231218
match expr.node {

0 commit comments

Comments
 (0)