suggest more prominently to `use` the trait when a trait method is used
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
#![feature(portable_simd)]
use std::simd::Simd;
fn foo(bes_vec: Simd<f64, 4>) {
bes_vec.ln();
}
Current output
error[E0599]: no method named `ln` found for struct `Simd<T, N>` in the current scope
--> src/lib.rs:6:13
|
6 | bes_vec.ln();
| ^^
|
::: /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/../../portable-simd/crates/std_float/src/lib.rs:90:8
|
90 | fn ln(self) -> Self;
| -- the method is available for `Simd<f64, 4>` here
|
= help: items from traits can only be used if the trait is in scope
help: there is a method `le` with a similar name, but with different arguments
--> /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/cmp.rs:1405:5
|
1405 | fn le(&self, other: &Rhs) -> bool {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: trait `StdFloat` which provides `ln` is implemented but not in scope; perhaps you want to import it
|
3 + use std::simd::StdFloat;
|
Desired output
error[E0599]: no method named `ln` found for struct `Simd<T, N>` in the current scope
--> src/main.rs:6:21
|
6 | let term4 = bes_vec.ln();
| ^^
|
::: /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/../../portable-simd/crates/std_float/src/lib.rs:90:8
|
90 | fn ln(self) -> Self;
| -- the method is available for `Simd<f64, 4>` here
|
= help: items from traits can only be used if the trait is in scope
help: trait `StdFloat` which provides `ln` is implemented but not in scope; perhaps you want to import it
|
4 + use std::simd::StdFloat;
|
help: there is a method `le` with a similar name, but with different arguments
--> /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/cmp.rs:1405:5
|
1405 | fn le(&self, other: &Rhs) -> bool {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Rationale and extra context
I think the suggestion to use the trait should follow the line about "items from traits can only be used if the trait is in scope", especially if it is an exact match.
The error is kind of long, so there is a higher likelyhood that folks just miss the suggestion, see e.g. #project-portable-simd > SimdFloat ln() and exp() @ 💬
Other cases
Rust Version
rustc 1.91.0-nightly (a1208bf76 2025-09-03)
binary: rustc
commit-hash: a1208bf765ba783ee4ebdc4c29ab0a0c215806ef
commit-date: 2025-09-03
host: x86_64-unknown-linux-gnu
release: 1.91.0-nightly
LLVM version: 21.1.0
Anything else?
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the provided portable_simd example with the reported nightly rustc version and compare the current and desired diagnostics. Trace the diagnostic suggestions for the missing trait method; done means the exact trait-import suggestion appears immediately after the trait-scope explanation, before the similar-method suggestion, without losing the existing guidance.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100