11943: fix: Don't create `hir::Local`s from const path patterns r=Veykril a=Veykril

Fixes https://github.com/rust-analyzer/rust-analyzer/issues/11941

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
bors[bot] 2022-04-08 23:09:18 +00:00 committed by GitHub
commit 9093941ed0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 2 deletions

View File

@ -213,10 +213,15 @@ pub(super) fn bind_pat_to_def(
src: InFile<ast::IdentPat>,
) -> Option<(DefWithBodyId, PatId)> {
let container = self.find_pat_or_label_container(src.syntax())?;
let (_body, source_map) = self.db.body_with_source_map(container);
let (body, source_map) = self.db.body_with_source_map(container);
let src = src.map(ast::Pat::from);
let pat_id = source_map.node_pat(src.as_ref())?;
Some((container, pat_id))
// the pattern could resolve to a constant, verify that that is not the case
if let crate::Pat::Bind { .. } = body[pat_id] {
Some((container, pat_id))
} else {
None
}
}
pub(super) fn self_param_to_def(
&mut self,

View File

@ -935,6 +935,20 @@ fn f() {
0
};
}
"#,
);
}
#[test]
fn test_inline_let_unit_struct() {
check_assist_not_applicable(
inline_local_variable,
r#"
struct S;
fn f() {
let S$0 = S;
S;
}
"#,
);
}