fix type of const params in associated types.
This commit is contained in:
parent
f4c675c476
commit
a9c2378b7d
@ -256,15 +256,18 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
|
|||||||
// figure out which generic parameter it corresponds to and return
|
// figure out which generic parameter it corresponds to and return
|
||||||
// the relevant type.
|
// the relevant type.
|
||||||
let generics = match path.res {
|
let generics = match path.res {
|
||||||
Res::Def(DefKind::Ctor(..), def_id) => {
|
Res::Def(DefKind::Ctor(..), def_id)
|
||||||
|
| Res::Def(DefKind::AssocTy, def_id) => {
|
||||||
tcx.generics_of(tcx.parent(def_id).unwrap())
|
tcx.generics_of(tcx.parent(def_id).unwrap())
|
||||||
}
|
}
|
||||||
Res::Def(_, def_id) => tcx.generics_of(def_id),
|
Res::Def(_, def_id) => tcx.generics_of(def_id),
|
||||||
Res::Err => return tcx.types.err,
|
|
||||||
res => {
|
res => {
|
||||||
tcx.sess.delay_span_bug(
|
tcx.sess.delay_span_bug(
|
||||||
DUMMY_SP,
|
DUMMY_SP,
|
||||||
&format!("unexpected const parent path def {:?}", res,),
|
&format!(
|
||||||
|
"unexpected const parent path def, parent: {:?}, def: {:?}",
|
||||||
|
parent_node, res
|
||||||
|
),
|
||||||
);
|
);
|
||||||
return tcx.types.err;
|
return tcx.types.err;
|
||||||
}
|
}
|
||||||
@ -284,7 +287,16 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
|
|||||||
.map(|param| tcx.type_of(param.def_id))
|
.map(|param| tcx.type_of(param.def_id))
|
||||||
// This is no generic parameter associated with the arg. This is
|
// This is no generic parameter associated with the arg. This is
|
||||||
// probably from an extra arg where one is not needed.
|
// probably from an extra arg where one is not needed.
|
||||||
.unwrap_or(tcx.types.err)
|
.unwrap_or_else(|| {
|
||||||
|
tcx.sess.delay_span_bug(
|
||||||
|
DUMMY_SP,
|
||||||
|
&format!(
|
||||||
|
"missing generic parameter for `AnonConst`, parent {:?}",
|
||||||
|
parent_node
|
||||||
|
),
|
||||||
|
);
|
||||||
|
tcx.types.err
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
tcx.sess.delay_span_bug(
|
tcx.sess.delay_span_bug(
|
||||||
DUMMY_SP,
|
DUMMY_SP,
|
||||||
|
12
src/test/ui/const-generics/issues/issue-66906.rs
Normal file
12
src/test/ui/const-generics/issues/issue-66906.rs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
// check-pass
|
||||||
|
|
||||||
|
#![feature(const_generics)]
|
||||||
|
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
|
||||||
|
|
||||||
|
pub struct Tuple;
|
||||||
|
|
||||||
|
pub trait Trait<const I: usize> {
|
||||||
|
type Input: From<<Self as Trait<I>>::Input>;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
8
src/test/ui/const-generics/issues/issue-66906.stderr
Normal file
8
src/test/ui/const-generics/issues/issue-66906.stderr
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
|
||||||
|
--> $DIR/issue-66906.rs:3:12
|
||||||
|
|
|
||||||
|
LL | #![feature(const_generics)]
|
||||||
|
| ^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= note: `#[warn(incomplete_features)]` on by default
|
||||||
|
|
10
src/test/ui/const-generics/issues/issue-70167.rs
Normal file
10
src/test/ui/const-generics/issues/issue-70167.rs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
// check-pass
|
||||||
|
|
||||||
|
#![feature(const_generics)]
|
||||||
|
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
|
||||||
|
|
||||||
|
pub trait Trait<const N: usize>: From<<Self as Trait<N>>::Item> {
|
||||||
|
type Item;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
8
src/test/ui/const-generics/issues/issue-70167.stderr
Normal file
8
src/test/ui/const-generics/issues/issue-70167.stderr
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
|
||||||
|
--> $DIR/issue-70167.rs:3:12
|
||||||
|
|
|
||||||
|
LL | #![feature(const_generics)]
|
||||||
|
| ^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= note: `#[warn(incomplete_features)]` on by default
|
||||||
|
|
Loading…
Reference in New Issue
Block a user