Skip to content

Commit

Permalink
Merge pull request #1574 from dtolnay/precedence
Browse files Browse the repository at this point in the history
Move expression Precedence enum to own module
  • Loading branch information
dtolnay authored Jan 2, 2024
2 parents 6bfa278 + 36182d4 commit 61dee89
Showing 1 changed file with 31 additions and 25 deletions.
56 changes: 31 additions & 25 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -957,31 +957,10 @@ pub(crate) fn requires_terminator(expr: &Expr) -> bool {
}

#[cfg(feature = "parsing")]
pub(crate) mod parsing {
use super::*;
#[cfg(feature = "full")]
use crate::ext::IdentExt as _;
use crate::parse::discouraged::Speculative as _;
#[cfg(feature = "full")]
use crate::parse::ParseBuffer;
use crate::parse::{Parse, ParseStream, Result};
use crate::path;
use std::cmp::Ordering;
mod precedence {
use super::BinOp;

mod kw {
crate::custom_keyword!(builtin);
crate::custom_keyword!(raw);
}

// When we're parsing expressions which occur before blocks, like in an if
// statement's condition, we cannot parse a struct literal.
//
// Struct literals are ambiguous in certain positions
// https://github.com/rust-lang/rfcs/pull/92
#[cfg(feature = "full")]
pub(crate) struct AllowStruct(bool);

enum Precedence {
pub(crate) enum Precedence {
Any,
Assign,
Range,
Expand All @@ -998,7 +977,7 @@ pub(crate) mod parsing {
}

impl Precedence {
fn of(op: &BinOp) -> Self {
pub(crate) fn of(op: &BinOp) -> Self {
match op {
BinOp::Add(_) | BinOp::Sub(_) => Precedence::Arithmetic,
BinOp::Mul(_) | BinOp::Div(_) | BinOp::Rem(_) => Precedence::Term,
Expand Down Expand Up @@ -1027,6 +1006,33 @@ pub(crate) mod parsing {
}
}
}
}

#[cfg(feature = "parsing")]
pub(crate) mod parsing {
use super::precedence::Precedence;
use super::*;
#[cfg(feature = "full")]
use crate::ext::IdentExt as _;
use crate::parse::discouraged::Speculative as _;
#[cfg(feature = "full")]
use crate::parse::ParseBuffer;
use crate::parse::{Parse, ParseStream, Result};
use crate::path;
use std::cmp::Ordering;

mod kw {
crate::custom_keyword!(builtin);
crate::custom_keyword!(raw);
}

// When we're parsing expressions which occur before blocks, like in an if
// statement's condition, we cannot parse a struct literal.
//
// Struct literals are ambiguous in certain positions
// https://github.com/rust-lang/rfcs/pull/92
#[cfg(feature = "full")]
pub(crate) struct AllowStruct(bool);

#[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
impl Parse for Expr {
Expand Down

0 comments on commit 61dee89

Please sign in to comment.