Skip to content

Conversation

@ShoyuVanilla
Copy link
Member

Fixes #17191

We are not inserting a generic arg when lowering generics like

fn foo<T: B<impl A>(..) { ... }

but when we are lowering predicates we do;

pub(crate) fn generic_predicates_query(
db: &dyn HirDatabase,
def: GenericDefId,
) -> GenericPredicates {
let resolver = def.resolver(db.upcast());
let (impl_trait_lowering, param_lowering) = match def {
GenericDefId::FunctionId(_) => {
(ImplTraitLoweringMode::Variable, ParamLoweringMode::Variable)
}
_ => (ImplTraitLoweringMode::Disallowed, ParamLoweringMode::Variable),
};
let ctx = TyLoweringContext::new(db, &resolver, def.into())
.with_impl_trait_mode(impl_trait_lowering)
.with_type_param_mode(param_lowering);
let generics = generics(db.upcast(), def);
let mut predicates = resolver
.where_predicates_in_scope()
.flat_map(|(pred, def)| {
ctx.lower_where_predicate(pred, def, false).map(|p| make_binders(db, &generics, p))
})
.collect::<Vec<_>>();

TypeRef::ImplTrait(bounds) => {

and this mismatch causes index out of bound panic while substituting the predicates

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 4, 2024
fn test() {
let f = foo;
//^ fn foo<{unknown}>()
Copy link
Member Author

@ShoyuVanilla ShoyuVanilla Aug 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is making a panic like in the original issue

@Veykril
Copy link
Member

Veykril commented Aug 4, 2024

Thanks!
@bors r+

@bors
Copy link
Contributor

bors commented Aug 4, 2024

📌 Commit 8fa454d has been approved by Veykril

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Aug 4, 2024

⌛ Testing commit 8fa454d with merge c9109f2...

@bors
Copy link
Contributor

bors commented Aug 4, 2024

☀️ Test successful - checks-actions
Approved by: Veykril
Pushing c9109f2 to master...

@bors bors merged commit c9109f2 into rust-lang:master Aug 4, 2024
@ShoyuVanilla ShoyuVanilla deleted the issue-17191 branch August 5, 2024 00:03
@lnicola lnicola mentioned this pull request Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Panic when binding a type param to a trait with an impl type param

4 participants