Skip to content

Commit a71a032

Browse files
committed
Auto merge of rust-lang#16830 - Jesse-Bakker:fix-ty-panic, r=ShoyuVanilla
Fix panic with impl trait associated types in where clause Not sure if this is the correct fix, but the tests are green :') Fixes rust-lang#16823
2 parents f07489a + 9582885 commit a71a032

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

crates/hir-ty/src/lower.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1107,8 +1107,12 @@ impl<'a> TyLoweringContext<'a> {
11071107
binding.type_ref.as_ref().map_or(0, |_| 1) + binding.bounds.len(),
11081108
);
11091109
if let Some(type_ref) = &binding.type_ref {
1110-
if let (TypeRef::ImplTrait(bounds), ImplTraitLoweringState::Disallowed) =
1111-
(type_ref, &self.impl_trait_mode)
1110+
if let (
1111+
TypeRef::ImplTrait(bounds),
1112+
ImplTraitLoweringState::Param(_)
1113+
| ImplTraitLoweringState::Variable(_)
1114+
| ImplTraitLoweringState::Disallowed,
1115+
) = (type_ref, &self.impl_trait_mode)
11121116
{
11131117
for bound in bounds {
11141118
predicates.extend(

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

+34
Original file line numberDiff line numberDiff line change
@@ -1278,6 +1278,40 @@ fn bar() {
12781278
);
12791279
}
12801280

1281+
#[test]
1282+
fn argument_assoc_impl_trait() {
1283+
check_infer(
1284+
r#"
1285+
trait Outer {
1286+
type Item;
1287+
}
1288+
1289+
trait Inner { }
1290+
1291+
fn foo<T: Outer<Item = impl Inner>>(baz: T) {
1292+
}
1293+
1294+
impl Outer for usize {
1295+
type Item = usize;
1296+
}
1297+
1298+
impl Inner for usize {}
1299+
1300+
fn main() {
1301+
foo(2);
1302+
}
1303+
"#,
1304+
expect![[r#"
1305+
85..88 'baz': T
1306+
93..96 '{ }': ()
1307+
182..197 '{ foo(2); }': ()
1308+
188..191 'foo': fn foo<usize>(usize)
1309+
188..194 'foo(2)': ()
1310+
192..193 '2': usize
1311+
"#]],
1312+
);
1313+
}
1314+
12811315
#[test]
12821316
fn simple_return_pos_impl_trait() {
12831317
cov_mark::check!(lower_rpit);

0 commit comments

Comments
 (0)