Skip to content

Commit 2445375

Browse files
committed
fix type of const params in assoc fn.
1 parent a624df6 commit 2445375

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

src/librustc_typeck/collect/type_of.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,10 @@ 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)
260-
| Res::Def(DefKind::AssocTy, def_id) => {
261-
tcx.generics_of(tcx.parent(def_id).unwrap())
262-
}
259+
Res::Def(
260+
DefKind::Ctor(..) | DefKind::AssocTy | DefKind::AssocFn,
261+
def_id,
262+
) => tcx.generics_of(tcx.parent(def_id).unwrap()),
263263
Res::Def(_, def_id) => tcx.generics_of(def_id),
264264
res => {
265265
tcx.sess.delay_span_bug(
@@ -291,8 +291,8 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
291291
tcx.sess.delay_span_bug(
292292
DUMMY_SP,
293293
&format!(
294-
"missing generic parameter for `AnonConst`, parent {:?}",
295-
parent_node
294+
"missing generic parameter for `AnonConst`, parent: {:?}, path.res: {:?}",
295+
parent_node, path.res
296296
),
297297
);
298298
tcx.types.err

src/librustc_typeck/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ This API is completely unstable and subject to change.
6262
#![feature(crate_visibility_modifier)]
6363
#![feature(in_band_lifetimes)]
6464
#![feature(nll)]
65+
#![feature(or_patterns)]
6566
#![feature(try_blocks)]
6667
#![feature(never_type)]
6768
#![feature(slice_partition_dedup)]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
trait T<const A: usize> {
7+
fn f();
8+
}
9+
struct S;
10+
11+
impl T<0usize> for S {
12+
fn f() {}
13+
}
14+
15+
fn main() {
16+
let _err = <S as T<0usize>>::f();
17+
}
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/issue70273-assoc-fn.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)