Conversation
Includes minor refactor and more helpful errors in case of incorrect repr attributes
compiler/rustc_attr/src/builtin.rs
Outdated
| .span_suggestion( | ||
| item.path.span.shrink_to_hi().to(item.span.shrink_to_hi()), | ||
| "remove additional values", | ||
| format!("{}", name), | ||
| Applicability::MachineApplicable, | ||
| ) |
There was a problem hiding this comment.
Note that if the suggestion is applied, the resulting code would be malformed. Change this to the following, to make it clear for the user and correct for the machines.
| .span_suggestion( | |
| item.path.span.shrink_to_hi().to(item.span.shrink_to_hi()), | |
| "remove additional values", | |
| format!("{}", name), | |
| Applicability::MachineApplicable, | |
| ) | |
| .span_suggestion_verbose( | |
| item.path.span.shrink_to_hi().to(item.span.shrink_to_hi()), | |
| "remove additional values", | |
| String::new(), | |
| Applicability::MachineApplicable, | |
| ) |
| @@ -0,0 +1,69 @@ | |||
| #![feature(repr_simd)] | |||
There was a problem hiding this comment.
Check if we can make this test also check for diagnostic applicability. It might not be possible (if there are further errors afterwards), but let's confirm.
| #![feature(repr_simd)] | |
| // run-rustfix | |
| #![feature(repr_simd)] |
There was a problem hiding this comment.
I've added a separate file for fixable suggestions
compiler/rustc_attr/src/builtin.rs
Outdated
| err.span_suggestion( | ||
| item.span, | ||
| "use parentheses instead", | ||
| format!("{}({})", name, int), | ||
| Applicability::MachineApplicable, | ||
| ); | ||
| } | ||
| ast::LitKind::Str(s, _) => { | ||
| err.span_suggestion( | ||
| item.span, | ||
| "use parentheses instead", | ||
| format!("{}({})", name, s), | ||
| Applicability::MachineApplicable, | ||
| ); | ||
| } |
There was a problem hiding this comment.
Could we see if we could make these multipart_suggestions where we add the parentheses in the right place?
compiler/rustc_attr/src/builtin.rs
Outdated
| .span_suggestion( | ||
| item.span, | ||
| "add a value", | ||
| format!("{}(/* value */)", name), | ||
| Applicability::HasPlaceholders, | ||
| ) |
There was a problem hiding this comment.
| .span_suggestion( | |
| item.span, | |
| "add a value", | |
| format!("{}(/* value */)", name), | |
| Applicability::HasPlaceholders, | |
| ) | |
| .span_suggestion_verbose( | |
| item.span.shrink_to_hi(), | |
| "add a value", | |
| "(/* value */)".to_string(), | |
| Applicability::HasPlaceholders, | |
| ) |
There was a problem hiding this comment.
I have no idea why but I can't make this fix to work. The suggestion is machine applicable, shows in stderr but for whatever reason doesn't show up in suggestions after I added a dbg call:
diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs
--- a/src/tools/compiletest/src/runtest.rs (revision 4319f72eca7f720d458355f517f59502fa986dd7)
+++ b/src/tools/compiletest/src/runtest.rs (date 1622939470653)
@@ -3313,6 +3313,7 @@
},
)
.unwrap();
+ dbg!(&suggestions);
let fixed_code = apply_suggestions(&unfixed_code, &suggestions).unwrap_or_else(|_| {
panic!("failed to apply suggestions for {:?} with rustfix", self.testpaths.file)
});
src/test/ui/repr/rustfix.stderr
Outdated
There was a problem hiding this comment.
Should this be divided into two separate errors or is it fine left as is?
There was a problem hiding this comment.
It's somewhat concerning that it suggests "use parentheses" and leaving foo alone when a number is expected there. This might not need to be addressed now.
Should this be divided into two separate errors or is it fine left as is?
What do you mean? Having one for the lack of parentheses and a separate for foo not being a positive number? Personally I prefer to consolidate errors when possible, and I think it's fine overall as is.
This comment has been minimized.
This comment has been minimized.
|
The job Click to see the possible cause of the failure (guessed by this bot) |
|
@mibac138 Triage: Seems CI is still red here. |
|
☔ The latest upstream changes (presumably #87029) made this pull request unmergeable. Please resolve the merge conflicts. |
|
Ping from triage |
Includes minor refactor and more helpful errors in case of incorrect
repr attributes
Fixes #85713
r? @estebank