Skip to content

Commit 2fd29d0

Browse files
bors[bot]matklad
andauthored
Merge #6510
6510: Fix panic when extracting struct r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents 6b92cc4 + 4a16c22 commit 2fd29d0

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

crates/assists/src/assist_context.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,10 @@ impl AssistBuilder {
277277
algo::diff(old.syntax(), new.syntax()).into_text_edit(&mut self.edit)
278278
}
279279
pub(crate) fn rewrite(&mut self, rewriter: SyntaxRewriter) {
280-
let node = rewriter.rewrite_root().unwrap();
281-
let new = rewriter.rewrite(&node);
282-
algo::diff(&node, &new).into_text_edit(&mut self.edit);
280+
if let Some(node) = rewriter.rewrite_root() {
281+
let new = rewriter.rewrite(&node);
282+
algo::diff(&node, &new).into_text_edit(&mut self.edit);
283+
}
283284
}
284285

285286
fn finish(mut self) -> SourceChange {

crates/assists/src/handlers/extract_struct_from_enum_variant.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,36 @@ use crate::E;
378378
fn f() {
379379
let e = E::V(V(9, 2));
380380
}
381+
"#,
382+
)
383+
}
384+
385+
#[test]
386+
fn test_several_files_record() {
387+
// FIXME: this should fix the usage as well!
388+
check_assist(
389+
extract_struct_from_enum_variant,
390+
r#"
391+
//- /main.rs
392+
enum E {
393+
<|>V { i: i32, j: i32 }
394+
}
395+
mod foo;
396+
397+
//- /foo.rs
398+
use crate::E;
399+
fn f() {
400+
let e = E::V { i: 9, j: 2 };
401+
}
402+
"#,
403+
r#"
404+
struct V{ pub i: i32, pub j: i32 }
405+
406+
enum E {
407+
V(V)
408+
}
409+
mod foo;
410+
381411
"#,
382412
)
383413
}

0 commit comments

Comments
 (0)