-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Fix repr(...)
validation ICE
#85976
Fix repr(...)
validation ICE
#85976
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.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, | |
) |
@@ -2,11 +2,11 @@ | |||
|
|||
#![allow(dead_code)] | |||
|
|||
#[repr(align(8))] //~ ERROR incorrect `repr(align)` attribute format | |||
#[repr(align=8)] //~ ERROR incorrect `repr(align)` attribute format |
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 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)
});
error[E0693]: incorrect `repr(align)` attribute format | ||
--> $DIR/rustfix.rs:6:8 | ||
| | ||
LL | #[repr(align = r###"foo"###)] | ||
| ^^^^^^^^------------ | ||
| | | ||
| must be a non-negative number | ||
| | ||
help: use parentheses instead | ||
| | ||
LL | #[repr(align(foo))] | ||
| ^ ^ |
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.
Should this be divided into two separate errors or is it fine left as is?
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.
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