Skip to content

Commit 906e528

Browse files
committed
Fix formatting of const trait aliases
1 parent e792d9c commit 906e528

File tree

4 files changed

+14
-17
lines changed

4 files changed

+14
-17
lines changed

src/tools/rustfmt/src/items.rs

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

13761376
pub(crate) fn format_trait_alias(
13771377
context: &RewriteContext<'_>,
1378-
ident: symbol::Ident,
1378+
ta: &ast::TraitAlias,
13791379
vis: &ast::Visibility,
1380-
generics: &ast::Generics,
1381-
generic_bounds: &ast::GenericBounds,
13821380
shape: Shape,
13831381
) -> Option<String> {
1384-
let alias = rewrite_ident(context, ident);
1382+
let alias = rewrite_ident(context, ta.ident);
13851383
// 6 = "trait ", 2 = " ="
13861384
let g_shape = shape.offset_left(6)?.sub_width(2)?;
1387-
let generics_str = rewrite_generics(context, alias, generics, g_shape).ok()?;
1385+
let generics_str = rewrite_generics(context, alias, &ta.generics, g_shape).ok()?;
13881386
let vis_str = format_visibility(context, vis);
1389-
let lhs = format!("{vis_str}trait {generics_str} =");
1387+
let constness = format_constness(ta.constness);
1388+
let lhs = format!("{vis_str}{constness}trait {generics_str} =");
13901389
// 1 = ";"
13911390
let trait_alias_bounds = TraitAliasBounds {
1392-
generic_bounds,
1393-
generics,
1391+
generic_bounds: &ta.bounds,
1392+
generics: &ta.generics,
13941393
};
13951394
rewrite_assign_rhs(
13961395
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(..) => {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#![feature(trait_alias, const_trait_impl)]
2+
3+
const trait Bar {}
4+
5+
const trait Foo = Bar;

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)