Skip to content

Commit a4192e3

Browse files
Benoît CCBenoit
Benoît C
andauthored
Fix incorrect use statements (#137)
* Fix incorrect use statements * Fix new clippy warnings Co-authored-by: Benoît CORTIER <benoit.cortier@fried-world.eu>
1 parent 5f3602d commit a4192e3

File tree

10 files changed

+26
-24
lines changed

10 files changed

+26
-24
lines changed

saphir/src/file/range.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ impl FromStr for Range {
148148
}
149149
Ok(Range::Bytes(ranges))
150150
}
151-
(Some(unit), Some(range_str)) if unit != "" && range_str != "" => Ok(Range::Unregistered(unit.to_owned(), range_str.to_owned())),
151+
(Some(unit), Some(range_str)) if !unit.is_empty() && !range_str.is_empty() => Ok(Range::Unregistered(unit.to_owned(), range_str.to_owned())),
152152
_ => Err(SaphirError::Other("Bad Format".to_owned())),
153153
}
154154
}

saphir/src/utils.rs

+1
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ impl UriPathMatcher {
426426
}
427427

428428
#[derive(Debug)]
429+
#[allow(clippy::large_enum_variant)]
429430
pub(crate) enum UriPathSegmentMatcher {
430431
Static { segment: String },
431432
Variable { name: Option<String> },

saphir_cli/src/openapi/generate/crate_syn_browser/item.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use super::Module;
22
use crate::openapi::generate::crate_syn_browser::UseScope;
33
use lazycell::LazyCell;
4-
use std::fmt::Debug;
4+
use std::fmt::{Debug, Formatter};
55
use syn::{
6-
export::Formatter, ImplItem as SynImplItem, ImplItemMethod as SynImplItemMethod, Item as SynItem, ItemEnum as SynItemEnum, ItemImpl as SynItemImpl,
6+
ImplItem as SynImplItem, ImplItemMethod as SynImplItemMethod, Item as SynItem, ItemEnum as SynItemEnum, ItemImpl as SynItemImpl,
77
ItemStruct as SynItemStruct, ItemUse as SynItemUse,
88
};
99

saphir_cli/src/openapi/generate/crate_syn_browser/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
use std::{fmt::Debug, path::PathBuf};
2-
use syn::export::{fmt::Display, Formatter};
1+
use std::{
2+
fmt::{Debug, Display, Formatter},
3+
path::PathBuf,
4+
};
35
use Error::*;
46

57
mod browser;

saphir_cli/src/openapi/generate/mod.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,15 @@ use serde_derive::Deserialize;
1919
use std::{
2020
cell::RefCell,
2121
collections::{BTreeMap, HashMap, HashSet},
22+
fmt::{Display, Formatter},
2223
fs::File as FsFile,
2324
io::Read,
2425
path::PathBuf,
2526
str::FromStr,
2627
time::Instant,
2728
};
2829
use structopt::StructOpt;
29-
use syn::{
30-
export::{fmt::Display, Formatter},
31-
Attribute, Fields, Item as SynItem, ItemEnum, ItemStruct, Lit, Meta, NestedMeta, Signature,
32-
};
30+
use syn::{Attribute, Fields, Item as SynItem, ItemEnum, ItemStruct, Lit, Meta, NestedMeta, Signature};
3331

3432
mod controller_info;
3533
mod crate_syn_browser;
@@ -151,11 +149,12 @@ impl Command for Gen {
151149
type Args = GenArgs;
152150

153151
fn new(args: Self::Args) -> Self {
154-
let mut doc = OpenApi::default();
155-
doc.openapi_version = "3.0.3".to_string();
156152
Self {
157153
args,
158-
doc,
154+
doc: OpenApi {
155+
openapi_version: "3.0.3".to_string(),
156+
..OpenApi::default()
157+
},
159158
operation_ids: RefCell::new(Default::default()),
160159
generated_schema_names: Default::default(),
161160
}

saphir_cli/src/openapi/generate/response_info.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl Gen {
9191
Ok(c) => c,
9292
_ => continue,
9393
};
94-
if c < 100 || c >= 600 {
94+
if !(100..600).contains(&c) {
9595
continue;
9696
}
9797
codes.push(c);
@@ -214,7 +214,7 @@ impl Gen {
214214
Ok(c) => c,
215215
_ => continue,
216216
};
217-
if c < 100 || c >= 600 {
217+
if !(100..600).contains(&c) {
218218
continue;
219219
}
220220
codes.push(c);

saphir_macro/src/controller/controller_attr.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ use crate::controller::handler::{HandlerAttrs, HandlerRepr};
22
use proc_macro2::{Ident, TokenStream};
33
use syn::{AttributeArgs, Error, ItemImpl, Lit, Meta, MetaNameValue, NestedMeta, Result};
44

5-
use quote::quote;
6-
use syn::export::ToTokens;
5+
use quote::{quote, ToTokens};
76

87
#[derive(Debug)]
98
pub struct ControllerAttr {

saphir_macro/src/controller/handler.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ use std::str::FromStr;
22

33
use http::Method;
44
use proc_macro2::{Ident, TokenStream};
5-
use quote::quote_spanned;
5+
use quote::{quote_spanned, ToTokens};
66
use syn::{
7-
export::ToTokens, spanned::Spanned, Attribute, Error, Expr, FnArg, GenericArgument, ImplItem, ImplItemMethod, ItemImpl, Lit, Meta, MetaNameValue,
8-
NestedMeta, Pat, PatIdent, PatType, Path, PathArguments, PathSegment, Result, ReturnType, Type, TypePath,
7+
spanned::Spanned, Attribute, Error, Expr, FnArg, GenericArgument, ImplItem, ImplItemMethod, ItemImpl, Lit, Meta, MetaNameValue, NestedMeta, Pat, PatIdent,
8+
PatType, Path, PathArguments, PathSegment, Result, ReturnType, Type, TypePath,
99
};
1010

1111
#[derive(Clone, Debug)]
@@ -433,7 +433,7 @@ impl HandlerAttrs {
433433
let c: u16 = i
434434
.base10_parse()
435435
.map_err(|_| Error::new_spanned(i, "Invalid status code"))?;
436-
if c < 100 || c >= 600 {
436+
if !(100..600).contains(&c) {
437437
return Err(Error::new_spanned(i, "Invalid status code"));
438438
}
439439
nb_code += 1;
@@ -522,7 +522,7 @@ impl HandlerAttrs {
522522
let c: u16 = i
523523
.base10_parse()
524524
.map_err(|_| Error::new_spanned(i, "Invalid status code"))?;
525-
if c < 100 || c >= 600 {
525+
if !(100..600).contains(&c) {
526526
return Err(Error::new_spanned(i, "Invalid status code"));
527527
}
528528
nb_code += 1;

saphir_macro/src/controller/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use proc_macro2::{Ident, Span, TokenStream};
2-
use syn::{export::ToTokens, spanned::Spanned, AttributeArgs, Error, GenericArgument, ItemImpl, PathArguments, Result, Type};
2+
use syn::{spanned::Spanned, AttributeArgs, Error, GenericArgument, ItemImpl, PathArguments, Result, Type};
33

4-
use quote::quote;
4+
use quote::{quote, ToTokens};
55

66
use crate::controller::{
77
controller_attr::ControllerAttr,

saphir_macro/src/openapi/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use proc_macro2::TokenStream;
2-
use syn::{export::ToTokens, AttributeArgs, Error, Item, Lit, Meta, NestedMeta, Result};
2+
use quote::ToTokens;
3+
use syn::{AttributeArgs, Error, Item, Lit, Meta, NestedMeta, Result};
34

45
const MISSING_ATRIBUTE: &str = "openapi macro require at least one of the following attributes :
56
- mime

0 commit comments

Comments
 (0)