Spans from built-in macro expansions are not "from expansion"

While working on a late-pass clippy lint, I found that calling from_expansion on string literal spans from built-in macros like stringify! and include_str! returns false. Is there a more correct way to check if these spans came from a built-in macro expansion, or is this a bug in rustc?

This query belongs in (URLO); this IRLO forum is for proposed enhancements and/or changes to Rust's language and tooling.

I think this is fine here because it is directly relatted to compiler internals, and there wouldn't be enough people who know about that on users


Both stringify and include_str are buggy, and do not produce correct spans.
Some other built-in macros may be similarly buggy as well.

The fix is to create the output expression with span cx.with_def_site_ctxt(sp) instead of just sp.
The relevant code is in libsyntax_ext/


Thanks for the help. I'll work on a PR to fix it.