Skip to content

Commit 6403dbf

Browse files
committed
fix ast::Path::segments callers that implicitly relied on behavior of previous implementation
1 parent 08c44a6 commit 6403dbf

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

crates/ide-assists/src/handlers/generate_constant.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ pub(crate) fn generate_constant(acc: &mut Assists, ctx: &AssistContext<'_>) -> O
5050
ty.original().display_source_code(ctx.db(), constant_module.into(), false).ok()?;
5151
let target = statement.syntax().parent()?.text_range();
5252
let path = constant_token.syntax().ancestors().find_map(ast::Path::cast)?;
53+
if path.parent_path().is_some() {
54+
cov_mark::hit!(not_last_path_segment);
55+
return None;
56+
}
5357

5458
let name_refs = path.segments().map(|s| s.name_ref());
5559
let mut outer_exists = false;
@@ -250,6 +254,18 @@ fn bar() -> i32 {
250254
}
251255
fn bar() -> i32 {
252256
foo::goo::A_CONSTANT
257+
}"#,
258+
);
259+
}
260+
261+
#[test]
262+
fn test_wont_apply_when_not_last_path_segment() {
263+
cov_mark::check!(not_last_path_segment);
264+
check_assist_not_applicable(
265+
generate_constant,
266+
r#"mod foo {}
267+
fn bar() -> i32 {
268+
foo::A_CON$0STANT::invalid_segment
253269
}"#,
254270
);
255271
}

0 commit comments

Comments
 (0)