Skip to content

Commit fb8396d

Browse files
authored
Rollup merge of #59574 - JohnTitor:distinguish-error-vs-warning, r=Centril
Distinguish message for external macros depending on error level fixes #57716 (I picked you because assigned to this issue.) r? @estebank
2 parents 61222b5 + 45c82ab commit fb8396d

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

src/librustc_errors/emitter.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::{
66
Level, CodeSuggestion, DiagnosticBuilder, SubDiagnostic,
77
SuggestionStyle, SourceMapperDyn, DiagnosticId,
88
};
9+
use crate::Level::Error;
910
use crate::snippet::{Annotation, AnnotationType, Line, MultilineAnnotation, StyledString, Style};
1011
use crate::styled_buffer::StyledBuffer;
1112

@@ -72,6 +73,7 @@ impl Emitter for EmitterWriter {
7273

7374
self.fix_multispans_in_std_macros(&mut primary_span,
7475
&mut children,
76+
&db.level,
7577
db.handler.flags.external_macro_backtrace);
7678

7779
self.emit_messages_default(&db.level,
@@ -888,18 +890,27 @@ impl EmitterWriter {
888890
fn fix_multispans_in_std_macros(&mut self,
889891
span: &mut MultiSpan,
890892
children: &mut Vec<SubDiagnostic>,
893+
level: &Level,
891894
backtrace: bool) {
892895
let mut spans_updated = self.fix_multispan_in_std_macros(span, backtrace);
893896
for child in children.iter_mut() {
894897
spans_updated |= self.fix_multispan_in_std_macros(&mut child.span, backtrace);
895898
}
899+
let msg = if level == &Error {
900+
"this error originates in a macro outside of the current crate \
901+
(in Nightly builds, run with -Z external-macro-backtrace \
902+
for more info)".to_string()
903+
} else {
904+
"this warning originates in a macro outside of the current crate \
905+
(in Nightly builds, run with -Z external-macro-backtrace \
906+
for more info)".to_string()
907+
};
908+
896909
if spans_updated {
897910
children.push(SubDiagnostic {
898911
level: Level::Note,
899912
message: vec![
900-
("this error originates in a macro outside of the current crate \
901-
(in Nightly builds, run with -Z external-macro-backtrace \
902-
for more info)".to_string(),
913+
(msg,
903914
Style::NoStyle),
904915
],
905916
span: MultiSpan::new(),

src/test/ui/imports/import-crate-var.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ LL | m!();
55
| ^^^^^
66
|
77
= note: `use $crate;` was erroneously allowed and will become a hard error in a future release
8-
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
8+
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
99

src/test/ui/macros/must-use-in-macro-55516.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ LL | write!(&mut example, "{}", 42);
66
|
77
= note: `-W unused-must-use` implied by `-W unused`
88
= note: this `Result` may be an `Err` variant, which should be handled
9-
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
9+
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
1010

0 commit comments

Comments
 (0)