diff options
| author | bors <bors@rust-lang.org> | 2024-03-18 08:35:53 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-03-18 08:35:53 +0000 |
| commit | a71a0328d8819590edb636426cacc1f847f13adc (patch) | |
| tree | e9cc09cbf2140e05fda1cbe5559d13af6755267f | |
| parent | f07489ada9920c83a16a71667d4792287e137205 (diff) | |
| parent | 95828850b2117cda5c6766f6af862f955a4b8382 (diff) | |
| download | rust-a71a0328d8819590edb636426cacc1f847f13adc.tar.gz rust-a71a0328d8819590edb636426cacc1f847f13adc.zip | |
Auto merge of #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 #16823
| -rw-r--r-- | crates/hir-ty/src/lower.rs | 8 | ||||
| -rw-r--r-- | crates/hir-ty/src/tests/traits.rs | 34 |
2 files changed, 40 insertions, 2 deletions
diff --git a/crates/hir-ty/src/lower.rs b/crates/hir-ty/src/lower.rs index dac20f22597..3e6d81f6ca9 100644 --- a/crates/hir-ty/src/lower.rs +++ b/crates/hir-ty/src/lower.rs @@ -1107,8 +1107,12 @@ impl<'a> TyLoweringContext<'a> { binding.type_ref.as_ref().map_or(0, |_| 1) + binding.bounds.len(), ); if let Some(type_ref) = &binding.type_ref { - if let (TypeRef::ImplTrait(bounds), ImplTraitLoweringState::Disallowed) = - (type_ref, &self.impl_trait_mode) + if let ( + TypeRef::ImplTrait(bounds), + ImplTraitLoweringState::Param(_) + | ImplTraitLoweringState::Variable(_) + | ImplTraitLoweringState::Disallowed, + ) = (type_ref, &self.impl_trait_mode) { for bound in bounds { predicates.extend( diff --git a/crates/hir-ty/src/tests/traits.rs b/crates/hir-ty/src/tests/traits.rs index b80cfe18e4c..ddb6ed82145 100644 --- a/crates/hir-ty/src/tests/traits.rs +++ b/crates/hir-ty/src/tests/traits.rs @@ -1279,6 +1279,40 @@ fn bar() { } #[test] +fn argument_assoc_impl_trait() { + check_infer( + r#" +trait Outer { + type Item; +} + +trait Inner { } + +fn foo<T: Outer<Item = impl Inner>>(baz: T) { +} + +impl Outer for usize { + type Item = usize; +} + +impl Inner for usize {} + +fn main() { + foo(2); +} +"#, + expect![[r#" + 85..88 'baz': T + 93..96 '{ }': () + 182..197 '{ foo(2); }': () + 188..191 'foo': fn foo<usize>(usize) + 188..194 'foo(2)': () + 192..193 '2': usize + "#]], + ); +} + +#[test] fn simple_return_pos_impl_trait() { cov_mark::check!(lower_rpit); check_infer( |
