Skip to content

fix(rsx): quote_spanned! -> quote!. Resolves clippy::useless_format lints.#5636

Open
scottfones wants to merge 1 commit into
DioxusLabs:mainfrom
scottfones:fix/rsx-useless-format
Open

fix(rsx): quote_spanned! -> quote!. Resolves clippy::useless_format lints.#5636
scottfones wants to merge 1 commit into
DioxusLabs:mainfrom
scottfones:fix/rsx-useless-format

Conversation

@scottfones

Copy link
Copy Markdown

Problem

ifmt.rs's is_simple_expr path emits format! with quote_spanned! { raw.span() => ... }, giving the call the user's source span. After rust-lang/rust-clippy#17060 , useless_format resolves a format!'s macro context from its span, so clippy isn't aware of the call's macro-generated context.

Fix

Using quote! gives it the macro's span instead, so clippy treats it as part of the rsx! expansion and ignores it.

The #raw literal keeps its source span, so rust-analyzer is unaffected.

Verification

Confirmed: clippy no longer lints bare interpolations as before.

Confirmed rust-analyzer functionality in-editor: renaming a variable still rewrites its "{var}" inside rsx!.

Fixes #5635

@scottfones scottfones requested a review from a team as a code owner June 18, 2026 00:11
@ealmloff

ealmloff commented Jun 18, 2026

Copy link
Copy Markdown
Member

We forward the span to help rust analyzers highlighting/rename functionality. We should keep the span and #[allow(clippy::useless_format)] instead so we get both the rust analyzer features and no clippy warning

@scottfones

Copy link
Copy Markdown
Author

Thanks for the quick feedback @ealmloff !

I saw the comment about the RA functionality and wanted to maintain that with the fix. I did test that highlighting and renaming work. My understanding is that the interpolated #raw literal will keep its own source span with quote!.

Here's the code I'm testing on:

use dioxus::prelude::*;

pub fn render(renamed: &str) -> Element {
    rsx! {
        span { "{renamed}" }
    }
}

Here, renamed is an artifact of the renaming test. Querying rust analyzer for references returns: [[3, 14], [5, 17]], which matches the parameter definition and the reference inside the rsx! block.

I also tested a format! error with {x}. That pointed back to the user source (identical to using quote_spanned!).

I'm happy to go with the allow attribute if you still prefer that.

@scottfones scottfones force-pushed the fix/rsx-useless-format branch from 10004c6 to 3761d72 Compare June 18, 2026 22:17
@scottfones

Copy link
Copy Markdown
Author

I've updated the commit, which should fix the CI.

The first commit was a hybrid of the original code and my fix; I messed up when I was cleaning up my edits. I left the raw.span() => from the quote_spanned!, which is no longer necessary.

The corrected line is return quote! { ::std::format!(#raw) }.to_tokens(tokens);

Sorry for the mix up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nightly clippy emits clippy::useless_format for bare interpolations in dev builds.

2 participants