From 24e1071d21bc41d3224f4fedcd9779b45ebf62f3 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Fri, 29 Mar 2024 13:34:01 -0700 Subject: [PATCH] clippy: fix up `include_str!` spans in diagnostics --- clippy_lints/src/large_include_file.rs | 2 +- clippy_lints/src/strings.rs | 2 +- .../large_include_file/large_include_file.stderr | 2 -- tests/ui/empty_docs.stderr | 11 ++++++----- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/clippy_lints/src/large_include_file.rs b/clippy_lints/src/large_include_file.rs index 1b5981ecc28..553d447d440 100644 --- a/clippy_lints/src/large_include_file.rs +++ b/clippy_lints/src/large_include_file.rs @@ -71,7 +71,7 @@ fn check_expr(&mut self, cx: &LateContext<'_>, expr: &'_ Expr<'_>) { span_lint_and_note( cx, LARGE_INCLUDE_FILE, - expr.span, + expr.span.source_callsite(), "attempted to include a large file", None, &format!( diff --git a/clippy_lints/src/strings.rs b/clippy_lints/src/strings.rs index 13ae1ff52dd..21790134854 100644 --- a/clippy_lints/src/strings.rs +++ b/clippy_lints/src/strings.rs @@ -300,7 +300,7 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { e.span, "calling `as_bytes()` on `include_str!(..)`", "consider using `include_bytes!(..)` instead", - snippet_with_applicability(cx, receiver.span, r#""foo""#, &mut applicability).replacen( + snippet_with_applicability(cx, receiver.span.source_callsite(), r#""foo""#, &mut applicability).replacen( "include_str", "include_bytes", 1, diff --git a/tests/ui-toml/large_include_file/large_include_file.stderr b/tests/ui-toml/large_include_file/large_include_file.stderr index b45cb11939f..34224065f07 100644 --- a/tests/ui-toml/large_include_file/large_include_file.stderr +++ b/tests/ui-toml/large_include_file/large_include_file.stderr @@ -7,7 +7,6 @@ LL | const TOO_BIG_INCLUDE_BYTES: &[u8; 654] = include_bytes!("too_big.txt"); = note: the configuration allows a maximum size of 600 bytes = note: `-D clippy::large-include-file` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::large_include_file)]` - = note: this error originates in the macro `include_bytes` (in Nightly builds, run with -Z macro-backtrace for more info) error: attempted to include a large file --> tests/ui-toml/large_include_file/large_include_file.rs:14:35 @@ -16,7 +15,6 @@ LL | const TOO_BIG_INCLUDE_STR: &str = include_str!("too_big.txt"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: the configuration allows a maximum size of 600 bytes - = note: this error originates in the macro `include_str` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 2 previous errors diff --git a/tests/ui/empty_docs.stderr b/tests/ui/empty_docs.stderr index 28ebea22c5d..5fd7272d7c1 100644 --- a/tests/ui/empty_docs.stderr +++ b/tests/ui/empty_docs.stderr @@ -25,19 +25,20 @@ LL | /// = help: consider removing or filling it error: empty doc comment - --> tests/ui/empty_docs.rs:30:5 + --> tests/ui/empty_docs.rs:30:13 | LL | #[doc = ""] - | ^^^^^^^^^^^ + | ^^ | = help: consider removing or filling it error: empty doc comment - --> tests/ui/empty_docs.rs:33:5 + --> tests/ui/empty_docs.rs:33:13 | -LL | / #[doc = ""] +LL | #[doc = ""] + | _____________^ LL | | #[doc = ""] - | |_______________^ + | |______________^ | = help: consider removing or filling it