rust-lang / rust-lang/rust

Lints stop firing if macro reports with `Span::call_site`?

Open
#124,145 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics A-lints A-macros T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I was trying to apply this diff:

Code
         let variants = self.variants.iter().map(|variant| variant.ident.clone());
-        let sql_graph_entity_fn_name =
-            syn::Ident::new(&format!("__pgrx_internals_enum_{}", name), Span::call_site());
+        let sql_graph_entity_fn_name = quote::format_ident!("__pgrx_internals_enum_{}", name);
Current output
warning: function `__pgrx_internals_enum_SomeValue` should have a snake case name
  --> pgrx-examples/custom_types/src/generic_enum.rs:15:10
   |
15 | pub enum SomeValue {
   |          ^^^^^^^^^ help: convert the identifier to snake case: `__pgrx_internals_enum_some_value`
   |
   = note: `#[warn(non_snake_case)]` on by default

   Compiling schemas v0.0.0 (/home/jubilee/tcdi/pgrx/pgrx-examples/schemas)
Desired output

None?

Rationale and extra context

This takes in an enum's name, so of course it formats out to using __pgrx_internals_enum_SomeEnum or whatever. But format_ident is basically just constructing an Ident but with the Span of the original ident it is based on. Apparently the expanded code triggers lints only if it has that span, but Span::call_site does not! It seems odd/annoying for the lint to ignore irrational spans like this but punish me for trying to forward the correct span so that errors get reported more clearly from the macro.

This is slightly different from https://github.com/rust-lang/rust/issues/24580 because it's about the lint firing being inconsistent but I don't mind if it's closed for technically duplication I guess.

Other cases

No response

Rust Version
rustc 1.79.0-nightly (ccfcd950b 2024-04-15)
binary: rustc
commit-hash: ccfcd950b333fed046275dd8d54fe736ca498aa7
commit-date: 2024-04-15
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.3
Anything else?

No response

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

Reproduce the lint difference using the example at pgrx-examples/custom_types/src/generic_enum.rs and the reported Rust 1.79.0-nightly version. Compare identifiers created with Span::call_site and quote::format_ident!, then trace how their spans affect the non_snake_case lint; done means the behavior is explained and covered by a regression test.

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.