Skip to content

Commit 6cf4fd3

Browse files
authored
Rollup merge of #140548 - BoxyUwU:gci_patterns_user_ty_annotation, r=compiler-errors
Emit user type annotations for free consts in pattern position This previously wasnt done because free consts couldn't have any generic parameters that need to be preserved for borrowck. This is no longer the case with `feature(generic_const_items)` r? fmease
2 parents b803f45 + bfe3d54 commit 6cf4fd3

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

compiler/rustc_mir_build/src/thir/pattern/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -553,8 +553,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
553553
let res = self.typeck_results.qpath_res(qpath, id);
554554

555555
let (def_id, user_ty) = match res {
556-
Res::Def(DefKind::Const, def_id) => (def_id, None),
557-
Res::Def(DefKind::AssocConst, def_id) => {
556+
Res::Def(DefKind::Const, def_id) | Res::Def(DefKind::AssocConst, def_id) => {
558557
(def_id, self.typeck_results.user_provided_types().get(id))
559558
}
560559

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#![feature(generic_const_items)]
2+
#![expect(incomplete_features)]
3+
4+
const FOO<'a: 'static>: usize = 10;
5+
6+
fn bar<'a>() {
7+
match 10_usize {
8+
FOO::<'a> => todo!(),
9+
//~^ ERROR: lifetime may not live long enough
10+
_ => todo!(),
11+
}
12+
}
13+
14+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error: lifetime may not live long enough
2+
--> $DIR/user_type_annotations_pattern.rs:8:9
3+
|
4+
LL | fn bar<'a>() {
5+
| -- lifetime `'a` defined here
6+
LL | match 10_usize {
7+
LL | FOO::<'a> => todo!(),
8+
| ^^^^^^^^^ requires that `'a` must outlive `'static`
9+
10+
error: aborting due to 1 previous error
11+

0 commit comments

Comments
 (0)