diff --git a/src/data.rs b/src/data.rs
index dda2d0db03..78ba606b8a 100644
--- a/src/data.rs
+++ b/src/data.rs
@@ -157,6 +157,8 @@ ast_struct! {
pub(crate) mod parsing {
use super::*;
use crate::ext::IdentExt as _;
+ #[cfg(not(feature = "full"))]
+ use crate::parse::discouraged::Speculative as _;
use crate::parse::{Parse, ParseStream, Result};
#[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
@@ -174,7 +176,26 @@ pub(crate) mod parsing {
};
let discriminant = if input.peek(Token![=]) {
let eq_token: Token![=] = input.parse()?;
+ #[cfg(feature = "full")]
let discriminant: Expr = input.parse()?;
+ #[cfg(not(feature = "full"))]
+ let discriminant = {
+ let ahead = input.fork();
+ match ahead.parse() {
+ Ok(expr) => {
+ input.advance_to(&ahead);
+ expr
+ }
+ Err(discriminant_error) => {
+ let begin = input.fork();
+ if scan_lenient_discriminant(input).is_ok() {
+ Expr::Verbatim(verbatim::between(&begin, input))
+ } else {
+ return Err(discriminant_error);
+ }
+ }
+ }
+ };
Some((eq_token, discriminant))
} else {
None
@@ -188,6 +209,83 @@ pub(crate) mod parsing {
}
}
+ #[cfg(not(feature = "full"))]
+ pub(crate) fn scan_lenient_discriminant(input: ParseStream) -> Result<()> {
+ use proc_macro2::Delimiter::{self, Brace, Bracket, Parenthesis};
+
+ let consume = |delimiter: Delimiter| {
+ Result::unwrap(input.step(|cursor| match cursor.group(delimiter) {
+ Some((_inside, _span, rest)) => Ok((true, rest)),
+ None => Ok((false, *cursor)),
+ }))
+ };
+
+ macro_rules! consume {
+ [$token:tt] => {
+ input.parse::