rust-lang / rust-lang/rust-analyzer

Strangly dyn type lifetimes in cast to `*mut dyn`

Open
#21,427 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

rust-analyzer version: rust-analyzer 0.4.2733-standalone

rustc version: rustc 1.94.0-nightly (4fa80a5e7 2026-01-05)

editor or extension: Vim

code snippet to reproduce:

fn foo<T: Sync>(s: *mut T) -> *mut (dyn Sync + 'static) {
    let x = s as *mut dyn Sync;
     // ^ *mut (dyn Sync + 'static)
    x // but cannot return this value
}

Did something strange happen in as?

can compile case:

fn foo<T: Sync>(s: *mut T) -> *mut (dyn Sync + 'static) {
    let x = s as *mut dyn Sync;
    todo!()
}

cannot compile case:

fn foo<T: Sync>(s: *mut T) -> *mut (dyn Sync + 'static) {
    let x = s as *mut (dyn Sync + 'static);
    todo!()
}

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 two Rust reproducer functions in the issue and compare rust-analyzer's inferred type for the cast with the compiler's acceptance or rejection of each return expression. The rust-analyzer and rustc versions are given in the report; done means the cast's displayed lifetime and compatibility with the declared return type are handled consistently.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.