Skip to content

Commit 8ab05ad

Browse files
Do not write user type annotation for const param value path
1 parent 9067f7c commit 8ab05ad

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+7
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
220220
) {
221221
debug!("fcx {}", self.tag());
222222

223+
// Don't write user type annotations for const param types, since we give them
224+
// identity args just so that we can trivially substitute their `EarlyBinder`.
225+
// We enforce that they match their type in MIR later on.
226+
if matches!(self.tcx.def_kind(def_id), DefKind::ConstParam) {
227+
return;
228+
}
229+
223230
if Self::can_contain_user_lifetime_bounds((args, user_self_ty)) {
224231
let canonicalized = self.canonicalize_user_type_annotation(ty::UserType::new(
225232
ty::UserTypeKind::TypeOf(def_id, UserArgs { args, user_self_ty }),

tests/crashes/138048.rs

-8
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
struct Foo<'a>(&'a ());
2+
3+
// We need a lifetime in scope or else we do not write a user type annotation as a fast-path.
4+
impl<'a> Foo<'a> {
5+
fn bar<const V: u8>() {
6+
let V;
7+
//~^ ERROR constant parameters cannot be referenced in patterns
8+
}
9+
}
10+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0158]: constant parameters cannot be referenced in patterns
2+
--> $DIR/bad-param-in-pat.rs:6:13
3+
|
4+
LL | fn bar<const V: u8>() {
5+
| ----------- constant defined here
6+
LL | let V;
7+
| ^ can't be used in patterns
8+
9+
error: aborting due to 1 previous error
10+
11+
For more information about this error, try `rustc --explain E0158`.

0 commit comments

Comments
 (0)