Skip to content

Commit d6a436c

Browse files
authored
Unrolled build for rust-lang#118317
Rollup merge of rust-lang#118317 - bvanjoi:fix-118295, r=petrochenkov tip for define macro name after `macro_rules!` Fixes rust-lang#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`
2 parents 1fdfe12 + 0f14e8e commit d6a436c

File tree

5 files changed

+37
-4
lines changed

5 files changed

+37
-4
lines changed

compiler/rustc_resolve/messages.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ resolve_method_not_member_of_trait =
181181
method `{$method}` is not a member of trait `{$trait_}`
182182
.label = not a member of trait `{$trait_}`
183183
184+
resolve_missing_macro_rules_name = maybe you have forgotten to define a name for this `macro_rules!`
185+
184186
resolve_module_only =
185187
visibility must resolve to a module
186188

compiler/rustc_resolve/src/diagnostics.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@ use rustc_span::symbol::{kw, sym, Ident, Symbol};
2727
use rustc_span::{BytePos, Span, SyntaxContext};
2828
use thin_vec::{thin_vec, ThinVec};
2929

30-
use crate::errors::{
31-
AddedMacroUse, ChangeImportBinding, ChangeImportBindingSuggestion, ConsiderAddingADerive,
32-
ExplicitUnsafeTraits,
33-
};
30+
use crate::errors::{AddedMacroUse, ChangeImportBinding, ChangeImportBindingSuggestion};
31+
use crate::errors::{ConsiderAddingADerive, ExplicitUnsafeTraits, MaybeMissingMacroRulesName};
3432
use crate::imports::{Import, ImportKind};
3533
use crate::late::{PatternSource, Rib};
3634
use crate::path_names_to_string;
@@ -1421,14 +1419,21 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
14211419
"",
14221420
);
14231421

1422+
if macro_kind == MacroKind::Bang && ident.name == sym::macro_rules {
1423+
err.subdiagnostic(MaybeMissingMacroRulesName { span: ident.span });
1424+
return;
1425+
}
1426+
14241427
if macro_kind == MacroKind::Derive && (ident.name == sym::Send || ident.name == sym::Sync) {
14251428
err.subdiagnostic(ExplicitUnsafeTraits { span: ident.span, ident });
14261429
return;
14271430
}
1431+
14281432
if self.macro_names.contains(&ident.normalize_to_macros_2_0()) {
14291433
err.subdiagnostic(AddedMacroUse);
14301434
return;
14311435
}
1436+
14321437
if ident.name == kw::Default
14331438
&& let ModuleKind::Def(DefKind::Enum, def_id, _) = parent_scope.module.kind
14341439
{

compiler/rustc_resolve/src/errors.rs

+7
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,13 @@ pub(crate) struct ExplicitUnsafeTraits {
665665
pub(crate) ident: Ident,
666666
}
667667

668+
#[derive(Subdiagnostic)]
669+
#[note(resolve_missing_macro_rules_name)]
670+
pub(crate) struct MaybeMissingMacroRulesName {
671+
#[primary_span]
672+
pub(crate) span: Span,
673+
}
674+
668675
#[derive(Subdiagnostic)]
669676
#[help(resolve_added_macro_use)]
670677
pub(crate) struct AddedMacroUse;

tests/ui/resolve/issue-118295.rs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
macro_rules! {}
2+
//~^ ERROR cannot find macro `macro_rules` in this scope
3+
//~| NOTE maybe you have forgotten to define a name for this `macro_rules!`
4+
5+
fn main() {}

tests/ui/resolve/issue-118295.stderr

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: cannot find macro `macro_rules` in this scope
2+
--> $DIR/issue-118295.rs:1:1
3+
|
4+
LL | macro_rules! {}
5+
| ^^^^^^^^^^^
6+
|
7+
note: maybe you have forgotten to define a name for this `macro_rules!`
8+
--> $DIR/issue-118295.rs:1:1
9+
|
10+
LL | macro_rules! {}
11+
| ^^^^^^^^^^^
12+
13+
error: aborting due to 1 previous error
14+

0 commit comments

Comments
 (0)