mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 11:59:49 +00:00
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 (?)) * there were a few `then(|| ctor{})` that clippy suggested to replace with `then_some(ctor{})` -- seems reasonable? * 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)`
This commit is contained in:
parent
2872e05589
commit
d3dbf9c194
15 changed files with 22 additions and 26 deletions
|
@ -119,7 +119,7 @@ impl Expr {
|
|||
fn binding_power(&self) -> (u8, u8) {
|
||||
use ast::{ArithOp::*, BinaryOp::*, Expr::*, LogicOp::*};
|
||||
|
||||
let dps = match self {
|
||||
match self {
|
||||
// (0, 0) -- paren-like/nullary
|
||||
// (0, N) -- prefix
|
||||
// (N, 0) -- postfix
|
||||
|
@ -170,9 +170,7 @@ impl Expr {
|
|||
ArrayExpr(_) | TupleExpr(_) | Literal(_) | PathExpr(_) | ParenExpr(_) | IfExpr(_)
|
||||
| WhileExpr(_) | ForExpr(_) | LoopExpr(_) | MatchExpr(_) | BlockExpr(_)
|
||||
| RecordExpr(_) | UnderscoreExpr(_) => (0, 0),
|
||||
};
|
||||
|
||||
dps
|
||||
}
|
||||
}
|
||||
|
||||
fn is_paren_like(&self) -> bool {
|
||||
|
|
|
@ -82,7 +82,7 @@ impl<N: AstNode> AstPtr<N> {
|
|||
|
||||
/// Like `SyntaxNodePtr::cast` but the trait bounds work out.
|
||||
pub fn try_from_raw(raw: SyntaxNodePtr) -> Option<AstPtr<N>> {
|
||||
N::can_cast(raw.kind()).then(|| AstPtr { raw, _ty: PhantomData })
|
||||
N::can_cast(raw.kind()).then_some(AstPtr { raw, _ty: PhantomData })
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -196,7 +196,7 @@ pub(crate) fn validate_block_structure(root: &SyntaxNode) {
|
|||
|
||||
fn validate_numeric_name(name_ref: Option<ast::NameRef>, errors: &mut Vec<SyntaxError>) {
|
||||
if let Some(int_token) = int_token(name_ref) {
|
||||
if int_token.text().chars().any(|c| !c.is_digit(10)) {
|
||||
if int_token.text().chars().any(|c| !c.is_ascii_digit()) {
|
||||
errors.push(SyntaxError::new(
|
||||
"Tuple (struct) field access is only allowed through \
|
||||
decimal integers with no underscores or suffix",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue