-
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
Impl StyleEditionDefault
trait for all configs
#5937
Impl StyleEditionDefault
trait for all configs
#5937
Conversation
max_width: MaxWidth, true, "Maximum width of each line"; | ||
hard_tabs: HardTabs, true, "Use tab characters for indentation, spaces for alignment"; | ||
tab_spaces: TabSpaces, true, "Number of spaces per tab"; | ||
newline_style: NewlineStyleConfig, true, "Unix or Windows line endings"; | ||
indent_style: IndentStyleConfig, false, "How do we indent expressions or items"; |
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.
Not a change we need to make now (or ever), but as I was working on this I wondered if we could generalize StyleEditionDefault
and rename it to something like RustfmtConfigOption
(happy to bikeshed on the name). That trait could also be used to define each configuration option's description, stability, and default value for different style editions.
For example:
use crate::config::StyleEdition;
use crate::config::config_type::ConfigType;
pub trait RustfmtConfigOption {
type ConfigType: ConfigType;
fn default(style_edition: StyleEdition) -> Self::ConfigType;
fn description() -> &'static str;
fn stability() -> bool;
}
That way, create_config!
could focus on setting field names and ty
s that impl RustfmtConfigOption
.
For example if we implemented RustfmtConfigOption
for MaxWidth
it might look something like this:
impl RustfmtConfigOption for MaxWidth {
type ConfigType = usize;
fn default(_: StyleEdition) -> Self::ConfigType { 100 }
fn description() -> &'static str { "Maximum width of each line" }
fn stability() -> bool { true }
}
And then the call to create_config!
would be simplified to:
create_config! {
max_width: MaxWidth,
}
This would also eliminate some of the duplication for the test config we create in mod test
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 the sound of this, but agree it's something worth deferring
src/config/options.rs
Outdated
config_option_with_style_edition_default!( | ||
// Fundamental stuff | ||
MaxWidth, usize, 100; | ||
HardTabs, bool, false; | ||
TabSpaces, usize, 4; | ||
NewlineStyleConfig, NewlineStyle, NewlineStyle::Auto; | ||
IndentStyleConfig, IndentStyle, IndentStyle::Block; |
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.
Defines a unit struct for each config option that implements StyleEditionDefault
09eb6ff
to
37b0505
Compare
pub use crate::config::lists::*; | ||
#[allow(unreachable_pub)] | ||
pub use crate::config::macro_names::{MacroSelector, MacroSelectors}; | ||
pub use crate::config::macro_names::MacroSelector; |
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 unused import lint was triggering for crate::config::lists::*;
and MacroSelectors
so I removed the import for crate::config::lists::*;
, and I moved the MacroSelectors
import down to the test module.
use crate::config::macro_names::MacroName; | ||
use crate::config::macro_names::{MacroName, MacroSelectors}; |
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.
MacroSelectros
import moved here: https://github.com/rust-lang/rustfmt/pull/5937/files#r1428877853
37b0505
to
e9da818
Compare
@ytmimi do you think this would be better to merge before or after the next sync? (no promises but I'm going to try to do one today) |
@calebcartwright If we're going to do a sync we should update the changelog. I've started that on #6004, but there are a few other fixes that I merged that don't have entries yet. |
That said, we can probably wait to merge this until after the sync |
d1d1f41
to
3e03c8d
Compare
3e03c8d
to
2adf879
Compare
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.
Still have a bit more to get through but leaving some initial thoughts now
max_width: MaxWidth, true, "Maximum width of each line"; | ||
hard_tabs: HardTabs, true, "Use tab characters for indentation, spaces for alignment"; | ||
tab_spaces: TabSpaces, true, "Number of spaces per tab"; | ||
newline_style: NewlineStyleConfig, true, "Unix or Windows line endings"; | ||
indent_style: IndentStyleConfig, false, "How do we indent expressions or items"; |
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 the sound of this, but agree it's something worth deferring
verbose: Verbosity, Verbosity::Normal, false, | ||
"How much to information to emit to the user"; | ||
file_lines: FileLines, FileLines::all(), false, | ||
max_width: MaxWidth, true, "Maximum width of each line"; |
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.
just leaving this as a thought, not requesting/suggesting a pivot, but I found myself having to dart back and forth between the two sites to get a "full picture" of a given option.
that's fine for moving ahead with 2024 edition support, but it's definitely something I want to address sooner rather than later, as it's going to be prone for errors IMO (perhaps you're earlier suggestion on future refactoring would help as well)
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.
Agreed that there's plenty of room for improvement, and I'm open to suggestions on how to make this better
2adf879
to
0e612d5
Compare
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.
Let's go ahead with this as this is the big domino we need to fall to start knocking out the other work for 2024 edition.
Couple minor items left inline for future follow up
Makes internal changes to define each configuration in terms of the `StyleEditionDefault` trait, and hard codes `StyleEdition::Edition2015` anywhere the new `style_edition` is needed. **Note** users are still unable to configure `style edition`.
0e612d5
to
312be6a
Compare
This PR is a follow up to #5933,
but currently includes all the changes from that PR since it hasn't been merged yet.This PR makes internal changes to define each configuration in terms of the
StyleEditionDefault
trait, and hard codesStyleEdition::Edition2015
anywhere the newstyle_edition
is needed.Note users are still unable to configure
style edition
.r? @calebcartwright
Edit: #5933 was merged and I rebased this PR.