diff --git a/src/items.rs b/src/items.rs index 31998c35d33..644837bd30b 100644 --- a/src/items.rs +++ b/src/items.rs @@ -1512,12 +1512,16 @@ fn span_for_return(ret: &ast::FunctionRetTy) -> Span { fn span_for_ty_param(ty: &ast::TyParam) -> Span { // Note that ty.span is the span for ty.ident, not the whole item. - let lo = ty.span.lo; + let lo = if ty.attrs.is_empty() { + ty.span.lo + } else { + ty.attrs[0].span.lo + }; if let Some(ref def) = ty.default { return mk_sp(lo, def.span.hi); } if ty.bounds.is_empty() { - return ty.span; + return mk_sp(lo, ty.span.hi); } let hi = match ty.bounds[ty.bounds.len() - 1] { ast::TyParamBound::TraitTyParamBound(ref ptr, _) => ptr.span.hi, diff --git a/src/types.rs b/src/types.rs index 82f68976225..adade891075 100644 --- a/src/types.rs +++ b/src/types.rs @@ -509,6 +509,12 @@ impl Rewrite for ast::TyParamBounds { impl Rewrite for ast::TyParam { fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { let mut result = String::with_capacity(128); + // FIXME: If there are more than one attributes, this will force multiline. + let attr_str = match (&*self.attrs).rewrite(context, shape) { + Some(ref rw) if !rw.is_empty() => format!("{} ", rw), + _ => String::new(), + }; + result.push_str(&attr_str); result.push_str(&self.ident.to_string()); if !self.bounds.is_empty() { if context.config.space_before_bound() { diff --git a/tests/source/impls.rs b/tests/source/impls.rs index 060376b113e..1c38a2ff284 100644 --- a/tests/source/impls.rs +++ b/tests/source/impls.rs @@ -117,3 +117,8 @@ impl Issue1249 Drop for RawTable { + fn drop() {} +} diff --git a/tests/target/impls.rs b/tests/target/impls.rs index dacaa1f5601..f8b9f43aeb0 100644 --- a/tests/target/impls.rs +++ b/tests/target/impls.rs @@ -149,3 +149,8 @@ impl // Creates a new flow constructor. fn foo() {} } + +// #1600 +impl<#[may_dangle] K, #[may_dangle] V> Drop for RawTable { + fn drop() {} +}