Skip to content

Commit 14982db

Browse files
committed
in which the unused-parens lint comes to cover function and method args
Resolves rust-lang#46137.
1 parent 44afd76 commit 14982db

File tree

7 files changed

+25
-11
lines changed

7 files changed

+25
-11
lines changed

src/liballoc/vec_deque.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2480,7 +2480,7 @@ impl<T> From<VecDeque<T>> for Vec<T> {
24802480
if other.is_contiguous() {
24812481
ptr::copy(buf.offset(tail as isize), buf, len);
24822482
} else {
2483-
if (tail - head) >= cmp::min((cap - tail), head) {
2483+
if (tail - head) >= cmp::min(cap - tail, head) {
24842484
// There is enough free space in the centre for the shortest block so we can
24852485
// do this in at most three copy moves.
24862486
if (cap - tail) > head {

src/librustc_apfloat/ieee.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1434,7 +1434,7 @@ impl<S: Semantics> Float for IeeeFloat<S> {
14341434
let max_change = S::MAX_EXP as i32 - (S::MIN_EXP as i32 - sig_bits) + 1;
14351435

14361436
// Clamp to one past the range ends to let normalize handle overflow.
1437-
let exp_change = cmp::min(cmp::max(exp as i32, (-max_change - 1)), max_change);
1437+
let exp_change = cmp::min(cmp::max(exp as i32, -max_change - 1), max_change);
14381438
self.exp = self.exp.saturating_add(exp_change as ExpInt);
14391439
self = self.normalize(round, Loss::ExactlyZero).value;
14401440
if self.is_nan() {

src/librustc_lint/unused.rs

+12
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,18 @@ impl EarlyLintPass for UnusedParens {
302302
Assign(_, ref value) => (value, "assigned value", false),
303303
AssignOp(.., ref value) => (value, "assigned value", false),
304304
InPlace(_, ref value) => (value, "emplacement value", false),
305+
Call(_, ref args) => {
306+
for arg in args {
307+
self.check_unused_parens_core(cx, arg, "function argument", false)
308+
}
309+
return;
310+
},
311+
MethodCall(_, ref args) => {
312+
for arg in &args[1..] { // first "argument" is self (which sometimes needs parens)
313+
self.check_unused_parens_core(cx, arg, "method argument", false)
314+
}
315+
return;
316+
}
305317
_ => return,
306318
};
307319
self.check_unused_parens_core(cx, &value, msg, struct_lit_needs_parens);

src/librustc_mir/dataflow/impls/borrows.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl<'tcx> fmt::Display for BorrowData<'tcx> {
131131
}
132132

133133
impl ReserveOrActivateIndex {
134-
fn reserved(i: BorrowIndex) -> Self { ReserveOrActivateIndex::new((i.index() * 2)) }
134+
fn reserved(i: BorrowIndex) -> Self { ReserveOrActivateIndex::new(i.index() * 2) }
135135
fn active(i: BorrowIndex) -> Self { ReserveOrActivateIndex::new((i.index() * 2) + 1) }
136136

137137
pub(crate) fn is_reservation(self) -> bool { self.index() % 2 == 0 }

src/librustc_resolve/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ impl<'a> ModuleData<'a> {
963963
unresolved_invocations: RefCell::new(FxHashSet()),
964964
no_implicit_prelude: false,
965965
glob_importers: RefCell::new(Vec::new()),
966-
globs: RefCell::new((Vec::new())),
966+
globs: RefCell::new(Vec::new()),
967967
traits: RefCell::new(None),
968968
populated: Cell::new(normal_ancestor_id.is_local()),
969969
span,

src/libstd/sys/unix/thread.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,8 @@ pub mod guard {
311311

312312
#[cfg(target_os = "macos")]
313313
pub unsafe fn current() -> Option<usize> {
314-
Some((libc::pthread_get_stackaddr_np(libc::pthread_self()) as usize -
315-
libc::pthread_get_stacksize_np(libc::pthread_self())))
314+
Some(libc::pthread_get_stackaddr_np(libc::pthread_self()) as usize -
315+
libc::pthread_get_stacksize_np(libc::pthread_self()))
316316
}
317317

318318
#[cfg(any(target_os = "openbsd", target_os = "bitrig"))]

src/test/compile-fail/lint-unnecessary-parens.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@
1313
#[derive(Eq, PartialEq)]
1414
struct X { y: bool }
1515
impl X {
16-
fn foo(&self) -> bool { self.y }
16+
fn foo(&self, conjunct: bool) -> bool { self.y && conjunct }
1717
}
1818

1919
fn foo() -> isize {
2020
return (1); //~ ERROR unnecessary parentheses around `return` value
2121
}
22-
fn bar() -> X {
23-
return (X { y: true }); //~ ERROR unnecessary parentheses around `return` value
22+
fn bar(y: bool) -> X {
23+
return (X { y }); //~ ERROR unnecessary parentheses around `return` value
2424
}
2525

2626
fn main() {
2727
foo();
28-
bar();
28+
bar((true)); //~ ERROR unnecessary parentheses around function argument
2929

3030
if (true) {} //~ ERROR unnecessary parentheses around `if` condition
3131
while (true) {} //~ ERROR unnecessary parentheses around `while` condition
@@ -40,13 +40,15 @@ fn main() {
4040
if (X { y: true } == v) {}
4141
if (X { y: false }.y) {}
4242

43-
while (X { y: false }.foo()) {}
43+
while (X { y: false }.foo(true)) {}
4444
while (true | X { y: false }.y) {}
4545

4646
match (X { y: false }) {
4747
_ => {}
4848
}
4949

50+
X { y: false }.foo((true)); //~ ERROR unnecessary parentheses around method argument
51+
5052
let mut _a = (0); //~ ERROR unnecessary parentheses around assigned value
5153
_a = (0); //~ ERROR unnecessary parentheses around assigned value
5254
_a += (1); //~ ERROR unnecessary parentheses around assigned value

0 commit comments

Comments
 (0)