Only expect a GAT const arg
This commit is contained in:
parent
ab9bb3ea36
commit
252fa78283
3 changed files with 39 additions and 5 deletions
|
@ -475,7 +475,9 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder<Ty<'_>>
|
||||||
def_id.to_def_id(),
|
def_id.to_def_id(),
|
||||||
);
|
);
|
||||||
if let Some(assoc_item) = assoc_item {
|
if let Some(assoc_item) = assoc_item {
|
||||||
tcx.type_of(assoc_item.def_id).subst_identity()
|
tcx.type_of(assoc_item.def_id)
|
||||||
|
.no_bound_vars()
|
||||||
|
.expect("const parameter types cannot be generic")
|
||||||
} else {
|
} else {
|
||||||
// FIXME(associated_const_equality): add a useful error message here.
|
// FIXME(associated_const_equality): add a useful error message here.
|
||||||
tcx.ty_error_with_message(
|
tcx.ty_error_with_message(
|
||||||
|
@ -517,15 +519,18 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder<Ty<'_>>
|
||||||
},
|
},
|
||||||
def_id.to_def_id(),
|
def_id.to_def_id(),
|
||||||
);
|
);
|
||||||
if let Some(param)
|
if let Some(assoc_item) = assoc_item
|
||||||
= assoc_item.map(|item| &tcx.generics_of(item.def_id).params[idx]).filter(|param| param.kind.is_ty_or_const())
|
&& let param = &tcx.generics_of(assoc_item.def_id).params[idx]
|
||||||
|
&& matches!(param.kind, ty::GenericParamDefKind::Const { .. })
|
||||||
{
|
{
|
||||||
tcx.type_of(param.def_id).subst_identity()
|
tcx.type_of(param.def_id)
|
||||||
|
.no_bound_vars()
|
||||||
|
.expect("const parameter types cannot be generic")
|
||||||
} else {
|
} else {
|
||||||
// FIXME(associated_const_equality): add a useful error message here.
|
// FIXME(associated_const_equality): add a useful error message here.
|
||||||
tcx.ty_error_with_message(
|
tcx.ty_error_with_message(
|
||||||
DUMMY_SP,
|
DUMMY_SP,
|
||||||
"Could not find associated const on trait",
|
"Could not find const param on associated item",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
#![feature(generic_const_exprs)]
|
||||||
|
//~^ WARN the feature `generic_const_exprs` is incomplete
|
||||||
|
|
||||||
|
trait B {
|
||||||
|
type U<T>;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn f<T: B<U<1i32> = ()>>() {}
|
||||||
|
//~^ ERROR constant provided when a type was expected
|
||||||
|
|
||||||
|
fn main() {}
|
|
@ -0,0 +1,18 @@
|
||||||
|
warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||||
|
--> $DIR/mismatched-gat-subst-kind.rs:1:12
|
||||||
|
|
|
||||||
|
LL | #![feature(generic_const_exprs)]
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information
|
||||||
|
= note: `#[warn(incomplete_features)]` on by default
|
||||||
|
|
||||||
|
error[E0747]: constant provided when a type was expected
|
||||||
|
--> $DIR/mismatched-gat-subst-kind.rs:8:13
|
||||||
|
|
|
||||||
|
LL | fn f<T: B<U<1i32> = ()>>() {}
|
||||||
|
| ^^^^
|
||||||
|
|
||||||
|
error: aborting due to previous error; 1 warning emitted
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0747`.
|
Loading…
Add table
Add a link
Reference in a new issue