diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 8df3b685829d..88ed3128164d 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -1365,6 +1365,14 @@ impl HumanEmitter { ); line += 1; } + // We add lines above, but if the last line has no explicit newline (which would + // yield an empty line), then we revert one line up to continue with the next + // styled text chunk on the same line as the last one from the prior one. Otherwise + // every `text` would appear on their own line (because even though they didn't end + // in '\n', they advanced `line` by one). + if line > 0 { + line -= 1; + } } if self.short_message { let labels = msp diff --git a/tests/run-make/crate-loading/rmake.rs b/tests/run-make/crate-loading/rmake.rs index 2aa396fd2d97..fd5b66ae8793 100644 --- a/tests/run-make/crate-loading/rmake.rs +++ b/tests/run-make/crate-loading/rmake.rs @@ -13,19 +13,15 @@ fn main() { .input("multiple-dep-versions.rs") .extern_("dependency", rust_lib_name("dependency")) .extern_("dep_2_reexport", rust_lib_name("dependency2")) - .inspect(|cmd| eprintln!("{cmd:?}")) - .run_fail(); - let stderr = out.stderr_utf8(); - assert_contains( - &stderr, - "you have multiple different versions of crate `dependency` in your dependency graph", - ); - assert_contains( - &stderr, - "two types coming from two different versions of the same crate are different types even \ - if they look the same", - ); - assert_contains(&stderr, "this type doesn't implement the required trait"); - assert_contains(&stderr, "this type implements the required trait"); - assert_contains(&stderr, "this is the required trait"); + .run_fail() + .assert_stderr_contains( + "you have multiple different versions of crate `dependency` in your dependency graph", + ) + .assert_stderr_contains( + "two types coming from two different versions of the same crate are different types \ + even if they look the same", + ) + .assert_stderr_contains("this type doesn't implement the required trait") + .assert_stderr_contains("this type implements the required trait") + .assert_stderr_contains("this is the required trait"); }