mirror of https://github.com/rwf2/Rocket.git
Fix clippy lints within rocket_codegen
Some of these warnings were in code that rocket's macros would produce, and so would also produce extraneous clippy warnings in crates using rocket's macros.
This commit is contained in:
parent
855d9b7b00
commit
2be02ca4eb
|
@ -32,8 +32,8 @@ impl ErrorGenerateExt for ErrorParams {
|
||||||
// (Imperfectly) inspect the types to figure which params to pass in.
|
// (Imperfectly) inspect the types to figure which params to pass in.
|
||||||
let args = input_args.iter().map(|arg| &arg.ty).filter_map(|ty| {
|
let args = input_args.iter().map(|arg| &arg.ty).filter_map(|ty| {
|
||||||
match ty.node {
|
match ty.node {
|
||||||
TyKind::Rptr(..) => Some(req.clone()),
|
TyKind::Rptr(..) => Some(req),
|
||||||
TyKind::Path(..) => Some(err.clone()),
|
TyKind::Path(..) => Some(err),
|
||||||
_ => {
|
_ => {
|
||||||
ecx.struct_span_err(ty.span, "unexpected error handler argument")
|
ecx.struct_span_err(ty.span, "unexpected error handler argument")
|
||||||
.help(arg_help).emit();
|
.help(arg_help).emit();
|
||||||
|
|
|
@ -58,7 +58,7 @@ impl RouteGenerateExt for RouteParams {
|
||||||
if param.is_none() {
|
if param.is_none() {
|
||||||
return None;
|
return None;
|
||||||
} else if arg.is_none() {
|
} else if arg.is_none() {
|
||||||
self.missing_declared_err(ecx, ¶m.unwrap());
|
self.missing_declared_err(ecx, param.unwrap());
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ impl RouteGenerateExt for RouteParams {
|
||||||
if param.is_none() {
|
if param.is_none() {
|
||||||
return None;
|
return None;
|
||||||
} else if arg.is_none() {
|
} else if arg.is_none() {
|
||||||
self.missing_declared_err(ecx, ¶m.unwrap());
|
self.missing_declared_err(ecx, param.unwrap());
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@ impl RouteGenerateExt for RouteParams {
|
||||||
// Generate a statement for every declared paramter in the path.
|
// Generate a statement for every declared paramter in the path.
|
||||||
let mut declared_set = HashSet::new();
|
let mut declared_set = HashSet::new();
|
||||||
for (i, param) in self.path_params(ecx).enumerate() {
|
for (i, param) in self.path_params(ecx).enumerate() {
|
||||||
declared_set.insert(param.ident().name.clone());
|
declared_set.insert(param.ident().name);
|
||||||
let ty = match self.annotated_fn.find_input(¶m.ident().name) {
|
let ty = match self.annotated_fn.find_input(¶m.ident().name) {
|
||||||
Some(arg) => strip_ty_lifetimes(arg.ty.clone()),
|
Some(arg) => strip_ty_lifetimes(arg.ty.clone()),
|
||||||
None => {
|
None => {
|
||||||
|
|
|
@ -35,7 +35,7 @@ impl Function {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn find_input<'a>(&'a self, name: &Name) -> Option<&'a Arg> {
|
pub fn find_input<'a>(&'a self, name: &Name) -> Option<&'a Arg> {
|
||||||
self.decl().inputs.iter().filter(|arg| arg.named(name)).next()
|
self.decl().inputs.iter().find(|arg| arg.named(name))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ impl<'s, 'a, 'c> Iterator for ParamIter<'s, 'a, 'c> {
|
||||||
fn next(&mut self) -> Option<Param> {
|
fn next(&mut self) -> Option<Param> {
|
||||||
let err = |ecx: &ExtCtxt, sp: Span, msg: &str| {
|
let err = |ecx: &ExtCtxt, sp: Span, msg: &str| {
|
||||||
ecx.span_err(sp, msg);
|
ecx.span_err(sp, msg);
|
||||||
return None;
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
// Find the start and end indexes for the next parameter, if any.
|
// Find the start and end indexes for the next parameter, if any.
|
||||||
|
@ -65,9 +65,10 @@ impl<'s, 'a, 'c> Iterator for ParamIter<'s, 'a, 'c> {
|
||||||
|
|
||||||
// Calculate the parameter's ident.
|
// Calculate the parameter's ident.
|
||||||
let full_param = &self.string[(start + 1)..end];
|
let full_param = &self.string[(start + 1)..end];
|
||||||
let (is_many, param) = match full_param.ends_with("..") {
|
let (is_many, param) = if full_param.ends_with("..") {
|
||||||
true => (true, &full_param[..(full_param.len() - 2)]),
|
(true, &full_param[..(full_param.len() - 2)])
|
||||||
false => (false, full_param)
|
} else {
|
||||||
|
(false, full_param)
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut param_span = self.span;
|
let mut param_span = self.span;
|
||||||
|
@ -83,7 +84,7 @@ impl<'s, 'a, 'c> Iterator for ParamIter<'s, 'a, 'c> {
|
||||||
err(self.ctxt, param_span, "parameter names cannot be empty")
|
err(self.ctxt, param_span, "parameter names cannot be empty")
|
||||||
} else if !is_valid_ident(param) {
|
} else if !is_valid_ident(param) {
|
||||||
err(self.ctxt, param_span, "parameter names must be valid identifiers")
|
err(self.ctxt, param_span, "parameter names must be valid identifiers")
|
||||||
} else if param.starts_with("_") {
|
} else if param.starts_with('_') {
|
||||||
err(self.ctxt, param_span, "parameters cannot be ignored")
|
err(self.ctxt, param_span, "parameters cannot be ignored")
|
||||||
} else if is_many && !self.string.is_empty() {
|
} else if is_many && !self.string.is_empty() {
|
||||||
let sp = self.span.shorten_to(self.string.len());
|
let sp = self.span.shorten_to(self.string.len());
|
||||||
|
@ -93,9 +94,10 @@ impl<'s, 'a, 'c> Iterator for ParamIter<'s, 'a, 'c> {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
let spanned_ident = span(Ident::from_str(param), param_span);
|
let spanned_ident = span(Ident::from_str(param), param_span);
|
||||||
match is_many {
|
if is_many {
|
||||||
true => Some(Param::Many(spanned_ident)),
|
Some(Param::Many(spanned_ident))
|
||||||
false => Some(Param::Single(spanned_ident))
|
} else {
|
||||||
|
Some(Param::Single(spanned_ident))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,7 +75,7 @@ impl RouteParams {
|
||||||
let mut seen_keys = HashSet::new();
|
let mut seen_keys = HashSet::new();
|
||||||
let (mut rank, mut data, mut format) = Default::default();
|
let (mut rank, mut data, mut format) = Default::default();
|
||||||
for param in &attr_params[1..] {
|
for param in &attr_params[1..] {
|
||||||
let kv_opt = kv_from_nested(¶m);
|
let kv_opt = kv_from_nested(param);
|
||||||
if kv_opt.is_none() {
|
if kv_opt.is_none() {
|
||||||
ecx.span_err(param.span(), "expected key = value");
|
ecx.span_err(param.span(), "expected key = value");
|
||||||
continue;
|
continue;
|
||||||
|
@ -183,7 +183,7 @@ fn parse_method(ecx: &ExtCtxt, meta_item: &NestedMetaItem) -> Spanned<Method> {
|
||||||
.help("valid methods are: GET, PUT, POST, DELETE, PATCH")
|
.help("valid methods are: GET, PUT, POST, DELETE, PATCH")
|
||||||
.emit();
|
.emit();
|
||||||
|
|
||||||
return dummy_spanned(Method::Get);
|
dummy_spanned(Method::Get)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_path(ecx: &ExtCtxt, meta_item: &NestedMetaItem) -> (Spanned<String>, Option<Spanned<Ident>>) {
|
fn parse_path(ecx: &ExtCtxt, meta_item: &NestedMetaItem) -> (Spanned<String>, Option<Spanned<Ident>>) {
|
||||||
|
@ -230,9 +230,8 @@ fn parse_data(ecx: &ExtCtxt, kv: &KVSpanned<LitKind>) -> Ident {
|
||||||
let mut ident = Ident::from_str("unknown");
|
let mut ident = Ident::from_str("unknown");
|
||||||
if let LitKind::Str(ref s, _) = *kv.value() {
|
if let LitKind::Str(ref s, _) = *kv.value() {
|
||||||
ident = Ident::from_str(&s.as_str());
|
ident = Ident::from_str(&s.as_str());
|
||||||
match param_string_to_ident(ecx, span(&s.as_str(), kv.value.span)) {
|
if let Some(ident) = param_string_to_ident(ecx, span(&s.as_str(), kv.value.span)) {
|
||||||
Some(ident) => return ident,
|
return ident;
|
||||||
_ => { /* fall through if not an ident */ }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ use std::path::PathBuf;
|
||||||
|
|
||||||
fn run_mode(mode: &'static str) {
|
fn run_mode(mode: &'static str) {
|
||||||
let mut config = compiletest::default_config();
|
let mut config = compiletest::default_config();
|
||||||
let cfg_mode = mode.parse().ok().expect("Invalid mode");
|
let cfg_mode = mode.parse().expect("Invalid mode");
|
||||||
|
|
||||||
config.mode = cfg_mode;
|
config.mode = cfg_mode;
|
||||||
config.src_base = PathBuf::from(format!("tests/{}", mode));
|
config.src_base = PathBuf::from(format!("tests/{}", mode));
|
||||||
|
|
Loading…
Reference in New Issue