-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Add do yeet
expressions to allow experimentation in nightly
#96376
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
ast::ExprKind::Yeet(None) => Some("do yeet".to_owned()), | ||
ast::ExprKind::Yeet(Some(ref expr)) => { | ||
rewrite_unary_prefix(context, "do yeet ", &**expr, 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.
Typically with a new variant we'd start with rustfmt just spitting back out whatever the user wrote, but in this particular case I can't imagine a universe where we'd do anything different. As such I've no concerns with these rustfmt changes 👍
Will use this to mention an aside, and realize the style team hasn't fully come to fruition yet @joshtriplett, but I think one future question/consideration for that team should be when/how new syntax gets incorporated into the guide, including for cases like this that are obvious and noncontroversial.
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.
Oh, thanks @calebcartwright; I wasn't thinking about the stability details here at all. But yes, I agree that I'd be very surprised if we wanted this to format differently from return
/break
. Also, the syntax for this will change later, so we'll have another opportunity to rethink the formatting once that happens.
As another aside: Is there a way this match
could have a catch-all arm that just does the "spit back what the user wrote", so that additions to the AST like this would do the right thing without needing a code change? I only updated the file because the PR build broke when I did nothing.
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.
Is there a way this match could have a catch-all arm that just does the "spit back what the user wrote", so that additions to the AST like this would do the right thing without needing a code change?
Potentially. IIRC many of the big match expressions used to have a catch-all pattern arm in the earlier days when rustfmt used the AP crates, but that was intentionally changed some time back as part of an effort to ensure the rustfmt team would become aware of new syntax associated with new variants.
If/when we can implement some of the process changes previously discussed elsewhere then I'd certainly be open to adding such arms back. In the interim, for future reference, the behavior can be triggered with None
or something like Some(context.snippet(<<span>>).to_owned())
This comment was marked as off-topic.
This comment was marked as off-topic.
Error: The "Author" shortcut only works on pull requests. Please let |
); | ||
|
||
if let Some(catch_node) = self.catch_scope { | ||
let target_id = Ok(self.lower_node_id(catch_node)); |
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.
preexisting, but I wish we didn't have to lower the node id twice.
| ^^^^^^^ cannot infer type | ||
| | ||
= note: cannot satisfy `<_ as Try>::Residual == _` | ||
help: consider specifying the type argument in the method call | ||
| | ||
LL | l.iter().map(f).collect::<B>()? | ||
| +++++ | ||
| ^ cannot infer type |
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.
Unfortunate that the second FromResidual impl breaks this
= help: the following other types implement trait `FromResidual<R>`: | ||
<Result<T, F> as FromResidual<Result<Infallible, E>>> | ||
<Result<T, F> as FromResidual<Yeet<E>>> |
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.
Technically adding a second impl when there was only one before is a breaking change I think. There are some cases where inference figures something out. Considering that users can't mention FromResidual themselves, we're good here, but probably good to keep in mind.
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.
Crater says we're clean, but I think the other thing that helps is the direction in which we're using it -- AsRef<T>
has this problem all the time when used as a method, because with self
known then if there's only one impl it's easy to know the T
. But here we're going the other direction, and I know know that the inference engine allows taking advantage of "FromResidual<Concrete>
is only implemented for one type", since that's fundamentally less stable, as anyone who wants could implement that themselves later if they want.
(And if there is a way that adding another impl here can be a breaking change, all the better to get a second one in early to keep anyone from finding a way to write stable code that depends on it 🙃)
Should we crater this? I think there are no actual problems here, but may have missed something |
Looks like the crater queue is currently empty, so might as well -- especially since check-only is fine. @bors try |
⌛ Trying commit 778944ca1ffaf781928cc846a5d41389c95da009 with merge ea2bf32540662c61547071aad6cf0851a0b02f58... |
☀️ Try build successful - checks-actions |
@craterbot check |
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🎉 Experiment
|
No real regressions here. Errors:
But it looks like I have some conflicts to fix, so |
Using an obviously-placeholder syntax. An RFC would still be needed before this could have any chance at stabilization, and it might be removed at any point. But I'd really like to have it in nightly at least to ensure it works well with try_trait_v2, especially as we refactor the traits.
@bors r+ |
📌 Commit b317ec1 has been approved by |
☀️ Test successful - checks-actions |
Finished benchmarking commit (508e058): comparison url. Summary: This benchmark run did not return any relevant results. If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. @rustbot label: -perf-regression |
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.
The new syntax doesn't bring anything over return Err(...)
Two main goals for this:
try_trait_v2
, A new design for the?
desugaring (RFC#3058) #84277 (comment) doesn't accidentally close us off from the possibility of doing this in future, as sketched in https://rust-lang.github.io/rfcs/3058-try-trait-v2.html#possibilities-for-yeetdo
) and name in this PR are not intended as candidates for stabilization, but they make a good v0 PR for adding this with minimal impact to compiler maintenance or priming one possible name choice over another.r? @oli-obk
The lang
second
for doing this: rust-lang/lang-team#160 (comment)Tracking issues
yeet
expressions (feature(yeet_expr)
) #96373ops::Yeet
(feature(try_trait_v2_yeet)
) #96374