Skip to content
This repository has been archived by the owner on Jul 26, 2024. It is now read-only.

Commit

Permalink
chore: Update code for newest rust 1.54 (#231)
Browse files Browse the repository at this point in the history
* Address newest clippy concerns
  • Loading branch information
jrconlin authored Jul 30, 2021
1 parent 13ee087 commit f063e81
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
ARG APPNAME=contile

# make sure that the build and run environments are the same version
FROM rust:1.53-slim-buster as builder
FROM rust:1.54-slim-buster as builder
ARG APPNAME
ADD . /app
WORKDIR /app
Expand Down
16 changes: 8 additions & 8 deletions src/adm/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl AdmFilter {
Err(e) => {
tags.add_tag("type", species);
tags.add_extra("tile", &tile.name);
tags.add_extra("url", &url);
tags.add_extra("url", url);
tags.add_extra("parse_error", &e.to_string());
return Err(HandlerErrorKind::InvalidHost(species, url.to_string()).into());
}
Expand Down Expand Up @@ -126,7 +126,7 @@ impl AdmFilter {
Err(e) => {
tags.add_tag("type", species);
tags.add_extra("tile", &tile.name);
tags.add_extra("url", &url);
tags.add_extra("url", url);

tags.add_extra("parse_error", &e.to_string());
return Err(HandlerErrorKind::InvalidHost(species, url.to_string()).into());
Expand All @@ -142,7 +142,7 @@ impl AdmFilter {
trace!("bad url: url={:?}", url.to_string());
tags.add_tag("type", species);
tags.add_extra("tile", &tile.name);
tags.add_extra("url", &url);
tags.add_extra("url", url);

tags.add_extra("reason", "bad host");
return Err(HandlerErrorKind::InvalidHost(species, url.to_string()).into());
Expand All @@ -152,10 +152,10 @@ impl AdmFilter {
trace!("missing param: key={:?} url={:?}", &key, url.to_string());
tags.add_tag("type", species);
tags.add_extra("tile", &tile.name);
tags.add_extra("url", &url);
tags.add_extra("url", url);

tags.add_extra("reason", "missing required query param");
tags.add_extra("param", &key);
tags.add_extra("param", key);
return Err(HandlerErrorKind::InvalidHost(species, url.to_string()).into());
}
}
Expand All @@ -164,7 +164,7 @@ impl AdmFilter {
trace!("invalid param key={:?} url={:?}", &key, url.to_string());
tags.add_tag("type", species);
tags.add_extra("tile", &tile.name);
tags.add_extra("url", &url);
tags.add_extra("url", url);

tags.add_extra("reason", "invalid query param");
tags.add_extra("param", &key);
Expand All @@ -190,7 +190,7 @@ impl AdmFilter {
Err(e) => {
tags.add_tag("type", species);
tags.add_extra("tile", &tile.name);
tags.add_extra("url", &url);
tags.add_extra("url", url);
tags.add_extra("parse_error", &e.to_string());
return Err(HandlerErrorKind::InvalidHost(species, url.to_string()).into());
}
Expand All @@ -204,7 +204,7 @@ impl AdmFilter {
trace!("missing param key=id url={:?}", url.to_string());
tags.add_tag("type", species);
tags.add_extra("tile", &tile.name);
tags.add_extra("url", &url);
tags.add_extra("url", url);
tags.add_extra("reason", "invalid query param");
tags.add_extra("param", "id");
return Err(HandlerErrorKind::InvalidHost(species, url.to_string()).into());
Expand Down
6 changes: 3 additions & 3 deletions src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl Drop for Metrics {
let tags = timer.tags.tags.clone();
let keys = tags.keys();
for tag in keys {
tagged = tagged.with_tag(tag, &tags.get(tag).unwrap())
tagged = tagged.with_tag(tag, tags.get(tag).unwrap())
}
match tagged.try_send() {
Err(e) => {
Expand Down Expand Up @@ -146,7 +146,7 @@ impl Metrics {
}
for key in mtags.tags.keys().clone() {
if let Some(val) = mtags.tags.get(key) {
tagged = tagged.with_tag(&key, val.as_ref());
tagged = tagged.with_tag(key, val.as_ref());
}
}
// Include any "hard coded" tags.
Expand Down Expand Up @@ -176,7 +176,7 @@ impl Metrics {
}
for key in mtags.tags.keys().clone() {
if let Some(val) = mtags.tags.get(key) {
tagged = tagged.with_tag(&key, val.as_ref());
tagged = tagged.with_tag(key, val.as_ref());
}
}
// Include any "hard coded" tags.
Expand Down
2 changes: 1 addition & 1 deletion src/server/img_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ impl StoreImage {
return Err(err);
}
};
self.meta(&image, fmt)?
self.meta(image, fmt)?
};
if self.settings.metrics.symmetric && image_metrics.width != image_metrics.height {
let mut tags = Tags::default();
Expand Down
6 changes: 3 additions & 3 deletions src/server/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ impl Location {
match self.iploc.clone().unwrap().lookup::<City<'_>>(ip_addr) {
Ok(location) => {
if let Some(names) = location.city.and_then(|c| c.names) {
result.city = get_preferred_language_element(&preferred_languages, &names)
result.city = get_preferred_language_element(preferred_languages, &names)
} else {
metrics.incr_with_tags("location.unknown.city", Some(&tags));
};
Expand Down Expand Up @@ -472,7 +472,7 @@ pub mod test {
let hv = "US, USCA";
test_head.headers_mut().append(
HeaderName::from_static(test_header),
HeaderValue::from_static(&hv),
HeaderValue::from_static(hv),
);

let loc = LocationResult::from_header(&test_head, &settings, &metrics);
Expand Down Expand Up @@ -502,7 +502,7 @@ pub mod test {
let hv = ", ";
test_head.headers_mut().append(
HeaderName::from_static(GOOG_LOC_HEADER),
HeaderValue::from_static(&hv),
HeaderValue::from_static(hv),
);
let loc = LocationResult::from_header(&test_head, &settings, &metrics);
assert!(loc.region() == "");
Expand Down
4 changes: 2 additions & 2 deletions src/tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const VALID_UA_OS: &[&str] = &["Firefox OS", "Linux", "Mac OSX"];
/// metrics and logging).
pub fn parse_user_agent(agent: &str) -> (WootheeResult<'_>, &str) {
let parser = Parser::new();
let wresult = parser.parse(&agent).unwrap_or_else(|| WootheeResult {
let wresult = parser.parse(agent).unwrap_or_else(|| WootheeResult {
name: "",
category: "",
os: "",
Expand Down Expand Up @@ -294,7 +294,7 @@ impl From<Tags> for BTreeMap<String, String> {
impl KV for Tags {
fn serialize(&self, _rec: &Record<'_>, serializer: &mut dyn slog::Serializer) -> slog::Result {
for (key, val) in &self.tags {
serializer.emit_str(Key::from(key.clone()), &val)?;
serializer.emit_str(Key::from(key.clone()), val)?;
}
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion src/web/extractors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl FromRequest for DeviceInfo {
.unwrap_or(&EMPTY_HEADER)
.to_str()
.unwrap_or_default();
Ok(get_device_info(&ua)?)
Ok(get_device_info(ua)?)
}
.boxed_local()
}
Expand Down
4 changes: 2 additions & 2 deletions src/web/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ pub async fn get_tiles(
metrics.incr_with_tags("tiles.invalid", Some(&tags));
// Report directly to sentry
// (This is starting to become a pattern. 🤔)
let mut tags = Tags::from_head(request.head(), &settings);
tags.add_extra("err", &es);
let mut tags = Tags::from_head(request.head(), settings);
tags.add_extra("err", es);
tags.add_tag("level", "warning");
l_sentry::report(&tags, sentry::event_from_error(&e));
warn!("ADM Server error: {:?}", e);
Expand Down
11 changes: 4 additions & 7 deletions src/web/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::HashMap;

use actix_cors::Cors;
use actix_web::{
dev, http::header, http::StatusCode, middleware::errhandlers::ErrorHandlers, test, web, App,
http::header, http::StatusCode, middleware::errhandlers::ErrorHandlers, test, web, App,
HttpRequest, HttpResponse, HttpServer,
};
use futures::{channel::mpsc, StreamExt};
Expand Down Expand Up @@ -66,7 +66,6 @@ macro_rules! init_app {
}

struct MockAdm {
pub server: dev::Server,
pub endpoint_url: String,
pub request_rx: mpsc::UnboundedReceiver<String>,
}
Expand Down Expand Up @@ -111,8 +110,8 @@ fn init_mock_adm(response: String) -> MockAdm {
.bind(("127.0.0.1", 0))
.expect("Couldn't bind mock_adm");
let addr = server.addrs().pop().expect("No mock_adm addr");
server.run();
MockAdm {
server: server.run(),
endpoint_url: format!("http://{}:{}/?partner=foo&sub1=bar", addr.ip(), addr.port()),
request_rx,
}
Expand Down Expand Up @@ -372,11 +371,9 @@ async fn basic_default() {
let tiles = result["tiles"].as_array().expect("!tiles.is_array()");
// remember, we cap at `settings.adm_max_tiles` (currently 2)
assert_eq!(tiles.len(), 2);
let names: Vec<&str> = tiles
assert!(!tiles
.iter()
.map(|tile| tile["name"].as_str().unwrap())
.collect();
assert!(!names.contains(&"Los Pollos Hermanos"));
.any(|tile| tile["name"].as_str().unwrap() == "Los Pollos Hermanos"));
}

#[actix_rt::test]
Expand Down
2 changes: 1 addition & 1 deletion src/web/user_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub fn get_device_info(ua: &str) -> HandlerResult<DeviceInfo> {
// XXX: Tags::from_head already adds this
err.tags.add_extra("ua", ua);
err.tags
.add_extra("name", &wresult.name.to_lowercase().as_str());
.add_extra("name", wresult.name.to_lowercase().as_str());
return Err(err);
}

Expand Down

0 comments on commit f063e81

Please sign in to comment.