Skip to content

Commit 5d3eb69

Browse files
committed
Fix formatting of const trait aliases
1 parent 3223981 commit 5d3eb69

File tree

3 files changed

+9
-17
lines changed

3 files changed

+9
-17
lines changed

src/tools/rustfmt/src/items.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,22 +1387,21 @@ impl<'a> Rewrite for TraitAliasBounds<'a> {
13871387

13881388
pub(crate) fn format_trait_alias(
13891389
context: &RewriteContext<'_>,
1390-
ident: symbol::Ident,
1390+
ta: &ast::TraitAlias,
13911391
vis: &ast::Visibility,
1392-
generics: &ast::Generics,
1393-
generic_bounds: &ast::GenericBounds,
13941392
shape: Shape,
13951393
) -> Option<String> {
1396-
let alias = rewrite_ident(context, ident);
1394+
let alias = rewrite_ident(context, ta.ident);
13971395
// 6 = "trait ", 2 = " ="
13981396
let g_shape = shape.offset_left(6)?.sub_width(2)?;
1399-
let generics_str = rewrite_generics(context, alias, generics, g_shape).ok()?;
1397+
let generics_str = rewrite_generics(context, alias, &ta.generics, g_shape).ok()?;
14001398
let vis_str = format_visibility(context, vis);
1401-
let lhs = format!("{vis_str}trait {generics_str} =");
1399+
let constness = format_constness(ta.constness);
1400+
let lhs = format!("{vis_str}{constness}trait {generics_str} =");
14021401
// 1 = ";"
14031402
let trait_alias_bounds = TraitAliasBounds {
1404-
generic_bounds,
1405-
generics,
1403+
generic_bounds: &ta.bounds,
1404+
generics: &ta.generics,
14061405
};
14071406
rewrite_assign_rhs(
14081407
context,

src/tools/rustfmt/src/visitor.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -499,14 +499,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
499499
}
500500
ast::ItemKind::TraitAlias(ref ta) => {
501501
let shape = Shape::indented(self.block_indent, self.config);
502-
let rw = format_trait_alias(
503-
&self.get_context(),
504-
ta.ident,
505-
&item.vis,
506-
&ta.generics,
507-
&ta.bounds,
508-
shape,
509-
);
502+
let rw = format_trait_alias(&self.get_context(), ta, &item.vis, shape);
510503
self.push_rewrite(item.span, rw);
511504
}
512505
ast::ItemKind::ExternCrate(..) => {

src/tools/rustfmt/tests/target/trait.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,4 +219,4 @@ trait Visible {
219219
pub fn g() {}
220220
}
221221

222-
trait Foomp = Hash;
222+
const trait Foomp = Hash;

0 commit comments

Comments
 (0)