rust-lang / rust-lang/rust-analyzer
Strangly dyn type lifetimes in cast to `*mut dyn`
Nobody has claimed this yet.
- 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
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 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