Skip to content

Commit ca3a54f

Browse files
bors[bot]Veykril
andauthored
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 <lukastw97@gmail.com>
2 parents a15d196 + ae8a802 commit ca3a54f

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

crates/hir_def/src/item_tree.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,10 @@ struct GenericParamsStorage {
246246

247247
impl GenericParamsStorage {
248248
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+
{
250253
return GenericParamsId::EMPTY;
251254
}
252255

crates/hir_ty/src/infer/expr.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,12 @@ impl<'a> InferenceContext<'a> {
856856
// handle provided type arguments
857857
if let Some(generic_args) = generic_args {
858858
// 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+
{
860865
match arg {
861866
GenericArg::Type(type_ref) => {
862867
let ty = self.make_ty(type_ref);

crates/hir_ty/src/lower.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,13 @@ fn substs_from_path_segment(
565565
if generic_args.has_self_type { self_params + type_params } else { type_params };
566566
let skip = if generic_args.has_self_type && self_params == 0 { 1 } else { 0 };
567567
// 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+
{
569575
match arg {
570576
GenericArg::Type(type_ref) => {
571577
had_explicit_type_args = true;

0 commit comments

Comments
 (0)