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

Add visitors for checking #[inline] #80641

Merged
merged 2 commits into from
Feb 1, 2021
Merged

Add visitors for checking #[inline] #80641

merged 2 commits into from
Feb 1, 2021

Conversation

Danue1
Copy link
Contributor

@Danue1 Danue1 commented Jan 3, 2021

For #80564

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @oli-obk (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 3, 2021
@rust-log-analyzer
Copy link
Collaborator

The job mingw-check failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
configure: rust.channel         := nightly
configure: rust.debug-assertions := True
configure: llvm.assertions      := True
configure: dist.missing-tools   := True
configure: build.configure-args := ['--enable-sccache', '--disable-manage-submodu ...
configure: writing `config.toml` in current directory
configure: 
configure: run `python /checkout/x.py --help`
configure: 
---
skip untracked path cpu-usage.csv during rustfmt invocations
skip untracked path src/doc/book/ during rustfmt invocations
skip untracked path src/doc/rust-by-example/ during rustfmt invocations
skip untracked path src/llvm-project/ during rustfmt invocations
Diff in /checkout/compiler/rustc_middle/src/hir/map/mod.rs at line 527:
     /// Retrieves the `Node` corresponding to `id`, returning `None` if cannot be found.
     pub fn find(&self, hir_id: HirId) -> Option<Node<'hir>> {
         self.find_entry(hir_id).and_then(|entry| {
-            if let Node::Crate(..) = entry.node {
Running `"/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/rustfmt" "--config-path" "/checkout" "--edition" "2018" "--unstable-features" "--skip-children" "--check" "/checkout/compiler/rustc_middle/src/hir/map/mod.rs"` failed.
If you're running `tidy`, try again with `--bless`. Or, if you just want to format code, run `./x.py fmt` instead.
-                None
-            } else {
-                Some(entry.node)
-            }
+            if let Node::Crate(..) = entry.node { None } else { Some(entry.node) }
     }
 
failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test --stage 2 src/tools/tidy
Build completed unsuccessfully in 0:00:17

Copy link
Contributor

@oli-obk oli-obk left a comment

Choose a reason for hiding this comment

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

Similarly to Target::AssocConst, the check_inline function should emit lints instead of errors on the newly added Target kinds, as we did not emit errors on them before.

I think we also need to vet the other things that check_attributes runs on to see if we need to opt out of erroring on them

compiler/rustc_passes/src/check_attr.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@oli-obk oli-obk left a comment

Choose a reason for hiding this comment

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

Ok... I only now see the extent of this change. We need to catch all field/arm/macrodef arms and return true for them in all the check functions at https://github.com/rust-lang/rust/blob/b3e39da0bc1c26b39b0a600b3735805722108992/compiler/rustc_passes/src/check_attr.rs#L188 or below. Ideally we start linting on them, too, but since it's strictly an improvement to start linting on #[inline] I propose to add an arm similar to what you did in check_allow_internal_usntable to all other check functions that ensures no error is emitted for them and leave a FIXME on these new arms. Then we can merge this PR now and address the FIXMEs in future PRs.

What do you think? Or do you prefer to do everything in this PR? It may take a bit longer for the PR to end up getting merged in that case, so your call :)

compiler/rustc_passes/src/check_attr.rs Outdated Show resolved Hide resolved
@rust-log-analyzer
Copy link
Collaborator

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

Click to see the possible cause of the failure (guessed by this bot)
.................................................................................................... 9000/11240
.................................................................................................... 9100/11240
.................................................................................................... 9200/11240
....................................i......i........................................................ 9300/11240
...........................................................................iiiiii..iiiiii.i......... 9400/11240
.................................................................................................... 9600/11240
.................................................................................................... 9700/11240
.................................................................................................... 9800/11240
.................................................................................................... 9900/11240
---

6 LL | struct S;
7    | --------- not a function or closure
8 
- error[E0518]: `#[inline]` is ignored on struct fields, match arms and macro defs
-   --> $DIR/attr-usage-inline.rs:10:5
-    |
- LL |     #[inline]
-    |     ^^^^^^^^^
- LL |     i: u8,
- 
- 
- error[E0518]: `#[inline]` is ignored on struct fields, match arms and macro defs
-   --> $DIR/attr-usage-inline.rs:15:1
-    |
- LL |   #[inline]
-    |   ^^^^^^^^^
- LL | / macro_rules! m_e {
- LL | |     () => {};
- LL | | }
-    | |_- not a function
27 error[E0518]: attribute should be applied to function or closure
28   --> $DIR/attr-usage-inline.rs:20:1
29    |


30 LL | #[inline]
32 
- error: aborting due to 4 previous errors
+ error: aborting due to 2 previous errors
34 
34 
35 For more information about this error, try `rustc --explain E0518`.
36 


The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/attr-usage-inline/attr-usage-inline.stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args attr-usage-inline.rs`
error: 1 errors occurred comparing output.
status: exit code: 1
status: exit code: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/attr-usage-inline.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-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/attr-usage-inline" "-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/attr-usage-inline/auxiliary"
------------------------------------------

------------------------------------------
stderr:
stderr:
------------------------------------------
error[E0518]: attribute should be applied to function or closure
  --> /checkout/src/test/ui/attr-usage-inline.rs:6:1
   |
LL | #[inline] //~ ERROR: attribute should be applied to function or closure
LL | struct S;
   | --------- not a function or closure

error[E0518]: attribute should be applied to function or closure
error[E0518]: attribute should be applied to function or closure
  --> /checkout/src/test/ui/attr-usage-inline.rs:20:1
   |
LL | #[inline] //~ ERROR: attribute should be applied to function or closure

error: aborting due to 2 previous errors

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

Some tests failed in compiletest suite=ui mode=ui host=x86_64-unknown-linux-gnu target=x86_64-unknown-linux-gnu


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-9/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/python2.7" "--lldb-python" "/usr/bin/python2.7" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "9.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 codegen core coroutines coverage debuginfocodeview debuginfodwarf debuginfogsym debuginfomsf debuginfopdb demangle dlltooldriver engine executionengine 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 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:15:03

@rust-log-analyzer
Copy link
Collaborator

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

Click to see the possible cause of the failure (guessed by this bot)
   Compiling libc v0.2.79
   Compiling std v0.0.0 (/checkout/library/std)
   Compiling compiler_builtins v0.1.39
   Compiling unwind v0.0.0 (/checkout/library/unwind)
error: internal compiler error: compiler/rustc_middle/src/hir/map/mod.rs:831:21: no name for macro macros::r#try (hir_id=HirId { owner: DefId(0:10 ~ core[8e42]::macros::try), local_id: 0 })
thread 'rustc' panicked at 'Box<Any>', compiler/rustc_errors/src/lib.rs:958:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

note: the compiler unexpectedly panicked. this is a bug.
note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.51.0-nightly (22d7c2d2d 2021-01-10) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z macro-backtrace -Z binary-dep-depinfo -Z force-unstable-if-unmarked -C opt-level=3 -C embed-bitcode=no -C codegen-units=1 -C debuginfo=0 -C debug-assertions=on -C overflow-checks=off -C link-args=-Wl,-rpath,$ORIGIN/../lib -C prefer-dynamic -C llvm-args=-import-instr-limit=10 -C embed-bitcode=yes --crate-type lib
note: some of the compiler flags provided by cargo are hidden

query stack during panic:
query stack during panic:
#0 [check_mod_attrs] checking attributes in top-level module
#1 [analysis] running analysis passes on this crate
end of query stack

error: could not compile `core`

To learn more, run the command again with --verbose.

@rust-log-analyzer
Copy link
Collaborator

The job mingw-check failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
configure: rust.channel         := nightly
configure: rust.debug-assertions := True
configure: llvm.assertions      := True
configure: dist.missing-tools   := True
configure: build.configure-args := ['--enable-sccache', '--disable-manage-submodu ...
configure: writing `config.toml` in current directory
configure: 
configure: run `python /checkout/x.py --help`
configure: 
---
Checking which error codes lack tests...
Found 435 error codes
Found 0 error codes with no tests
Done!
tidy error: /checkout/src/test/ui/internal/internal-unstable.rs:10: line longer than 100 chars
tidy error: /checkout/src/test/ui/internal/internal-unstable.rs:51: line longer than 100 chars
some tidy checks failed

command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "/checkout/obj/build"
expected success, got: exit code: 1

@rust-log-analyzer
Copy link
Collaborator

The job mingw-check failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
configure: rust.channel         := nightly
configure: rust.debug-assertions := True
configure: llvm.assertions      := True
configure: dist.missing-tools   := True
configure: build.configure-args := ['--enable-sccache', '--disable-manage-submodu ...
configure: writing `config.toml` in current directory
configure: 
configure: run `python /checkout/x.py --help`
configure: 
---
skip untracked path cpu-usage.csv during rustfmt invocations
skip untracked path src/doc/book/ during rustfmt invocations
skip untracked path src/doc/rust-by-example/ during rustfmt invocations
skip untracked path src/llvm-project/ during rustfmt invocations
Diff in /checkout/compiler/rustc_middle/src/hir/map/mod.rs at line 525:
     /// Retrieves the `Node` corresponding to `id`, returning `None` if cannot be found.
     pub fn find(&self, hir_id: HirId) -> Option<Node<'hir>> {
         self.find_entry(hir_id).and_then(|entry| {
-            if let Node::Crate(..) = entry.node {
-                None
-            } else {
Running `"/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/rustfmt" "--config-path" "/checkout" "--edition" "2018" "--unstable-features" "--skip-children" "--check" "/checkout/compiler/rustc_middle/src/hir/map/mod.rs"` failed.
If you're running `tidy`, try again with `--bless`. Or, if you just want to format code, run `./x.py fmt` instead.
-                Some(entry.node)
-            }
+            if let Node::Crate(..) = entry.node { None } else { Some(entry.node) }
     }
 
failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test --stage 2 src/tools/tidy
Build completed unsuccessfully in 0:00:16

@rust-log-analyzer
Copy link
Collaborator

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

Click to see the possible cause of the failure (guessed by this bot)
.................................................................................................... 9000/11246
.................................................................................................... 9100/11246
.................................................................................................... 9200/11246
..........................................i......i.................................................. 9300/11246
.................................................................................iiiiii..iiiiii.i... 9400/11246
.................................................................................................... 9600/11246
.................................................................................................... 9700/11246
.................................................................................................... 9800/11246
.................................................................................................... 9900/11246
---

---- [ui] ui/internal/internal-unstable.rs stdout ----
diff of stderr:

1 error[E0658]: use of unstable library feature 'function'
-   --> $DIR/internal-unstable.rs:40:25
3    |
3    |
4 LL |     pass_through_allow!(internal_unstable::unstable());


7    = help: add `#![feature(function)]` to the crate attributes to enable
8 
9 error[E0658]: use of unstable library feature 'function'
-   --> $DIR/internal-unstable.rs:42:27
11    |
11    |
12 LL |     pass_through_noallow!(internal_unstable::unstable());


15    = help: add `#![feature(function)]` to the crate attributes to enable
16 
17 error[E0658]: use of unstable library feature 'function'
-   --> $DIR/internal-unstable.rs:46:22
19    |
19    |
20 LL |     println!("{:?}", internal_unstable::unstable());


23    = help: add `#![feature(function)]` to the crate attributes to enable
24 
25 error[E0658]: use of unstable library feature 'function'
Some tests failed in compiletest suite=ui mode=ui host=x86_64-unknown-linux-gnu target=x86_64-unknown-linux-gnu
-   --> $DIR/internal-unstable.rs:48:10
27    |
27    |
28 LL |     bar!(internal_unstable::unstable());


31    = help: add `#![feature(function)]` to the crate attributes to enable
32 
33 error[E0658]: use of unstable library feature 'function'
-   --> $DIR/internal-unstable.rs:18:9
35    |
36 LL |         internal_unstable::unstable();
37    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^



The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/internal/internal-unstable/internal-unstable.stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args internal/internal-unstable.rs`
error: 1 errors occurred comparing output.
status: exit code: 1
status: exit code: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/internal/internal-unstable.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-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/internal/internal-unstable" "-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/internal/internal-unstable/auxiliary"
------------------------------------------

------------------------------------------
stderr:
stderr:
------------------------------------------
error[E0658]: use of unstable library feature 'function'
   |
   |
LL |     pass_through_allow!(internal_unstable::unstable()); //~ ERROR use of unstable
   |
   |
   = help: add `#![feature(function)]` to the crate attributes to enable

error[E0658]: use of unstable library feature 'function'
   |
   |
LL |     pass_through_noallow!(internal_unstable::unstable()); //~ ERROR use of unstable
   |
   |
   = help: add `#![feature(function)]` to the crate attributes to enable

error[E0658]: use of unstable library feature 'function'
   |
   |
LL |     println!("{:?}", internal_unstable::unstable()); //~ ERROR use of unstable
   |
   |
   = help: add `#![feature(function)]` to the crate attributes to enable

error[E0658]: use of unstable library feature 'function'
   |
   |
LL |     bar!(internal_unstable::unstable()); //~ ERROR use of unstable
   |
   |
   = help: add `#![feature(function)]` to the crate attributes to enable

error[E0658]: use of unstable library feature 'function'
   |
   |
LL |         internal_unstable::unstable(); //~ ERROR use of unstable
...
...
LL |     bar!(internal_unstable::unstable()); //~ ERROR use of unstable
   |
   |
   = help: add `#![feature(function)]` to the crate attributes to enable
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 5 previous errors

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

---
test result: FAILED. 11159 passed; 1 failed; 86 ignored; 0 measured; 0 filtered out; finished in 143.95s



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-9/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/python2.7" "--lldb-python" "/usr/bin/python2.7" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "9.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 codegen core coroutines coverage debuginfocodeview debuginfodwarf debuginfogsym debuginfomsf debuginfopdb demangle dlltooldriver engine executionengine 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 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:16:15

@oli-obk
Copy link
Contributor

oli-obk commented Jan 11, 2021

Ok... I only now see the extent of this change. We need to catch all field/arm/macrodef arms and return true for them in all the check functions at

https://github.com/rust-lang/rust/blob/b3e39da0bc1c26b39b0a600b3735805722108992/compiler/rustc_passes/src/check_attr.rs#L188
or below. Ideally we start linting on them, too, but since it's strictly an improvement to start linting on #[inline] I propose to add an arm similar to what you did in check_allow_internal_unstable to all other check functions that ensures no error is emitted for them and leave a FIXME on these new arms. Then we can merge this PR now and address the FIXMEs in future PRs.

What do you think? Or do you prefer to do everything in this PR? It may take a bit longer for the PR to end up getting merged in that case, so your call :)

This has not been addressed yet. Would you like me to elaborate more on it or is it already clear what I mean with the text above?

@rylev
Copy link
Member

rylev commented Jan 12, 2021

@Danue1 @oli-obk I didn't realize this was being worked on so I opened #80920 which does something similar. The PRs are not exactly the same so we should probably coordinate to make sure all the relevant changes make it into master.

Two things in particular:

  • We are running a crater run to see the impact of denying if users included attributes in places they should not have. We can at least use that as a discussion of whether "deny-by-default" or "warn-by-default" is appropriate.
  • Visit more targets when validating attributes #80920 also adds a visitor for function params which also need to be validated.

Also, see the PR's opening description for some thoughts on next steps for attribute validation. In general, I'm happy to close my PR in favor of this one if we can address the two points above.

@oli-obk
Copy link
Contributor

oli-obk commented Jan 12, 2021

Oh heh, I guess we can crater it instead of emitting future incompat lints. I was just thinking about the minimal way forward, but if crater is deemed acceptable, then by all means, let's just forbid it directly.

@bors
Copy link
Contributor

bors commented Jan 17, 2021

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

@rust-log-analyzer
Copy link
Collaborator

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

Click to see the possible cause of the failure (guessed by this bot)

---- [ui] ui/proc-macro/ambiguous-builtin-attrs.rs stdout ----
diff of stderr:

61    = help: use `crate::repr` to refer to this attribute macro unambiguously
62 
63 error[E0659]: `allow` is ambiguous (built-in attribute vs any other name)
-   --> $DIR/ambiguous-builtin-attrs.rs:36:3
+   --> $DIR/ambiguous-builtin-attrs.rs:38:3
65    |
66 LL | #[allow(unused)]
67    |   ^^^^^ ambiguous name
68    |
68    |
69    = note: `allow` could refer to a built-in attribute
70 note: `allow` could also refer to the built-in attribute imported here
-   --> $DIR/ambiguous-builtin-attrs.rs:35:5
+   --> $DIR/ambiguous-builtin-attrs.rs:37:5
72    |
73 LL | use deny as allow;

103 LL |         _ => {}
103 LL |         _ => {}
104    |         ------- not a struct, enum, or union
- error: aborting due to 8 previous errors
+ error: aborting due to 9 previous errors
107 
108 Some errors have detailed explanations: E0425, E0517, E0659.
108 Some errors have detailed explanations: E0425, E0517, E0659.
109 For more information about an error, try `rustc --explain E0425`.


The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/proc-macro/ambiguous-builtin-attrs/ambiguous-builtin-attrs.stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args proc-macro/ambiguous-builtin-attrs.rs`
error: 1 errors occurred comparing output.
status: exit code: 1
status: exit code: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/proc-macro/ambiguous-builtin-attrs.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-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/proc-macro/ambiguous-builtin-attrs" "-A" "unused" "-Crpath" "-O" "-Cdebuginfo=0" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--edition=2018" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/proc-macro/ambiguous-builtin-attrs/auxiliary"
------------------------------------------

------------------------------------------
stderr:
stderr:
------------------------------------------
error[E0425]: cannot find value `NonExistent` in this scope
   |
   |
LL |     NonExistent; //~ ERROR cannot find value `NonExistent` in this scope


error[E0659]: `repr` is ambiguous (built-in attribute vs any other name)
   |
   |
LL | #[repr(C)] //~ ERROR `repr` is ambiguous
   |   ^^^^ ambiguous name
   |
   = note: `repr` could refer to a built-in attribute
note: `repr` could also refer to the attribute macro imported here
   |
   |
LL | use builtin_attrs::*;
   |     ^^^^^^^^^^^^^^^^
   = help: use `crate::repr` to refer to this attribute macro unambiguously

error[E0659]: `repr` is ambiguous (built-in attribute vs any other name)
   |
   |
LL | #[cfg_attr(all(), repr(C))] //~ ERROR `repr` is ambiguous
   |                   ^^^^ ambiguous name
   |
   = note: `repr` could refer to a built-in attribute
note: `repr` could also refer to the attribute macro imported here
   |
   |
LL | use builtin_attrs::*;
   |     ^^^^^^^^^^^^^^^^
   = help: use `crate::repr` to refer to this attribute macro unambiguously

error[E0659]: `repr` is ambiguous (built-in attribute vs any other name)
   |
   |
LL | fn non_macro_expanded_location<#[repr(C)] T>() {
   |                                  ^^^^ ambiguous name
   |
   = note: `repr` could refer to a built-in attribute
note: `repr` could also refer to the attribute macro imported here
   |
   |
LL | use builtin_attrs::*;
   |     ^^^^^^^^^^^^^^^^
   = help: use `crate::repr` to refer to this attribute macro unambiguously
Some tests failed in compiletest suite=ui mode=ui host=x86_64-unknown-linux-gnu target=x86_64-unknown-linux-gnu

error[E0659]: `repr` is ambiguous (built-in attribute vs any other name)
   |
   |
LL |         #[repr(C)]
   |           ^^^^ ambiguous name
   |
   = note: `repr` could refer to a built-in attribute
note: `repr` could also refer to the attribute macro imported here
   |
   |
LL | use builtin_attrs::*;
   |     ^^^^^^^^^^^^^^^^
   = help: use `crate::repr` to refer to this attribute macro unambiguously

error[E0659]: `allow` is ambiguous (built-in attribute vs any other name)
   |
   |
LL | #[allow(unused)] //~ ERROR `allow` is ambiguous (built-in attribute vs any other name)
   |   ^^^^^ ambiguous name
   |
   = note: `allow` could refer to a built-in attribute
note: `allow` could also refer to the built-in attribute imported here
   |
   |
LL | use deny as allow;
   |     ^^^^^^^^^^^^^
   = help: use `crate::allow` to refer to this built-in attribute unambiguously

error[E0659]: `feature` is ambiguous (built-in attribute vs any other name)
   |
   |
LL | #![feature(decl_macro)] //~ ERROR `feature` is ambiguous
   |    ^^^^^^^ ambiguous name
   |
   = note: `feature` could refer to a built-in attribute
note: `feature` could also refer to the attribute macro imported here
   |
   |
LL | use builtin_attrs::*;
   |     ^^^^^^^^^^^^^^^^
   = help: use `crate::feature` to refer to this attribute macro unambiguously

error[E0517]: attribute should be applied to a struct, enum, or union
   |
   |
LL | fn non_macro_expanded_location<#[repr(C)] T>() {
   |                                       ^   - not a struct, enum, or union

error[E0517]: attribute should be applied to a struct, enum, or union
   |
   |
LL |         #[repr(C)]
...
LL |         _ => {}
LL |         _ => {}
   |         ------- not a struct, enum, or union
error: aborting due to 9 previous errors

Some errors have detailed explanations: E0425, E0517, E0659.
For more information about an error, try `rustc --explain E0425`.
---
test result: FAILED. 11179 passed; 1 failed; 87 ignored; 0 measured; 0 filtered out; finished in 132.29s



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-9/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" "9.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 codegen core coroutines coverage debuginfocodeview debuginfodwarf debuginfogsym debuginfomsf debuginfopdb demangle dlltooldriver engine executionengine 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 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:15:32

@oli-obk
Copy link
Contributor

oli-obk commented Jan 19, 2021

Please rebase instead of merging (you can also squash your commits at the same time to clean up the back and forth). You also need to run the test suite with --bless again to update the .stderr files and potentially add some more //~ WARN comments to the file to mark the new warning sites.

The implementation looks good to me now

@rylev
Copy link
Member

rylev commented Jan 20, 2021

@oli-obk can you take a look at #80920 (including the crater run) and give your opinion on how to proceed with that PR? There are some differences in the PRs that closing #80920 would leave some functionality on the cutting room floor.

@oli-obk
Copy link
Contributor

oli-obk commented Jan 20, 2021

I'm always a bit wary of crater runs, as they don't cover windows, embedded or private code at all. But I guess we do have precedents for this, so... My proposal would be to finish this PR (rebase, squash, r=me), then do your PR, which covers more constructs. I don't want to put more work on @Danue1 , so I think we should just merge the current PR, even if it makes some things future incompat warnings that could have been made hard errors.

Would that be ok with you, or is the rebase over this PR going to be very painful?

@rylev
Copy link
Member

rylev commented Jan 20, 2021

Sounds like a plan to me.

@Danue1
Copy link
Contributor Author

Danue1 commented Feb 1, 2021

Apologizing for lating...
With the help of @sanxiyn , I will try it from around 20:00(UTC+9).

@rust-log-analyzer
Copy link
Collaborator

The job mingw-check failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
configure: rust.channel         := nightly
configure: rust.debug-assertions := True
configure: llvm.assertions      := True
configure: dist.missing-tools   := True
configure: build.configure-args := ['--enable-sccache', '--disable-manage-submodu ...
configure: writing `config.toml` in current directory
configure: 
configure: run `python /checkout/x.py --help`
configure: 
---
Found 435 error codes
Found 0 error codes with no tests
Done!
* 316 features
tidy error: crate `rustc-ap-rustc_ast` is duplicated in `Cargo.lock`, it is too expensive to build multiple times, so make sure only one version appears across all dependencies
  * rustc-ap-rustc_ast 691.0.0 (registry+https://github.com/rust-lang/crates.io-index)
  * rustc-ap-rustc_ast 697.0.0 (registry+https://github.com/rust-lang/crates.io-index)
some tidy checks failed

command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "/checkout/obj/build"
expected success, got: exit code: 1

Add visitors for checking #[inline]

Add visitors for checking #[inline] with struct field

Fix test for #[inline]

Add visitors for checking #[inline] with #[macro_export] macro

Add visitors for checking #[inline] without #[macro_export] macro

Add use alias with Visitor

Fix lint error

Reduce unnecessary variable

Co-authored-by: LingMan <LingMan@users.noreply.github.com>

Change error to warning

Add warning for checking field, arm with #[allow_internal_unstable]

Add name resolver

Formatting

Formatting

Fix error fixture

Add checking field, arm, macro def
@oli-obk
Copy link
Contributor

oli-obk commented Feb 1, 2021

@bors r+

Thanks!

@bors
Copy link
Contributor

bors commented Feb 1, 2021

📌 Commit 838f487 has been approved by oli-obk

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 1, 2021
@bors
Copy link
Contributor

bors commented Feb 1, 2021

⌛ Testing commit 838f487 with merge d4e3570...

@bors
Copy link
Contributor

bors commented Feb 1, 2021

☀️ Test successful - checks-actions
Approved by: oli-obk
Pushing d4e3570 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Feb 1, 2021
@bors bors merged commit d4e3570 into rust-lang:master Feb 1, 2021
@rustbot rustbot added this to the 1.51.0 milestone Feb 1, 2021
@Mark-Simulacrum
Copy link
Member

As may have been expected, this is a performance regression -- largely for incremental benchmarks which presumably avoided these edges in the depgraph previously. I do not expect that we can do much about it, so seems fine to just let it slide.

bors added a commit to rust-lang-ci/rust that referenced this pull request May 16, 2021
…henkov

Fix unused attributes on macro_rules.

The `unused_attributes` lint wasn't firing on attributes of `macro_rules` definitions. The consequence is that many attributes are silently ignored on `macro_rules`. The reason is that `unused_attributes` is a late-lint pass, and only has access to the HIR, which does not have macro_rules definitions.

My solution here is to change `non_exported_macro_attrs` to be `macro_attrs` (a list of all attributes used for `macro_rules`, instead of just those for `macro_export`), and then to check this list in the `unused_attributes` lint. There are a number of alternate approaches, but this seemed the most reliable and least invasive. I am open to completely different approaches, though.

One concern is that I don't fully understand the implications of extending `non_exported_macro_attrs` to include non-exported macros. That list was originally added in rust-lang#62042 to handle stability attributes, so I suspect it was just an optimization since that was all that was needed. It was later extended to be included in SVH in rust-lang#83901. rust-lang#80641 also added a use to check for `invalid` attributes, which seems a little odd to me (it didn't validate non-exported macros, and seems highly specific).

Overall, there doesn't seem to be a clear story of when `unused_attributes` should be used versus an error like E0518. I considered alternatively using an "allow list" of built-in attributes that can be used on macro_rules (allow, warn, deny, forbid, cfg, cfg_attr, macro_export, deprecated, doc), but I feel like that could be a pain to maintain.

Some built-in attributes already present hard-errors when used with macro_rules. These are each hard-coded in various places:
- `derive`
- `test` and `bench`
- `proc_macro` and `proc_macro_derive`
- `inline`
- `global_allocator`

The primary motivation is that I sometimes see people use `#[macro_use]` in front of `macro_rules`, which indicates there is some confusion out there (evident that there was even a case of it in rustc).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants