Skip to content

Commit debaef8

Browse files
authored
Merge pull request #19738 from ChayimFriedman2/weird-gats
fix: Don't panic on some weird code
2 parents 8c43442 + 3b3e892 commit debaef8

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

crates/hir-def/src/expr_store/lower/path.rs

+8
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,14 @@ pub(super) fn lower_path(
232232
.with_borrow_mut(|map| map.extend(ast_segments.into_iter().zip(ast_segments_offset..)));
233233
}
234234

235+
if let Some(last_segment_args @ Some(GenericArgs { has_self_type: true, .. })) =
236+
generic_args.last_mut()
237+
{
238+
// Well-formed code cannot have `<T as Trait>` without an associated item after,
239+
// and this causes panics in hir-ty lowering.
240+
*last_segment_args = None;
241+
}
242+
235243
let mod_path = Interned::new(ModPath::from_segments(kind, segments));
236244
if type_anchor.is_none() && generic_args.is_empty() {
237245
return Some(Path::BarePath(mod_path));

crates/hir-ty/src/tests/simple.rs

+24
Original file line numberDiff line numberDiff line change
@@ -3902,3 +3902,27 @@ fn main() {
39023902
"#]],
39033903
);
39043904
}
3905+
3906+
#[test]
3907+
fn regression_19734() {
3908+
check_infer(
3909+
r#"
3910+
trait Foo {
3911+
type Gat<'o>;
3912+
}
3913+
3914+
trait Bar {
3915+
fn baz() -> <Self::Xyz as Foo::Gat<'_>>;
3916+
}
3917+
3918+
fn foo<T: Bar>() {
3919+
T::baz();
3920+
}
3921+
"#,
3922+
expect![[r#"
3923+
110..127 '{ ...z(); }': ()
3924+
116..122 'T::baz': fn baz<T>() -> <{unknown} as Foo>::Gat<'?>
3925+
116..124 'T::baz()': Foo::Gat<'?, {unknown}>
3926+
"#]],
3927+
);
3928+
}

0 commit comments

Comments
 (0)