Merge pull request #2507 from kngwyu/issue-2506

Issue 2506
This commit is contained in:
Seiichi Uchida 2018-03-06 00:41:16 +09:00 committed by GitHub
commit 61919022dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 1 deletions

View file

@ -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 ",

View file

@ -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,>) {}
}

View file

@ -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
{
fn method(&self) -> u64;
}
fn f2(
a: Box<
dyn Very_______________________Long__________________Name____________________Trait
+ 'static,
>,
) {
}
}