-
Notifications
You must be signed in to change notification settings - Fork 34
WIP: rustfix-mode flag
#353
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,12 +8,14 @@ use crate::{ | |
| per_test_config::{Comments, Revisioned, TestConfig}, | ||
| Error, Errored, TestOk, | ||
| }; | ||
| use anyhow::bail; | ||
| use rustfix::{CodeFix, Filter, Suggestion}; | ||
| use spanned::{Span, Spanned}; | ||
| use std::{ | ||
| collections::HashSet, | ||
| path::{Path, PathBuf}, | ||
| process::Output, | ||
| str::FromStr, | ||
| sync::Arc, | ||
| }; | ||
|
|
||
|
|
@@ -47,6 +49,7 @@ impl Flag for RustfixMode { | |
| output: &Output, | ||
| build_manager: &BuildManager, | ||
| ) -> Result<(), Errored> { | ||
| dbg!(*self); | ||
| let global_rustfix = match config.exit_status()? { | ||
| Some(Spanned { | ||
| content: 101 | 0, .. | ||
|
|
@@ -56,6 +59,7 @@ impl Flag for RustfixMode { | |
| let output = output.clone(); | ||
| let no_run_rustfix = config.find_one_custom("no-rustfix")?; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is how the value is loaded.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When this function is entered,
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh I forgot this was how it's done. See my other comment for what's happening |
||
| let fixes = if no_run_rustfix.is_none() && global_rustfix.enabled() { | ||
| dbg!(global_rustfix); | ||
| fix(&output.stderr, config.status.path(), global_rustfix).map_err(|err| Errored { | ||
| command: format!("rustfix {}", display(config.status.path())), | ||
| errors: vec![Error::Rustfix(err)], | ||
|
|
@@ -99,11 +103,25 @@ impl Flag for RustfixMode { | |
| } | ||
| } | ||
|
|
||
| impl FromStr for RustfixMode { | ||
| type Err = anyhow::Error; | ||
| fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
| match s { | ||
| "disabled" => Ok(RustfixMode::Disabled), | ||
| "everything" => Ok(RustfixMode::Everything), | ||
| "machine-applicable" => Ok(RustfixMode::MachineApplicable), | ||
| _ => bail!("unknown `RustfixMode`: {s}"), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fn fix(stderr: &[u8], path: &Path, mode: RustfixMode) -> anyhow::Result<Vec<String>> { | ||
| dbg!(path); | ||
| let suggestions = std::str::from_utf8(stderr) | ||
| .unwrap() | ||
| .lines() | ||
| .filter_map(|line| { | ||
| // dbg!(line); | ||
| if !line.starts_with('{') { | ||
| return None; | ||
| } | ||
|
|
@@ -121,6 +139,8 @@ fn fix(stderr: &[u8], path: &Path, mode: RustfixMode) -> anyhow::Result<Vec<Stri | |
| ) | ||
| }) | ||
| .collect::<Vec<_>>(); | ||
| // dbg!(mode); | ||
| // dbg!(&suggestions); | ||
| if suggestions.is_empty() { | ||
| return Ok(Vec::new()); | ||
| } | ||
|
|
||
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.
If you set
rustfixinstead ofrustfix-modethe other rustfix flag (line 158) gets overridden if the flag is set instead of both of the flags getting runThere 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 to be clear, this
rustflixflag?ui_test/src/config.rs
Lines 156 to 158 in 2a32015
Could you point me to where that flag is checked?
Uh oh!
There was an error while loading. Please reload this page.
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.
Flags are automatically handled. I'd need to look it up but likely you can grep for
Box<dyn Flag>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 apologize. I am genuinely trying to understand what is going on here. But automatically handled by what?
ui_testor something else?If I grep for
Box, I get 123 hits. Grepping forBox::newreduces that to 54. But is there anything more specific I could look for?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 lmao sorry. Github ate the generic params because it thought they are HTML. Edited
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.
@oli-obk Can I just confirm that this is how you want/expect
ui_testto work? I'm just asking because I don't think I've seen a.fixedfile with a$HASHannotation before.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 think you should use the
$HASHinCargo.stdoutfiles, such as the one you linked.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, @kirtchev-adacore. My question to @oli-obk stands, though.
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 like dumping lots of info normally to users, so printing the command somewhere is useful. Not sure the current style is the thing I want long term, but just replacing output hashes with $HASH is what I do whenever it shows up in stdout/stderr.
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 your suggestion, @kirtchev-adacore. I pushed that change. I think there may still be some non-determinism in the ordering of the fields, though. For example, I see this in the diff between the previous version and the one I just pushed:
Regardless, I suspect this is tangential to my real problem: I cannot tell whether the
.fixedfiles are being generated and checked. I wish there was an easy way to make that determination.