Skip to content

Fails to parse attribute in expression: return #[attr] v.f(); inside attribute macro's input. #22149

@programmerjake

Description

@programmerjake

Gives error:
Syntax Error: expected SEMICOLON on the return in lib.rs.

rust-analyzer version: rust-analyzer version: 0.3.2862-standalone [/home/jacob/.vscode-oss/extensions/rust-lang.rust-analyzer-0.3.2862-linux-x64/server/rust-analyzer]

rustc version: rustc 1.93.0 (254b59607 2026-01-19)

editor or extension: VSCodium with rust-analyzer extension

relevant settings:

{
  "rust-analyzer.imports.prefix": "crate",
  "rust-analyzer.imports.merge.glob": false,
  "rust-analyzer.cargo.features": "all",
  "rust-analyzer.runnables.extraTestBinaryArgs": [
      "--nocapture"
  ],
  "rust-analyzer.checkOnSave": true,
}

code snippet to reproduce:

Rustc compiles it with no errors or warnings:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=a0e293172a696adb24d2255941a1ad52

my_macro:

const BODY: &str = r#"
pub fn f(v: S) -> bool {
    return v.f();
}
"#;
use proc_macro::TokenStream;
#[proc_macro_attribute]
pub fn my_macro(_arg: TokenStream, _body: TokenStream) -> TokenStream {
    BODY.parse().unwrap()
}

lib:

pub struct S;

impl S {
    fn f(self) -> bool {
        true
    }
}

#[my_macro::my_macro]
pub fn f(v: S) -> bool {
    return #[foo] v.f();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macromacro expansionA-parserparser issuesC-bugCategory: bug

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions