Go to definition on a type in a Rocket handler signature also returns targets inside the attribute expansion
rust-analyzer version: 0.3.3057-standalone (aaddfb73fd 2026-09-20), the 2026-09-21 release. Also reproduces with the newest release, 2026-09-28, in 3 of 3 runs.
rustc version: rustc 1.98.1 (48a229cea 2026-09-01), the version the project pins in rust-toolchain.toml
editor or extension: none; I drive the server over stdio from a small LSP client script on macOS 27 (Apple silicon).
relevant settings: {"checkOnSave": false, "cargo": {"buildScripts": {"enable": true}}, "procMacro": {"enable": true}, "diagnostics": {"enable": true}}. No cargo features are set, so vaultwarden's build script fails and rust-analyzer logs FetchBuildDataError: error: You need to enable one DB backend. To build with previous defaults do: cargo build --features sqlite. I have not tried with a DB feature enabled.
repository link (if public, optional): https://github.com/dani-garcia/vaultwarden/tree/cc67d644f62605cb46f4d16c4a2eed1a861cc8bb
code snippet to reproduce:
// src/api/admin.rs, lines 288 to 291
#[get("/", rank = 2)]
fn admin_page_login() -> ApiResult<Html<String>> {
render_admin_login(None, None)
}
// src/api/mod.rs, line 44
pub type ApiResult<T> = Result<T, crate::error::Error>;Positions below are 0-based LSP positions; line numbers in text are 1-based.
- Open
src/api/core/two_factor/duo.rs(two other files were open as well:src/db/models/attachment.rs,src/sso.rs).textDocument/definitionat{line: 7, character: 12}, onApiResultin theuse crate::{..., api::{ApiResult, ...}}list on line 8. Result: one target, the type alias insrc/api/mod.rsline 44. - Open
src/api/admin.rs.textDocument/definitionat{line: 288, character: 29}, onApiResultin the return type on line 289 (the snippet above).
Result of step 2, 10 targets:
src/api/mod.rsline 44, the type aliassrc/api/admin.rsline 289, 25 to 34: the queriedApiResulttoken itselfsrc/api/admin.rsline 288, 2 to 20:get("/", rank = 2)in the attribute- rocket-0.5.1
src/lib.rs(the whole file),src/route/mod.rs(the whole file),src/sentinel.rs(the whole file) - rocket-0.5.1
src/route/handler.rsline 7 (Outcome) and line 188 (from) - rocket-0.5.1
src/sentinel.rsline 395 (macro_rules! resolve) - rocket_codegen-0.5.1
src/lib.rsline 282 (route_attribute!(get => Method::Get);)
The same happens with DbConn (a struct declared once, in src/db/mod.rs line 123): in the parameter list of the #[put] handler activate_duo_put (src/api/core/two_factor/duo.rs line 197) go to definition returns 20 targets, while DbConn in a function nested inside the body of a #[post] handler (src/api/admin.rs line 309) returns only the struct. Both reproduced in 3 of 3 runs.
Expected: only the type alias, as at the use site. The protocol allows several targets, but these point into code generated by the attribute and at the token itself, so jumping to the definition from a handler signature opens a list of mostly unrelated places.
This may be the span behaviour discussed in #20441 (closed as not planned), where a proc macro that re-spans tokens makes go to definition also return places in the expansion (Box::pin for async_trait). If this is the same case for rocket_codegen, this can be closed as such. #21496 (derive helper spans) and #21721 (go to definition jumping to the macro attribute, closed in March) are in the same area.
URIs shortened: file:///repo/... for the project, file:///registry/... for ~/.cargo/registry/src/index.crates.io-.../.
--> textDocument/definition {"textDocument":{"uri":"file:///repo/src/api/core/two_factor/duo.rs"},"position":{"line":7,"character":12}}
<-- [{"originSelectionRange":{"start":{"line":7,"character":8},"end":{"line":7,"character":17}},"targetUri":"file:///repo/src/api/mod.rs",
"targetRange":{"start":{"line":42,"character":0},"end":{"line":43,"character":55}},"targetSelectionRange":{"start":{"line":43,"character":9},"end":{"line":43,"character":18}}}]
--> textDocument/didOpen {"textDocument":{"uri":"file:///repo/src/api/admin.rs","languageId":"rust","version":1,"text":"..."}}
--> textDocument/definition {"textDocument":{"uri":"file:///repo/src/api/admin.rs"},"position":{"line":288,"character":29}}
<-- [ every entry has "originSelectionRange":{"start":{"line":288,"character":25},"end":{"line":288,"character":34}}; targetUri and targetSelectionRange:
file:///repo/src/api/mod.rs 43:9-43:18
file:///repo/src/api/admin.rs 288:25-288:34
file:///repo/src/api/admin.rs 287:2-287:20
file:///registry/rocket-0.5.1/src/lib.rs 0:0-364:0
file:///registry/rocket-0.5.1/src/route/mod.rs 0:0-12:0
file:///registry/rocket-0.5.1/src/route/handler.rs 6:9-6:16
file:///registry/rocket-0.5.1/src/route/handler.rs 187:11-187:15
file:///registry/rocket_codegen-0.5.1/src/lib.rs 281:0-281:5
file:///registry/rocket-0.5.1/src/sentinel.rs 0:0-487:0
file:///registry/rocket-0.5.1/src/sentinel.rs 394:13-394:20 ]Source: rust-lang/rust-analyzer