mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-08-31 07:37:30 +00:00
replace_arith_op not applicable on selected
This commit is contained in:
parent
e10fa9393e
commit
0fe2d7ffa1
1 changed files with 16 additions and 1 deletions
|
@ -102,6 +102,9 @@ fn is_primitive_int(ctx: &AssistContext<'_>, expr: &ast::Expr) -> bool {
|
|||
|
||||
/// Extract the operands of an arithmetic expression (e.g. `1 + 2` or `1.checked_add(2)`)
|
||||
fn parse_binary_op(ctx: &AssistContext<'_>) -> Option<(ast::Expr, ArithOp, ast::Expr)> {
|
||||
if !ctx.has_empty_selection() {
|
||||
return None;
|
||||
}
|
||||
let expr = ctx.find_node_at_offset::<ast::BinExpr>()?;
|
||||
|
||||
let op = match expr.op_kind() {
|
||||
|
@ -163,7 +166,7 @@ impl ArithKind {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::tests::check_assist;
|
||||
use crate::tests::{check_assist, check_assist_not_applicable};
|
||||
|
||||
use super::*;
|
||||
|
||||
|
@ -220,6 +223,18 @@ fn main() {
|
|||
fn main() {
|
||||
let x = 1.wrapping_add(2);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn replace_arith_not_applicable_with_non_empty_selection() {
|
||||
check_assist_not_applicable(
|
||||
replace_arith_with_checked,
|
||||
r#"
|
||||
fn main() {
|
||||
let x = 1 $0+$0 2;
|
||||
}
|
||||
"#,
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue