From 7a4fd3e1e9ecfa5c6b5c00f14b0c192a2785152a Mon Sep 17 00:00:00 2001 From: Scott Schafer Date: Thu, 3 Jul 2025 14:48:28 -0600 Subject: [PATCH 1/2] test: Add test for Message text ending with \n --- tests/rustc_tests.rs | 74 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/tests/rustc_tests.rs b/tests/rustc_tests.rs index b32dd8f..52e8bbe 100644 --- a/tests/rustc_tests.rs +++ b/tests/rustc_tests.rs @@ -3370,3 +3370,77 @@ note: the traits `Iterator` and `ToTokens` must be implemented let renderer = renderer.theme(OutputTheme::Unicode); assert_data_eq!(renderer.render(input), expected_unicode); } + +#[test] +fn not_found_self_type_differs_shadowing_trait_item() { + // tests/ui/associated-inherent-types/not-found-self-type-differs-shadowing-trait-item.rs + + let source = r#"#![feature(inherent_associated_types)] +#![allow(incomplete_features)] + +// Check that it's okay to report “[inherent] associated type […] not found” for inherent associated +// type candidates that are not applicable (due to unsuitable Self type) even if there exists a +// “shadowed” associated type from a trait with the same name since its use would be ambiguous +// anyway if the IAT didn't exist. +// FIXME(inherent_associated_types): Figure out which error would be more helpful here. + +//@ revisions: shadowed uncovered + +struct S(T); + +trait Tr { + type Pr; +} + +impl Tr for S { + type Pr = (); +} + +#[cfg(shadowed)] +impl S<()> { + type Pr = i32; +} + +fn main() { + let _: S::::Pr = (); + //[shadowed]~^ ERROR associated type `Pr` not found + //[uncovered]~^^ ERROR associated type `Pr` not found +} +"#; + + let input = &[Group::with_title( + Level::ERROR + .title("associated type `Pr` not found for `S` in the current scope") + .id("E0220"), + ) + .element( + Snippet::source(source) + .path("$DIR/not-found-self-type-differs-shadowing-trait-item.rs") + .annotation( + AnnotationKind::Primary + .span(705..707) + .label("associated item not found in `S`"), + ) + .annotation( + AnnotationKind::Context + .span(532..543) + .label("associated type `Pr` not found for this struct"), + ), + ) + .element(Level::NOTE.title("the associated type was found for\n"))]; + + let expected = str![[r#" +error[E0220]: associated type `Pr` not found for `S` in the current scope + --> $DIR/not-found-self-type-differs-shadowing-trait-item.rs:28:23 + | +LL | struct S(T); + | ----------- associated type `Pr` not found for this struct +... +LL | let _: S::::Pr = (); + | ^^ associated item not found in `S` + | + = note: the associated type was found for +"#]]; + let renderer = Renderer::plain().anonymized_line_numbers(true); + assert_data_eq!(renderer.render(input), expected); +} From 82abe2699d655cb946bbf7684b67a5e7291051f2 Mon Sep 17 00:00:00 2001 From: Scott Schafer Date: Thu, 3 Jul 2025 14:56:12 -0600 Subject: [PATCH 2/2] fix: Render newline if a Message ends with one --- src/renderer/mod.rs | 2 +- tests/rustc_tests.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs index 80a8811..8d3c6a2 100644 --- a/src/renderer/mod.rs +++ b/src/renderer/mod.rs @@ -636,7 +636,7 @@ impl Renderer { } else { (normalize_whitespace(title.text()), title_element_style) }; - for (i, text) in title_str.lines().enumerate() { + for (i, text) in title_str.split('\n').enumerate() { if i != 0 { buffer.append(buffer_msg_line_offset + i, &padding, ElementStyle::NoStyle); if title_style == TitleStyle::Secondary diff --git a/tests/rustc_tests.rs b/tests/rustc_tests.rs index 52e8bbe..dd5dbe8 100644 --- a/tests/rustc_tests.rs +++ b/tests/rustc_tests.rs @@ -3440,6 +3440,7 @@ LL | let _: S::::Pr = (); | ^^ associated item not found in `S` | = note: the associated type was found for + "#]]; let renderer = Renderer::plain().anonymized_line_numbers(true); assert_data_eq!(renderer.render(input), expected);