Skip to content

Issue 2506 #2507

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,18 @@ impl Rewrite for ast::TraitRef {
impl Rewrite for ast::Ty {
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
match self.node {
ast::TyKind::TraitObject(ref bounds, ..) => bounds.rewrite(context, shape),
ast::TyKind::TraitObject(ref bounds, tobj_syntax) => {
// we have to consider 'dyn' keyword is used or not!!!
let is_dyn = tobj_syntax == ast::TraitObjectSyntax::Dyn;
// 4 is length of 'dyn '
let shape = if is_dyn { shape.offset_left(4)? } else { shape };
let res = bounds.rewrite(context, shape)?;
if is_dyn {
Some(format!("dyn {}", res))
} else {
Some(res)
}
}
ast::TyKind::Ptr(ref mt) => {
let prefix = match mt.mutbl {
Mutability::Mutable => "*mut ",
Expand Down
16 changes: 16 additions & 0 deletions tests/source/issue-2506.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#![feature(dyn_trait)]
fn main() {
// checks rustfmt doesn't remove dyn
trait MyTrait {
fn method(&self) -> u64;
}
fn f1(a: Box<dyn MyTrait>) {}

// checks if line wrap works correctly
trait Very_______________________Long__________________Name____________________Trait {
fn method(&self) -> u64;
}

fn f2(a: Box<dyn Very_______________________Long__________________Name____________________Trait+ 'static,>) {}

}
22 changes: 22 additions & 0 deletions tests/target/issue-2506.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#![feature(dyn_trait)]
fn main() {
// checks rustfmt doesn't remove dyn
trait MyTrait {
fn method(&self) -> u64;
}
fn f1(a: Box<dyn MyTrait>) {}

// checks if line wrap works correctly
trait Very_______________________Long__________________Name____________________Trait
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The opening bracket should not be indented, but I guess this is a seperate issue. So this is fine as is.

fn method(&self) -> u64;
}

fn f2(
a: Box<
dyn Very_______________________Long__________________Name____________________Trait
+ 'static,
>,
) {
}
}