in which the unused-parens lint comes to cover function and method args
Resolves #46137.
This commit is contained in:
parent
44afd76788
commit
14982db2d6
@ -2480,7 +2480,7 @@ impl<T> From<VecDeque<T>> for Vec<T> {
|
|||||||
if other.is_contiguous() {
|
if other.is_contiguous() {
|
||||||
ptr::copy(buf.offset(tail as isize), buf, len);
|
ptr::copy(buf.offset(tail as isize), buf, len);
|
||||||
} else {
|
} else {
|
||||||
if (tail - head) >= cmp::min((cap - tail), head) {
|
if (tail - head) >= cmp::min(cap - tail, head) {
|
||||||
// There is enough free space in the centre for the shortest block so we can
|
// There is enough free space in the centre for the shortest block so we can
|
||||||
// do this in at most three copy moves.
|
// do this in at most three copy moves.
|
||||||
if (cap - tail) > head {
|
if (cap - tail) > head {
|
||||||
|
@ -1434,7 +1434,7 @@ impl<S: Semantics> Float for IeeeFloat<S> {
|
|||||||
let max_change = S::MAX_EXP as i32 - (S::MIN_EXP as i32 - sig_bits) + 1;
|
let max_change = S::MAX_EXP as i32 - (S::MIN_EXP as i32 - sig_bits) + 1;
|
||||||
|
|
||||||
// Clamp to one past the range ends to let normalize handle overflow.
|
// Clamp to one past the range ends to let normalize handle overflow.
|
||||||
let exp_change = cmp::min(cmp::max(exp as i32, (-max_change - 1)), max_change);
|
let exp_change = cmp::min(cmp::max(exp as i32, -max_change - 1), max_change);
|
||||||
self.exp = self.exp.saturating_add(exp_change as ExpInt);
|
self.exp = self.exp.saturating_add(exp_change as ExpInt);
|
||||||
self = self.normalize(round, Loss::ExactlyZero).value;
|
self = self.normalize(round, Loss::ExactlyZero).value;
|
||||||
if self.is_nan() {
|
if self.is_nan() {
|
||||||
|
@ -302,6 +302,18 @@ impl EarlyLintPass for UnusedParens {
|
|||||||
Assign(_, ref value) => (value, "assigned value", false),
|
Assign(_, ref value) => (value, "assigned value", false),
|
||||||
AssignOp(.., ref value) => (value, "assigned value", false),
|
AssignOp(.., ref value) => (value, "assigned value", false),
|
||||||
InPlace(_, ref value) => (value, "emplacement value", false),
|
InPlace(_, ref value) => (value, "emplacement value", false),
|
||||||
|
Call(_, ref args) => {
|
||||||
|
for arg in args {
|
||||||
|
self.check_unused_parens_core(cx, arg, "function argument", false)
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
},
|
||||||
|
MethodCall(_, ref args) => {
|
||||||
|
for arg in &args[1..] { // first "argument" is self (which sometimes needs parens)
|
||||||
|
self.check_unused_parens_core(cx, arg, "method argument", false)
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
_ => return,
|
_ => return,
|
||||||
};
|
};
|
||||||
self.check_unused_parens_core(cx, &value, msg, struct_lit_needs_parens);
|
self.check_unused_parens_core(cx, &value, msg, struct_lit_needs_parens);
|
||||||
|
@ -131,7 +131,7 @@ impl<'tcx> fmt::Display for BorrowData<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ReserveOrActivateIndex {
|
impl ReserveOrActivateIndex {
|
||||||
fn reserved(i: BorrowIndex) -> Self { ReserveOrActivateIndex::new((i.index() * 2)) }
|
fn reserved(i: BorrowIndex) -> Self { ReserveOrActivateIndex::new(i.index() * 2) }
|
||||||
fn active(i: BorrowIndex) -> Self { ReserveOrActivateIndex::new((i.index() * 2) + 1) }
|
fn active(i: BorrowIndex) -> Self { ReserveOrActivateIndex::new((i.index() * 2) + 1) }
|
||||||
|
|
||||||
pub(crate) fn is_reservation(self) -> bool { self.index() % 2 == 0 }
|
pub(crate) fn is_reservation(self) -> bool { self.index() % 2 == 0 }
|
||||||
|
@ -963,7 +963,7 @@ impl<'a> ModuleData<'a> {
|
|||||||
unresolved_invocations: RefCell::new(FxHashSet()),
|
unresolved_invocations: RefCell::new(FxHashSet()),
|
||||||
no_implicit_prelude: false,
|
no_implicit_prelude: false,
|
||||||
glob_importers: RefCell::new(Vec::new()),
|
glob_importers: RefCell::new(Vec::new()),
|
||||||
globs: RefCell::new((Vec::new())),
|
globs: RefCell::new(Vec::new()),
|
||||||
traits: RefCell::new(None),
|
traits: RefCell::new(None),
|
||||||
populated: Cell::new(normal_ancestor_id.is_local()),
|
populated: Cell::new(normal_ancestor_id.is_local()),
|
||||||
span,
|
span,
|
||||||
|
@ -311,8 +311,8 @@ pub mod guard {
|
|||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
pub unsafe fn current() -> Option<usize> {
|
pub unsafe fn current() -> Option<usize> {
|
||||||
Some((libc::pthread_get_stackaddr_np(libc::pthread_self()) as usize -
|
Some(libc::pthread_get_stackaddr_np(libc::pthread_self()) as usize -
|
||||||
libc::pthread_get_stacksize_np(libc::pthread_self())))
|
libc::pthread_get_stacksize_np(libc::pthread_self()))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(target_os = "openbsd", target_os = "bitrig"))]
|
#[cfg(any(target_os = "openbsd", target_os = "bitrig"))]
|
||||||
|
@ -13,19 +13,19 @@
|
|||||||
#[derive(Eq, PartialEq)]
|
#[derive(Eq, PartialEq)]
|
||||||
struct X { y: bool }
|
struct X { y: bool }
|
||||||
impl X {
|
impl X {
|
||||||
fn foo(&self) -> bool { self.y }
|
fn foo(&self, conjunct: bool) -> bool { self.y && conjunct }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn foo() -> isize {
|
fn foo() -> isize {
|
||||||
return (1); //~ ERROR unnecessary parentheses around `return` value
|
return (1); //~ ERROR unnecessary parentheses around `return` value
|
||||||
}
|
}
|
||||||
fn bar() -> X {
|
fn bar(y: bool) -> X {
|
||||||
return (X { y: true }); //~ ERROR unnecessary parentheses around `return` value
|
return (X { y }); //~ ERROR unnecessary parentheses around `return` value
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
foo();
|
foo();
|
||||||
bar();
|
bar((true)); //~ ERROR unnecessary parentheses around function argument
|
||||||
|
|
||||||
if (true) {} //~ ERROR unnecessary parentheses around `if` condition
|
if (true) {} //~ ERROR unnecessary parentheses around `if` condition
|
||||||
while (true) {} //~ ERROR unnecessary parentheses around `while` condition
|
while (true) {} //~ ERROR unnecessary parentheses around `while` condition
|
||||||
@ -40,13 +40,15 @@ fn main() {
|
|||||||
if (X { y: true } == v) {}
|
if (X { y: true } == v) {}
|
||||||
if (X { y: false }.y) {}
|
if (X { y: false }.y) {}
|
||||||
|
|
||||||
while (X { y: false }.foo()) {}
|
while (X { y: false }.foo(true)) {}
|
||||||
while (true | X { y: false }.y) {}
|
while (true | X { y: false }.y) {}
|
||||||
|
|
||||||
match (X { y: false }) {
|
match (X { y: false }) {
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
X { y: false }.foo((true)); //~ ERROR unnecessary parentheses around method argument
|
||||||
|
|
||||||
let mut _a = (0); //~ ERROR unnecessary parentheses around assigned value
|
let mut _a = (0); //~ ERROR unnecessary parentheses around assigned value
|
||||||
_a = (0); //~ ERROR unnecessary parentheses around assigned value
|
_a = (0); //~ ERROR unnecessary parentheses around assigned value
|
||||||
_a += (1); //~ ERROR unnecessary parentheses around assigned value
|
_a += (1); //~ ERROR unnecessary parentheses around assigned value
|
||||||
|
Loading…
Reference in New Issue
Block a user