Skip to content

Commit 684fbd5

Browse files
Rollup merge of #78089 - varkor:opt_const_param_of-error, r=lcnr
Fix issue with specifying generic arguments for primitive types Fixes #78005. r? @lcnr
2 parents a6919ef + c0d29fe commit 684fbd5

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

compiler/rustc_typeck/src/collect/type_of.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,16 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<
112112
tcx.sess.delay_span_bug(tcx.def_span(def_id), "anon const with Res::Err");
113113
return None;
114114
}
115-
_ => span_bug!(
116-
DUMMY_SP,
117-
"unexpected anon const res {:?} in path: {:?}",
118-
res,
119-
path,
120-
),
115+
_ => {
116+
// If the user tries to specify generics on a type that does not take them,
117+
// e.g. `usize<T>`, we may hit this branch, in which case we treat it as if
118+
// no arguments have been passed. An error should already have been emitted.
119+
tcx.sess.delay_span_bug(
120+
tcx.def_span(def_id),
121+
&format!("unexpected anon const res {:?} in path: {:?}", res, path),
122+
);
123+
return None;
124+
}
121125
};
122126

123127
generics
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fn foo() {
2+
let x: usize<foo>; //~ ERROR const arguments are not allowed for this type
3+
}
4+
5+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0109]: const arguments are not allowed for this type
2+
--> $DIR/usize-generic-argument-parent.rs:2:18
3+
|
4+
LL | let x: usize<foo>;
5+
| ^^^ const argument not allowed
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0109`.

0 commit comments

Comments
 (0)