Use .as_ref() in lieu of &** (#5874)

I find this less opaque (and often more succinct).
This commit is contained in:
Charlie Marsh 2023-07-18 20:49:13 -04:00 committed by GitHub
parent 7ffcd93afd
commit 626d8dc2cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 17 additions and 21 deletions

View file

@ -65,7 +65,7 @@ where
}) => {
// Allow `tuple()` and `list()` calls.
if keywords.is_empty() && args.len() <= 1 {
if let Expr::Name(ast::ExprName { id, .. }) = &**func {
if let Expr::Name(ast::ExprName { id, .. }) = func.as_ref() {
let id = id.as_str();
if id == "tuple" || id == "list" {
if is_builtin(id) {
@ -106,7 +106,7 @@ where
Stmt::AugAssign(ast::StmtAugAssign { value, .. }) => Some(value),
_ => None,
} {
if let Expr::BinOp(ast::ExprBinOp { left, right, .. }) = &**value {
if let Expr::BinOp(ast::ExprBinOp { left, right, .. }) = value.as_ref() {
let mut current_left = left;
let mut current_right = right;
loop {
@ -119,7 +119,7 @@ where
// Process the left side, which can be a "real" value or the "rest" of the
// binary operation.
if let Expr::BinOp(ast::ExprBinOp { left, right, .. }) = &**current_left {
if let Expr::BinOp(ast::ExprBinOp { left, right, .. }) = current_left.as_ref() {
current_left = left;
current_right = right;
} else {

View file

@ -274,7 +274,7 @@ impl<'a> From<&'a ast::Pattern> for ComparablePattern<'a> {
impl<'a> From<&'a Box<ast::Pattern>> for Box<ComparablePattern<'a>> {
fn from(pattern: &'a Box<ast::Pattern>) -> Self {
Box::new((&**pattern).into())
Box::new((pattern.as_ref()).into())
}
}
@ -362,13 +362,13 @@ impl<'a> From<&'a ast::Arguments> for ComparableArguments<'a> {
impl<'a> From<&'a Box<ast::Arguments>> for ComparableArguments<'a> {
fn from(arguments: &'a Box<ast::Arguments>) -> Self {
(&**arguments).into()
(arguments.as_ref()).into()
}
}
impl<'a> From<&'a Box<ast::Arg>> for ComparableArg<'a> {
fn from(arg: &'a Box<ast::Arg>) -> Self {
(&**arg).into()
(arg.as_ref()).into()
}
}
@ -685,13 +685,13 @@ pub enum ComparableExpr<'a> {
impl<'a> From<&'a Box<ast::Expr>> for Box<ComparableExpr<'a>> {
fn from(expr: &'a Box<ast::Expr>) -> Self {
Box::new((&**expr).into())
Box::new((expr.as_ref()).into())
}
}
impl<'a> From<&'a Box<ast::Expr>> for ComparableExpr<'a> {
fn from(expr: &'a Box<ast::Expr>) -> Self {
(&**expr).into()
(expr.as_ref()).into()
}
}
@ -737,7 +737,7 @@ impl<'a> From<&'a ast::Expr> for ComparableExpr<'a> {
body,
range: _range,
}) => Self::Lambda(ExprLambda {
args: (&**args).into(),
args: (args.as_ref()).into(),
body: body.into(),
}),
ast::Expr::IfExp(ast::ExprIfExp {

View file

@ -1156,7 +1156,7 @@ impl<'a> Generator<'a> {
range: _range,
})],
[],
) = (&**args, &**keywords)
) = (args.as_slice(), keywords.as_slice())
{
// Ensure that a single generator doesn't get double-parenthesized.
self.unparse_expr(elt, precedence::COMMA);