Skip to content

Commit 5b27c97

Browse files
authored
Rust 1.46 clippy fixes (#135)
* Fix linux unneeded extra * Other clippy issues * Review update * Clippy for the webdriver feature, also enable in CI * More clippy * More clippy
1 parent 026ce08 commit 5b27c97

File tree

8 files changed

+31
-35
lines changed

8 files changed

+31
-35
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ script:
3333
echo "Running rustfmt"
3434
cargo fmt --all -- --check
3535
echo "Running clippy"
36-
cargo clippy --all-targets -- -A renamed_and_removed_lints -A clippy::new-ret-no-self -D warnings
36+
cargo clippy --all-targets --all-features -- -A renamed_and_removed_lints -A clippy::new-ret-no-self -D warnings
3737
3838
rustup install nightly
3939
cargo install cargo-fuzz
4040
cargo +nightly fuzz build
4141
fi
42-
- cargo test --all-targets
42+
- cargo test --all-targets --all-features

src/authenticatorservice.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ impl AuthenticatorService {
136136
);
137137

138138
transport_mutex.lock().unwrap().register(
139-
flags.clone(),
139+
flags,
140140
timeout,
141141
challenge.clone(),
142142
application.clone(),
@@ -189,7 +189,7 @@ impl AuthenticatorService {
189189
transports_to_cancel.remove(idx);
190190

191191
transport_mutex.lock().unwrap().sign(
192-
flags.clone(),
192+
flags,
193193
timeout,
194194
challenge.clone(),
195195
app_ids.clone(),
@@ -544,7 +544,7 @@ mod tests {
544544
mk_challenge(),
545545
mk_appid(),
546546
vec![],
547-
status_tx.clone(),
547+
status_tx,
548548
callback.clone(),
549549
)
550550
.is_ok());
@@ -616,7 +616,7 @@ mod tests {
616616
mk_challenge(),
617617
mk_appid(),
618618
vec![],
619-
status_tx.clone(),
619+
status_tx,
620620
callback.clone(),
621621
)
622622
.is_ok());

src/linux/monitor.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

55
use libc::{c_int, c_short, c_ulong};
6-
use libudev;
76
use libudev::EventType;
87
use runloop::RunLoop;
98
use std::collections::HashMap;

src/manager.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,7 @@ impl AuthenticatorTransport for U2FManager {
140140
status,
141141
callback,
142142
};
143-
self.tx
144-
.send(action)
145-
.map_err(|e| AuthenticatorError::from(e))
143+
Ok(self.tx.send(action)?)
146144
}
147145

148146
fn sign(

src/statecallback.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ pub struct StateCallback<T> {
1111
}
1212

1313
impl<T> StateCallback<T> {
14+
// This is used for the Condvar, which requires this kind of construction
15+
#[allow(clippy::mutex_atomic)]
1416
pub fn new(cb: Box<dyn Fn(T) + Send>) -> Self {
1517
Self {
1618
callback: Arc::new(Mutex::new(Some(cb))),
@@ -134,11 +136,13 @@ mod tests {
134136
}
135137

136138
#[test]
139+
#[allow(clippy::redundant_clone)]
137140
fn test_statecallback_observer_unclonable() {
138141
let mut sc = StateCallback::<()>::new(Box::new(move |_| {}));
139142
sc.add_uncloneable_observer(Box::new(move || {}));
140143

141144
assert!(sc.observer.lock().unwrap().is_some());
145+
// This is deliberate, to force an extra clone
142146
assert!(sc.clone().observer.lock().unwrap().is_none());
143147
}
144148

src/virtualdevices/webdriver/testtoken.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,17 @@ impl TestToken {
5252
has_resident_key: bool,
5353
) -> TestToken {
5454
match protocol {
55-
TestWireProtocol::CTAP1 => {
56-
return Self {
57-
id,
58-
protocol,
59-
transport,
60-
is_user_consenting,
61-
has_user_verification,
62-
is_user_verified,
63-
has_resident_key,
64-
u2f_impl: Some(SoftwareU2FToken::new()),
65-
credentials: Vec::new(),
66-
}
67-
}
55+
TestWireProtocol::CTAP1 => Self {
56+
id,
57+
protocol,
58+
transport,
59+
is_user_consenting,
60+
has_user_verification,
61+
is_user_verified,
62+
has_resident_key,
63+
u2f_impl: Some(SoftwareU2FToken::new()),
64+
credentials: Vec::new(),
65+
},
6866
_ => unreachable!(),
6967
}
7068
}
@@ -91,7 +89,7 @@ impl TestToken {
9189
.credentials
9290
.binary_search_by_key(&credential, |probe| &probe.credential)
9391
{
94-
Ok(_) => return,
92+
Ok(_) => {}
9593
Err(idx) => self.credentials.insert(idx, c),
9694
}
9795
}

src/virtualdevices/webdriver/virtualmanager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl VirtualManager {
4343

4444
let builder = thread::Builder::new().name("WebDriver Command Server".into());
4545
builder.spawn(move || {
46-
web_api::serve(stateclone, addr.clone());
46+
web_api::serve(stateclone, addr);
4747
})?;
4848

4949
Ok(Self {

src/virtualdevices/webdriver/web_api.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -248,14 +248,12 @@ mod handlers {
248248
&& uri.path_and_query().is_none()
249249
&& uri.port().is_none()
250250
&& uri.host().is_some()
251+
&& uri.authority().unwrap() == uri.host().unwrap()
252+
// Don't try too hard to ensure it's a valid domain, just
253+
// ensure there's a label delim in there somewhere
254+
&& uri.host().unwrap().find('.').is_some()
251255
{
252-
if uri.authority().unwrap() == uri.host().unwrap() {
253-
// Don't try too hard to ensure it's a valid domain, just
254-
// ensure there's a label delim in there somewhere
255-
if uri.host().unwrap().find('.').is_some() {
256-
return Ok(());
257-
}
258-
}
256+
return Ok(());
259257
}
260258
}
261259
Err(crate::errors::AuthenticatorError::U2FToken(
@@ -514,7 +512,6 @@ mod tests {
514512
use super::*;
515513
use crate::virtualdevices::webdriver::virtualmanager::VirtualManagerState;
516514
use bytes::Buf;
517-
use serde_json;
518515
use std::sync::{Arc, Mutex};
519516
use warp::http::StatusCode;
520517

@@ -599,8 +596,8 @@ mod tests {
599596
}
600597

601598
fn assert_creds_equals_test_token_params(
602-
a: &Vec<CredentialParameters>,
603-
b: &Vec<TestTokenCredential>,
599+
a: &[CredentialParameters],
600+
b: &[TestTokenCredential],
604601
) {
605602
assert_eq!(a.len(), b.len());
606603

0 commit comments

Comments
 (0)