Skip to content

Commit

Permalink
Make scan_expr compilable from integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Nov 2, 2024
1 parent 7c102c3 commit 0132c44
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@
clippy::wildcard_imports,
)]

extern crate self as syn;

#[cfg(feature = "proc-macro")]
extern crate proc_macro;

Expand Down
22 changes: 9 additions & 13 deletions src/scan_expr.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
use crate::expr::Member;
use crate::lifetime::Lifetime;
use crate::lit::Lit;
use crate::lit::LitFloat;
use crate::op::{BinOp, UnOp};
use crate::parse::{ParseStream, Result};
use crate::path::{self, AngleBracketedGenericArguments};
use crate::token;
use crate::ty::Type;
use proc_macro2::Delimiter::{self, Brace, Bracket, Parenthesis};
use syn::parse::{ParseStream, Result};
use syn::{
token, AngleBracketedGenericArguments, BinOp, ExprPath, Lifetime, Lit, LitFloat, Member, Token,
Type, UnOp,
};

pub(crate) fn scan_expr(input: ParseStream) -> Result<()> {
let consume = |delimiter: Delimiter| {
Expand Down Expand Up @@ -44,13 +40,13 @@ pub(crate) fn scan_expr(input: ParseStream) -> Result<()> {
|| (consume![..=] || consume![..] || consume![&] || consume![_])
|| (consume(Brace) || consume(Bracket) || consume(Parenthesis)))
{
path::parsing::qpath(input, true)?;
input.parse::<ExprPath>()?;
}
}
} else if input.parse::<Option<Lifetime>>()?.is_some() && !consume![:] {
break;
} else if input.parse::<UnOp>().is_err() {
path::parsing::qpath(input, true)?;
input.parse::<ExprPath>()?;
initial = consume![!] || depth == 0 && input.peek(token::Brace);
}
} else if input.is_empty() || input.peek(Token![,]) {
Expand All @@ -65,9 +61,9 @@ pub(crate) fn scan_expr(input: ParseStream) -> Result<()> {
initial = true;
} else if consume![.] {
if input.parse::<Option<LitFloat>>()?.is_none()
&& (input.parse::<Member>()?.is_named() && consume![::])
&& (matches!(input.parse()?, Member::Named(_)) && input.peek(Token![::]))
{
AngleBracketedGenericArguments::do_parse(None, input)?;
input.parse::<AngleBracketedGenericArguments>()?;
}
} else if consume![as] {
input.parse::<Type>()?;
Expand Down
4 changes: 4 additions & 0 deletions tests/test_precedence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ mod macros;
mod common;
mod repo;

#[path = "../src/scan_expr.rs"]
#[allow(dead_code)]
mod scan_expr;

#[test]
fn test_rustc_precedence() {
repo::rayon_init();
Expand Down

0 comments on commit 0132c44

Please sign in to comment.