Skip to content
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

Closed
wants to merge 2 commits into from
Closed

Conversation

mibac138
Copy link
Contributor

@mibac138 mibac138 commented Jun 3, 2021

Includes minor refactor and more helpful errors in case of incorrect
repr attributes

Fixes #85713
r? @estebank

Includes minor refactor and more helpful errors in case of incorrect
repr attributes
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 3, 2021
Comment on lines 846 to 851
.span_suggestion(
item.path.span.shrink_to_hi().to(item.span.shrink_to_hi()),
"remove additional values",
format!("{}", name),
Applicability::MachineApplicable,
)
Copy link
Contributor

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.

Suggested change
.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)]
Copy link
Contributor

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.

Suggested change
#![feature(repr_simd)]
// run-rustfix
#![feature(repr_simd)]

Copy link
Contributor Author

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

Comment on lines 866 to 880
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,
);
}
Copy link
Contributor

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?

Comment on lines 892 to 897
.span_suggestion(
item.span,
"add a value",
format!("{}(/* value */)", name),
Applicability::HasPlaceholders,
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.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
Copy link
Contributor Author

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)
             });

Comment on lines +12 to +23
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))]
| ^ ^
Copy link
Contributor Author

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?

Copy link
Contributor

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.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-llvm-10 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
...................................................ii...............i............................... 9100/11965
.................................................................................................... 9200/11965
.................................................................................................... 9300/11965
.................................................................................................... 9400/11965
....................................F.......F....................................................... 9500/11965
.................................................................................................... 9700/11965
.................i.i.......i........................................................................ 9800/11965
.........................................................................iiiiii.i..iiiiii.i......... 9900/11965
.................................................................................................... 10000/11965
---
---- [ui] ui/attributes/nonterminal-expansion.rs stdout ----
diff of stderr:

9    |
10    = note: this error originates in the macro `pass_nonterminal` (in Nightly builds, run with -Z macro-backtrace for more info)
- error: aborting due to previous error
- error: aborting due to previous error
+ error[E0589]: invalid `repr(align)` attribute
+    |
+    |
+ LL | pass_nonterminal!(n!());
+    |                   ^ not a non-negative number
Some tests failed in compiletest suite=ui mode=ui host=x86_64-unknown-linux-gnu target=x86_64-unknown-linux-gnu
+ error: aborting due to 2 previous errors
+ 
+ For more information about this error, try `rustc --explain E0589`.
14 
---
To only update this specific test, also pass `--test-args attributes/nonterminal-expansion.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/attributes/nonterminal-expansion.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zemit-future-incompat-report" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/attributes/nonterminal-expansion" "-A" "unused" "-Crpath" "-O" "-Cdebuginfo=0" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/attributes/nonterminal-expansion/auxiliary"
------------------------------------------

------------------------------------------
stderr:
stderr:
------------------------------------------
error: expected unsuffixed literal or identifier, found `n!()`
   |
   |
LL |         #[repr(align($n))] //~ ERROR expected unsuffixed literal or identifier, found `n!()`
...
...
LL | pass_nonterminal!(n!());
   |
   |
   = note: this error originates in the macro `pass_nonterminal` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0589]: invalid `repr(align)` attribute
   |
   |
LL | pass_nonterminal!(n!());
   |                   ^ not a non-negative number
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0589`.


------------------------------------------


---- [ui] ui/repr/repr-align-assign.rs stdout ----

error: failed to compile fixed code
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/repr/repr-align-assign.fixed" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zemit-future-incompat-report" "--emit" "metadata" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/repr/repr-align-assign/a" "-Crpath" "-O" "-Cdebuginfo=0" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/repr/repr-align-assign/auxiliary"
------------------------------------------

------------------------------------------
stderr:
stderr:
------------------------------------------
error[E0693]: incorrect `repr(align)` attribute format
  --> /checkout/src/test/ui/repr/repr-align-assign.fixed:5:8
   |
LL | #[repr(align=8)] //~ ERROR incorrect `repr(align)` attribute format
   |
help: use parentheses instead
   |
   |
LL | #[repr(align(8))] //~ ERROR incorrect `repr(align)` attribute format
   |             ^ ^

error[E0693]: incorrect `repr(align)` attribute format
  --> /checkout/src/test/ui/repr/repr-align-assign.fixed:9:8
   |
LL | #[repr(align="8")] //~ ERROR incorrect `repr(align)` attribute format
   |
help: use parentheses instead
   |
   |
LL | #[repr(align(8))] //~ ERROR incorrect `repr(align)` attribute format
   |             ^ ^

error[E0693]: incorrect `repr(align)` attribute format
  --> /checkout/src/test/ui/repr/repr-align-assign.fixed:5:8
   |
LL | #[repr(align=8)] //~ ERROR incorrect `repr(align)` attribute format
   |
help: use parentheses instead
   |
   |
LL | #[repr(align(8))] //~ ERROR incorrect `repr(align)` attribute format
   |             ^ ^

error[E0693]: incorrect `repr(align)` attribute format
  --> /checkout/src/test/ui/repr/repr-align-assign.fixed:9:8
   |
LL | #[repr(align="8")] //~ ERROR incorrect `repr(align)` attribute format
   |
help: use parentheses instead
   |
   |
LL | #[repr(align(8))] //~ ERROR incorrect `repr(align)` attribute format
   |             ^ ^
error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0693`.


------------------------------------------


---- [ui] ui/repr/rustfix.rs stdout ----

error: failed to compile fixed code
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/repr/rustfix.fixed" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zemit-future-incompat-report" "--emit" "metadata" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/repr/rustfix/a" "-Crpath" "-O" "-Cdebuginfo=0" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/repr/rustfix/auxiliary"
------------------------------------------

------------------------------------------
stderr:
stderr:
------------------------------------------
error[E0693]: incorrect `repr(align)` attribute format
  --> /checkout/src/test/ui/repr/rustfix.fixed:2:8
   |
LL | #[repr(align = r#"1"#)] //~ ERROR incorrect `repr(align)` attribute format
   |
help: use parentheses instead
   |
   |
LL | #[repr(align(1))] //~ ERROR incorrect `repr(align)` attribute format
   |             ^ ^

error[E0693]: incorrect `repr(align)` attribute format
  --> /checkout/src/test/ui/repr/rustfix.fixed:6:8
   |
LL | #[repr(align = r###"foo"###)] //~ ERROR incorrect `repr(align)` attribute format
   |                |
   |                must be a non-negative number
   |
help: use parentheses instead
help: use parentheses instead
   |
LL | #[repr(align(foo))] //~ ERROR incorrect `repr(align)` attribute format
   |             ^   ^

error[E0693]: incorrect `repr(align)` attribute format
  --> /checkout/src/test/ui/repr/rustfix.fixed:10:8
   |
LL | #[repr(align = 1)] //~ ERROR incorrect `repr(align)` attribute format
   |
help: use parentheses instead
   |
   |
LL | #[repr(align(1))] //~ ERROR incorrect `repr(align)` attribute format
   |             ^ ^

error[E0589]: invalid `repr(align)` attribute
  --> /checkout/src/test/ui/repr/rustfix.fixed:22:14
   |
LL | #[repr(align("1"))] //~ ERROR invalid `repr(align)` attribute
   |
help: remove the quotes
   |
   |
LL | #[repr(align(1))] //~ ERROR invalid `repr(align)` attribute


error[E0589]: invalid `repr(align)` attribute
  --> /checkout/src/test/ui/repr/rustfix.fixed:26:14
   |
LL | #[repr(align(r############"1"############))] //~ ERROR invalid `repr(align)` attribute
   |
help: remove the quotes
   |
   |
LL | #[repr(align(1))] //~ ERROR invalid `repr(align)` attribute


error[E0693]: incorrect `repr(align)` attribute format
  --> /checkout/src/test/ui/repr/rustfix.fixed:2:8
   |
LL | #[repr(align = r#"1"#)] //~ ERROR incorrect `repr(align)` attribute format
   |
help: use parentheses instead
   |
   |
LL | #[repr(align(1))] //~ ERROR incorrect `repr(align)` attribute format
   |             ^ ^

error[E0693]: incorrect `repr(align)` attribute format
  --> /checkout/src/test/ui/repr/rustfix.fixed:6:8
   |
LL | #[repr(align = r###"foo"###)] //~ ERROR incorrect `repr(align)` attribute format
   |                |
   |                must be a non-negative number
   |
help: use parentheses instead
help: use parentheses instead
   |
LL | #[repr(align(foo))] //~ ERROR incorrect `repr(align)` attribute format
   |             ^   ^

error[E0693]: incorrect `repr(align)` attribute format
  --> /checkout/src/test/ui/repr/rustfix.fixed:10:8
   |
LL | #[repr(align = 1)] //~ ERROR incorrect `repr(align)` attribute format
   |
help: use parentheses instead
   |
   |
LL | #[repr(align(1))] //~ ERROR incorrect `repr(align)` attribute format
   |             ^ ^

error[E0589]: invalid `repr(align)` attribute
  --> /checkout/src/test/ui/repr/rustfix.fixed:22:14
   |
LL | #[repr(align("1"))] //~ ERROR invalid `repr(align)` attribute
   |
help: remove the quotes
   |
   |
LL | #[repr(align(1))] //~ ERROR invalid `repr(align)` attribute


error[E0589]: invalid `repr(align)` attribute
  --> /checkout/src/test/ui/repr/rustfix.fixed:26:14
   |
LL | #[repr(align(r############"1"############))] //~ ERROR invalid `repr(align)` attribute
   |
help: remove the quotes
   |
   |
LL | #[repr(align(1))] //~ ERROR invalid `repr(align)` attribute

error: aborting due to 10 previous errors

Some errors have detailed explanations: E0589, E0693.
---
test result: FAILED. 11861 passed; 3 failed; 101 ignored; 0 measured; 0 filtered out; finished in 117.74s



command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/compiletest" "--compile-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" "--run-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib" "--rustc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--src-base" "/checkout/src/test/ui" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--suite" "ui" "--mode" "ui" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-10/bin/FileCheck" "--nodejs" "/usr/bin/node" "--host-rustcflags" "-Crpath -O -Cdebuginfo=0 -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--target-rustcflags" "-Crpath -O -Cdebuginfo=0 -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python3" "--lldb-python" "/usr/bin/python3" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "10.0.0" "--llvm-components" "aarch64 aarch64asmparser aarch64codegen aarch64desc aarch64disassembler aarch64info aarch64utils aggressiveinstcombine all all-targets amdgpu amdgpuasmparser amdgpucodegen amdgpudesc amdgpudisassembler amdgpuinfo amdgpuutils analysis arm armasmparser armcodegen armdesc armdisassembler arminfo armutils asmparser asmprinter avr avrasmparser avrcodegen avrdesc avrdisassembler avrinfo binaryformat bitreader bitstreamreader bitwriter bpf bpfasmparser bpfcodegen bpfdesc bpfdisassembler bpfinfo cfguard codegen core coroutines coverage debuginfocodeview debuginfodwarf debuginfogsym debuginfomsf debuginfopdb demangle dlltooldriver dwarflinker engine executionengine frontendopenmp fuzzmutate globalisel hexagon hexagonasmparser hexagoncodegen hexagondesc hexagondisassembler hexagoninfo instcombine instrumentation interpreter ipo irreader jitlink lanai lanaiasmparser lanaicodegen lanaidesc lanaidisassembler lanaiinfo libdriver lineeditor linker lto mc mca mcdisassembler mcjit mcparser mips mipsasmparser mipscodegen mipsdesc mipsdisassembler mipsinfo mirparser msp430 msp430asmparser msp430codegen msp430desc msp430disassembler msp430info native nativecodegen nvptx nvptxcodegen nvptxdesc nvptxinfo objcarcopts object objectyaml option orcerror orcjit passes perfjitevents powerpc powerpcasmparser powerpccodegen powerpcdesc powerpcdisassembler powerpcinfo profiledata remarks riscv riscvasmparser riscvcodegen riscvdesc riscvdisassembler riscvinfo riscvutils runtimedyld scalaropts selectiondag sparc sparcasmparser sparccodegen sparcdesc sparcdisassembler sparcinfo support symbolize systemz systemzasmparser systemzcodegen systemzdesc systemzdisassembler systemzinfo tablegen target textapi transformutils vectorize webassembly webassemblyasmparser webassemblycodegen webassemblydesc webassemblydisassembler webassemblyinfo windowsmanifest x86 x86asmparser x86codegen x86desc x86disassembler x86info x86utils xcore xcorecodegen xcoredesc xcoredisassembler xcoreinfo xray" "--system-llvm" "--cc" "" "--cxx" "" "--cflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"


failed to run: /checkout/obj/build/bootstrap/debug/bootstrap --stage 2 test --exclude src/tools/tidy
Build completed unsuccessfully in 0:11:55

@crlf0710
Copy link
Member

@mibac138 Triage: Seems CI is still red here.

@crlf0710 crlf0710 added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 26, 2021
@bors
Copy link
Contributor

bors commented Jul 10, 2021

☔ The latest upstream changes (presumably #87029) made this pull request unmergeable. Please resolve the merge conflicts.

@JohnCSimon JohnCSimon added the S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. label Jul 25, 2021
@JohnCSimon
Copy link
Member

Ping from triage
@mibac138 I'm closing this as inactive. Please feel free to reopen if you're willing to continue.

@JohnCSimon JohnCSimon closed this Jul 25, 2021
@Dylan-DPC Dylan-DPC removed the S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. label Jun 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

#[repr(align)] with no argument to align leads to ICE on Nightly/Beta.
8 participants