Handle dyn*
syntax when rewriting ast::TyKind::TraitObject
Resolves 5542 Prior to rust-lang/rust#101212 the `ast::TraitObjectSyntax` enum only had two variants `Dyn` and `None`. The PR that introduced the `dyn*` syntax added a new variant `DynStar`, but did not update the formatting rules to account for the new variant. Now the new `DynStar` variant is properly handled and is no longer removed by rustfmt.
This commit is contained in:
parent
a9ae746267
commit
cdfa2f86b7
14
src/types.rs
14
src/types.rs
@ -683,9 +683,11 @@ impl Rewrite for ast::Ty {
|
|||||||
match self.kind {
|
match self.kind {
|
||||||
ast::TyKind::TraitObject(ref bounds, tobj_syntax) => {
|
ast::TyKind::TraitObject(ref bounds, tobj_syntax) => {
|
||||||
// we have to consider 'dyn' keyword is used or not!!!
|
// we have to consider 'dyn' keyword is used or not!!!
|
||||||
let is_dyn = tobj_syntax == ast::TraitObjectSyntax::Dyn;
|
let (shape, prefix) = match tobj_syntax {
|
||||||
// 4 is length of 'dyn '
|
ast::TraitObjectSyntax::Dyn => (shape.offset_left(4)?, "dyn "),
|
||||||
let shape = if is_dyn { shape.offset_left(4)? } else { shape };
|
ast::TraitObjectSyntax::DynStar => (shape.offset_left(5)?, "dyn* "),
|
||||||
|
ast::TraitObjectSyntax::None => (shape, ""),
|
||||||
|
};
|
||||||
let mut res = bounds.rewrite(context, shape)?;
|
let mut res = bounds.rewrite(context, shape)?;
|
||||||
// We may have falsely removed a trailing `+` inside macro call.
|
// We may have falsely removed a trailing `+` inside macro call.
|
||||||
if context.inside_macro() && bounds.len() == 1 {
|
if context.inside_macro() && bounds.len() == 1 {
|
||||||
@ -693,11 +695,7 @@ impl Rewrite for ast::Ty {
|
|||||||
res.push('+');
|
res.push('+');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if is_dyn {
|
Some(format!("{}{}", prefix, res))
|
||||||
Some(format!("dyn {}", res))
|
|
||||||
} else {
|
|
||||||
Some(res)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ast::TyKind::Ptr(ref mt) => {
|
ast::TyKind::Ptr(ref mt) => {
|
||||||
let prefix = match mt.mutbl {
|
let prefix = match mt.mutbl {
|
||||||
|
10
tests/target/issue_5542.rs
Normal file
10
tests/target/issue_5542.rs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#![feature(dyn_star)]
|
||||||
|
#![allow(incomplete_features)]
|
||||||
|
|
||||||
|
use core::fmt::Debug;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let i = 42;
|
||||||
|
let dyn_i = i as dyn* Debug;
|
||||||
|
dbg!(dyn_i);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user