rust-lang / rust-lang/rust

suggest broken template code

Open
#135,435 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
pub type AM<T> = Arc<Mutex<T>>;
pub trait ArcMutexTrait<T> {
    fn n(t: T) -> AM<T> { Arc::new(Mutex::new(t)) }
    fn get(&self) -> T { self.clone().lock().unwrap() }
}
impl<T> ArcMutexTrait<T> for AM<T> {}
Current output
error[E0599]: no method named `lock` found for reference `&Self` in the current scope
 --> src/common.rs:8:39
  |
8 |     fn get(&self) -> T { self.clone().lock().unwrap() }
  |                                       ^^^^ method not found in `&Self`
  |
  = help: items from traits can only be used if the type parameter is bounded by the trait
help: the following trait defines an item `lock`, perhaps you need to add a supertrait for it:
  |
6 | pub trait ArcMutexTrait: lock_api::mutex::RawMutex<T> {
  |                        +++++++++++++++++++++++++++
Desired output
something compilable.
Rationale and extra context

No response

Other cases

Rust Version
rustc 1.84.0 (9fc6b4312 2025-01-07)
binary: rustc
commit-hash: 9fc6b43126469e3858e2fe86cafb4f0fd5068869
commit-date: 2025-01-07
host: aarch64-apple-darwin
release: 1.84.0
LLVM version: 19.1.5
Anything else?

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the Rust snippet with rustc 1.84.0 and inspect the compiler's suggested fix for the missing lock method. Determine what compilable suggestion is expected; done means the diagnostic no longer recommends invalid template code.

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
Needs clarification
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.