Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rustc and clippy warnings #247

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open

Fix rustc and clippy warnings #247

wants to merge 15 commits into from

Conversation

taiki-e
Copy link

@taiki-e taiki-e commented Feb 11, 2022

Basically, each commit corresponds to one warning each.
Each commit message contains the details of the warning.

(the first commit is from #245 -- without it, master fails to build)

master is currently broken because platforms crate yanked the old versions.

```
cargo install -f --path .
  Installing cargo-asm v0.1.17 (/Users/taiki/projects/cargo-asm)
    Updating crates.io index
error: failed to compile `cargo-asm v0.1.17 (/Users/taiki/projects/cargo-asm)`, intermediate artifacts can be found at `/Users/taiki/projects/cargo-asm/target`

Caused by:
  failed to select a version for the requirement `platforms = "^0.2"`
  candidate versions found which didn't match: 2.0.0, 1.1.0, 1.0.3, ...
  location searched: crates.io index
  required by package `cargo-asm v0.1.17 (/Users/taiki/projects/cargo-asm)
```
```text
warning: unnecessary braces around block return value
  --> src/options.rs:12:9
   |
12 |         { ::parking_lot::RwLock::new(read()) };
   |         ^^                                  ^^
   |
   = note: `#[warn(unused_braces)]` on by default
help: remove these braces
   |
12 -         { ::parking_lot::RwLock::new(read()) };
12 +         ::parking_lot::RwLock::new(read());
   |
```
```text
warning: unused return value of `Path::parent` that must be used
   --> src/rust.rs:176:5
    |
176 |     sysroot.parent();
    |     ^^^^^^^^^^^^^^^^^
    |
    = note: `#[warn(unused_must_use)]` on by default
```
```text
warning: this expression creates a reference which is immediately dereferenced by the compiler
   --> src/llvmir.rs:166:62
    |
166 |                     crate::demangle::demangle(&mangled_name, &target)
    |                                                              ^^^^^^^ help: change this to: `target`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
```
```text
warning: this import is redundant
 --> src/demangle.rs:5:1
  |
5 | use rustc_demangle;
  | ^^^^^^^^^^^^^^^^^^^ help: remove it entirely
  |
  = note: `#[warn(clippy::single_component_path_imports)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_component_path_imports
```
```text
warning: redundant clone
   --> src/target.rs:114:42
    |
114 | ...                   return target.to_owned();
    |                                    ^^^^^^^^^^^ help: remove this
    |
note: this value is dropped without further use
   --> src/target.rs:114:36
    |
114 | ...                   return target.to_owned();
    |                              ^^^^^^
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone
```
```text
arning: unneeded `return` statement
   --> src/display.rs:304:9
    |
304 |         return;
    |         ^^^^^^^ help: remove `return`
    |
    = note: `#[warn(clippy::needless_return)]` on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return
```
```text
warning: this loop could be written as a `for` loop
   --> src/asm/parse.rs:207:17
    |
207 |                 while let Some(l) = line_iter.next() {
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for l in line_iter.by_ref()`
    |
    = note: `#[warn(clippy::while_let_on_iterator)]` on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#while_let_on_iterator
```
```text
warning: manual implementation of `Option::map`
   --> src/display.rs:252:31
    |
252 |       let function_file_index = if let Some(loc) = f.loc {
    |  _______________________________^
253 | |         Some(loc.file_index)
254 | |     } else {
255 | |         None
256 | |     };
    | |_____^ help: try this: `f.loc.map(|loc| loc.file_index)`
    |
    = note: `#[warn(clippy::manual_map)]` on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_map
```
```text
warning: field assignment outside of initializer for an instance created with Default::default()
  --> src/target.rs:26:9
   |
26 |         ti.triple = triple;
   |         ^^^^^^^^^^^^^^^^^^^
   |
   = note: requested on the command line with `-W clippy::field-reassign-with-default`
note: consider initializing the variable with `target::TargetInfo { triple: triple }` and removing relevant reassignments
  --> src/target.rs:25:9
   |
25 |         let mut ti = TargetInfo::default();
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#field_reassign_with_default
```
```text
warning: this `if let` can be collapsed into the outer `if let`
  --> src/path.rs:19:13
   |
19 | /             if let ::std::path::Component::RootDir = next_sp {
20 | |                 if !cfg!(target_os = "windows") {
21 | |                     next_sub_path = sub_path_iter.next();
22 | |                 }
23 | |             }
   | |_____________^
   |
   = note: requested on the command line with `-W clippy::collapsible-match`
help: the outer pattern can be modified to include the inner pattern
  --> src/path.rs:18:21
   |
18 |         if let Some(next_sp) = next_sub_path {
   |                     ^^^^^^^ replace this binding
19 |             if let ::std::path::Component::RootDir = next_sp {
   |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ with this pattern
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_match

warning: this `if let` can be collapsed into the outer `if let`
  --> src/path.rs:63:17
   |
63 | /                 if let ::std::path::Component::RootDir = next_sp {
64 | |                     if !cfg!(target_os = "windows") {
65 | |                         next_sub_path = sub_path_iter.next();
66 | |                     }
67 | |                 }
   | |_________________^
   |
help: the outer pattern can be modified to include the inner pattern
  --> src/path.rs:62:25
   |
62 |             if let Some(next_sp) = next_sub_path {
   |                         ^^^^^^^ replace this binding
63 |                 if let ::std::path::Component::RootDir = next_sp {
   |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ with this pattern
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_match

warning: this `if let` can be collapsed into the outer `if let`
  --> src/rust.rs:17:13
   |
17 | /             if let Some(ref l) = l {
18 | |                 return Some(l.clone());
19 | |             }
   | |_____________^
   |
help: the outer pattern can be modified to include the inner pattern
  --> src/rust.rs:16:21
   |
16 |         if let Some(l) = self.lines.get(&line_idx) {
   |                     ^ replace this binding
17 |             if let Some(ref l) = l {
   |                    ^^^^^^^^^^^ with this pattern
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_match
```
```text
warning: called `.nth(0)` on a `std::iter::Iterator`, when `.next()` is equivalent
  --> src/demangle.rs:23:9
   |
23 |         n.split("@plt").nth(0).unwrap().to_string()
   |         ^^^^^^^^^^^^^^^^^^^^^^ help: try calling `.next()` instead of `.nth(0)`: `n.split("@plt").next()`
   |
   = note: `#[warn(clippy::iter_nth_zero)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#iter_nth_zero
```
```text
warning: manual `RangeInclusive::contains` implementation
  --> src/demangle.rs:18:5
   |
18 |     byte >= b'0' && byte <= b'9' || byte >= b'a' && byte <= b'f'
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `(b'0'..=b'9').contains(&byte)`
   |
   = note: `#[warn(clippy::manual_range_contains)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_range_contains

warning: manual `RangeInclusive::contains` implementation
  --> src/demangle.rs:18:37
   |
18 |     byte >= b'0' && byte <= b'9' || byte >= b'a' && byte <= b'f'
   |                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `(b'a'..=b'f').contains(&byte)`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_range_contains
```
```text
warning: name `ATT` contains a capitalized acronym
  --> src/asm/mod.rs:10:5
   |
10 |     ATT,
   |     ^^^ help: consider making the acronym lowercase, except the initial letter: `Att`
   |
   = note: `#[warn(clippy::upper_case_acronyms)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#upper_case_acronyms
```
False positive has been fixed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant