Skip to content

Commit a9c2378

Browse files
committed
fix type of const params in associated types.
1 parent f4c675c commit a9c2378

File tree

5 files changed

+54
-4
lines changed

5 files changed

+54
-4
lines changed

src/librustc_typeck/collect/type_of.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -256,15 +256,18 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
256256
// figure out which generic parameter it corresponds to and return
257257
// the relevant type.
258258
let generics = match path.res {
259-
Res::Def(DefKind::Ctor(..), def_id) => {
259+
Res::Def(DefKind::Ctor(..), def_id)
260+
| Res::Def(DefKind::AssocTy, def_id) => {
260261
tcx.generics_of(tcx.parent(def_id).unwrap())
261262
}
262263
Res::Def(_, def_id) => tcx.generics_of(def_id),
263-
Res::Err => return tcx.types.err,
264264
res => {
265265
tcx.sess.delay_span_bug(
266266
DUMMY_SP,
267-
&format!("unexpected const parent path def {:?}", res,),
267+
&format!(
268+
"unexpected const parent path def, parent: {:?}, def: {:?}",
269+
parent_node, res
270+
),
268271
);
269272
return tcx.types.err;
270273
}
@@ -284,7 +287,16 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
284287
.map(|param| tcx.type_of(param.def_id))
285288
// This is no generic parameter associated with the arg. This is
286289
// probably from an extra arg where one is not needed.
287-
.unwrap_or(tcx.types.err)
290+
.unwrap_or_else(|| {
291+
tcx.sess.delay_span_bug(
292+
DUMMY_SP,
293+
&format!(
294+
"missing generic parameter for `AnonConst`, parent {:?}",
295+
parent_node
296+
),
297+
);
298+
tcx.types.err
299+
})
288300
} else {
289301
tcx.sess.delay_span_bug(
290302
DUMMY_SP,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// check-pass
2+
3+
#![feature(const_generics)]
4+
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
5+
6+
pub struct Tuple;
7+
8+
pub trait Trait<const I: usize> {
9+
type Input: From<<Self as Trait<I>>::Input>;
10+
}
11+
12+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
2+
--> $DIR/issue-66906.rs:3:12
3+
|
4+
LL | #![feature(const_generics)]
5+
| ^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// check-pass
2+
3+
#![feature(const_generics)]
4+
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
5+
6+
pub trait Trait<const N: usize>: From<<Self as Trait<N>>::Item> {
7+
type Item;
8+
}
9+
10+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
2+
--> $DIR/issue-70167.rs:3:12
3+
|
4+
LL | #![feature(const_generics)]
5+
| ^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
8+

0 commit comments

Comments
 (0)