rust-lang / rust-lang/rust

"implementation is not general enough" even if only `'static` is used.

Open
#136,726 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-async-await A-borrow-checker C-bug T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Check https://github.com/fast/fastimer/pull/22 as a small reproduction.

I expected to see this happen:

Since the trait MakeDelay is implemented for &'static MakeTokioDelay and the use point can ensure that only &'static MakeTokioDelay is used, it should compiled.

Actually, with the tricky workaround to eliminate 'static in type (but still in field), the compiler is happy to compile the code.

Instead, this happened:

error: implementation of `MakeDelay` is not general enough
  --> fastimer-tokio/tests/lifetime.rs:49:17
   |
49 |       let spawn = rt1.spawn(async move {
   |  _________________^
50 | |         let mut interval = fastimer::interval(Duration::from_secs(1), timer());
51 | |         for _ in 0..3 {
52 | |             interval.tick().await;
53 | |         }
54 | |     });
   | |______^ implementation of `MakeDelay` is not general enough
   |
   = note: `&'0 MakeTokioDelay` must implement `MakeDelay`, for any lifetime `'0`...
   = note: ...but `MakeDelay` is actually implemented for the type `&'static MakeTokioDelay`
Meta

rustc --version --verbose:

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

Can reproduce with:

rustc 1.86.0-nightly (854f22563 2025-01-31)
binary: rustc
commit-hash: 854f22563c8daf92709fae18ee6aed52953835cd
commit-date: 2025-01-31
host: aarch64-apple-darwin
release: 1.86.0-nightly
LLVM version: 19.1.7
Backtrace

<backtrace>

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 with the reproduction in fastimer-tokio/tests/lifetime.rs from fast/fastimer#22 and confirm the diagnostic using the listed stable and nightly rustc versions. Investigate the compiler's treatment of the MakeDelay implementation for 'static references; done means the reported case is handled as expected and has regression coverage.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.