diff options
| author | Lukas Wirth <lukastw97@gmail.com> | 2025-05-06 09:05:19 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-06 09:05:19 +0000 |
| commit | 45f2d3c67a49cb44f9c1da050dad2714714b0c2e (patch) | |
| tree | 8793a2123215952a5ba490ecd0f8513064a90ddf | |
| parent | 0b75b2d0fe629dc47fcb28469a62de223c920b25 (diff) | |
| parent | 1ed416de0388493ed9d604522399af5f9fd4eab6 (diff) | |
| download | rust-45f2d3c67a49cb44f9c1da050dad2714714b0c2e.tar.gz rust-45f2d3c67a49cb44f9c1da050dad2714714b0c2e.zip | |
Merge pull request #19738 from ChayimFriedman2/weird-gats
fix: Don't panic on some weird code
| -rw-r--r-- | src/tools/rust-analyzer/crates/hir-def/src/expr_store/lower/path.rs | 8 | ||||
| -rw-r--r-- | src/tools/rust-analyzer/crates/hir-ty/src/tests/simple.rs | 24 |
2 files changed, 32 insertions, 0 deletions
diff --git a/src/tools/rust-analyzer/crates/hir-def/src/expr_store/lower/path.rs b/src/tools/rust-analyzer/crates/hir-def/src/expr_store/lower/path.rs index 629d1f2ada7..be006c98a58 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/expr_store/lower/path.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/expr_store/lower/path.rs @@ -232,6 +232,14 @@ pub(super) fn lower_path( .with_borrow_mut(|map| map.extend(ast_segments.into_iter().zip(ast_segments_offset..))); } + if let Some(last_segment_args @ Some(GenericArgs { has_self_type: true, .. })) = + generic_args.last_mut() + { + // Well-formed code cannot have `<T as Trait>` without an associated item after, + // and this causes panics in hir-ty lowering. + *last_segment_args = None; + } + let mod_path = Interned::new(ModPath::from_segments(kind, segments)); if type_anchor.is_none() && generic_args.is_empty() { return Some(Path::BarePath(mod_path)); diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/tests/simple.rs b/src/tools/rust-analyzer/crates/hir-ty/src/tests/simple.rs index eeebe38f182..08127eeb463 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/tests/simple.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/tests/simple.rs @@ -3902,3 +3902,27 @@ fn main() { "#]], ); } + +#[test] +fn regression_19734() { + check_infer( + r#" +trait Foo { + type Gat<'o>; +} + +trait Bar { + fn baz() -> <Self::Xyz as Foo::Gat<'_>>; +} + +fn foo<T: Bar>() { + T::baz(); +} + "#, + expect![[r#" + 110..127 '{ ...z(); }': () + 116..122 'T::baz': fn baz<T>() -> <{unknown} as Foo>::Gat<'?> + 116..124 'T::baz()': Foo::Gat<'?, {unknown}> + "#]], + ); +} |
