mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-14 04:56:49 +00:00
commit
61919022dd
13
src/types.rs
13
src/types.rs
@ -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 ",
|
||||
|
16
tests/source/issue-2506.rs
Normal file
16
tests/source/issue-2506.rs
Normal 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,>) {}
|
||||
|
||||
}
|
22
tests/target/issue-2506.rs
Normal file
22
tests/target/issue-2506.rs
Normal 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,
|
||||
>,
|
||||
) {
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user