Skip to content

Commit 691ee1c

Browse files
committed
implement lowering of guard patterns to THIR
1 parent ef4394d commit 691ee1c

File tree

6 files changed

+83
-109
lines changed

6 files changed

+83
-109
lines changed

compiler/rustc_mir_build/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use rustc_middle::util::Providers;
2222
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
2323

2424
pub fn provide(providers: &mut Providers) {
25-
providers.check_match = thir::pattern::check_match;
25+
providers.check_match = thir::check_match::check_match;
2626
providers.lit_to_const = thir::constant::lit_to_const;
2727
providers.hooks.build_mir = build::mir_build;
2828
providers.closure_saved_names_of_captured_variables =

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

+4-10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
//! structures into the THIR. The `builder` is generally ignorant of the tcx,
33
//! etc., and instead goes through the `Cx` for most of its work.
44
5+
mod block;
6+
mod expr;
7+
mod pattern;
8+
59
use rustc_data_structures::steal::Steal;
610
use rustc_errors::ErrorGuaranteed;
711
use rustc_hir as hir;
@@ -13,9 +17,7 @@ use rustc_middle::bug;
1317
use rustc_middle::middle::region;
1418
use rustc_middle::thir::*;
1519
use rustc_middle::ty::{self, RvalueScopes, TyCtxt};
16-
use tracing::instrument;
1720

18-
use crate::thir::pattern::pat_from_hir;
1921
use crate::thir::util::UserAnnotatedTyHelpers;
2022

2123
pub(crate) fn thir_body(
@@ -109,11 +111,6 @@ impl<'tcx> Cx<'tcx> {
109111
}
110112
}
111113

112-
#[instrument(level = "debug", skip(self))]
113-
fn pattern_from_hir(&mut self, p: &'tcx hir::Pat<'tcx>) -> Box<Pat<'tcx>> {
114-
pat_from_hir(self.tcx, self.param_env, self.typeck_results(), p)
115-
}
116-
117114
fn closure_env_param(&self, owner_def: LocalDefId, expr_id: HirId) -> Option<Param<'tcx>> {
118115
if self.tcx.def_kind(owner_def) != DefKind::Closure {
119116
return None;
@@ -206,6 +203,3 @@ impl<'tcx> UserAnnotatedTyHelpers<'tcx> for Cx<'tcx> {
206203
self.typeck_results
207204
}
208205
}
209-
210-
mod block;
211-
mod expr;

compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs renamed to compiler/rustc_mir_build/src/thir/cx/pattern/const_to_pat.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ use rustc_trait_selection::traits::ObligationCause;
1414
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
1515
use tracing::{debug, instrument, trace};
1616

17-
use super::PatCtxt;
17+
use super::PatCx;
1818
use crate::errors::{
1919
ConstPatternDependsOnGenericParameter, CouldNotEvalConstPattern, InvalidPattern, NaNPattern,
2020
PointerPattern, TypeNotPartialEq, TypeNotStructural, UnionPattern, UnsizedPattern,
2121
};
2222

23-
impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
23+
impl<'a, 'tcx> PatCx<'a, 'tcx> {
2424
/// Converts a constant to a pattern (if possible).
2525
/// This means aggregate values (like structs and enums) are converted
2626
/// to a pattern that matches the value (as if you'd compared via structural equality).
@@ -36,7 +36,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
3636
id: hir::HirId,
3737
span: Span,
3838
) -> Box<Pat<'tcx>> {
39-
let infcx = self.tcx.infer_ctxt().build();
39+
let infcx = self.cx.tcx.infer_ctxt().build();
4040
let mut convert = ConstToPat::new(self, id, span, infcx);
4141
convert.to_pat(c, ty)
4242
}
@@ -54,19 +54,15 @@ struct ConstToPat<'tcx> {
5454
}
5555

5656
impl<'tcx> ConstToPat<'tcx> {
57-
fn new(
58-
pat_ctxt: &PatCtxt<'_, 'tcx>,
59-
id: hir::HirId,
60-
span: Span,
61-
infcx: InferCtxt<'tcx>,
62-
) -> Self {
63-
trace!(?pat_ctxt.typeck_results.hir_owner);
57+
fn new(pat_ctxt: &PatCx<'_, 'tcx>, id: hir::HirId, span: Span, infcx: InferCtxt<'tcx>) -> Self {
58+
trace!(?pat_ctxt.cx.typeck_results.hir_owner);
6459
ConstToPat {
6560
id,
6661
span,
6762
infcx,
68-
param_env: pat_ctxt.param_env,
63+
param_env: pat_ctxt.cx.param_env,
6964
treat_byte_string_as_slice: pat_ctxt
65+
.cx
7066
.typeck_results
7167
.treat_byte_string_as_slice
7268
.contains(&id.local_id),

0 commit comments

Comments
 (0)