Improve code

This commit is contained in:
Sosthène Guédon 2022-11-02 19:02:46 +01:00
parent 3428da6e00
commit a867c17ab3
2 changed files with 30 additions and 6 deletions

View File

@ -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;

View File

@ -60,6 +60,29 @@ unsafe fn c(&self) -> &u8 {
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() {