Skip to content

Commit b6f7f24

Browse files
authored
Merge pull request #3661 from calebcartwright/associated-type-bounds
fix handling on associated type bounds
2 parents 1ee51a4 + d9e42ae commit b6f7f24

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

src/types.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,22 @@ impl<'a> Rewrite for SegmentParam<'a> {
168168
SegmentParam::LifeTime(lt) => lt.rewrite(context, shape),
169169
SegmentParam::Type(ty) => ty.rewrite(context, shape),
170170
SegmentParam::Binding(assoc_ty_constraint) => {
171-
let mut result = match context.config.type_punctuation_density() {
172-
TypeDensity::Wide => {
173-
format!("{} = ", rewrite_ident(context, assoc_ty_constraint.ident))
171+
let mut result = match assoc_ty_constraint.kind {
172+
ast::AssocTyConstraintKind::Bound { .. } => {
173+
format!("{}: ", rewrite_ident(context, assoc_ty_constraint.ident))
174174
}
175-
TypeDensity::Compressed => {
176-
format!("{}=", rewrite_ident(context, assoc_ty_constraint.ident))
175+
ast::AssocTyConstraintKind::Equality { .. } => {
176+
match context.config.type_punctuation_density() {
177+
TypeDensity::Wide => {
178+
format!("{} = ", rewrite_ident(context, assoc_ty_constraint.ident))
179+
}
180+
TypeDensity::Compressed => {
181+
format!("{}=", rewrite_ident(context, assoc_ty_constraint.ident))
182+
}
183+
}
177184
}
178185
};
186+
179187
let budget = shape.width.checked_sub(result.len())?;
180188
let rewrite = assoc_ty_constraint
181189
.kind
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// See #3657 - https://github.com/rust-lang/rustfmt/issues/3657
2+
3+
#![feature(associated_type_bounds)]
4+
5+
fn f<I: Iterator<Item: Clone>>() {}
6+
7+
fn g<I: Iterator<Item : Clone>>() {}
8+
9+
fn h<I: Iterator<Item : Clone>>() {}
10+
11+
fn i<I: Iterator<Item:Clone>>() {}
12+
13+
fn j<I: Iterator<Item : Clone+'a>>() {}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// See #3657 - https://github.com/rust-lang/rustfmt/issues/3657
2+
3+
#![feature(associated_type_bounds)]
4+
5+
fn f<I: Iterator<Item: Clone>>() {}
6+
7+
fn g<I: Iterator<Item: Clone>>() {}
8+
9+
fn h<I: Iterator<Item: Clone>>() {}
10+
11+
fn i<I: Iterator<Item: Clone>>() {}
12+
13+
fn j<I: Iterator<Item: Clone + 'a>>() {}

0 commit comments

Comments
 (0)