Skip to content

Commit 519b1ab

Browse files
mejrsdtolnay
mejrs
authored andcommitted
Translate const_to_pat.rs
1 parent ef4046e commit 519b1ab

File tree

3 files changed

+122
-138
lines changed

3 files changed

+122
-138
lines changed

compiler/rustc_error_messages/locales/en-US/mir_build.ftl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,3 +299,22 @@ mir_build_multiple_mut_borrows = cannot borrow value as mutable more than once a
299299
.mutable_borrow = another mutable borrow, by `{$name_mut}`, occurs here
300300
.immutable_borrow = also borrowed as immutable, by `{$name_immut}`, here
301301
.moved = also moved into `{$name_moved}` here
302+
303+
mir_build_union_pattern = cannot use unions in constant patterns
304+
305+
mir_build_type_not_structural =
306+
to use a constant of type `{$non_sm_ty}` in a pattern, `{$non_sm_ty}` must be annotated with `#[derive(PartialEq, Eq)]`
307+
308+
mir_build_unsized_pattern = cannot use unsized non-slice type `{$non_sm_ty}` in constant patterns
309+
310+
mir_build_invalid_pattern = `{$non_sm_ty}` cannot be used in patterns
311+
312+
mir_build_float_pattern = floating-point types cannot be used in patterns
313+
314+
mir_build_pointer_pattern = function pointers and unsized pointers in patterns behave unpredictably and should not be relied upon. See https://github.com/rust-lang/rust/issues/70861 for details.
315+
316+
mir_build_indirect_structural_match =
317+
to use a constant of type `{$non_sm_ty}` in a pattern, `{$non_sm_ty}` must be annotated with `#[derive(PartialEq, Eq)]`
318+
319+
mir_build_nontrivial_structural_match =
320+
to use a constant of type `{$non_sm_ty}` in a pattern, the constant's initializer must be trivial or `{$non_sm_ty}` must be annotated with `#[derive(PartialEq, Eq)]`

compiler/rustc_mir_build/src/errors.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,3 +614,54 @@ pub enum MultipleMutBorrowOccurence {
614614
name_moved: Ident,
615615
},
616616
}
617+
618+
#[derive(Diagnostic)]
619+
#[diag(mir_build_union_pattern)]
620+
pub struct UnionPattern {
621+
#[primary_span]
622+
pub span: Span,
623+
}
624+
625+
#[derive(Diagnostic)]
626+
#[diag(mir_build_type_not_structural)]
627+
pub struct TypeNotStructural<'tcx> {
628+
#[primary_span]
629+
pub span: Span,
630+
pub non_sm_ty: Ty<'tcx>,
631+
}
632+
633+
#[derive(Diagnostic)]
634+
#[diag(mir_build_invalid_pattern)]
635+
pub struct InvalidPattern<'tcx> {
636+
#[primary_span]
637+
pub span: Span,
638+
pub non_sm_ty: Ty<'tcx>,
639+
}
640+
641+
#[derive(Diagnostic)]
642+
#[diag(mir_build_unsized_pattern)]
643+
pub struct UnsizedPattern<'tcx> {
644+
#[primary_span]
645+
pub span: Span,
646+
pub non_sm_ty: Ty<'tcx>,
647+
}
648+
649+
#[derive(LintDiagnostic)]
650+
#[diag(mir_build_float_pattern)]
651+
pub struct FloatPattern;
652+
653+
#[derive(LintDiagnostic)]
654+
#[diag(mir_build_pointer_pattern)]
655+
pub struct PointerPattern;
656+
657+
#[derive(LintDiagnostic)]
658+
#[diag(mir_build_indirect_structural_match)]
659+
pub struct IndirectStructuralMatch<'tcx> {
660+
pub non_sm_ty: Ty<'tcx>,
661+
}
662+
663+
#[derive(LintDiagnostic)]
664+
#[diag(mir_build_nontrivial_structural_match)]
665+
pub struct NontrivialStructuralMatch<'tcx> {
666+
pub non_sm_ty: Ty<'tcx>,
667+
}

0 commit comments

Comments
 (0)