Skip to content

Commit 9050db2

Browse files
committed
fix: Don't create hir::Locals from const path patterns
1 parent 15e7112 commit 9050db2

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

crates/hir/src/semantics/source_to_def.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,15 @@ impl SourceToDefCtx<'_, '_> {
213213
src: InFile<ast::IdentPat>,
214214
) -> Option<(DefWithBodyId, PatId)> {
215215
let container = self.find_pat_or_label_container(src.syntax())?;
216-
let (_body, source_map) = self.db.body_with_source_map(container);
216+
let (body, source_map) = self.db.body_with_source_map(container);
217217
let src = src.map(ast::Pat::from);
218218
let pat_id = source_map.node_pat(src.as_ref())?;
219-
Some((container, pat_id))
219+
// the pattern could resolve to a constant, verify that that is not the case
220+
if let crate::Pat::Bind { .. } = body[pat_id] {
221+
Some((container, pat_id))
222+
} else {
223+
None
224+
}
220225
}
221226
pub(super) fn self_param_to_def(
222227
&mut self,

crates/ide_assists/src/handlers/inline_local_variable.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,20 @@ fn f() {
935935
0
936936
};
937937
}
938+
"#,
939+
);
940+
}
941+
942+
#[test]
943+
fn test_inline_let_unit_struct() {
944+
check_assist_not_applicable(
945+
inline_local_variable,
946+
r#"
947+
struct S;
948+
fn f() {
949+
let S$0 = S;
950+
S;
951+
}
938952
"#,
939953
);
940954
}

0 commit comments

Comments
 (0)