1
Fork 0

Moved structs to rustc_expand::errors, added several more migrations, fixed slug name

This commit is contained in:
nidnogg 2022-08-17 11:18:19 -03:00
parent 72ce216def
commit c6f9a9c410
5 changed files with 70 additions and 36 deletions

View file

@ -10,5 +10,13 @@ expand_expr_repeat_no_syntax_vars =
expand_must_repeat_once = expand_must_repeat_once =
this must repeat at least once this must repeat at least once
count_repetition_misplaced = expand_count_repetition_misplaced =
`count` can not be placed inside the inner-most repetition `count` can not be placed inside the inner-most repetition
expand_meta_var_expr_unrecognized_var =
variable `{$key}` is not recognized in meta-variable expression
expand_var_still_repeating =
variable '{$ident}' is still repeating at this depth
expand_meta_var_dif_seq_matchers = {$msg}

View file

@ -8,7 +8,7 @@ use rustc_error_messages::FluentValue;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_lint_defs::{Applicability, LintExpectationId}; use rustc_lint_defs::{Applicability, LintExpectationId};
use rustc_span::edition::LATEST_STABLE_EDITION; use rustc_span::edition::LATEST_STABLE_EDITION;
use rustc_span::symbol::{Ident, Symbol}; use rustc_span::symbol::{Ident, MacroRulesNormalizedIdent, Symbol};
use rustc_span::{edition::Edition, Span, DUMMY_SP}; use rustc_span::{edition::Edition, Span, DUMMY_SP};
use std::borrow::Cow; use std::borrow::Cow;
use std::fmt; use std::fmt;
@ -87,6 +87,7 @@ into_diagnostic_arg_using_display!(
hir::Target, hir::Target,
Edition, Edition,
Ident, Ident,
MacroRulesNormalizedIdent,
); );
impl IntoDiagnosticArg for bool { impl IntoDiagnosticArg for bool {

View file

@ -0,0 +1,50 @@
use rustc_macros::SessionDiagnostic;
use rustc_span::Span;
use rustc_span::symbol::{MacroRulesNormalizedIdent};
#[derive(SessionDiagnostic)]
#[error(expand::expr_repeat_no_syntax_vars)]
pub(crate) struct NoSyntaxVarsExprRepeat {
#[primary_span]
pub span: Span,
}
#[derive(SessionDiagnostic)]
#[error(expand::must_repeat_once)]
pub(crate) struct MustRepeatOnce {
#[primary_span]
pub span: Span,
}
#[derive(SessionDiagnostic)]
#[error(expand::count_repetition_misplaced)]
pub(crate) struct CountRepetitionMisplaced {
#[primary_span]
pub span: Span,
}
#[derive(SessionDiagnostic)]
#[error(expand::meta_var_expr_unrecognized_var)]
pub(crate) struct MetaVarExprUnrecognizedVar {
#[primary_span]
pub span: Span,
pub key: MacroRulesNormalizedIdent,
}
#[derive(SessionDiagnostic)]
#[error(expand::var_still_repeating)]
pub(crate) struct VarStillRepeating {
#[primary_span]
pub span: Span,
pub ident: MacroRulesNormalizedIdent,
}
#[derive(SessionDiagnostic)]
#[error(expand::var_still_repeating)]
pub(crate) struct MetaVarsDifSeqMatchers {
#[primary_span]
pub span: Span,
pub msg: String,
}

View file

@ -25,6 +25,7 @@ pub mod base;
pub mod build; pub mod build;
#[macro_use] #[macro_use]
pub mod config; pub mod config;
pub mod errors;
pub mod expand; pub mod expand;
pub mod module; pub mod module;
pub mod proc_macro; pub mod proc_macro;

View file

@ -1,4 +1,8 @@
use crate::base::ExtCtxt; use crate::base::ExtCtxt;
use crate::errors::{
CountRepetitionMisplaced, MetaVarExprUnrecognizedVar, MetaVarsDifSeqMatchers, MustRepeatOnce,
NoSyntaxVarsExprRepeat, VarStillRepeating,
};
use crate::mbe::macro_parser::{MatchedNonterminal, MatchedSeq, MatchedTokenTree, NamedMatch}; use crate::mbe::macro_parser::{MatchedNonterminal, MatchedSeq, MatchedTokenTree, NamedMatch};
use crate::mbe::{self, MetaVarExpr}; use crate::mbe::{self, MetaVarExpr};
use rustc_ast::mut_visit::{self, MutVisitor}; use rustc_ast::mut_visit::{self, MutVisitor};
@ -7,7 +11,6 @@ use rustc_ast::tokenstream::{DelimSpan, Spacing, TokenStream, TokenTree};
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_errors::{pluralize, PResult}; use rustc_errors::{pluralize, PResult};
use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed}; use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed};
use rustc_macros::SessionDiagnostic;
use rustc_span::hygiene::{LocalExpnId, Transparency}; use rustc_span::hygiene::{LocalExpnId, Transparency};
use rustc_span::symbol::{sym, Ident, MacroRulesNormalizedIdent}; use rustc_span::symbol::{sym, Ident, MacroRulesNormalizedIdent};
use rustc_span::Span; use rustc_span::Span;
@ -54,20 +57,6 @@ impl<'a> Iterator for Frame<'a> {
} }
} }
#[derive(SessionDiagnostic)]
#[error(expand::expr_repeat_no_syntax_vars)]
struct NoSyntaxVarsExprRepeat {
#[primary_span]
span: Span,
}
#[derive(SessionDiagnostic)]
#[error(expand::must_repeat_once)]
struct MustRepeatOnce {
#[primary_span]
span: Span,
}
/// This can do Macro-By-Example transcription. /// This can do Macro-By-Example transcription.
/// - `interp` is a map of meta-variables to the tokens (non-terminals) they matched in the /// - `interp` is a map of meta-variables to the tokens (non-terminals) they matched in the
/// invocation. We are assuming we already know there is a match. /// invocation. We are assuming we already know there is a match.
@ -188,7 +177,7 @@ pub(super) fn transcribe<'a>(
// happens when two meta-variables are used in the same repetition in a // happens when two meta-variables are used in the same repetition in a
// sequence, but they come from different sequence matchers and repeat // sequence, but they come from different sequence matchers and repeat
// different amounts. // different amounts.
return Err(cx.struct_span_err(seq.span(), &msg)); return Err(cx.create_err(MetaVarsDifSeqMatchers { span: seq.span(), msg }));
} }
LockstepIterSize::Constraint(len, _) => { LockstepIterSize::Constraint(len, _) => {
@ -247,10 +236,7 @@ pub(super) fn transcribe<'a>(
} }
MatchedSeq(..) => { MatchedSeq(..) => {
// We were unable to descend far enough. This is an error. // We were unable to descend far enough. This is an error.
return Err(cx.struct_span_err( return Err(cx.create_err(VarStillRepeating { span: sp, ident }));
sp, /* blame the macro writer */
&format!("variable '{}' is still repeating at this depth", ident),
));
} }
} }
} else { } else {
@ -428,13 +414,6 @@ fn lockstep_iter_size(
} }
} }
#[derive(SessionDiagnostic)]
#[error(expand::count_repetition_misplaced)]
struct CountRepetitionMisplaced {
#[primary_span]
span: Span,
}
/// Used solely by the `count` meta-variable expression, counts the outer-most repetitions at a /// Used solely by the `count` meta-variable expression, counts the outer-most repetitions at a
/// given optional nested depth. /// given optional nested depth.
/// ///
@ -511,12 +490,7 @@ where
{ {
let span = ident.span; let span = ident.span;
let key = MacroRulesNormalizedIdent::new(ident); let key = MacroRulesNormalizedIdent::new(ident);
interp.get(&key).ok_or_else(|| { interp.get(&key).ok_or_else(|| cx.create_err(MetaVarExprUnrecognizedVar { span, key }))
cx.struct_span_err(
span,
&format!("variable `{}` is not recognized in meta-variable expression", key),
)
})
} }
/// Used by meta-variable expressions when an user input is out of the actual declared bounds. For /// Used by meta-variable expressions when an user input is out of the actual declared bounds. For