Skip to content

Commit 252fa78

Browse files
Only expect a GAT const arg
1 parent ab9bb3e commit 252fa78

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

compiler/rustc_hir_analysis/src/collect/type_of.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,9 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder<Ty<'_>>
475475
def_id.to_def_id(),
476476
);
477477
if let Some(assoc_item) = assoc_item {
478-
tcx.type_of(assoc_item.def_id).subst_identity()
478+
tcx.type_of(assoc_item.def_id)
479+
.no_bound_vars()
480+
.expect("const parameter types cannot be generic")
479481
} else {
480482
// FIXME(associated_const_equality): add a useful error message here.
481483
tcx.ty_error_with_message(
@@ -517,15 +519,18 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder<Ty<'_>>
517519
},
518520
def_id.to_def_id(),
519521
);
520-
if let Some(param)
521-
= assoc_item.map(|item| &tcx.generics_of(item.def_id).params[idx]).filter(|param| param.kind.is_ty_or_const())
522+
if let Some(assoc_item) = assoc_item
523+
&& let param = &tcx.generics_of(assoc_item.def_id).params[idx]
524+
&& matches!(param.kind, ty::GenericParamDefKind::Const { .. })
522525
{
523-
tcx.type_of(param.def_id).subst_identity()
526+
tcx.type_of(param.def_id)
527+
.no_bound_vars()
528+
.expect("const parameter types cannot be generic")
524529
} else {
525530
// FIXME(associated_const_equality): add a useful error message here.
526531
tcx.ty_error_with_message(
527532
DUMMY_SP,
528-
"Could not find associated const on trait",
533+
"Could not find const param on associated item",
529534
)
530535
}
531536
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![feature(generic_const_exprs)]
2+
//~^ WARN the feature `generic_const_exprs` is incomplete
3+
4+
trait B {
5+
type U<T>;
6+
}
7+
8+
fn f<T: B<U<1i32> = ()>>() {}
9+
//~^ ERROR constant provided when a type was expected
10+
11+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/mismatched-gat-subst-kind.rs:1:12
3+
|
4+
LL | #![feature(generic_const_exprs)]
5+
| ^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
error[E0747]: constant provided when a type was expected
11+
--> $DIR/mismatched-gat-subst-kind.rs:8:13
12+
|
13+
LL | fn f<T: B<U<1i32> = ()>>() {}
14+
| ^^^^
15+
16+
error: aborting due to previous error; 1 warning emitted
17+
18+
For more information about this error, try `rustc --explain E0747`.

0 commit comments

Comments
 (0)