Skip to content

Commit

Permalink
Merge pull request #3661 from calebcartwright/associated-type-bounds
Browse files Browse the repository at this point in the history
fix handling on associated type bounds
  • Loading branch information
scampi committed Jun 29, 2019
2 parents 1ee51a4 + d9e42ae commit b6f7f24
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,22 @@ impl<'a> Rewrite for SegmentParam<'a> {
SegmentParam::LifeTime(lt) => lt.rewrite(context, shape),
SegmentParam::Type(ty) => ty.rewrite(context, shape),
SegmentParam::Binding(assoc_ty_constraint) => {
let mut result = match context.config.type_punctuation_density() {
TypeDensity::Wide => {
format!("{} = ", rewrite_ident(context, assoc_ty_constraint.ident))
let mut result = match assoc_ty_constraint.kind {
ast::AssocTyConstraintKind::Bound { .. } => {
format!("{}: ", rewrite_ident(context, assoc_ty_constraint.ident))
}
TypeDensity::Compressed => {
format!("{}=", rewrite_ident(context, assoc_ty_constraint.ident))
ast::AssocTyConstraintKind::Equality { .. } => {
match context.config.type_punctuation_density() {
TypeDensity::Wide => {
format!("{} = ", rewrite_ident(context, assoc_ty_constraint.ident))
}
TypeDensity::Compressed => {
format!("{}=", rewrite_ident(context, assoc_ty_constraint.ident))
}
}
}
};

let budget = shape.width.checked_sub(result.len())?;
let rewrite = assoc_ty_constraint
.kind
Expand Down
13 changes: 13 additions & 0 deletions tests/source/associated_type_bounds.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// See #3657 - https://github.com/rust-lang/rustfmt/issues/3657

#![feature(associated_type_bounds)]

fn f<I: Iterator<Item: Clone>>() {}

fn g<I: Iterator<Item : Clone>>() {}

fn h<I: Iterator<Item : Clone>>() {}

fn i<I: Iterator<Item:Clone>>() {}

fn j<I: Iterator<Item : Clone+'a>>() {}
13 changes: 13 additions & 0 deletions tests/target/associated_type_bounds.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// See #3657 - https://github.com/rust-lang/rustfmt/issues/3657

#![feature(associated_type_bounds)]

fn f<I: Iterator<Item: Clone>>() {}

fn g<I: Iterator<Item: Clone>>() {}

fn h<I: Iterator<Item: Clone>>() {}

fn i<I: Iterator<Item: Clone>>() {}

fn j<I: Iterator<Item: Clone + 'a>>() {}

0 comments on commit b6f7f24

Please sign in to comment.