Merge pull request #2862 from topecongiro/issue-2852
Preserve parens in trait bounds
This commit is contained in:
commit
814f6339b4
19
src/types.rs
19
src/types.rs
@ -521,7 +521,24 @@ impl Rewrite for ast::GenericBound {
|
||||
|
||||
impl Rewrite for ast::GenericBounds {
|
||||
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
|
||||
join_bounds(context, shape, self, true)
|
||||
if self.is_empty() {
|
||||
return Some(String::new());
|
||||
}
|
||||
|
||||
let span = mk_sp(self.get(0)?.span().lo(), self.last()?.span().hi());
|
||||
let has_paren = context.snippet(span).starts_with("(");
|
||||
let bounds_shape = if has_paren {
|
||||
shape.offset_left(1)?.sub_width(1)?
|
||||
} else {
|
||||
shape
|
||||
};
|
||||
join_bounds(context, bounds_shape, self, true).map(|s| {
|
||||
if has_paren {
|
||||
format!("({})", s)
|
||||
} else {
|
||||
s
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
#![feature(dyn_trait)]
|
||||
|
||||
fn main() {
|
||||
// #2506
|
||||
// checks rustfmt doesn't remove dyn
|
||||
trait MyTrait {
|
||||
fn method(&self) -> u64;
|
||||
@ -13,4 +15,6 @@ fn main() {
|
||||
|
||||
fn f2(a: Box<dyn Very_______________________Long__________________Name____________________Trait+ 'static,>) {}
|
||||
|
||||
// #2582
|
||||
let _: &dyn (::std::any::Any) = &msg;
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
#![feature(dyn_trait)]
|
||||
|
||||
fn main() {
|
||||
// #2506
|
||||
// checks rustfmt doesn't remove dyn
|
||||
trait MyTrait {
|
||||
fn method(&self) -> u64;
|
||||
@ -19,4 +21,7 @@ fn main() {
|
||||
>,
|
||||
) {
|
||||
}
|
||||
|
||||
// #2582
|
||||
let _: &dyn (::std::any::Any) = &msg;
|
||||
}
|
@ -107,4 +107,4 @@ pub(crate) fn init() {}
|
||||
crate fn init() {}
|
||||
|
||||
// #2630
|
||||
fn make_map<T, F: Fn(&T) -> String>(records: &Vec<T>, key_fn: F) -> HashMap<String, usize> {}
|
||||
fn make_map<T, F: (Fn(&T) -> String)>(records: &Vec<T>, key_fn: F) -> HashMap<String, usize> {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user