Skip to content

Commit 3033c3d

Browse files
committed
Auto merge of #13841 - nyurik:lints2, r=lnicola
Moar linting: needless_borrow, let_unit_value, ... * There are a few needless borrows that don't seem to be needed. I even did a quick assembly comparison and posted a q to stackoveflow on it. See [here](https://stackoverflow.com/questions/74910196/advantages-of-pass-by-ref-val-with-impl-intoiteratoritem-impl-asrefstr) * removed several `let _ = ...` when they don't look necessary (even a few ones that were not suggested by clippy (?)) * some unneeded assignment+return - keep the code a bit leaner * a few `writeln!` instead of `write!`, or even consolidate write! * a nice optimization to use `ch.is_ascii_digit` instead of `ch.is_digit(10)`
2 parents 74ae2dd + d3dbf9c commit 3033c3d

File tree

15 files changed

+22
-26
lines changed

15 files changed

+22
-26
lines changed

crates/flycheck/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,11 @@ impl FlycheckActor {
297297
let mut cmd = Command::new(toolchain::cargo());
298298
cmd.arg(command);
299299
cmd.current_dir(&self.root);
300-
cmd.args(&["--workspace", "--message-format=json", "--manifest-path"])
300+
cmd.args(["--workspace", "--message-format=json", "--manifest-path"])
301301
.arg(self.root.join("Cargo.toml").as_os_str());
302302

303303
for target in target_triples {
304-
cmd.args(&["--target", target.as_str()]);
304+
cmd.args(["--target", target.as_str()]);
305305
}
306306
if *all_targets {
307307
cmd.arg("--all-targets");

crates/parser/src/grammar.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub(crate) mod entry {
5151
use super::*;
5252

5353
pub(crate) fn vis(p: &mut Parser<'_>) {
54-
let _ = opt_visibility(p, false);
54+
opt_visibility(p, false);
5555
}
5656

5757
pub(crate) fn block(p: &mut Parser<'_>) {
@@ -70,10 +70,10 @@ pub(crate) mod entry {
7070
types::type_(p);
7171
}
7272
pub(crate) fn expr(p: &mut Parser<'_>) {
73-
let _ = expressions::expr(p);
73+
expressions::expr(p);
7474
}
7575
pub(crate) fn path(p: &mut Parser<'_>) {
76-
let _ = paths::type_path(p);
76+
paths::type_path(p);
7777
}
7878
pub(crate) fn item(p: &mut Parser<'_>) {
7979
items::item_or_macro(p, true);

crates/parser/src/shortcuts.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ impl<'a> LexedStr<'a> {
8080
State::PendingEnter | State::Normal => unreachable!(),
8181
}
8282

83-
let is_eof = builder.pos == builder.lexed.len();
84-
is_eof
83+
// is_eof?
84+
builder.pos == builder.lexed.len()
8585
}
8686
}
8787

crates/parser/src/tests.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,12 @@ fn parse(entry: TopEntryPoint, text: &str) -> (String, bool) {
9393
crate::StrStep::Token { kind, text } => {
9494
assert!(depth > 0);
9595
len += text.len();
96-
write!(buf, "{indent}").unwrap();
97-
write!(buf, "{kind:?} {text:?}\n").unwrap();
96+
writeln!(buf, "{indent}{kind:?} {text:?}").unwrap();
9897
}
9998
crate::StrStep::Enter { kind } => {
10099
assert!(depth > 0 || len == 0);
101100
depth += 1;
102-
write!(buf, "{indent}").unwrap();
103-
write!(buf, "{kind:?}\n").unwrap();
101+
writeln!(buf, "{indent}{kind:?}").unwrap();
104102
indent.push_str(" ");
105103
}
106104
crate::StrStep::Exit => {

crates/proc-macro-api/src/process.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl Process {
6767
args: impl IntoIterator<Item = impl AsRef<OsStr>>,
6868
) -> io::Result<Process> {
6969
let args: Vec<OsString> = args.into_iter().map(|s| s.as_ref().into()).collect();
70-
let child = JodChild(mk_child(&path, &args)?);
70+
let child = JodChild(mk_child(&path, args)?);
7171
Ok(Process { child })
7272
}
7373

crates/proc-macro-test/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ fn main() {
6363
};
6464

6565
cmd.current_dir(&staging_dir)
66-
.args(&["build", "-p", "proc-macro-test-impl", "--message-format", "json"])
66+
.args(["build", "-p", "proc-macro-test-impl", "--message-format", "json"])
6767
// Explicit override the target directory to avoid using the same one which the parent
6868
// cargo is using, or we'll deadlock.
6969
// This can happen when `CARGO_TARGET_DIR` is set or global config forces all cargo

crates/syntax/src/ast/prec.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ impl Expr {
119119
fn binding_power(&self) -> (u8, u8) {
120120
use ast::{ArithOp::*, BinaryOp::*, Expr::*, LogicOp::*};
121121

122-
let dps = match self {
122+
match self {
123123
// (0, 0) -- paren-like/nullary
124124
// (0, N) -- prefix
125125
// (N, 0) -- postfix
@@ -170,9 +170,7 @@ impl Expr {
170170
ArrayExpr(_) | TupleExpr(_) | Literal(_) | PathExpr(_) | ParenExpr(_) | IfExpr(_)
171171
| WhileExpr(_) | ForExpr(_) | LoopExpr(_) | MatchExpr(_) | BlockExpr(_)
172172
| RecordExpr(_) | UnderscoreExpr(_) => (0, 0),
173-
};
174-
175-
dps
173+
}
176174
}
177175

178176
fn is_paren_like(&self) -> bool {

crates/syntax/src/ptr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl<N: AstNode> AstPtr<N> {
8282

8383
/// Like `SyntaxNodePtr::cast` but the trait bounds work out.
8484
pub fn try_from_raw(raw: SyntaxNodePtr) -> Option<AstPtr<N>> {
85-
N::can_cast(raw.kind()).then(|| AstPtr { raw, _ty: PhantomData })
85+
N::can_cast(raw.kind()).then_some(AstPtr { raw, _ty: PhantomData })
8686
}
8787
}
8888

crates/syntax/src/validation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ pub(crate) fn validate_block_structure(root: &SyntaxNode) {
196196

197197
fn validate_numeric_name(name_ref: Option<ast::NameRef>, errors: &mut Vec<SyntaxError>) {
198198
if let Some(int_token) = int_token(name_ref) {
199-
if int_token.text().chars().any(|c| !c.is_digit(10)) {
199+
if int_token.text().chars().any(|c| !c.is_ascii_digit()) {
200200
errors.push(SyntaxError::new(
201201
"Tuple (struct) field access is only allowed through \
202202
decimal integers with no underscores or suffix",

crates/test-utils/src/bench_fixture.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ struct S{} {{
3636

3737
pub fn glorious_old_parser() -> String {
3838
let path = project_root().join("bench_data/glorious_old_parser");
39-
fs::read_to_string(&path).unwrap()
39+
fs::read_to_string(path).unwrap()
4040
}
4141

4242
pub fn numerous_macro_rules() -> String {
4343
let path = project_root().join("bench_data/numerous_macro_rules");
44-
fs::read_to_string(&path).unwrap()
44+
fs::read_to_string(path).unwrap()
4545
}

crates/test-utils/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ pub fn skip_slow_tests() -> bool {
396396
eprintln!("ignoring slow test");
397397
} else {
398398
let path = project_root().join("./target/.slow_tests_cookie");
399-
fs::write(&path, ".").unwrap();
399+
fs::write(path, ".").unwrap();
400400
}
401401
should_skip
402402
}

crates/toolchain/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fn get_path_for_executable(executable_name: &'static str) -> PathBuf {
3535
// example: for cargo, this tries ~/.cargo/bin/cargo
3636
// It seems that this is a reasonable place to try for cargo, rustc, and rustup
3737
let env_var = executable_name.to_ascii_uppercase();
38-
if let Some(path) = env::var_os(&env_var) {
38+
if let Some(path) = env::var_os(env_var) {
3939
return path.into();
4040
}
4141

xtask/src/install.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ fn fix_path_for_mac(sh: &Shell) -> Result<()> {
6262
let mut paths = env::split_paths(&vars).collect::<Vec<_>>();
6363
paths.append(&mut vscode_path);
6464
let new_paths = env::join_paths(paths).context("build env PATH")?;
65-
sh.set_var("PATH", &new_paths);
65+
sh.set_var("PATH", new_paths);
6666
}
6767

6868
Ok(())

xtask/src/release.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl flags::Release {
6565

6666
let contents = changelog::get_changelog(sh, changelog_n, &commit, prev_tag, &today)?;
6767
let path = changelog_dir.join(format!("{today}-changelog-{changelog_n}.adoc"));
68-
sh.write_file(&path, &contents)?;
68+
sh.write_file(path, contents)?;
6969

7070
Ok(())
7171
}

xtask/src/release/changelog.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub(crate) fn get_changelog(
2323
let mut others = String::new();
2424
for line in git_log.lines() {
2525
let line = line.trim_start();
26-
if let Some(pr_num) = parse_pr_number(&line) {
26+
if let Some(pr_num) = parse_pr_number(line) {
2727
let accept = "Accept: application/vnd.github.v3+json";
2828
let authorization = format!("Authorization: token {token}");
2929
let pr_url = "https://api.github.com/repos/rust-lang/rust-analyzer/issues";

0 commit comments

Comments
 (0)