Skip to content

Commit 3dd7a23

Browse files
committed
Fix imported syn code compilation
1 parent 3ea1499 commit 3dd7a23

File tree

4 files changed

+63
-192
lines changed

4 files changed

+63
-192
lines changed

src/classify.rs

+24-20
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,18 @@
1-
#[cfg(feature = "full")]
2-
use crate::expr::Expr;
3-
#[cfg(any(feature = "printing", feature = "full"))]
4-
use crate::generics::TypeParamBound;
5-
#[cfg(any(feature = "printing", feature = "full"))]
6-
use crate::path::{Path, PathArguments};
7-
#[cfg(any(feature = "printing", feature = "full"))]
8-
use crate::punctuated::Punctuated;
9-
#[cfg(any(feature = "printing", feature = "full"))]
10-
use crate::ty::{ReturnType, Type};
11-
#[cfg(feature = "full")]
121
use proc_macro2::{Delimiter, TokenStream, TokenTree};
13-
#[cfg(any(feature = "printing", feature = "full"))]
142
use std::ops::ControlFlow;
3+
use syn::punctuated::Punctuated;
4+
use syn::{Expr, MacroDelimiter, Path, PathArguments, ReturnType, Token, Type, TypeParamBound};
155

16-
#[cfg(feature = "full")]
176
pub(crate) fn requires_semi_to_be_stmt(expr: &Expr) -> bool {
187
match expr {
19-
Expr::Macro(expr) => !expr.mac.delimiter.is_brace(),
8+
Expr::Macro(expr) => !matches!(expr.mac.delimiter, MacroDelimiter::Brace(_)),
209
_ => requires_comma_to_be_match_arm(expr),
2110
}
2211
}
2312

24-
#[cfg(feature = "full")]
2513
pub(crate) fn requires_comma_to_be_match_arm(expr: &Expr) -> bool {
2614
match expr {
15+
#![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
2716
Expr::If(_)
2817
| Expr::Match(_)
2918
| Expr::Block(_) | Expr::Unsafe(_) // both under ExprKind::Block in rustc
@@ -64,13 +53,15 @@ pub(crate) fn requires_comma_to_be_match_arm(expr: &Expr) -> bool {
6453
| Expr::Unary(_)
6554
| Expr::Yield(_)
6655
| Expr::Verbatim(_) => true,
56+
57+
_ => true,
6758
}
6859
}
6960

70-
#[cfg(feature = "printing")]
7161
pub(crate) fn trailing_unparameterized_path(mut ty: &Type) -> bool {
7262
loop {
7363
match ty {
64+
#![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
7465
Type::BareFn(t) => match &t.output {
7566
ReturnType::Default => return false,
7667
ReturnType::Type(_, ret) => ty = ret,
@@ -99,6 +90,8 @@ pub(crate) fn trailing_unparameterized_path(mut ty: &Type) -> bool {
9990
| Type::Slice(_)
10091
| Type::Tuple(_)
10192
| Type::Verbatim(_) => return false,
93+
94+
_ => return false,
10295
}
10396
}
10497

@@ -117,19 +110,21 @@ pub(crate) fn trailing_unparameterized_path(mut ty: &Type) -> bool {
117110
bounds: &Punctuated<TypeParamBound, Token![+]>,
118111
) -> ControlFlow<bool, &Type> {
119112
match bounds.last().unwrap() {
113+
#![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
120114
TypeParamBound::Trait(t) => last_type_in_path(&t.path),
121115
TypeParamBound::Lifetime(_)
122116
| TypeParamBound::PreciseCapture(_)
123117
| TypeParamBound::Verbatim(_) => ControlFlow::Break(false),
118+
_ => ControlFlow::Break(false),
124119
}
125120
}
126121
}
127122

128123
/// Whether the expression's first token is the label of a loop/block.
129-
#[cfg(all(feature = "printing", feature = "full"))]
130124
pub(crate) fn expr_leading_label(mut expr: &Expr) -> bool {
131125
loop {
132126
match expr {
127+
#![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
133128
Expr::Block(e) => return e.label.is_some(),
134129
Expr::ForLoop(e) => return e.label.is_some(),
135130
Expr::Loop(e) => return e.label.is_some(),
@@ -175,15 +170,17 @@ pub(crate) fn expr_leading_label(mut expr: &Expr) -> bool {
175170
| Expr::Unsafe(_)
176171
| Expr::Verbatim(_)
177172
| Expr::Yield(_) => return false,
173+
174+
_ => return false,
178175
}
179176
}
180177
}
181178

182179
/// Whether the expression's last token is `}`.
183-
#[cfg(feature = "full")]
184180
pub(crate) fn expr_trailing_brace(mut expr: &Expr) -> bool {
185181
loop {
186182
match expr {
183+
#![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
187184
Expr::Async(_)
188185
| Expr::Block(_)
189186
| Expr::Const(_)
@@ -205,7 +202,7 @@ pub(crate) fn expr_trailing_brace(mut expr: &Expr) -> bool {
205202
Expr::Cast(e) => return type_trailing_brace(&e.ty),
206203
Expr::Closure(e) => expr = &e.body,
207204
Expr::Let(e) => expr = &e.expr,
208-
Expr::Macro(e) => return e.mac.delimiter.is_brace(),
205+
Expr::Macro(e) => return matches!(e.mac.delimiter, MacroDelimiter::Brace(_)),
209206
Expr::Range(e) => match &e.end {
210207
Some(end) => expr = end,
211208
None => return false,
@@ -238,12 +235,15 @@ pub(crate) fn expr_trailing_brace(mut expr: &Expr) -> bool {
238235
| Expr::Repeat(_)
239236
| Expr::Try(_)
240237
| Expr::Tuple(_) => return false,
238+
239+
_ => return false,
241240
}
242241
}
243242

244243
fn type_trailing_brace(mut ty: &Type) -> bool {
245244
loop {
246245
match ty {
246+
#![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
247247
Type::BareFn(t) => match &t.output {
248248
ReturnType::Default => return false,
249249
ReturnType::Type(_, ret) => ty = ret,
@@ -252,7 +252,7 @@ pub(crate) fn expr_trailing_brace(mut expr: &Expr) -> bool {
252252
ControlFlow::Break(trailing_brace) => return trailing_brace,
253253
ControlFlow::Continue(t) => ty = t,
254254
},
255-
Type::Macro(t) => return t.mac.delimiter.is_brace(),
255+
Type::Macro(t) => return matches!(t.mac.delimiter, MacroDelimiter::Brace(_)),
256256
Type::Path(t) => match last_type_in_path(&t.path) {
257257
Some(t) => ty = t,
258258
None => return false,
@@ -272,6 +272,8 @@ pub(crate) fn expr_trailing_brace(mut expr: &Expr) -> bool {
272272
| Type::Paren(_)
273273
| Type::Slice(_)
274274
| Type::Tuple(_) => return false,
275+
276+
_ => return false,
275277
}
276278
}
277279
}
@@ -290,6 +292,7 @@ pub(crate) fn expr_trailing_brace(mut expr: &Expr) -> bool {
290292
bounds: &Punctuated<TypeParamBound, Token![+]>,
291293
) -> ControlFlow<bool, &Type> {
292294
match bounds.last().unwrap() {
295+
#![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
293296
TypeParamBound::Trait(t) => match last_type_in_path(&t.path) {
294297
Some(t) => ControlFlow::Continue(t),
295298
None => ControlFlow::Break(false),
@@ -298,6 +301,7 @@ pub(crate) fn expr_trailing_brace(mut expr: &Expr) -> bool {
298301
ControlFlow::Break(false)
299302
}
300303
TypeParamBound::Verbatim(t) => ControlFlow::Break(tokens_trailing_brace(t)),
304+
_ => ControlFlow::Break(false),
301305
}
302306
}
303307

0 commit comments

Comments
 (0)