Skip to content

Commit 05082f5

Browse files
committed
Perform match checking on THIR.
1 parent 3b47cdc commit 05082f5

File tree

81 files changed

+650
-979
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+650
-979
lines changed

compiler/rustc_hir/src/pat_util.rs

-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use crate::def::{CtorOf, DefKind, Res};
22
use crate::def_id::DefId;
33
use crate::hir::{self, BindingAnnotation, ByRef, HirId, PatKind};
44
use rustc_data_structures::fx::FxHashSet;
5-
use rustc_span::hygiene::DesugaringKind;
65
use rustc_span::symbol::Ident;
76
use rustc_span::Span;
87

@@ -136,14 +135,4 @@ impl hir::Pat<'_> {
136135
});
137136
result
138137
}
139-
140-
/// If the pattern is `Some(<pat>)` from a desugared for loop, returns the inner pattern
141-
pub fn for_loop_some(&self) -> Option<&Self> {
142-
if self.span.desugaring_kind() == Some(DesugaringKind::ForLoop) {
143-
if let hir::PatKind::Struct(_, [pat_field], _) = self.kind {
144-
return Some(pat_field.pat);
145-
}
146-
}
147-
None
148-
}
149138
}

compiler/rustc_mir_build/messages.ftl

+1-11
Original file line numberDiff line numberDiff line change
@@ -239,19 +239,9 @@ mir_build_trailing_irrefutable_let_patterns = trailing irrefutable {$count ->
239239
} into the body
240240
241241
mir_build_bindings_with_variant_name =
242-
pattern binding `{$ident}` is named the same as one of the variants of the type `{$ty_path}`
242+
pattern binding `{$name}` is named the same as one of the variants of the type `{$ty_path}`
243243
.suggestion = to match on the variant, qualify the path
244244
245-
mir_build_irrefutable_let_patterns_generic_let = irrefutable `let` {$count ->
246-
[one] pattern
247-
*[other] patterns
248-
}
249-
.note = {$count ->
250-
[one] this pattern
251-
*[other] these patterns
252-
} will always match, so the `let` is useless
253-
.help = consider removing `let`
254-
255245
mir_build_irrefutable_let_patterns_if_let = irrefutable `if let` {$count ->
256246
[one] pattern
257247
*[other] patterns

compiler/rustc_mir_build/src/build/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ fn mir_build(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> Body<'_
5858
ty::WithOptConstParam { did, const_param_did: None } => {
5959
tcx.ensure_with_value().thir_check_unsafety(did);
6060
tcx.ensure_with_value().thir_abstract_const(did);
61+
tcx.ensure_with_value().check_match(did);
6162
}
6263
}
6364

compiler/rustc_mir_build/src/errors.rs

+8-15
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ use rustc_hir::def::Res;
1010
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
1111
use rustc_middle::thir::Pat;
1212
use rustc_middle::ty::{self, Ty};
13-
use rustc_span::{symbol::Ident, Span};
13+
use rustc_span::symbol::Symbol;
14+
use rustc_span::Span;
1415

1516
#[derive(LintDiagnostic)]
1617
#[diag(mir_build_unconditional_recursion)]
@@ -534,18 +535,10 @@ pub struct TrailingIrrefutableLetPatterns {
534535
#[derive(LintDiagnostic)]
535536
#[diag(mir_build_bindings_with_variant_name, code = "E0170")]
536537
pub struct BindingsWithVariantName {
537-
#[suggestion(code = "{ty_path}::{ident}", applicability = "machine-applicable")]
538+
#[suggestion(code = "{ty_path}::{name}", applicability = "machine-applicable")]
538539
pub suggestion: Option<Span>,
539540
pub ty_path: String,
540-
pub ident: Ident,
541-
}
542-
543-
#[derive(LintDiagnostic)]
544-
#[diag(mir_build_irrefutable_let_patterns_generic_let)]
545-
#[note]
546-
#[help]
547-
pub struct IrrefutableLetPatternsGenericLet {
548-
pub count: usize,
541+
pub name: Symbol,
549542
}
550543

551544
#[derive(LintDiagnostic)]
@@ -590,7 +583,7 @@ pub struct BorrowOfMovedValue<'tcx> {
590583
pub binding_span: Span,
591584
#[label(mir_build_value_borrowed_label)]
592585
pub conflicts_ref: Vec<Span>,
593-
pub name: Ident,
586+
pub name: Symbol,
594587
pub ty: Ty<'tcx>,
595588
#[suggestion(code = "ref ", applicability = "machine-applicable")]
596589
pub suggest_borrowing: Option<Span>,
@@ -638,19 +631,19 @@ pub enum Conflict {
638631
Mut {
639632
#[primary_span]
640633
span: Span,
641-
name: Ident,
634+
name: Symbol,
642635
},
643636
#[label(mir_build_borrow)]
644637
Ref {
645638
#[primary_span]
646639
span: Span,
647-
name: Ident,
640+
name: Symbol,
648641
},
649642
#[label(mir_build_moved)]
650643
Moved {
651644
#[primary_span]
652645
span: Span,
653-
name: Ident,
646+
name: Symbol,
654647
},
655648
}
656649

0 commit comments

Comments
 (0)