Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distinguish message for external macros depending on error level #59574

Merged
merged 1 commit into from
Mar 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/librustc_errors/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::{
Level, CodeSuggestion, DiagnosticBuilder, SubDiagnostic,
SuggestionStyle, SourceMapperDyn, DiagnosticId,
};
use crate::Level::Error;
use crate::snippet::{Annotation, AnnotationType, Line, MultilineAnnotation, StyledString, Style};
use crate::styled_buffer::StyledBuffer;

Expand Down Expand Up @@ -72,6 +73,7 @@ impl Emitter for EmitterWriter {

self.fix_multispans_in_std_macros(&mut primary_span,
&mut children,
&db.level,
db.handler.flags.external_macro_backtrace);

self.emit_messages_default(&db.level,
Expand Down Expand Up @@ -856,18 +858,27 @@ impl EmitterWriter {
fn fix_multispans_in_std_macros(&mut self,
span: &mut MultiSpan,
children: &mut Vec<SubDiagnostic>,
level: &Level,
backtrace: bool) {
let mut spans_updated = self.fix_multispan_in_std_macros(span, backtrace);
for child in children.iter_mut() {
spans_updated |= self.fix_multispan_in_std_macros(&mut child.span, backtrace);
}
let msg = if level == &Error {
"this error originates in a macro outside of the current crate \
(in Nightly builds, run with -Z external-macro-backtrace \
for more info)".to_string()
} else {
"this warning originates in a macro outside of the current crate \
(in Nightly builds, run with -Z external-macro-backtrace \
for more info)".to_string()
};

if spans_updated {
children.push(SubDiagnostic {
level: Level::Note,
message: vec![
("this error originates in a macro outside of the current crate \
(in Nightly builds, run with -Z external-macro-backtrace \
for more info)".to_string(),
(msg,
Style::NoStyle),
],
span: MultiSpan::new(),
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/imports/import-crate-var.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ LL | m!();
| ^^^^^
|
= note: `use $crate;` was erroneously allowed and will become a hard error in a future release
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

2 changes: 1 addition & 1 deletion src/test/ui/macros/must-use-in-macro-55516.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ LL | write!(&mut example, "{}", 42);
|
= note: `-W unused-must-use` implied by `-W unused`
= note: this `Result` may be an `Err` variant, which should be handled
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)