Diagnostic for using macro_rules macro as attr/derive
This commit is contained in:
parent
8522140caa
commit
4627db2a10
6 changed files with 58 additions and 34 deletions
|
@ -35,7 +35,8 @@ use tracing::debug;
|
|||
|
||||
use crate::errors::{
|
||||
self, AddedMacroUse, ChangeImportBinding, ChangeImportBindingSuggestion, ConsiderAddingADerive,
|
||||
ExplicitUnsafeTraits, MacroDefinedLater, MacroSuggMovePosition, MaybeMissingMacroRulesName,
|
||||
ExplicitUnsafeTraits, MacroDefinedLater, MacroRulesNot, MacroSuggMovePosition,
|
||||
MaybeMissingMacroRulesName,
|
||||
};
|
||||
use crate::imports::{Import, ImportKind};
|
||||
use crate::late::{PatternSource, Rib};
|
||||
|
@ -1475,8 +1476,19 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
let scope = self.local_macro_def_scopes[&def_id];
|
||||
let parent_nearest = parent_scope.module.nearest_parent_mod();
|
||||
if Some(parent_nearest) == scope.opt_def_id() {
|
||||
err.subdiagnostic(MacroDefinedLater { span: unused_ident.span });
|
||||
err.subdiagnostic(MacroSuggMovePosition { span: ident.span, ident });
|
||||
match macro_kind {
|
||||
MacroKind::Bang => {
|
||||
err.subdiagnostic(MacroDefinedLater { span: unused_ident.span });
|
||||
err.subdiagnostic(MacroSuggMovePosition { span: ident.span, ident });
|
||||
}
|
||||
MacroKind::Attr => {
|
||||
err.subdiagnostic(MacroRulesNot::Attr { span: unused_ident.span, ident });
|
||||
}
|
||||
MacroKind::Derive => {
|
||||
err.subdiagnostic(MacroRulesNot::Derive { span: unused_ident.span, ident });
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -665,6 +665,22 @@ pub(crate) struct MacroSuggMovePosition {
|
|||
pub(crate) ident: Ident,
|
||||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
pub(crate) enum MacroRulesNot {
|
||||
#[label(resolve_macro_cannot_use_as_attr)]
|
||||
Attr {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
ident: Ident,
|
||||
},
|
||||
#[label(resolve_macro_cannot_use_as_derive)]
|
||||
Derive {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
ident: Ident,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
#[note(resolve_missing_macro_rules_name)]
|
||||
pub(crate) struct MaybeMissingMacroRulesName {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue