-
Notifications
You must be signed in to change notification settings - Fork 889
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
config_type: add unstable_variant attribute #5379
config_type: add unstable_variant attribute #5379
Conversation
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 have some questions for someone with more project experience
@@ -57,7 +57,7 @@ unicode-segmentation = "1.9" | |||
unicode-width = "0.1" | |||
unicode_categories = "0.1" | |||
|
|||
rustfmt-config_proc_macro = { version = "0.2", path = "config_proc_macro" } | |||
rustfmt-config_proc_macro = { version = "0.3", path = "config_proc_macro" } |
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 pretty sure this needs a version bump, however I don't know if this has knock on impacts anywhere else? AFAIK this is an internal only crate that we can break without fear?
config_proc_macro/Cargo.lock
Outdated
@@ -1,68 +1,68 @@ | |||
# This file is automatically @generated by Cargo. | |||
# It is not intended for manual editing. | |||
version = 3 |
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 noted the lockfile versions have been upgraded by my local toolchain - happy to somehow keep to the original version if this is an issue for compatibility?
src/config/config_type.rs
Outdated
}, | ||
// Nightly: everything allowed | ||
// Stable with stable option and variant: allowed | ||
(true, _, _) | (false, true, true) => { |
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.
This could be _ => ...
, but I preferred to write the explicit cases to check they made semantic sense, and guard against future changes.
I would also ask - how should I go about testing this? I couldn't find any tests for the existing unstable options, or the proc macro code internals. In fact, I get test failures when I run |
Haven't really had a chance to look at this yet, but just wanted to say I love the idea! Attributes seem like a really clean and simple way of managing this and I'm excited about the possibilities |
@tommilligan as well as updating |
Do we need to define a new #[proc_macro_attribute]
pub fn unstable_variant(_args: TokenStream, input: TokenStream) -> TokenStream {
input
} Also I believe the tests are failing because the doc tests for |
I can see how testing this could be a little tricky since we don't currently have any options that are stable with // src/config/options.rs
/// This configuration option is only available for testing purposes
#[cfg(test)]
#[config_type]
pub enum SemiStableOption {
Stable,
#[unstable_variant]
Unstable,
} // src/config/config_types.rs
#[cfg(test)]
use crate::config::options::SemiStableOption;
macro_rules! create_config {
($($i:ident: $ty:ty, $def:expr, $stb:expr, $( $dstring:expr ),+ );+ $(;)*) => (
#[cfg(test)]
use std::collections::HashSet;
use std::io::Write;
use serde::{Deserialize, Serialize};
#[derive(Clone)]
#[allow(unreachable_pub)]
pub struct Config {
#[cfg(test)]
semi_stable_option: (Cell<bool>, bool, SemiStableOption, bool),
// For each config item, we store a bool indicating whether it has
// been accessed and the value, and a bool whether the option was
// manually initialised, or taken from the default,
$($i: (Cell<bool>, bool, $ty, bool)),+
}
... And then we could write a few tests in Not 100% sure if this approach will work. This might cause some issues with the |
//! | ||
//! - `doc_hint`: name-value pair whose value is string literal | ||
//! - `value`: name-value pair whose value is string literal | ||
//! - `unstable_variant`: name only |
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.
An idea for a follow up PR: I wonder if we could optionally include the tracking issue number in the unstable_variant
annotation. It might be nice to include a link to the tracking issue in the warning message. Thoughts?
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 like this idea, but agree it should be in followup
We don't - I've verified that the attribute works as intended locally. The reason is that the
Thanks for this - I've opened #5389 with a fix for this plus CI to enforce it. |
Thanks for pointing this out. Updated to factor out the common logic of updating with an unstable option/value from I think this points out that you could set unstable options using |
Thanks for the hints on this. I actually found we already have a |
@ytmimi Thanks for all your feedback - I think I've addressed everything you raised. CI appears to be failing with a lot of unrelated errors that I don't think are to do with this PR? |
If I had to guess I'd say it's this behavior that's causing the CI to fail, since it's only the "stable" tests that are failing. To reiterate, the "stable" tests don't actually run on a stable version of rustfmt they just run with In theory I agree that this would be a bugfix for unintended behaviour, but I think there's probably a larger discussion that needs to be had around whether we want to continue to let users set unstable options via the command line. #5025 looked to solve this by giving users control of that decision, and allowing them to decide whether rustfmt exits with an abort message or warns and continues formatting when using unstable options. For now, can you simply issue the warning in |
🤦 ah, thank you. Yes, makes-breaking-change-and-then-wonders-why-CI-is-failing sounds about right for me.
I think it would be counterintuitive to warn about unstable options/variants, while at the same time allowing them to be set from If this isn't desired, I can look into changing the behaviour of Added unit tests that confirm the behaviour of both |
Oh don't worry about it. I've definitely done the same thing before 😂
That's fine. I think restoring the original behaviour for now makes sense and we can decide what the best way forward is after we've had some more time to think on it.
Fantastic! I took a look at the tests and everything looks good to me! |
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.
Thanks for all your work on this! I feel pretty good about what we've got here. @calebcartwright I'm ready to move forward, but I definitely want to give you a chance to take a look before merging
Yes I want to review this one for sure 👍 Apologies as I'm not fully up to date with the entirety of the conversation, but given the CLI discussion there's a few things I wanted to go ahead and note:
|
Yup, that's the consensus. We won't look to deal with that here
The only difference being made right now is that a warning will be issued if you set an unstable value on stable via the config file, but if you set it from the command line no warning will be issued. I think that's fine for now, but I'm personally in favor of issuing the warning even if we end up setting the value. Because of the way #5025 is implemented a warning will be issued regardless of how the option was set once I rebase and integrate these changes.
I'm almost positive that it is. Probably a few minor tweaks need to be made when I rebase to pull these changes in, but should be relatively painless. |
This has unfortunately acquired a merge conflict, could you rebase and resolve when you get a chance? Overall I'm good with the approach, though may have a couple nits (e.g. function names) we can revisit at a later date.
We can continue that discussion on your PR to identify target behavior. The historical thinking, aiui, was to simply warn when the user asked rustfmt for an option that it wasn't going to apply. That's why the current behavior when taking advantage of the |
045ad45
to
68e6c6d
Compare
Squashed and rebased.
Happy to, I tried to stick with existing convention as far as I could, even though I don't think they're the most intuitive right now.
Thanks for confirming this - happy this PR maintains the original intent to warn only when an option will not be respected despite being specified. |
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.
Thank you so much for the excellent work on this!
It's a capability I've had in mind for a while but hadn't been able to make time for. I realize and appreciate your impetus was largely driven by imports_granularity
, but I just want to stress this will have far greater and broader import around our ability to get more options out (at least partially) on stable ❤️
Thanks, that's great to hear. Fingers crossed, look forward to seeing it in some good use cases in future! And thanks for the great iteration process from both of you, it's really made working on this feature a pleasure. |
First pass at #5378
Adds new functionality to the existing
config_proc_macro
crate, such that enums used for configuration can have their variants annotated asunstable_variant
:This will be checked upon loading config, and a warning emitted similar to using current unstable options on stable toolchain: