summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_parse/src/validate_attr.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
commit9835e2ae736235810b4ea1c162ca5e65c547e770 (patch)
tree3fcebf40ed70e581d776a8a4c65923e8ec20e026 /compiler/rustc_parse/src/validate_attr.rs
parentReleasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff)
downloadrustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz
rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_parse/src/validate_attr.rs')
-rw-r--r--compiler/rustc_parse/src/validate_attr.rs33
1 files changed, 19 insertions, 14 deletions
diff --git a/compiler/rustc_parse/src/validate_attr.rs b/compiler/rustc_parse/src/validate_attr.rs
index 72402a200..928fdce31 100644
--- a/compiler/rustc_parse/src/validate_attr.rs
+++ b/compiler/rustc_parse/src/validate_attr.rs
@@ -1,6 +1,6 @@
//! Meta-syntax validation logic of attributes for post-expansion.
-use crate::parse_in;
+use crate::{errors, parse_in};
use rustc_ast::tokenstream::DelimSpan;
use rustc_ast::MetaItemKind;
@@ -45,7 +45,7 @@ pub fn parse_meta<'a>(sess: &'a ParseSess, attr: &Attribute) -> PResult<'a, Meta
kind: match &item.args {
AttrArgs::Empty => MetaItemKind::Word,
AttrArgs::Delimited(DelimArgs { dspan, delim, tokens }) => {
- check_meta_bad_delim(sess, *dspan, *delim, "wrong meta list delimiters");
+ check_meta_bad_delim(sess, *dspan, *delim);
let nmis = parse_in(sess, tokens.clone(), "meta list", |p| p.parse_meta_seq_top())?;
MetaItemKind::List(nmis)
}
@@ -68,7 +68,7 @@ pub fn parse_meta<'a>(sess: &'a ParseSess, attr: &Attribute) -> PResult<'a, Meta
}
} else {
// The non-error case can happen with e.g. `#[foo = 1+1]`. The error case can
- // happen with e.g. `#[foo = include_str!("non-existent-file.rs")]`; in that
+ // happen with e.g. `#[foo = include_str!("nonexistent-file.rs")]`; in that
// case we delay the error because an earlier error will have already been
// reported.
let msg = format!("unexpected expression: `{}`", pprust::expr_to_string(expr));
@@ -84,19 +84,24 @@ pub fn parse_meta<'a>(sess: &'a ParseSess, attr: &Attribute) -> PResult<'a, Meta
})
}
-pub fn check_meta_bad_delim(sess: &ParseSess, span: DelimSpan, delim: MacDelimiter, msg: &str) {
+pub fn check_meta_bad_delim(sess: &ParseSess, span: DelimSpan, delim: MacDelimiter) {
if let ast::MacDelimiter::Parenthesis = delim {
return;
}
+ sess.emit_err(errors::MetaBadDelim {
+ span: span.entire(),
+ sugg: errors::MetaBadDelimSugg { open: span.open, close: span.close },
+ });
+}
- sess.span_diagnostic
- .struct_span_err(span.entire(), msg)
- .multipart_suggestion(
- "the delimiters should be `(` and `)`",
- vec![(span.open, "(".to_string()), (span.close, ")".to_string())],
- Applicability::MachineApplicable,
- )
- .emit();
+pub fn check_cfg_attr_bad_delim(sess: &ParseSess, span: DelimSpan, delim: MacDelimiter) {
+ if let ast::MacDelimiter::Parenthesis = delim {
+ return;
+ }
+ sess.emit_err(errors::CfgAttrBadDelim {
+ span: span.entire(),
+ sugg: errors::MetaBadDelimSugg { open: span.open, close: span.close },
+ });
}
/// Checks that the given meta-item is compatible with this `AttributeTemplate`.
@@ -181,10 +186,10 @@ fn emit_malformed_attribute(
suggestions.push(code);
}
if should_warn(name) {
- sess.buffer_lint(&ILL_FORMED_ATTRIBUTE_INPUT, span, ast::CRATE_NODE_ID, &msg);
+ sess.buffer_lint(&ILL_FORMED_ATTRIBUTE_INPUT, span, ast::CRATE_NODE_ID, msg);
} else {
sess.span_diagnostic
- .struct_span_err(span, &error_msg)
+ .struct_span_err(span, error_msg)
.span_suggestions(
span,
if suggestions.len() == 1 {