From 591e0810a23ea02f29ea4792e1f21ee70b3674e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 16 Sep 2026 22:35:56 +0000 Subject: [PATCH] Use context span more --- .../src/check/compare_impl_item.rs | 4 +- .../rustc_hir_typeck/src/method/suggest.rs | 2 +- compiler/rustc_hir_typeck/src/pat.rs | 4 +- .../in-trait/generics-mismatch.stderr | 2 - .../ban-self-when-feature-not-enabled.stderr | 2 - .../mismatched_ty_const_in_trait_impl.stderr | 10 - .../const-generics/issues/issue-86820.stderr | 2 - .../multiline-removal-suggestion.svg | 388 +++++++++--------- .../const_params_have_right_type.stderr | 2 - .../compare-impl-item.stderr | 2 - tests/ui/methods/method-call-err-msg.stderr | 12 +- tests/ui/pattern/pat-tuple-overfield.stderr | 3 +- tests/ui/typeck/issue-31173.stderr | 19 +- 13 files changed, 211 insertions(+), 241 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs index 40aeb3b8d2a..4061d247f59 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs @@ -2123,11 +2123,11 @@ fn compare_generic_param_kinds<'tcx>( }; let trait_header_span = tcx.def_ident_span(tcx.parent(trait_item.def_id)).unwrap(); - err.span_label(trait_header_span, ""); + err.span_context(trait_header_span); err.span_label(param_trait_span, make_param_message("expected", param_trait)); let impl_header_span = tcx.def_span(tcx.parent(impl_item.def_id)); - err.span_label(impl_header_span, ""); + err.span_context(impl_header_span); err.span_label(param_impl_span, make_param_message("found", param_impl)); let reported = err.emit_unless_delay(delay); diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index 1ca644d759d..07c98f884ce 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -3908,7 +3908,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ) { let tcx = self.tcx; if tcx.sess.source_map().is_multiline(sugg_span) { - err.span_label(sugg_span.with_hi(span.lo()), ""); + err.span_context(sugg_span.with_hi(span.lo())); } if let Some(within_macro_span) = within_macro_span { err.span_label(within_macro_span, "due to this macro variable"); diff --git a/compiler/rustc_hir_typeck/src/pat.rs b/compiler/rustc_hir_typeck/src/pat.rs index 81cdd278c3b..caffef6a217 100644 --- a/compiler/rustc_hir_typeck/src/pat.rs +++ b/compiler/rustc_hir_typeck/src/pat.rs @@ -1914,9 +1914,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { last_subpat_span, format!("expected {} field{}, found {}", fields.len(), fields_ending, subpats.len()), ); - if self.tcx.sess.source_map().is_multiline(qpath.span().between(last_subpat_span)) { - err.span_label(qpath.span(), ""); - } + err.span_context(qpath.span()); if self.tcx.sess.source_map().is_multiline(def_ident_span.between(last_field_def_span)) { err.span_label(def_ident_span, format!("{} defined here", res.descr())); } diff --git a/tests/ui/async-await/in-trait/generics-mismatch.stderr b/tests/ui/async-await/in-trait/generics-mismatch.stderr index cb0f95e8d09..7c6f665c4db 100644 --- a/tests/ui/async-await/in-trait/generics-mismatch.stderr +++ b/tests/ui/async-await/in-trait/generics-mismatch.stderr @@ -2,12 +2,10 @@ error[E0053]: associated function `foo` has an incompatible generic parameter fo --> $DIR/generics-mismatch.rs:8:18 | LL | trait Foo { - | --- LL | async fn foo(); | - expected type parameter ... LL | impl Foo for () { - | --------------- LL | async fn foo() {} | ^^^^^^^^^^^^^^ found const parameter of type `usize` diff --git a/tests/ui/const-generics/ban-self-when-feature-not-enabled.stderr b/tests/ui/const-generics/ban-self-when-feature-not-enabled.stderr index 4961d799003..4a74de9d566 100644 --- a/tests/ui/const-generics/ban-self-when-feature-not-enabled.stderr +++ b/tests/ui/const-generics/ban-self-when-feature-not-enabled.stderr @@ -10,12 +10,10 @@ error[E0053]: associated function `foo` has an incompatible generic parameter fo --> $DIR/ban-self-when-feature-not-enabled.rs:8:12 | LL | trait MyTrait { - | ------- LL | fn foo(); | ------------ expected const parameter of type `i32` ... LL | impl MyTrait for i32 { - | -------------------- LL | fn foo() {} | ^^^^^^^^^^^^^ found const parameter of type `{type error}` diff --git a/tests/ui/const-generics/defaults/mismatched_ty_const_in_trait_impl.stderr b/tests/ui/const-generics/defaults/mismatched_ty_const_in_trait_impl.stderr index 7ec162e1c29..cb37701f9ad 100644 --- a/tests/ui/const-generics/defaults/mismatched_ty_const_in_trait_impl.stderr +++ b/tests/ui/const-generics/defaults/mismatched_ty_const_in_trait_impl.stderr @@ -2,12 +2,10 @@ error[E0053]: associated function `foo` has an incompatible generic parameter fo --> $DIR/mismatched_ty_const_in_trait_impl.rs:5:12 | LL | trait Trait { - | ----- LL | fn foo() {} | - expected type parameter LL | } LL | impl Trait for () { - | ----------------- LL | fn foo() {} | ^^^^^^^^^^^^ found const parameter of type `u64` @@ -15,12 +13,10 @@ error[E0053]: associated function `bar` has an incompatible generic parameter fo --> $DIR/mismatched_ty_const_in_trait_impl.rs:13:12 | LL | trait Other { - | ----- LL | fn bar() {} | ----------- expected const parameter of type `u8` LL | } LL | impl Other for () { - | ----------------- LL | fn bar() {} | ^ found type parameter @@ -28,12 +24,10 @@ error[E0053]: associated function `baz` has an incompatible generic parameter fo --> $DIR/mismatched_ty_const_in_trait_impl.rs:21:12 | LL | trait Uwu { - | --- LL | fn baz() {} | ------------ expected const parameter of type `u32` LL | } LL | impl Uwu for () { - | --------------- LL | fn baz() {} | ^^^^^^^^^^^^ found const parameter of type `i32` @@ -41,12 +35,10 @@ error[E0053]: associated function `bbbb` has an incompatible generic parameter f --> $DIR/mismatched_ty_const_in_trait_impl.rs:29:13 | LL | trait Aaaaaa { - | ------ LL | fn bbbb() {} | ------------ expected const parameter of type `u32` LL | } LL | impl Aaaaaa for () { - | ------------------ LL | fn bbbb() {} | ^ found type parameter @@ -54,12 +46,10 @@ error[E0053]: associated function `abcd` has an incompatible generic parameter f --> $DIR/mismatched_ty_const_in_trait_impl.rs:37:13 | LL | trait Names { - | ----- LL | fn abcd() {} | - expected type parameter LL | } LL | impl Names for () { - | ----------------- LL | fn abcd() {} | ^^^^^^^^^^^^ found const parameter of type `u32` diff --git a/tests/ui/const-generics/issues/issue-86820.stderr b/tests/ui/const-generics/issues/issue-86820.stderr index 2928c1923b8..fda12fbda3a 100644 --- a/tests/ui/const-generics/issues/issue-86820.stderr +++ b/tests/ui/const-generics/issues/issue-86820.stderr @@ -2,12 +2,10 @@ error[E0053]: method `bit` has an incompatible generic parameter for trait `Bits --> $DIR/issue-86820.rs:16:12 | LL | trait Bits { - | ---- LL | fn bit(self) -> bool; | ----------- expected const parameter of type `u8` ... LL | impl Bits for u8 { - | ---------------- LL | fn bit(self) -> bool { | ^^^^^^^^^^^^^^ found const parameter of type `usize` diff --git a/tests/ui/error-emitter/multiline-removal-suggestion.svg b/tests/ui/error-emitter/multiline-removal-suggestion.svg index 5c47481d4c1..e1a15eba86f 100644 --- a/tests/ui/error-emitter/multiline-removal-suggestion.svg +++ b/tests/ui/error-emitter/multiline-removal-suggestion.svg @@ -1,4 +1,4 @@ - +

{ - | ----- ... LL | const D: usize; | -------------- expected const parameter of type `usize` ... LL | impl

Trait

for () { - | ----------------------- ... LL | const D: u16 = N; | ^^^^^^^^^^^^ found const parameter of type `u16` diff --git a/tests/ui/methods/method-call-err-msg.stderr b/tests/ui/methods/method-call-err-msg.stderr index 95de40ff891..c461c89abc3 100644 --- a/tests/ui/methods/method-call-err-msg.stderr +++ b/tests/ui/methods/method-call-err-msg.stderr @@ -50,14 +50,12 @@ LL | .two(0, /* isize */); error[E0599]: `Foo` is not an iterator --> $DIR/method-call-err-msg.rs:19:7 | -LL | pub struct Foo; - | -------------- method `take` not found for this struct because it doesn't satisfy `Foo: Iterator` +LL | pub struct Foo; + | -------------- method `take` not found for this struct because it doesn't satisfy `Foo: Iterator` ... -LL | / y.zero() -LL | | .take() - | | -^^^^ `Foo` is not an iterator - | |______| - | +LL | y.zero() +LL | .take() + | ^^^^ `Foo` is not an iterator | = note: the following trait bounds were not satisfied: `Foo: Iterator` diff --git a/tests/ui/pattern/pat-tuple-overfield.stderr b/tests/ui/pattern/pat-tuple-overfield.stderr index 0dc16bfb99f..151eee506d8 100644 --- a/tests/ui/pattern/pat-tuple-overfield.stderr +++ b/tests/ui/pattern/pat-tuple-overfield.stderr @@ -261,7 +261,7 @@ LL | u8, | -- tuple struct has 5 fields ... LL | M(1, - | - ^ + | ^ LL | 2, | ^ LL | 3, @@ -290,7 +290,6 @@ LL | u8, | -- tuple struct has 5 fields ... LL | M( - | - LL | 1, | ^ LL | 2, diff --git a/tests/ui/typeck/issue-31173.stderr b/tests/ui/typeck/issue-31173.stderr index 5815da4dea9..d3935c51d18 100644 --- a/tests/ui/typeck/issue-31173.stderr +++ b/tests/ui/typeck/issue-31173.stderr @@ -24,17 +24,14 @@ note: required by a bound in `cloned` error[E0599]: the method `collect` exists for struct `Cloned, {closure@$DIR/issue-31173.rs:7:21: 7:25}>>`, but its trait bounds were not satisfied --> $DIR/issue-31173.rs:12:10 | -LL | let temp: Vec = it - | _________________________- -LL | | .take_while(|&x| { -LL | | found_e = true; -LL | | false -LL | | }) -LL | | .cloned() -LL | | .collect(); - | | -^^^^^^^ method cannot be called due to unsatisfied trait bounds - | |_________| - | +LL | let temp: Vec = it +LL | .take_while(|&x| { +LL | found_e = true; +LL | false +LL | }) +LL | .cloned() +LL | .collect(); + | ^^^^^^^ method cannot be called due to unsatisfied trait bounds | = note: the following trait bounds were not satisfied: `, {closure@$DIR/issue-31173.rs:7:21: 7:25}> as Iterator>::Item = &_`