mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 23:24:24 +00:00
Improve code
This commit is contained in:
parent
3428da6e00
commit
a867c17ab3
2 changed files with 30 additions and 6 deletions
|
@ -16,7 +16,7 @@ pub fn check_fn(
|
|||
span: Span,
|
||||
_hir_id: HirId,
|
||||
) {
|
||||
let FnKind::Method(ref ident, sig) = kind else {
|
||||
let FnKind::Method(ref ident, _) = kind else {
|
||||
return;
|
||||
};
|
||||
|
||||
|
@ -27,7 +27,7 @@ pub fn check_fn(
|
|||
|
||||
let name = ident.name.as_str();
|
||||
|
||||
let name = match sig.decl.implicit_self {
|
||||
let name = match decl.implicit_self {
|
||||
ImplicitSelfKind::MutRef => {
|
||||
let Some(name) = name.strip_suffix("_mut") else {
|
||||
return;
|
||||
|
@ -53,11 +53,12 @@ pub fn check_fn(
|
|||
};
|
||||
let expr_span = block_expr.span;
|
||||
|
||||
let mut expr = block_expr;
|
||||
// Accept &<expr>, &mut <expr> and <expr>
|
||||
if let ExprKind::AddrOf(_, _, tmp) = expr.kind {
|
||||
expr = tmp;
|
||||
}
|
||||
let expr = if let ExprKind::AddrOf(_, _, tmp) = block_expr.kind {
|
||||
tmp
|
||||
} else {
|
||||
block_expr
|
||||
};
|
||||
let (self_data, used_ident) = if_chain! {
|
||||
if let ExprKind::Field(self_data, ident) = expr.kind;
|
||||
if ident.name.as_str() != name;
|
||||
|
|
|
@ -60,6 +60,29 @@ impl B {
|
|||
unsafe fn c_mut(&mut self) -> &mut u8 {
|
||||
&mut self.a
|
||||
}
|
||||
|
||||
unsafe fn a_unchecked(&self) -> &u8 {
|
||||
&self.b
|
||||
}
|
||||
unsafe fn a_unchecked_mut(&mut self) -> &mut u8 {
|
||||
&mut self.b
|
||||
}
|
||||
|
||||
unsafe fn b_unchecked(self) -> u8 {
|
||||
self.a
|
||||
}
|
||||
|
||||
unsafe fn b_unchecked_mut(&mut self) -> &mut u8 {
|
||||
&mut self.a
|
||||
}
|
||||
|
||||
unsafe fn c_unchecked(&self) -> &u8 {
|
||||
&self.b
|
||||
}
|
||||
|
||||
unsafe fn c_unchecked_mut(&mut self) -> &mut u8 {
|
||||
&mut self.a
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
Loading…
Reference in a new issue