mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Rollup merge of #118317 - bvanjoi:fix-118295, r=petrochenkov
tip for define macro name after `macro_rules!` Fixes #118295 ~Note that there are some bad case such as `macro_rules![]` or `macro_rules!()`. However, I think these are acceptable as they are likely to be seldom used (feel free to close this if you think its shortcomings outweigh its benefits)~ Edit: this problem was resolved by utilizing the `source_map.span_to_next_source`. r? `@petrochenkov`
This commit is contained in:
commit
aefbbc6dc6
@ -181,6 +181,8 @@ resolve_method_not_member_of_trait =
|
|||||||
method `{$method}` is not a member of trait `{$trait_}`
|
method `{$method}` is not a member of trait `{$trait_}`
|
||||||
.label = not a member of trait `{$trait_}`
|
.label = not a member of trait `{$trait_}`
|
||||||
|
|
||||||
|
resolve_missing_macro_rules_name = maybe you have forgotten to define a name for this `macro_rules!`
|
||||||
|
|
||||||
resolve_module_only =
|
resolve_module_only =
|
||||||
visibility must resolve to a module
|
visibility must resolve to a module
|
||||||
|
|
||||||
|
@ -27,10 +27,8 @@ use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
|||||||
use rustc_span::{BytePos, Span, SyntaxContext};
|
use rustc_span::{BytePos, Span, SyntaxContext};
|
||||||
use thin_vec::{thin_vec, ThinVec};
|
use thin_vec::{thin_vec, ThinVec};
|
||||||
|
|
||||||
use crate::errors::{
|
use crate::errors::{AddedMacroUse, ChangeImportBinding, ChangeImportBindingSuggestion};
|
||||||
AddedMacroUse, ChangeImportBinding, ChangeImportBindingSuggestion, ConsiderAddingADerive,
|
use crate::errors::{ConsiderAddingADerive, ExplicitUnsafeTraits, MaybeMissingMacroRulesName};
|
||||||
ExplicitUnsafeTraits,
|
|
||||||
};
|
|
||||||
use crate::imports::{Import, ImportKind};
|
use crate::imports::{Import, ImportKind};
|
||||||
use crate::late::{PatternSource, Rib};
|
use crate::late::{PatternSource, Rib};
|
||||||
use crate::path_names_to_string;
|
use crate::path_names_to_string;
|
||||||
@ -1421,14 +1419,21 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||||||
"",
|
"",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if macro_kind == MacroKind::Bang && ident.name == sym::macro_rules {
|
||||||
|
err.subdiagnostic(MaybeMissingMacroRulesName { span: ident.span });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if macro_kind == MacroKind::Derive && (ident.name == sym::Send || ident.name == sym::Sync) {
|
if macro_kind == MacroKind::Derive && (ident.name == sym::Send || ident.name == sym::Sync) {
|
||||||
err.subdiagnostic(ExplicitUnsafeTraits { span: ident.span, ident });
|
err.subdiagnostic(ExplicitUnsafeTraits { span: ident.span, ident });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.macro_names.contains(&ident.normalize_to_macros_2_0()) {
|
if self.macro_names.contains(&ident.normalize_to_macros_2_0()) {
|
||||||
err.subdiagnostic(AddedMacroUse);
|
err.subdiagnostic(AddedMacroUse);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ident.name == kw::Default
|
if ident.name == kw::Default
|
||||||
&& let ModuleKind::Def(DefKind::Enum, def_id, _) = parent_scope.module.kind
|
&& let ModuleKind::Def(DefKind::Enum, def_id, _) = parent_scope.module.kind
|
||||||
{
|
{
|
||||||
|
@ -665,6 +665,13 @@ pub(crate) struct ExplicitUnsafeTraits {
|
|||||||
pub(crate) ident: Ident,
|
pub(crate) ident: Ident,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Subdiagnostic)]
|
||||||
|
#[note(resolve_missing_macro_rules_name)]
|
||||||
|
pub(crate) struct MaybeMissingMacroRulesName {
|
||||||
|
#[primary_span]
|
||||||
|
pub(crate) span: Span,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Subdiagnostic)]
|
#[derive(Subdiagnostic)]
|
||||||
#[help(resolve_added_macro_use)]
|
#[help(resolve_added_macro_use)]
|
||||||
pub(crate) struct AddedMacroUse;
|
pub(crate) struct AddedMacroUse;
|
||||||
|
5
tests/ui/resolve/issue-118295.rs
Normal file
5
tests/ui/resolve/issue-118295.rs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
macro_rules! {}
|
||||||
|
//~^ ERROR cannot find macro `macro_rules` in this scope
|
||||||
|
//~| NOTE maybe you have forgotten to define a name for this `macro_rules!`
|
||||||
|
|
||||||
|
fn main() {}
|
14
tests/ui/resolve/issue-118295.stderr
Normal file
14
tests/ui/resolve/issue-118295.stderr
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
error: cannot find macro `macro_rules` in this scope
|
||||||
|
--> $DIR/issue-118295.rs:1:1
|
||||||
|
|
|
||||||
|
LL | macro_rules! {}
|
||||||
|
| ^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
note: maybe you have forgotten to define a name for this `macro_rules!`
|
||||||
|
--> $DIR/issue-118295.rs:1:1
|
||||||
|
|
|
||||||
|
LL | macro_rules! {}
|
||||||
|
| ^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to 1 previous error
|
||||||
|
|
Loading…
Reference in New Issue
Block a user