aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-12-13 11:34:43 +0000
committerGitHub <[email protected]>2020-12-13 11:34:43 +0000
commitca3a54f0a4b59fb2c4429096a1d5c1bc2b8e761e (patch)
treec9c4847ae019de3cc61ecb5a908c99d8a41d3d17 /crates
parenta15d19619e097b14b670064a4edc054a4251f479 (diff)
parentae8a8020857080ea527cc1d0e57a592d6e587a64 (diff)
Merge #6852
6852: Ignore lifetime params in substitutions r=matklad a=Veykril [`hir_ty::utils::Generics`](https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir_ty/src/utils.rs#L153) currently only assumes type parameters but not lifetime parameters and therefor creates incorrect index and length calculations, this PR just makes the use sites ignore LifetimeGenerics for now. This fixes the panic at least locally for me for `analysis-stats`. Funnily enough this panic prevented me from using reference search for the `args` field to fix this problem. Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/hir_def/src/item_tree.rs5
-rw-r--r--crates/hir_ty/src/infer/expr.rs7
-rw-r--r--crates/hir_ty/src/lower.rs8
3 files changed, 17 insertions, 3 deletions
diff --git a/crates/hir_def/src/item_tree.rs b/crates/hir_def/src/item_tree.rs
index c6ada271e..b08167281 100644
--- a/crates/hir_def/src/item_tree.rs
+++ b/crates/hir_def/src/item_tree.rs
@@ -246,7 +246,10 @@ struct GenericParamsStorage {
246 246
247impl GenericParamsStorage { 247impl GenericParamsStorage {
248 fn alloc(&mut self, params: GenericParams) -> GenericParamsId { 248 fn alloc(&mut self, params: GenericParams) -> GenericParamsId {
249 if params.types.is_empty() && params.where_predicates.is_empty() { 249 if params.types.is_empty()
250 && params.lifetimes.is_empty()
251 && params.where_predicates.is_empty()
252 {
250 return GenericParamsId::EMPTY; 253 return GenericParamsId::EMPTY;
251 } 254 }
252 255
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs
index ca005bc99..2cdce2cef 100644
--- a/crates/hir_ty/src/infer/expr.rs
+++ b/crates/hir_ty/src/infer/expr.rs
@@ -856,7 +856,12 @@ impl<'a> InferenceContext<'a> {
856 // handle provided type arguments 856 // handle provided type arguments
857 if let Some(generic_args) = generic_args { 857 if let Some(generic_args) = generic_args {
858 // if args are provided, it should be all of them, but we can't rely on that 858 // if args are provided, it should be all of them, but we can't rely on that
859 for arg in generic_args.args.iter().take(type_params) { 859 for arg in generic_args
860 .args
861 .iter()
862 .filter(|arg| matches!(arg, GenericArg::Type(_)))
863 .take(type_params)
864 {
860 match arg { 865 match arg {
861 GenericArg::Type(type_ref) => { 866 GenericArg::Type(type_ref) => {
862 let ty = self.make_ty(type_ref); 867 let ty = self.make_ty(type_ref);
diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs
index 92f779360..8392cb770 100644
--- a/crates/hir_ty/src/lower.rs
+++ b/crates/hir_ty/src/lower.rs
@@ -565,7 +565,13 @@ fn substs_from_path_segment(
565 if generic_args.has_self_type { self_params + type_params } else { type_params }; 565 if generic_args.has_self_type { self_params + type_params } else { type_params };
566 let skip = if generic_args.has_self_type && self_params == 0 { 1 } else { 0 }; 566 let skip = if generic_args.has_self_type && self_params == 0 { 1 } else { 0 };
567 // if args are provided, it should be all of them, but we can't rely on that 567 // if args are provided, it should be all of them, but we can't rely on that
568 for arg in generic_args.args.iter().skip(skip).take(expected_num) { 568 for arg in generic_args
569 .args
570 .iter()
571 .filter(|arg| matches!(arg, GenericArg::Type(_)))
572 .skip(skip)
573 .take(expected_num)
574 {
569 match arg { 575 match arg {
570 GenericArg::Type(type_ref) => { 576 GenericArg::Type(type_ref) => {
571 had_explicit_type_args = true; 577 had_explicit_type_args = true;