-
Notifications
You must be signed in to change notification settings - Fork 888
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
Handle dyn*
syntax when rewriting ast::TyKind::TraitObject
#5552
Conversation
PR on hold until we do a subtree sync and bump the nighty compiler version to one that supports parsing |
The other thing that's needed is input from the style team relative to how these should be formatted, or at least how we think they should be. Wheels are in motion there |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tentative approval as while I believe this is the direction we'll go, it will still need some level of confirmation first
src/types.rs
Outdated
let shape = if is_dyn { shape.offset_left(4)? } else { shape }; | ||
let shape = match tobj_syntax { | ||
ast::TraitObjectSyntax::Dyn => shape.offset_left(4)?, // 4 is offset 'dyn ' | ||
ast::TraitObjectSyntax::DynStar => shape.offset_left(5)?, // 5 is offset 'dyn* ' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm now that I'm thinking about it would it just be better to return None
if we get to a DynStart
since its experimental syntax?
Let's do a simple update to ensure rustfmt stops butchering the syntax altogether, but we should hold off on applying formatting for now. This was a topic in recent t-style discussions, but style/formatting rules are being deferred due to other priorities and focus areas |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm gonna bump this because I almost actually just put up my own PR that duplicated this 🤣.
Per nightly style policy, I'm pretty sure that rustfmt can now feel free to begin formatting dyn*
more than just ignoring it altogether. Speaking as an individual on T-style, I think treating dyn*
as a single token is what we want to do here anyways.
src/types.rs
Outdated
match tobj_syntax { | ||
ast::TraitObjectSyntax::Dyn => Some(format!("dyn {}", res)), | ||
ast::TraitObjectSyntax::DynStar => Some(format!("dyn* {}", res)), | ||
ast::TraitObjectSyntax::None => Some(res), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My only nit is that this could be merged into a single match with above,
something like:
let (shape, prefix) = match tobj_syntax {
ast::TraitObjectSyntax::Dyn => (shape.offset_left(4)?, "dyn "),
ast::TraitObjectSyntax::DynStar => (shape.offset_left(5)?, "dyn* "),
ast::TraitObjectSyntax::None => (shape, ""),
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be happy to make this change since it simplifies the code!
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.
@compiler-errors I made your suggest change. @calebcartwright does your earlier review still apply? |
Resolves #5542
Prior to rust-lang/rust#101212 the
ast::TraitObjectSyntax
enum only had two variantsDyn
andNone
. The PR that introduced thedyn*
syntax added a new variantDynStar
, 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.