mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 08:44:35 +00:00
Merge pull request #3035 from topecongiro/issue-3006
Format generics on associated types
This commit is contained in:
commit
635efdf69b
13
src/items.rs
13
src/items.rs
@ -1715,11 +1715,16 @@ fn rewrite_static(
|
||||
pub fn rewrite_associated_type(
|
||||
ident: ast::Ident,
|
||||
ty_opt: Option<&ptr::P<ast::Ty>>,
|
||||
generics: &ast::Generics,
|
||||
generic_bounds_opt: Option<&ast::GenericBounds>,
|
||||
context: &RewriteContext,
|
||||
indent: Indent,
|
||||
) -> Option<String> {
|
||||
let prefix = format!("type {}", rewrite_ident(context, ident));
|
||||
let ident_str = rewrite_ident(context, ident);
|
||||
// 5 = "type "
|
||||
let generics_shape = Shape::indented(indent, context.config).offset_left(5)?;
|
||||
let generics_str = rewrite_generics(context, ident_str, generics, generics_shape)?;
|
||||
let prefix = format!("type {}", generics_str);
|
||||
|
||||
let type_bounds_str = if let Some(bounds) = generic_bounds_opt {
|
||||
if bounds.is_empty() {
|
||||
@ -1746,10 +1751,11 @@ pub fn rewrite_associated_type(
|
||||
pub fn rewrite_existential_impl_type(
|
||||
context: &RewriteContext,
|
||||
ident: ast::Ident,
|
||||
generics: &ast::Generics,
|
||||
generic_bounds: &ast::GenericBounds,
|
||||
indent: Indent,
|
||||
) -> Option<String> {
|
||||
rewrite_associated_type(ident, None, Some(generic_bounds), context, indent)
|
||||
rewrite_associated_type(ident, None, generics, Some(generic_bounds), context, indent)
|
||||
.map(|s| format!("existential {}", s))
|
||||
}
|
||||
|
||||
@ -1757,10 +1763,11 @@ pub fn rewrite_associated_impl_type(
|
||||
ident: ast::Ident,
|
||||
defaultness: ast::Defaultness,
|
||||
ty_opt: Option<&ptr::P<ast::Ty>>,
|
||||
generics: &ast::Generics,
|
||||
context: &RewriteContext,
|
||||
indent: Indent,
|
||||
) -> Option<String> {
|
||||
let result = rewrite_associated_type(ident, ty_opt, None, context, indent)?;
|
||||
let result = rewrite_associated_type(ident, ty_opt, generics, None, context, indent)?;
|
||||
|
||||
match defaultness {
|
||||
ast::Defaultness::Default => Some(format!("default {}", result)),
|
||||
|
@ -497,6 +497,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
|
||||
let rewrite = rewrite_associated_type(
|
||||
ti.ident,
|
||||
type_default.as_ref(),
|
||||
&ti.generics,
|
||||
Some(generic_bounds),
|
||||
&self.get_context(),
|
||||
self.block_indent,
|
||||
@ -535,6 +536,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
|
||||
ii.ident,
|
||||
ii.defaultness,
|
||||
Some(ty),
|
||||
&ii.generics,
|
||||
&self.get_context(),
|
||||
self.block_indent,
|
||||
);
|
||||
@ -544,6 +546,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
|
||||
let rewrite = rewrite_existential_impl_type(
|
||||
&self.get_context(),
|
||||
ii.ident,
|
||||
&ii.generics,
|
||||
generic_bounds,
|
||||
self.block_indent,
|
||||
);
|
||||
|
@ -97,3 +97,12 @@ trait FooBar = Foo
|
||||
auto trait Example {}
|
||||
pub auto trait PubExample {}
|
||||
pub unsafe auto trait PubUnsafeExample {}
|
||||
|
||||
// #3006
|
||||
trait Foo<'a> {
|
||||
type Bar< 'a >;
|
||||
}
|
||||
|
||||
impl<'a> Foo<'a> for i32 {
|
||||
type Bar< 'a > = i32;
|
||||
}
|
||||
|
@ -135,3 +135,12 @@ trait FooBar = Foo
|
||||
auto trait Example {}
|
||||
pub auto trait PubExample {}
|
||||
pub unsafe auto trait PubUnsafeExample {}
|
||||
|
||||
// #3006
|
||||
trait Foo<'a> {
|
||||
type Bar<'a>;
|
||||
}
|
||||
|
||||
impl<'a> Foo<'a> for i32 {
|
||||
type Bar<'a> = i32;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user