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

Lint #[inline(always)] closure in #[target_feature] functions #133408

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

calebzulawski
Copy link
Member

Make #108655 a future-incompatible lint as suggested in #69098 (comment)

r? @RalfJung

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 24, 2024
@rust-log-analyzer
Copy link
Collaborator

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

Click to see the possible cause of the failure (guessed by this bot)
#16 exporting to docker image format
#16 sending tarball 29.0s done
#16 DONE 41.8s
##[endgroup]
Setting extra environment values for docker:  --env ENABLE_GCC_CODEGEN=1 --env GCC_EXEC_PREFIX=/usr/lib/gcc/
[CI_JOB_NAME=x86_64-gnu-llvm-18]
debug: `DISABLE_CI_RUSTC_IF_INCOMPATIBLE` configured.
---
sccache: Starting the server...
##[group]Configure the build
configure: processing command line
configure: 
configure: build.configure-args := ['--build=x86_64-unknown-linux-gnu', '--llvm-root=/usr/lib/llvm-18', '--enable-llvm-link-shared', '--set', 'rust.randomize-layout=true', '--set', 'rust.thin-lto-import-instr-limit=10', '--enable-verbose-configure', '--enable-sccache', '--disable-manage-submodules', '--enable-locked-deps', '--enable-cargo-native-static', '--set', 'rust.codegen-units-std=1', '--set', 'dist.compression-profile=balanced', '--dist-compression-formats=xz', '--set', 'rust.lld=false', '--disable-dist-src', '--release-channel=nightly', '--enable-debug-assertions', '--enable-overflow-checks', '--enable-llvm-assertions', '--set', 'rust.verify-llvm-ir', '--set', 'rust.codegen-backends=llvm,cranelift,gcc', '--set', 'llvm.static-libstdcpp', '--enable-new-symbol-mangling']
configure: target.x86_64-unknown-linux-gnu.llvm-config := /usr/lib/llvm-18/bin/llvm-config
configure: llvm.link-shared     := True
configure: rust.randomize-layout := True
configure: rust.thin-lto-import-instr-limit := 10
---
  Downloaded boml v0.3.1
   Compiling boml v0.3.1
   Compiling y v0.1.0 (/checkout/compiler/rustc_codegen_gcc/build_system)
    Finished `release` profile [optimized] target(s) in 4.07s
     Running `/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-codegen/x86_64-unknown-linux-gnu/release/y test --use-system-gcc --use-backend gcc --out-dir /checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools/cg_gcc --release --mini-tests --std-tests`
Using system GCC
[BUILD] example
[AOT] mini_core_hello_world
/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools/cg_gcc/mini_core_hello_world
abc
---

error[E0658]: attributes on expressions are experimental
##[error] --> lint_example.rs:6:19
  |
6 |     let closure = #[inline(always)] || {};
  |
  = note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
  = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
  = note: this compiler was built on 2024-11-24; consider upgrading it if it is out of date
  = note: this compiler was built on 2024-11-24; consider upgrading it if it is out of date


error[E0658]: `#[target_feature(..)]` can only be applied to `unsafe` functions
  |
  |
4 | #[target_feature(enable = "avx")]
5 | fn example() {
  | ------------ not an `unsafe` function
  |
  = note: see issue #69098 <https://github.com/rust-lang/rust/issues/69098> for more information
  = note: see issue #69098 <https://github.com/rust-lang/rust/issues/69098> for more information
  = help: add `#![feature(target_feature_11)]` to the crate attributes to enable


warning: unused variable: `closure`
##[warning] --> lint_example.rs:6:9
##[warning] --> lint_example.rs:6:9
  |
6 |     let closure = #[inline(always)] || {};
  |         ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_closure`
  = note: `#[warn(unused_variables)]` on by default


error: aborting due to 2 previous errors; 1 warning emitted
---

error[E0658]: attributes on expressions are experimental
##[error] --> lint_example.rs:6:19
  |
6 |     let closure = #[inline(always)] || {};
  |
  = note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
  = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
  = note: this compiler was built on 2024-11-24; consider upgrading it if it is out of date
  = note: this compiler was built on 2024-11-24; consider upgrading it if it is out of date


error[E0658]: `#[target_feature(..)]` can only be applied to `unsafe` functions
  |
  |
4 | #[target_feature(enable = "avx")]
5 | fn example() {
  | ------------ not an `unsafe` function
  |
  = note: see issue #69098 <https://github.com/rust-lang/rust/issues/69098> for more information
  = note: see issue #69098 <https://github.com/rust-lang/rust/issues/69098> for more information
  = help: add `#![feature(target_feature_11)]` to the crate attributes to enable


warning: unused variable: `closure`
##[warning] --> lint_example.rs:6:9
##[warning] --> lint_example.rs:6:9
  |
6 |     let closure = #[inline(always)] || {};
  |         ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_closure`
  = note: `#[warn(unused_variables)]` on by default


error: aborting due to 2 previous errors; 1 warning emitted
error: aborting due to 2 previous errors; 1 warning emitted


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


This error was generated by the lint-docs tool.
This tool extracts documentation for lints from the source code and places
them in the rustc book. See the declare_lint! documentation
https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint_defs/macro.declare_lint.html


To re-run these tests, run: ./x.py test --keep-stage=0 src/tools/lint-docs
The --keep-stage flag should be used if you have already built the compiler


Command has failed. Rerun with -v to see more details.
  local time: Sun Nov 24 07:11:53 UTC 2024
  network time: Sun, 24 Nov 2024 07:11:54 GMT
##[error]Process completed with exit code 1.
Post job cleanup.

@RalfJung
Copy link
Member

I am in favor of this lint, but IMO it should get input from some other people as well, so let's

r? compiler

@rustbot rustbot assigned chenyukang and unassigned RalfJung Nov 24, 2024
Copy link
Member

@RalfJung RalfJung left a comment

Choose a reason for hiding this comment

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

In fact since this is a new lint, we'll need approval from @rust-lang/lang. @calebzulawski can you make the PR description a bit more self-contained so t-lang has the required context here?

&& !tcx.codegen_fn_attrs(owner_id).target_features.is_empty()
{
if codegen_fn_attrs.inline == InlineAttr::Always {
if let Some(inline_span) = inline_span {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if let Some(inline_span) = inline_span {
// Do *not* inherit target features here, that could be unsound.
if let Some(inline_span) = inline_span {

&& !tcx.codegen_fn_attrs(owner_id).target_features.is_empty()
{
if codegen_fn_attrs.inline == InlineAttr::Always {
if let Some(inline_span) = inline_span {
Copy link
Member

Choose a reason for hiding this comment

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

What if we don't have the span? Something is still wrong, so we should still emit a lint -- it can point at the closure instead of the attribute, maybe?

@RalfJung RalfJung added the I-lang-nominated Nominated for discussion during a lang team meeting. label Nov 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-lang-nominated Nominated for discussion during a lang team meeting. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants