Skip to content

Conversation

@RalfJung
Copy link
Member

@RalfJung RalfJung commented May 23, 2025

target_feature in trait implementations makes basically no sense -- it's almost always unsound since a generic caller has no way of knowing the required target features! Strangely, we do have tests checking for this. I don't understand what the intended reasoning principles for soundness here would look like. At least someone thought of blocking this for safe functions / target-feature 1.1 so there's always some unsafe code somewhere before this causes UB.

As sound version of this would have to check that the same target features are already set in the trait declaration. But only functions with bodies can even have target features in the trait declaration!

I propose we just entirely forbid target features in trait impls and trait declarations. This will need an FCW, but before we do that let's get an idea for how big the fallout is by doing a crater run. The diagnostics that result from PR are terrible but it's good enough for crater.

@rustbot
Copy link
Collaborator

rustbot commented May 23, 2025

r? @compiler-errors

rustbot has assigned @compiler-errors.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot
Copy link
Collaborator

rustbot commented May 23, 2025

Some changes occurred in compiler/rustc_passes/src/check_attr.rs

cc @jdonszelmann

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) 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 May 23, 2025
@RalfJung
Copy link
Member Author

@bors try

@RalfJung RalfJung changed the title forbid target_feature in traits forbid #[target_feature] in traits May 23, 2025
bors added a commit that referenced this pull request May 23, 2025
forbid #[target_feature] in traits

`target_feature` in trait *implementations* makes basically no sense -- it's almost always unsound since a generic caller has no way of knowing the required target features! In particular, now that we can have *safe* target feature functions, that's *definitely* unsound in combination with `dyn`, see #139368.

As sound version of this would have to check that the same target features are already set in the trait declaration. But only functions with bodies can even have target features in the trait declaration!

So, this was never actually designed in a way that makes any sense, it just kinda did something. Interestingly there were tests for `#[target_feature]` in traits and trait impls... not sure how that didn't set off alarm bells. Oh well.

I propose we just entirely forbid target features in trait impls and trait declarations. This will need an FCW, but before we do that let's get an idea for how big the fallout is by doing a crater run. The diagnostics that result from PR are terrible but it's good enough for crater.
@bors
Copy link
Collaborator

bors commented May 23, 2025

⌛ Trying commit 3b43b6a with merge 4b869bf...

@rust-log-analyzer

This comment has been minimized.

@RalfJung RalfJung force-pushed the target-feature-in-trait branch from 3b43b6a to 7523e1d Compare May 23, 2025 19:26
@RalfJung
Copy link
Member Author

Hm, so apparently aho-corasick actually has target_feature in trait impls or so? Damn.^^

@rust-log-analyzer
Copy link
Collaborator

The job dist-x86_64-linux failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
file:.git/config remote.origin.url=https://github.com/rust-lang/rust
file:.git/config remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
file:.git/config gc.auto=0
file:.git/config http.https://github.com/.extraheader=AUTHORIZATION: basic ***
file:.git/config branch.try.remote=origin
file:.git/config branch.try.merge=refs/heads/try
file:.git/config submodule.library/backtrace.active=true
file:.git/config submodule.library/backtrace.url=https://github.com/rust-lang/backtrace-rs.git
file:.git/config submodule.library/stdarch.active=true
file:.git/config submodule.library/stdarch.url=https://github.com/rust-lang/stdarch.git
file:.git/config submodule.src/doc/book.active=true
---
[RUSTC-TIMING] tempfile test:false 1.215
error: attribute should be applied to a function definition
   --> /rust/deps/aho-corasick-1.1.3/src/packed/teddy/builder.rs:505:17
    |
470 | /      macro_rules! slim_ssse3 {
471 | |          ($len:expr) => {
472 | |              impl SlimSSSE3<$len> {
473 | |                  /// Creates a new searcher using "slim" Teddy with 128-bit
...   |
505 | |                  #[target_feature(enable = "ssse3")]
    | |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
506 | |                  #[inline]
507 | |/                 unsafe fn find(
508 | ||                     &self,
509 | ||                     start: *const u8,
---
    | ||_________________- not a function definition
518 | |              }
519 | |          };
520 | |      }
    | |______- in this expansion of `slim_ssse3!`
521 |
522 |        slim_ssse3!(1);
    |        -------------- in this macro invocation

error: attribute should be applied to a function definition
   --> /rust/deps/aho-corasick-1.1.3/src/packed/teddy/builder.rs:505:17
    |
470 | /      macro_rules! slim_ssse3 {
471 | |          ($len:expr) => {
472 | |              impl SlimSSSE3<$len> {
473 | |                  /// Creates a new searcher using "slim" Teddy with 128-bit
...   |
505 | |                  #[target_feature(enable = "ssse3")]
    | |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
506 | |                  #[inline]
507 | |/                 unsafe fn find(
508 | ||                     &self,
509 | ||                     start: *const u8,
---
    | ||_________________- not a function definition
518 | |              }
519 | |          };
520 | |      }
    | |______- in this expansion of `slim_ssse3!`
...
523 |        slim_ssse3!(2);
    |        -------------- in this macro invocation

error: attribute should be applied to a function definition
   --> /rust/deps/aho-corasick-1.1.3/src/packed/teddy/builder.rs:505:17
    |
470 | /      macro_rules! slim_ssse3 {
471 | |          ($len:expr) => {
472 | |              impl SlimSSSE3<$len> {
473 | |                  /// Creates a new searcher using "slim" Teddy with 128-bit
...   |
505 | |                  #[target_feature(enable = "ssse3")]
    | |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
506 | |                  #[inline]
507 | |/                 unsafe fn find(
508 | ||                     &self,
509 | ||                     start: *const u8,
---
    | ||_________________- not a function definition
518 | |              }
519 | |          };
520 | |      }
    | |______- in this expansion of `slim_ssse3!`
...
524 |        slim_ssse3!(3);
    |        -------------- in this macro invocation

error: attribute should be applied to a function definition
   --> /rust/deps/aho-corasick-1.1.3/src/packed/teddy/builder.rs:505:17
    |
470 | /      macro_rules! slim_ssse3 {
471 | |          ($len:expr) => {
472 | |              impl SlimSSSE3<$len> {
473 | |                  /// Creates a new searcher using "slim" Teddy with 128-bit
...   |
505 | |                  #[target_feature(enable = "ssse3")]
    | |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
506 | |                  #[inline]
507 | |/                 unsafe fn find(
508 | ||                     &self,
509 | ||                     start: *const u8,
---
    | ||_________________- not a function definition
518 | |              }
519 | |          };
520 | |      }
    | |______- in this expansion of `slim_ssse3!`
...
525 |        slim_ssse3!(4);
    |        -------------- in this macro invocation

error: attribute should be applied to a function definition
   --> /rust/deps/aho-corasick-1.1.3/src/packed/teddy/builder.rs:573:17
    |
534 | /      macro_rules! slim_avx2 {
535 | |          ($len:expr) => {
536 | |              impl SlimAVX2<$len> {
537 | |                  /// Creates a new searcher using "slim" Teddy with 256-bit
...   |
573 | |                  #[target_feature(enable = "avx2")]
    | |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
574 | |                  #[inline]
575 | |/                 unsafe fn find(
---
    | ||_________________- not a function definition
591 | |              }
592 | |          };
593 | |      }
    | |______- in this expansion of `slim_avx2!`
594 |
595 |        slim_avx2!(1);
    |        ------------- in this macro invocation

error: attribute should be applied to a function definition
   --> /rust/deps/aho-corasick-1.1.3/src/packed/teddy/builder.rs:573:17
    |
534 | /      macro_rules! slim_avx2 {
535 | |          ($len:expr) => {
536 | |              impl SlimAVX2<$len> {
537 | |                  /// Creates a new searcher using "slim" Teddy with 256-bit
...   |
573 | |                  #[target_feature(enable = "avx2")]
    | |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
574 | |                  #[inline]
575 | |/                 unsafe fn find(
---
    | ||_________________- not a function definition
591 | |              }
592 | |          };
593 | |      }
    | |______- in this expansion of `slim_avx2!`
...
596 |        slim_avx2!(2);
    |        ------------- in this macro invocation

error: attribute should be applied to a function definition
   --> /rust/deps/aho-corasick-1.1.3/src/packed/teddy/builder.rs:573:17
    |
534 | /      macro_rules! slim_avx2 {
535 | |          ($len:expr) => {
536 | |              impl SlimAVX2<$len> {
537 | |                  /// Creates a new searcher using "slim" Teddy with 256-bit
...   |
573 | |                  #[target_feature(enable = "avx2")]
    | |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
574 | |                  #[inline]
575 | |/                 unsafe fn find(
---
    | ||_________________- not a function definition
591 | |              }
592 | |          };
593 | |      }
    | |______- in this expansion of `slim_avx2!`
...
597 |        slim_avx2!(3);
    |        ------------- in this macro invocation

error: attribute should be applied to a function definition
   --> /rust/deps/aho-corasick-1.1.3/src/packed/teddy/builder.rs:573:17
    |
534 | /      macro_rules! slim_avx2 {
535 | |          ($len:expr) => {
536 | |              impl SlimAVX2<$len> {
537 | |                  /// Creates a new searcher using "slim" Teddy with 256-bit
...   |
573 | |                  #[target_feature(enable = "avx2")]
    | |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
574 | |                  #[inline]
575 | |/                 unsafe fn find(
---
    | ||_________________- not a function definition
591 | |              }
592 | |          };
593 | |      }
    | |______- in this expansion of `slim_avx2!`
...
598 |        slim_avx2!(4);
    |        ------------- in this macro invocation

error: attribute should be applied to a function definition
   --> /rust/deps/aho-corasick-1.1.3/src/packed/teddy/builder.rs:641:17
    |
606 | /      macro_rules! fat_avx2 {
607 | |          ($len:expr) => {
608 | |              impl FatAVX2<$len> {
609 | |                  /// Creates a new searcher using "slim" Teddy with 256-bit
...   |
641 | |                  #[target_feature(enable = "avx2")]
    | |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
642 | |                  #[inline]
643 | |/                 unsafe fn find(
---
655 | |          };
656 | |      }
    | |______- in this expansion of `fat_avx2!`
657 |
658 |        fat_avx2!(1);
    |        ------------ in this macro invocation

[RUSTC-TIMING] datafrog test:false 0.431
error: attribute should be applied to a function definition
   --> /rust/deps/aho-corasick-1.1.3/src/packed/teddy/builder.rs:641:17
    |
606 | /      macro_rules! fat_avx2 {
607 | |          ($len:expr) => {
608 | |              impl FatAVX2<$len> {
609 | |                  /// Creates a new searcher using "slim" Teddy with 256-bit
...   |
641 | |                  #[target_feature(enable = "avx2")]
    | |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
642 | |                  #[inline]
643 | |/                 unsafe fn find(
---
655 | |          };
656 | |      }
    | |______- in this expansion of `fat_avx2!`
...
659 |        fat_avx2!(2);
    |        ------------ in this macro invocation

error: attribute should be applied to a function definition
   --> /rust/deps/aho-corasick-1.1.3/src/packed/teddy/builder.rs:641:17
    |
606 | /      macro_rules! fat_avx2 {
607 | |          ($len:expr) => {
608 | |              impl FatAVX2<$len> {
609 | |                  /// Creates a new searcher using "slim" Teddy with 256-bit
...   |
641 | |                  #[target_feature(enable = "avx2")]
    | |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
642 | |                  #[inline]
643 | |/                 unsafe fn find(
---
655 | |          };
656 | |      }
    | |______- in this expansion of `fat_avx2!`
...
660 |        fat_avx2!(3);
    |        ------------ in this macro invocation

error: attribute should be applied to a function definition
   --> /rust/deps/aho-corasick-1.1.3/src/packed/teddy/builder.rs:641:17
    |
606 | /      macro_rules! fat_avx2 {
607 | |          ($len:expr) => {
608 | |              impl FatAVX2<$len> {
609 | |                  /// Creates a new searcher using "slim" Teddy with 256-bit
...   |
641 | |                  #[target_feature(enable = "avx2")]
    | |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
642 | |                  #[inline]
643 | |/                 unsafe fn find(
---
655 | |          };
656 | |      }
    | |______- in this expansion of `fat_avx2!`
...
661 |        fat_avx2!(4);
    |        ------------ in this macro invocation

   Compiling polonius-engine v0.13.0
   Compiling unicode-script v0.5.7
[RUSTC-TIMING] rand test:false 1.161
---
Caused by:
    Command RUST_BACKTRACE=full python3 /checkout/x.py build --target x86_64-unknown-linux-gnu --host x86_64-unknown-linux-gnu --stage 2 library/std --set rust.deny-warnings=false --rust-profile-generate /tmp/tmp-multistage/opt-artifacts/rustc-pgo --set llvm.thin-lto=false --set llvm.link-shared=true [at /checkout/obj] has failed with exit code Some(1)

Stack backtrace:
   0: <anyhow::Error>::msg::<alloc::string::String>
             at /rust/deps/anyhow-1.0.98/src/backtrace.rs:27:14
   1: <opt_dist::exec::CmdBuilder>::run
             at /rustc/4b869bf68e3ec527c7d00dd1c9461558d3864f2d/src/tools/opt-dist/src/exec.rs:80:17
   2: <opt_dist::exec::Bootstrap>::run
             at /rustc/4b869bf68e3ec527c7d00dd1c9461558d3864f2d/src/tools/opt-dist/src/exec.rs:184:9
   3: opt_dist::execute_pipeline::{closure#1}::{closure#0}
             at /rustc/4b869bf68e3ec527c7d00dd1c9461558d3864f2d/src/tools/opt-dist/src/main.rs:236:13
   4: <opt_dist::timer::TimerSection>::section::<opt_dist::execute_pipeline::{closure#1}::{closure#0}, ()>
             at /rustc/4b869bf68e3ec527c7d00dd1c9461558d3864f2d/src/tools/opt-dist/src/timer.rs:111:22
   5: opt_dist::execute_pipeline::{closure#1}
             at /rustc/4b869bf68e3ec527c7d00dd1c9461558d3864f2d/src/tools/opt-dist/src/main.rs:225:9
   6: <opt_dist::timer::TimerSection>::section::<opt_dist::execute_pipeline::{closure#1}, opt_dist::training::RustcPGOProfile>
             at /rustc/4b869bf68e3ec527c7d00dd1c9461558d3864f2d/src/tools/opt-dist/src/timer.rs:111:22
   7: opt_dist::execute_pipeline
             at /rustc/4b869bf68e3ec527c7d00dd1c9461558d3864f2d/src/tools/opt-dist/src/main.rs:222:29
   8: opt_dist::main
             at /rustc/4b869bf68e3ec527c7d00dd1c9461558d3864f2d/src/tools/opt-dist/src/main.rs:424:18
   9: <fn() -> core::result::Result<(), anyhow::Error> as core::ops::function::FnOnce<()>>::call_once
             at /rustc/5dadfd5c417f0b66816cb7ca662859e2c8751fb3/library/core/src/ops/function.rs:250:5
  10: std::sys::backtrace::__rust_begin_short_backtrace::<fn() -> core::result::Result<(), anyhow::Error>, core::result::Result<(), anyhow::Error>>
             at /rustc/5dadfd5c417f0b66816cb7ca662859e2c8751fb3/library/std/src/sys/backtrace.rs:152:18
  11: std::rt::lang_start::<core::result::Result<(), anyhow::Error>>::{closure#0}
             at /rustc/5dadfd5c417f0b66816cb7ca662859e2c8751fb3/library/std/src/rt.rs:199:18
  12: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once
             at /rustc/5dadfd5c417f0b66816cb7ca662859e2c8751fb3/library/core/src/ops/function.rs:284:13
  13: std::panicking::try::do_call
             at /rustc/5dadfd5c417f0b66816cb7ca662859e2c8751fb3/library/std/src/panicking.rs:589:40
  14: std::panicking::try
             at /rustc/5dadfd5c417f0b66816cb7ca662859e2c8751fb3/library/std/src/panicking.rs:552:19

@rust-log-analyzer
Copy link
Collaborator

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

Click to see the possible cause of the failure (guessed by this bot)
#18 exporting to docker image format
#18 sending tarball 19.9s done
#18 DONE 25.9s
##[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-19]
[CI_JOB_NAME=x86_64-gnu-llvm-19]
debug: `DISABLE_CI_RUSTC_IF_INCOMPATIBLE` configured.
---
sccache: Listening on address 127.0.0.1:4226
##[group]Configure the build
configure: processing command line
configure: 
configure: build.configure-args := ['--build=x86_64-unknown-linux-gnu', '--llvm-root=/usr/lib/llvm-19', '--enable-llvm-link-shared', '--set', 'rust.randomize-layout=true', '--set', 'rust.thin-lto-import-instr-limit=10', '--set', 'build.print-step-timings', '--enable-verbose-tests', '--set', 'build.metrics', '--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', '--set', 'gcc.download-ci-gcc=true', '--enable-new-symbol-mangling']
configure: build.build          := x86_64-unknown-linux-gnu
configure: target.x86_64-unknown-linux-gnu.llvm-config := /usr/lib/llvm-19/bin/llvm-config
configure: llvm.link-shared     := True
configure: rust.randomize-layout := True
configure: rust.thin-lto-import-instr-limit := 10
---
   Compiling unicode-script v0.5.7
error: attribute should be applied to a function definition
   --> /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/aho-corasick-1.1.3/src/packed/teddy/builder.rs:505:17
    |
470 | /      macro_rules! slim_ssse3 {
471 | |          ($len:expr) => {
472 | |              impl SlimSSSE3<$len> {
473 | |                  /// Creates a new searcher using "slim" Teddy with 128-bit
...   |
505 | |                  #[target_feature(enable = "ssse3")]
    | |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
506 | |                  #[inline]
507 | |/                 unsafe fn find(
508 | ||                     &self,
509 | ||                     start: *const u8,
---
    | ||_________________- not a function definition
518 | |              }
519 | |          };
520 | |      }
    | |______- in this expansion of `slim_ssse3!`
521 |
522 |        slim_ssse3!(1);
    |        -------------- in this macro invocation

error: attribute should be applied to a function definition
   --> /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/aho-corasick-1.1.3/src/packed/teddy/builder.rs:505:17
    |
470 | /      macro_rules! slim_ssse3 {
471 | |          ($len:expr) => {
472 | |              impl SlimSSSE3<$len> {
473 | |                  /// Creates a new searcher using "slim" Teddy with 128-bit
...   |
505 | |                  #[target_feature(enable = "ssse3")]
    | |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
506 | |                  #[inline]
507 | |/                 unsafe fn find(
508 | ||                     &self,
509 | ||                     start: *const u8,
---
    | ||_________________- not a function definition
518 | |              }
519 | |          };
520 | |      }
    | |______- in this expansion of `slim_ssse3!`
...
523 |        slim_ssse3!(2);
    |        -------------- in this macro invocation

error: attribute should be applied to a function definition
   --> /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/aho-corasick-1.1.3/src/packed/teddy/builder.rs:505:17
    |
470 | /      macro_rules! slim_ssse3 {
471 | |          ($len:expr) => {
472 | |              impl SlimSSSE3<$len> {
473 | |                  /// Creates a new searcher using "slim" Teddy with 128-bit
...   |
505 | |                  #[target_feature(enable = "ssse3")]
    | |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
506 | |                  #[inline]
507 | |/                 unsafe fn find(
508 | ||                     &self,
509 | ||                     start: *const u8,
---
    | ||_________________- not a function definition
518 | |              }
519 | |          };
520 | |      }
    | |______- in this expansion of `slim_ssse3!`
...
524 |        slim_ssse3!(3);
    |        -------------- in this macro invocation

error: attribute should be applied to a function definition
   --> /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/aho-corasick-1.1.3/src/packed/teddy/builder.rs:505:17
    |
470 | /      macro_rules! slim_ssse3 {
471 | |          ($len:expr) => {
472 | |              impl SlimSSSE3<$len> {
473 | |                  /// Creates a new searcher using "slim" Teddy with 128-bit
...   |
505 | |                  #[target_feature(enable = "ssse3")]
    | |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
506 | |                  #[inline]
507 | |/                 unsafe fn find(
508 | ||                     &self,
509 | ||                     start: *const u8,
---
    | ||_________________- not a function definition
518 | |              }
519 | |          };
520 | |      }
    | |______- in this expansion of `slim_ssse3!`
...
525 |        slim_ssse3!(4);
    |        -------------- in this macro invocation

error: attribute should be applied to a function definition
   --> /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/aho-corasick-1.1.3/src/packed/teddy/builder.rs:573:17
    |
534 | /      macro_rules! slim_avx2 {
535 | |          ($len:expr) => {
536 | |              impl SlimAVX2<$len> {
537 | |                  /// Creates a new searcher using "slim" Teddy with 256-bit
...   |
573 | |                  #[target_feature(enable = "avx2")]
    | |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
574 | |                  #[inline]
575 | |/                 unsafe fn find(
---
    | ||_________________- not a function definition
591 | |              }
592 | |          };
593 | |      }
    | |______- in this expansion of `slim_avx2!`
594 |
595 |        slim_avx2!(1);
    |        ------------- in this macro invocation

error: attribute should be applied to a function definition
   --> /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/aho-corasick-1.1.3/src/packed/teddy/builder.rs:573:17
    |
534 | /      macro_rules! slim_avx2 {
535 | |          ($len:expr) => {
536 | |              impl SlimAVX2<$len> {
537 | |                  /// Creates a new searcher using "slim" Teddy with 256-bit
...   |
573 | |                  #[target_feature(enable = "avx2")]
    | |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
574 | |                  #[inline]
575 | |/                 unsafe fn find(
---
    | ||_________________- not a function definition
591 | |              }
592 | |          };
593 | |      }
    | |______- in this expansion of `slim_avx2!`
...
596 |        slim_avx2!(2);
    |        ------------- in this macro invocation

error: attribute should be applied to a function definition
   --> /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/aho-corasick-1.1.3/src/packed/teddy/builder.rs:573:17
    |
534 | /      macro_rules! slim_avx2 {
535 | |          ($len:expr) => {
536 | |              impl SlimAVX2<$len> {
537 | |                  /// Creates a new searcher using "slim" Teddy with 256-bit
...   |
573 | |                  #[target_feature(enable = "avx2")]
    | |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
574 | |                  #[inline]
575 | |/                 unsafe fn find(
---
    | ||_________________- not a function definition
591 | |              }
592 | |          };
593 | |      }
    | |______- in this expansion of `slim_avx2!`
...
597 |        slim_avx2!(3);
    |        ------------- in this macro invocation

error: attribute should be applied to a function definition
   --> /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/aho-corasick-1.1.3/src/packed/teddy/builder.rs:573:17
    |
534 | /      macro_rules! slim_avx2 {
535 | |          ($len:expr) => {
536 | |              impl SlimAVX2<$len> {
537 | |                  /// Creates a new searcher using "slim" Teddy with 256-bit
...   |
573 | |                  #[target_feature(enable = "avx2")]
    | |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
574 | |                  #[inline]
575 | |/                 unsafe fn find(
---
    | ||_________________- not a function definition
591 | |              }
592 | |          };
593 | |      }
    | |______- in this expansion of `slim_avx2!`
...
598 |        slim_avx2!(4);
    |        ------------- in this macro invocation

error: attribute should be applied to a function definition
   --> /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/aho-corasick-1.1.3/src/packed/teddy/builder.rs:641:17
    |
606 | /      macro_rules! fat_avx2 {
607 | |          ($len:expr) => {
608 | |              impl FatAVX2<$len> {
609 | |                  /// Creates a new searcher using "slim" Teddy with 256-bit
...   |
641 | |                  #[target_feature(enable = "avx2")]
    | |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
642 | |                  #[inline]
643 | |/                 unsafe fn find(
---
655 | |          };
656 | |      }
    | |______- in this expansion of `fat_avx2!`
657 |
658 |        fat_avx2!(1);
    |        ------------ in this macro invocation

error: attribute should be applied to a function definition
   --> /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/aho-corasick-1.1.3/src/packed/teddy/builder.rs:641:17
    |
606 | /      macro_rules! fat_avx2 {
607 | |          ($len:expr) => {
608 | |              impl FatAVX2<$len> {
609 | |                  /// Creates a new searcher using "slim" Teddy with 256-bit
...   |
641 | |                  #[target_feature(enable = "avx2")]
    | |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
642 | |                  #[inline]
643 | |/                 unsafe fn find(
---
655 | |          };
656 | |      }
    | |______- in this expansion of `fat_avx2!`
...
659 |        fat_avx2!(2);
    |        ------------ in this macro invocation

error: attribute should be applied to a function definition
   --> /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/aho-corasick-1.1.3/src/packed/teddy/builder.rs:641:17
    |
606 | /      macro_rules! fat_avx2 {
607 | |          ($len:expr) => {
608 | |              impl FatAVX2<$len> {
609 | |                  /// Creates a new searcher using "slim" Teddy with 256-bit
...   |
641 | |                  #[target_feature(enable = "avx2")]
    | |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
642 | |                  #[inline]
643 | |/                 unsafe fn find(
---
655 | |          };
656 | |      }
    | |______- in this expansion of `fat_avx2!`
...
660 |        fat_avx2!(3);
    |        ------------ in this macro invocation

error: attribute should be applied to a function definition
   --> /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/aho-corasick-1.1.3/src/packed/teddy/builder.rs:641:17
    |
606 | /      macro_rules! fat_avx2 {
607 | |          ($len:expr) => {
608 | |              impl FatAVX2<$len> {
609 | |                  /// Creates a new searcher using "slim" Teddy with 256-bit
...   |
641 | |                  #[target_feature(enable = "avx2")]
    | |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
642 | |                  #[inline]
643 | |/                 unsafe fn find(
---
655 | |          };
656 | |      }
    | |______- in this expansion of `fat_avx2!`
...
661 |        fat_avx2!(4);
    |        ------------ in this macro invocation

[RUSTC-TIMING] measureme test:false 2.689
   Compiling libloading v0.8.7
[RUSTC-TIMING] datafrog test:false 0.888

@hanna-kruppe
Copy link
Contributor

hanna-kruppe commented May 23, 2025

Something's fishy with those errors. As far as I can see (might have missed something in the very long scroll box) the errors point at inherent methods, i.e., impl $ty {} blocks rather than impl $trait for $ty {}. Nevermind, I was misled by the spans and some lines being elided.

@traviscross traviscross added T-lang Relevant to the language team needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 23, 2025
@RalfJung
Copy link
Member Author

RalfJung commented May 23, 2025

@hanna-kruppe I think that's just an unfortunate case of a macro expansion span and some lines being omitted. I was confused the same way.

Anyway this PR isn't going to happen, we won't break aho-corasick.^^ See here for further discussion.

@RalfJung RalfJung closed this May 23, 2025
@RalfJung RalfJung deleted the target-feature-in-trait branch May 23, 2025 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-lang Relevant to the language team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants