Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix panic with impl trait associated types in where clause #16830

Merged
merged 1 commit into from Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions crates/hir-ty/src/lower.rs
Expand Up @@ -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(
Expand Down
34 changes: 34 additions & 0 deletions crates/hir-ty/src/tests/traits.rs
Expand Up @@ -1278,6 +1278,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);
Expand Down