Skip to content

Emit user type annotations for free consts in pattern position #140548

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions compiler/rustc_mir_build/src/thir/pattern/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
let res = self.typeck_results.qpath_res(qpath, id);

let (def_id, user_ty) = match res {
Res::Def(DefKind::Const, def_id) => (def_id, None),
Res::Def(DefKind::AssocConst, def_id) => {
Res::Def(DefKind::Const, def_id) | Res::Def(DefKind::AssocConst, def_id) => {
(def_id, self.typeck_results.user_provided_types().get(id))
}

Expand Down
14 changes: 14 additions & 0 deletions tests/ui/generic-const-items/user_type_annotations_pattern.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#![feature(generic_const_items)]
#![expect(incomplete_features)]

const FOO<'a: 'static>: usize = 10;

fn bar<'a>() {
match 10_usize {
FOO::<'a> => todo!(),
//~^ ERROR: lifetime may not live long enough
_ => todo!(),
}
}

fn main() {}
11 changes: 11 additions & 0 deletions tests/ui/generic-const-items/user_type_annotations_pattern.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error: lifetime may not live long enough
--> $DIR/user_type_annotations_pattern.rs:8:9
|
LL | fn bar<'a>() {
| -- lifetime `'a` defined here
LL | match 10_usize {
LL | FOO::<'a> => todo!(),
| ^^^^^^^^^ requires that `'a` must outlive `'static`

error: aborting due to 1 previous error

Loading