Skip to content

Commit 6624158

Browse files
Fix panic in replace_derive_with_manual_impl
1 parent 1834938 commit 6624158

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ pub(crate) fn replace_derive_with_manual_impl(
4747
return None;
4848
}
4949

50+
if !args.syntax().text_range().contains(ctx.offset()) {
51+
cov_mark::hit!(outside_of_attr_args);
52+
return None;
53+
}
54+
5055
let trait_token = args.syntax().token_at_offset(ctx.offset()).find(|t| t.kind() == IDENT)?;
5156
let trait_name = trait_token.text();
5257

@@ -396,4 +401,16 @@ struct Foo {}
396401
",
397402
)
398403
}
404+
405+
#[test]
406+
fn works_at_start_of_file() {
407+
cov_mark::check!(outside_of_attr_args);
408+
check_assist_not_applicable(
409+
replace_derive_with_manual_impl,
410+
r#"
411+
$0#[derive(Debug)]
412+
struct S;
413+
"#,
414+
);
415+
}
399416
}

0 commit comments

Comments
 (0)