-
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
Lint on invalid values passed to x.py --warnings #62406
Conversation
src/bootstrap/flags.rs
Outdated
@@ -443,6 +443,19 @@ Arguments: | |||
} | |||
}; | |||
|
|||
let warnings = match matches.opt_str("warnings").as_ref().map(|v| v.as_str()) { |
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.
Could you add this to its own function + a comment re. what is happening?
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 code looks pretty obvious to me - what exactly would you want in the comment?
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.
Well for one it would be good to know what the role of the warnings
field is (it just says "true => deny" which is pretty unclear), why "deny"
implies true
, etc. But also it is hard to read code when you just have a big blob inside a function.
Also, why isn't the closure usage
used here instead of using std::process::exit
? (Moreover, std::process
is in scope.)
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've added some docs to the field (previously warnings
, now deny_warnings
).
I disagree that this would be good to pull out into a separate function; I think that wouldn't actually help. This is a single statement, not a group, and this function is the one that deals with processing command line arguments. It's also not a repetition of code, i.e., we're not going to be able to have other code which calls this function.
We're not using usage
because I wanted to tailor the error message specifically to warnings, e.g., by including the permitted values. It's possibly that it could be made better, but I don't personally want to spend the time figuring out how to integrate with usage
. This works, is simple, and IMO easier to interpret for end-users and future readers of this code.
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've added some docs to the field (previously
warnings
, nowdeny_warnings
).
Thanks!
I disagree that this would be good to pull out into a separate function; I think that wouldn't actually help. This is a single statement, not a group, and this function is the one that deals with processing command line arguments. It's also not a repetition of code, i.e., we're not going to be able to have other code which calls this function.
I don't think that matters so much. By having large functions you force readers to pay attention to details which may be irrelevant to what the function does at large (in this case parsing all the arguments into flags instead of just dealing with --warnings
) and it makes skimming the code harder. We don't have to have 5 line functions everywhere, but 395 lines is not readable.
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 guess I don't care that much. I can do it if it'll unblock this PR. I've never read through this whole function though when trying to edit it, so I don't really see the point, and I continue to think it's actually harmful - makes understanding it harder rather than easier in straight-line code. I would have a different opinion if this function was a mess of if statements that were all nested, but it's not.
src/bootstrap/flags.rs
Outdated
@@ -468,7 +481,7 @@ Arguments: | |||
.into_iter() | |||
.map(|p| p.into()) | |||
.collect::<Vec<_>>(), | |||
warnings: matches.opt_str("warnings").map(|v| v == "deny"), | |||
warnings: warnings, |
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.
warnings: warnings, | |
warnings, |
60ee3d5
to
5f8c24c
Compare
Are you sure you want me to review bootstrap stuff? I can try, but I have basically not have had any contact with that code.^^ |
5f8c24c
to
7a1d635
Compare
This is just touching argument parsing; pretty much anyone can review it. Up to you. If you don't want to I'd assign to |
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.
Well I suppose I can try to just make guesses about the rest of the code. ;) Seems unlikely to have subtle interactions.
I just have a few questions and one nit, r=me otherwise.
@@ -405,7 +405,7 @@ impl Config { | |||
config.incremental = flags.incremental; | |||
config.dry_run = flags.dry_run; | |||
config.keep_stage = flags.keep_stage; | |||
if let Some(value) = flags.warnings { | |||
if let Some(value) = flags.deny_warnings { | |||
config.deny_warnings = value; | |||
} |
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.
So argument parsing here is some kind of two-stage process? &[String]
-> Flags
-> Config
? And this is specifically for what gets passed on the cmdline?
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.
Yep, that's correct -- configuration loading is a bit non-ideal.
@@ -571,7 +571,7 @@ impl Config { | |||
config.rustc_default_linker = rust.default_linker.clone(); | |||
config.musl_root = rust.musl_root.clone().map(PathBuf::from); | |||
config.save_toolstates = rust.save_toolstates.clone().map(PathBuf::from); | |||
set(&mut config.deny_warnings, rust.deny_warnings.or(flags.warnings)); | |||
set(&mut config.deny_warnings, flags.deny_warnings.or(rust.deny_warnings)); |
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.
rust
here refers to the config.toml
?
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 also, this inversion of priority won't disturb CI somehow? I don't know exactly how CI passes its parameters but I seem to recall it's not through config.toml
.
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.
Yes, that's true. CI doesn't pass the --warnings
flag so it should be fine.
src/bootstrap/flags.rs
Outdated
@@ -468,7 +472,7 @@ Arguments: | |||
.into_iter() | |||
.map(|p| p.into()) | |||
.collect::<Vec<_>>(), | |||
warnings: matches.opt_str("warnings").map(|v| v == "deny"), | |||
deny_warnings, |
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.
IMO readability is slightly improved by inlining the let
:
deny_warnings: parse_deny_warnings(&matches)
Not a blocker though.
This also introduces support for `--warnings allow` and fixes --warnings being overridden by the configuration file, config.toml.
7a1d635
to
f01e5e6
Compare
@bors r=RalfJung |
📌 Commit f01e5e6 has been approved by |
…lfJung Lint on invalid values passed to x.py --warnings This also introduces support for `--warnings allow` and fixes --warnings being overridden by the configuration file, config.toml. Fixes rust-lang#62402 r? @RalfJung
…lfJung Lint on invalid values passed to x.py --warnings This also introduces support for `--warnings allow` and fixes --warnings being overridden by the configuration file, config.toml. Fixes rust-lang#62402 r? @RalfJung
…lfJung Lint on invalid values passed to x.py --warnings This also introduces support for `--warnings allow` and fixes --warnings being overridden by the configuration file, config.toml. Fixes rust-lang#62402 r? @RalfJung
Rollup of 13 pull requests Successful merges: - #61545 (Implement another internal lints) - #62110 (Improve -Ztime-passes) - #62133 (Feature gate `rustc` attributes harder) - #62158 (Add MemoryExtra in InterpretCx constructor params) - #62168 (The (almost) culmination of HirIdification) - #62193 (Create async version of the dynamic-drop test) - #62369 (Remove `compile-pass` from compiletest) - #62380 (rustc_target: avoid negative register counts in the SysV x86_64 ABI.) - #62381 (Fix a typo in Write::write_vectored docs) - #62390 (Update README.md) - #62396 (remove Scalar::is_null_ptr) - #62406 (Lint on invalid values passed to x.py --warnings) - #62414 (Remove last use of mem::uninitialized in SGX) Failed merges: r? @ghost
This also introduces support for
--warnings allow
and fixes --warningsbeing overridden by the configuration file, config.toml.
Fixes #62402
r? @RalfJung