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 b32dd8f..dd5dbe8 100644 --- a/tests/rustc_tests.rs +++ b/tests/rustc_tests.rs @@ -3370,3 +3370,78 @@ 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); +}