Skip to content

Commit 6c244da

Browse files
committed
Fix ICE when using return type notation through trait alias
Add DefKind::TraitAlias to two locations in resolve_bound_vars.rs that only checked for DefKind::Trait, causing an ICE when RTN was used through a trait alias.
1 parent 8c5605e commit 6c244da

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1695,7 +1695,8 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
16951695
| DefKind::Union
16961696
| DefKind::Enum
16971697
| DefKind::TyAlias
1698-
| DefKind::Trait,
1698+
| DefKind::Trait
1699+
| DefKind::TraitAlias,
16991700
def_id,
17001701
) if depth == 0 => Some(def_id),
17011702
_ => None,
@@ -1865,7 +1866,10 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
18651866
if constraint.gen_args.parenthesized == hir::GenericArgsParentheses::ReturnTypeNotation
18661867
{
18671868
let bound_vars = if let Some(type_def_id) = type_def_id
1868-
&& self.tcx.def_kind(type_def_id) == DefKind::Trait
1869+
&& matches!(
1870+
self.tcx.def_kind(type_def_id),
1871+
DefKind::Trait | DefKind::TraitAlias
1872+
)
18691873
&& let Some((mut bound_vars, assoc_fn)) = BoundVarContext::supertrait_hrtb_vars(
18701874
self.tcx,
18711875
type_def_id,
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Regression test for #152158.
2+
3+
//@ check-pass
4+
5+
#![feature(return_type_notation, trait_alias)]
6+
7+
trait Tr {
8+
fn f() -> impl Sized;
9+
}
10+
11+
trait Al = Tr;
12+
13+
fn f<T: Al<f(..): Copy>>() {}
14+
15+
fn main() {}

0 commit comments

Comments
 (0)