|
1 | 1 | //! A bunch of methods and structures more or less related to resolving macros and
|
2 | 2 | //! interface provided by `Resolver` to macro expander.
|
3 | 3 |
|
| 4 | +use crate::errors::{MacroExpectedFound, RemoveAddAsNonDerive, RemoveSurroundingDerive}; |
4 | 5 | use crate::Namespace::*;
|
5 | 6 | use crate::{BuiltinMacroState, Determinacy};
|
6 | 7 | use crate::{DeriveData, Finalize, ParentScope, ResolutionError, Resolver, ScopeSet};
|
@@ -543,21 +544,30 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
543 | 544 | };
|
544 | 545 | if let Some((article, expected)) = unexpected_res {
|
545 | 546 | let path_str = pprust::path_to_string(path);
|
546 |
| - let msg = format!("expected {}, found {} `{}`", expected, res.descr(), path_str); |
547 |
| - let mut err = self.tcx.sess.struct_span_err(path.span, &msg); |
548 | 547 |
|
549 |
| - err.span_label(path.span, format!("not {} {}", article, expected)); |
| 548 | + let mut err = MacroExpectedFound { |
| 549 | + span: path.span, |
| 550 | + expected, |
| 551 | + found: res.descr(), |
| 552 | + macro_path: &path_str, |
| 553 | + ..Default::default() // Subdiagnostics default to None |
| 554 | + }; |
550 | 555 |
|
551 |
| - // Suggest moving the macro out of the derive() as the macro isn't Derive |
| 556 | + // Suggest moving the macro out of the derive() if the macro isn't Derive |
552 | 557 | if !path.span.from_expansion()
|
553 | 558 | && kind == MacroKind::Derive
|
554 | 559 | && ext.macro_kind() != MacroKind::Derive
|
555 | 560 | {
|
556 |
| - err.span_help(path.span, "remove from the surrounding `derive()`"); |
557 |
| - err.help(format!("add as non-Derive macro\n`#[{}]`", path_str)); |
| 561 | + err.remove_surrounding_derive = Some(RemoveSurroundingDerive { span: path.span }); |
| 562 | + err.remove_surrounding_derive_help = |
| 563 | + Some(RemoveAddAsNonDerive { macro_path: &path_str }); |
558 | 564 | }
|
559 | 565 |
|
| 566 | + let mut err = self.tcx.sess.create_err(err); |
| 567 | + err.span_label(path.span, format!("not {} {}", article, expected)); |
| 568 | + |
560 | 569 | err.emit();
|
| 570 | + |
561 | 571 | return Ok((self.dummy_ext(kind), Res::Err));
|
562 | 572 | }
|
563 | 573 |
|
|
0 commit comments