summaryrefslogtreecommitdiffstats
path: root/src/tools/rust-analyzer/crates/ide/src/typing.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:50 +0000
commit2e00214b3efbdfeefaa0fe9e8b8fd519de7adc35 (patch)
treed325add32978dbdc1db975a438b3a77d571b1ab8 /src/tools/rust-analyzer/crates/ide/src/typing.rs
parentReleasing progress-linux version 1.68.2+dfsg1-1~progress7.99u1. (diff)
downloadrustc-2e00214b3efbdfeefaa0fe9e8b8fd519de7adc35.tar.xz
rustc-2e00214b3efbdfeefaa0fe9e8b8fd519de7adc35.zip
Merging upstream version 1.69.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/rust-analyzer/crates/ide/src/typing.rs')
-rw-r--r--src/tools/rust-analyzer/crates/ide/src/typing.rs57
1 files changed, 33 insertions, 24 deletions
diff --git a/src/tools/rust-analyzer/crates/ide/src/typing.rs b/src/tools/rust-analyzer/crates/ide/src/typing.rs
index eba5a4856..c7e403f6b 100644
--- a/src/tools/rust-analyzer/crates/ide/src/typing.rs
+++ b/src/tools/rust-analyzer/crates/ide/src/typing.rs
@@ -205,10 +205,8 @@ fn on_eq_typed(file: &SourceFile, offset: TextSize) -> Option<TextEdit> {
if expr_stmt.semicolon_token().is_some() {
return None;
}
- } else {
- if !ast::StmtList::can_cast(binop.syntax().parent()?.kind()) {
- return None;
- }
+ } else if !ast::StmtList::can_cast(binop.syntax().parent()?.kind()) {
+ return None;
}
let expr = binop.rhs()?;
@@ -255,6 +253,10 @@ fn on_eq_typed(file: &SourceFile, offset: TextSize) -> Option<TextEdit> {
if file.syntax().text().slice(offset..expr_range.start()).contains_char('\n') {
return None;
}
+ // Good indicator that we will insert into a bad spot, so bail out.
+ if expr.syntax().descendants().any(|it| it.kind() == SyntaxKind::ERROR) {
+ return None;
+ }
let offset = let_stmt.syntax().text_range().end();
Some(TextEdit::insert(offset, ";".to_string()))
}
@@ -409,15 +411,14 @@ mod tests {
#[test]
fn test_semi_after_let() {
- // do_check(r"
- // fn foo() {
- // let foo =$0
- // }
- // ", r"
- // fn foo() {
- // let foo =;
- // }
- // ");
+ type_char_noop(
+ '=',
+ r"
+fn foo() {
+ let foo =$0
+}
+",
+ );
type_char(
'=',
r#"
@@ -431,17 +432,25 @@ fn foo() {
}
"#,
);
- // do_check(r"
- // fn foo() {
- // let foo =$0
- // let bar = 1;
- // }
- // ", r"
- // fn foo() {
- // let foo =;
- // let bar = 1;
- // }
- // ");
+ type_char_noop(
+ '=',
+ r#"
+fn foo() {
+ let difference $0(counts: &HashMap<(char, char), u64>, last: char) -> u64 {
+ // ...
+ }
+}
+"#,
+ );
+ type_char_noop(
+ '=',
+ r"
+fn foo() {
+ let foo =$0
+ let bar = 1;
+}
+",
+ );
}
#[test]