Skip to content

Commit

Permalink
Remove use of nested-or-patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
CAD97 committed Sep 25, 2021
1 parent 5286ab6 commit d08fce8
Showing 1 changed file with 27 additions and 15 deletions.
42 changes: 27 additions & 15 deletions tracing-subscriber/src/filter/env/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ macro_rules! switch_syntax {
}) => {{
let haystack: &str = &$haystack;
match find_syntax(haystack) {
$((ix, $(switch_syntax!(@syntax $needle))|+) => {
$($((ix, switch_syntax!(@syntax $needle)))|+ => {
#[allow(unused_variables)]
let $ix = ix;
$expr
Expand Down Expand Up @@ -137,10 +137,12 @@ pub(super) fn parse_one_directive(source: &str) -> (Result<Directive, ParseError
(None, _) => (Err(ParseErrorKind::Other), source.len()),
(Some(quoted), after_quoted) => match source.as_bytes().get(1 + after_quoted) {
None => (Err(ParseErrorKind::Other), source.len()),
Some(&syntax @ (b'/' | b'[' | b'}' | b'"' | b',' | b'=')) => (
Err(ParseErrorKind::UnexpectedSyntax(syntax as char)),
source.len(),
),
Some(b'/') => (Err(ParseErrorKind::UnexpectedSyntax('/')), source.len()),
Some(b'[') => (Err(ParseErrorKind::UnexpectedSyntax('[')), source.len()),
Some(b'}') => (Err(ParseErrorKind::UnexpectedSyntax('}')), source.len()),
Some(b'"') => (Err(ParseErrorKind::UnexpectedSyntax('"')), source.len()),
Some(b',') => (Err(ParseErrorKind::UnexpectedSyntax(',')), source.len()),
Some(b'=') => (Err(ParseErrorKind::UnexpectedSyntax('=')), source.len()),
Some(b']') => {
let (parsed, after_parsed) = parse_at_level(
&source[1 + after_quoted + 1..],
Expand Down Expand Up @@ -388,12 +390,20 @@ pub(super) fn parse_one_directive(source: &str) -> (Result<Directive, ParseError
match source[i..].as_bytes().get(0) {
None => (directive, i),
Some(b',') => (directive, i + 1),
Some(&syntax @ (b'[' | b'{' | b'"' | b'/')) => (
Err(ParseErrorKind::UnexpectedSyntax(syntax as char)),
source.len(),
Some(b'[') => (Err(ParseErrorKind::UnexpectedSyntax('[')), source.len()),
Some(b'{') => (Err(ParseErrorKind::UnexpectedSyntax('{')), source.len()),
Some(b'"') => (Err(ParseErrorKind::UnexpectedSyntax('"')), source.len()),
Some(b'/') => (Err(ParseErrorKind::UnexpectedSyntax('/')), source.len()),
Some(b']') => (
Err(ParseErrorKind::UnexpectedSyntax(']')),
try_recover_with(source, i + 1, Syntax::Comma),
),
Some(&syntax @ (b']' | b'}' | b'=')) => (
Err(ParseErrorKind::UnexpectedSyntax(syntax as char)),
Some(b'}') => (
Err(ParseErrorKind::UnexpectedSyntax('}')),
try_recover_with(source, i + 1, Syntax::Comma),
),
Some(b'=') => (
Err(ParseErrorKind::UnexpectedSyntax('=')),
try_recover_with(source, i + 1, Syntax::Comma),
),
_ => (
Expand Down Expand Up @@ -425,12 +435,14 @@ pub(super) fn parse_one_directive(source: &str) -> (Result<Directive, ParseError
}),
after_quoted + 1,
),
Some(&syntax @ (b'/' | b'{')) => (
Err(ParseErrorKind::UnexpectedSyntax(syntax as char)),
source.len(),
Some(b'/') => (Err(ParseErrorKind::UnexpectedSyntax('/')), source.len()),
Some(b'{') => (Err(ParseErrorKind::UnexpectedSyntax('{')), source.len()),
Some(b']') => (
Err(ParseErrorKind::UnexpectedSyntax(']')),
try_recover_with(source, after_quoted + 1, Syntax::Comma),
),
Some(&syntax @ (b']' | b'}')) => (
Err(ParseErrorKind::UnexpectedSyntax(syntax as char)),
Some(b'}') => (
Err(ParseErrorKind::UnexpectedSyntax('}')),
try_recover_with(source, after_quoted + 1, Syntax::Comma),
),
Some(b'[') => {
Expand Down

0 comments on commit d08fce8

Please sign in to comment.