mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-13 08:27:17 +00:00
Check const reference
This commit is contained in:
parent
81d7cbbbe2
commit
8d7a393008
1 changed files with 52 additions and 1 deletions
|
@ -16,7 +16,10 @@ fn binders_in_pat(
|
|||
IdentPat(p) => {
|
||||
let ident = p.name()?;
|
||||
let ismut = p.ref_token().is_none() && p.mut_token().is_some();
|
||||
acc.push((ident, ismut));
|
||||
// check for const reference
|
||||
if !(p.is_simple_ident() && sem.resolve_bind_pat_to_const(p).is_some()) {
|
||||
acc.push((ident, ismut));
|
||||
}
|
||||
if let Some(inner) = p.pat() {
|
||||
binders_in_pat(acc, &inner, sem)?;
|
||||
}
|
||||
|
@ -244,6 +247,54 @@ fn main() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn convert_let_else_to_match_const_ref() {
|
||||
check_assist(
|
||||
convert_let_else_to_match,
|
||||
r"
|
||||
enum Option<T> {
|
||||
Some(T),
|
||||
None,
|
||||
}
|
||||
use Option::*;
|
||||
fn main() {
|
||||
let None = f() el$0se { continue };
|
||||
}",
|
||||
r"
|
||||
enum Option<T> {
|
||||
Some(T),
|
||||
None,
|
||||
}
|
||||
use Option::*;
|
||||
fn main() {
|
||||
match f() {
|
||||
None => {}
|
||||
_ => continue,
|
||||
}
|
||||
}",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn convert_let_else_to_match_const_ref_const() {
|
||||
check_assist(
|
||||
convert_let_else_to_match,
|
||||
r"
|
||||
const NEG1: i32 = -1;
|
||||
fn main() {
|
||||
let NEG1 = f() el$0se { continue };
|
||||
}",
|
||||
r"
|
||||
const NEG1: i32 = -1;
|
||||
fn main() {
|
||||
match f() {
|
||||
NEG1 => {}
|
||||
_ => continue,
|
||||
}
|
||||
}",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn convert_let_else_to_match_mut() {
|
||||
check_assist(
|
||||
|
|
Loading…
Reference in a new issue