diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-04-08 23:09:18 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-08 23:09:18 +0000 |
| commit | 9093941ed01ccae2469285bb1783e03d8ef93cba (patch) | |
| tree | 4765eb32e9ec9ccd391bcaef60798dc1f179f4ac | |
| parent | e11959a82ba6728c6a1851827a3e657d16229c23 (diff) | |
| parent | 9050db2e80ee0190cc4a6eddc972a5e19bc9f926 (diff) | |
| download | rust-9093941ed01ccae2469285bb1783e03d8ef93cba.tar.gz rust-9093941ed01ccae2469285bb1783e03d8ef93cba.zip | |
Merge #11943
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>
| -rw-r--r-- | crates/hir/src/semantics/source_to_def.rs | 9 | ||||
| -rw-r--r-- | crates/ide_assists/src/handlers/inline_local_variable.rs | 14 |
2 files changed, 21 insertions, 2 deletions
diff --git a/crates/hir/src/semantics/source_to_def.rs b/crates/hir/src/semantics/source_to_def.rs index 4672e7db40c..5c4cfa7b45a 100644 --- a/crates/hir/src/semantics/source_to_def.rs +++ b/crates/hir/src/semantics/source_to_def.rs @@ -213,10 +213,15 @@ impl SourceToDefCtx<'_, '_> { 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, diff --git a/crates/ide_assists/src/handlers/inline_local_variable.rs b/crates/ide_assists/src/handlers/inline_local_variable.rs index 0b4f46caf41..65dc2a0d511 100644 --- a/crates/ide_assists/src/handlers/inline_local_variable.rs +++ b/crates/ide_assists/src/handlers/inline_local_variable.rs @@ -938,4 +938,18 @@ fn f() { "#, ); } + + #[test] + fn test_inline_let_unit_struct() { + check_assist_not_applicable( + inline_local_variable, + r#" +struct S; +fn f() { + let S$0 = S; + S; +} +"#, + ); + } } |
