mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
Merge 'thir and 'p
This commit is contained in:
parent
2b4f84f2b2
commit
48d089a800
@ -75,11 +75,11 @@ enum LetSource {
|
|||||||
WhileLet,
|
WhileLet,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct MatchVisitor<'thir, 'p, 'tcx> {
|
struct MatchVisitor<'p, 'tcx> {
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
param_env: ty::ParamEnv<'tcx>,
|
||||||
typeck_results: &'tcx ty::TypeckResults<'tcx>,
|
typeck_results: &'tcx ty::TypeckResults<'tcx>,
|
||||||
thir: &'thir Thir<'tcx>,
|
thir: &'p Thir<'tcx>,
|
||||||
lint_level: HirId,
|
lint_level: HirId,
|
||||||
let_source: LetSource,
|
let_source: LetSource,
|
||||||
pattern_arena: &'p TypedArena<DeconstructedPat<'p, 'tcx>>,
|
pattern_arena: &'p TypedArena<DeconstructedPat<'p, 'tcx>>,
|
||||||
@ -92,13 +92,13 @@ struct MatchVisitor<'thir, 'p, 'tcx> {
|
|||||||
|
|
||||||
// Visitor for a thir body. This calls `check_match`, `check_let` and `check_let_chain` as
|
// Visitor for a thir body. This calls `check_match`, `check_let` and `check_let_chain` as
|
||||||
// appropriate.
|
// appropriate.
|
||||||
impl<'thir, 'tcx> Visitor<'thir, 'tcx> for MatchVisitor<'thir, '_, 'tcx> {
|
impl<'p, 'tcx> Visitor<'p, 'tcx> for MatchVisitor<'p, 'tcx> {
|
||||||
fn thir(&self) -> &'thir Thir<'tcx> {
|
fn thir(&self) -> &'p Thir<'tcx> {
|
||||||
self.thir
|
self.thir
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(level = "trace", skip(self))]
|
#[instrument(level = "trace", skip(self))]
|
||||||
fn visit_arm(&mut self, arm: &'thir Arm<'tcx>) {
|
fn visit_arm(&mut self, arm: &'p Arm<'tcx>) {
|
||||||
self.with_lint_level(arm.lint_level, |this| {
|
self.with_lint_level(arm.lint_level, |this| {
|
||||||
match arm.guard {
|
match arm.guard {
|
||||||
Some(Guard::If(expr)) => {
|
Some(Guard::If(expr)) => {
|
||||||
@ -121,7 +121,7 @@ impl<'thir, 'tcx> Visitor<'thir, 'tcx> for MatchVisitor<'thir, '_, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(level = "trace", skip(self))]
|
#[instrument(level = "trace", skip(self))]
|
||||||
fn visit_expr(&mut self, ex: &'thir Expr<'tcx>) {
|
fn visit_expr(&mut self, ex: &'p Expr<'tcx>) {
|
||||||
match ex.kind {
|
match ex.kind {
|
||||||
ExprKind::Scope { value, lint_level, .. } => {
|
ExprKind::Scope { value, lint_level, .. } => {
|
||||||
self.with_lint_level(lint_level, |this| {
|
self.with_lint_level(lint_level, |this| {
|
||||||
@ -174,7 +174,7 @@ impl<'thir, 'tcx> Visitor<'thir, 'tcx> for MatchVisitor<'thir, '_, 'tcx> {
|
|||||||
self.with_let_source(LetSource::None, |this| visit::walk_expr(this, ex));
|
self.with_let_source(LetSource::None, |this| visit::walk_expr(this, ex));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_stmt(&mut self, stmt: &'thir Stmt<'tcx>) {
|
fn visit_stmt(&mut self, stmt: &'p Stmt<'tcx>) {
|
||||||
match stmt.kind {
|
match stmt.kind {
|
||||||
StmtKind::Let {
|
StmtKind::Let {
|
||||||
box ref pattern, initializer, else_block, lint_level, span, ..
|
box ref pattern, initializer, else_block, lint_level, span, ..
|
||||||
@ -195,7 +195,7 @@ impl<'thir, 'tcx> Visitor<'thir, 'tcx> for MatchVisitor<'thir, '_, 'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'thir, 'p, 'tcx> MatchVisitor<'thir, 'p, 'tcx> {
|
impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
|
||||||
#[instrument(level = "trace", skip(self, f))]
|
#[instrument(level = "trace", skip(self, f))]
|
||||||
fn with_let_source(&mut self, let_source: LetSource, f: impl FnOnce(&mut Self)) {
|
fn with_let_source(&mut self, let_source: LetSource, f: impl FnOnce(&mut Self)) {
|
||||||
let old_let_source = self.let_source;
|
let old_let_source = self.let_source;
|
||||||
@ -224,7 +224,7 @@ impl<'thir, 'p, 'tcx> MatchVisitor<'thir, 'p, 'tcx> {
|
|||||||
/// subexpressions we are not handling ourselves.
|
/// subexpressions we are not handling ourselves.
|
||||||
fn visit_land(
|
fn visit_land(
|
||||||
&mut self,
|
&mut self,
|
||||||
ex: &'thir Expr<'tcx>,
|
ex: &'p Expr<'tcx>,
|
||||||
accumulator: &mut Vec<Option<(Span, RefutableFlag)>>,
|
accumulator: &mut Vec<Option<(Span, RefutableFlag)>>,
|
||||||
) -> Result<(), ErrorGuaranteed> {
|
) -> Result<(), ErrorGuaranteed> {
|
||||||
match ex.kind {
|
match ex.kind {
|
||||||
@ -251,7 +251,7 @@ impl<'thir, 'p, 'tcx> MatchVisitor<'thir, 'p, 'tcx> {
|
|||||||
/// expression. This must call `visit_expr` on the subexpressions we are not handling ourselves.
|
/// expression. This must call `visit_expr` on the subexpressions we are not handling ourselves.
|
||||||
fn visit_land_rhs(
|
fn visit_land_rhs(
|
||||||
&mut self,
|
&mut self,
|
||||||
ex: &'thir Expr<'tcx>,
|
ex: &'p Expr<'tcx>,
|
||||||
) -> Result<Option<(Span, RefutableFlag)>, ErrorGuaranteed> {
|
) -> Result<Option<(Span, RefutableFlag)>, ErrorGuaranteed> {
|
||||||
match ex.kind {
|
match ex.kind {
|
||||||
ExprKind::Scope { value, lint_level, .. } => {
|
ExprKind::Scope { value, lint_level, .. } => {
|
||||||
@ -276,7 +276,7 @@ impl<'thir, 'p, 'tcx> MatchVisitor<'thir, 'p, 'tcx> {
|
|||||||
fn lower_pattern(
|
fn lower_pattern(
|
||||||
&mut self,
|
&mut self,
|
||||||
cx: &MatchCheckCtxt<'p, 'tcx>,
|
cx: &MatchCheckCtxt<'p, 'tcx>,
|
||||||
pat: &'thir Pat<'tcx>,
|
pat: &'p Pat<'tcx>,
|
||||||
) -> Result<&'p DeconstructedPat<'p, 'tcx>, ErrorGuaranteed> {
|
) -> Result<&'p DeconstructedPat<'p, 'tcx>, ErrorGuaranteed> {
|
||||||
if let Err(err) = pat.pat_error_reported() {
|
if let Err(err) = pat.pat_error_reported() {
|
||||||
self.error = Err(err);
|
self.error = Err(err);
|
||||||
@ -395,7 +395,7 @@ impl<'thir, 'p, 'tcx> MatchVisitor<'thir, 'p, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(level = "trace", skip(self))]
|
#[instrument(level = "trace", skip(self))]
|
||||||
fn check_let(&mut self, pat: &'thir Pat<'tcx>, scrutinee: Option<ExprId>, span: Span) {
|
fn check_let(&mut self, pat: &'p Pat<'tcx>, scrutinee: Option<ExprId>, span: Span) {
|
||||||
assert!(self.let_source != LetSource::None);
|
assert!(self.let_source != LetSource::None);
|
||||||
let scrut = scrutinee.map(|id| &self.thir[id]);
|
let scrut = scrutinee.map(|id| &self.thir[id]);
|
||||||
if let LetSource::PlainLet = self.let_source {
|
if let LetSource::PlainLet = self.let_source {
|
||||||
@ -547,7 +547,7 @@ impl<'thir, 'p, 'tcx> MatchVisitor<'thir, 'p, 'tcx> {
|
|||||||
|
|
||||||
fn analyze_binding(
|
fn analyze_binding(
|
||||||
&mut self,
|
&mut self,
|
||||||
pat: &'thir Pat<'tcx>,
|
pat: &'p Pat<'tcx>,
|
||||||
refutability: RefutableFlag,
|
refutability: RefutableFlag,
|
||||||
scrut: Option<&Expr<'tcx>>,
|
scrut: Option<&Expr<'tcx>>,
|
||||||
) -> Result<(MatchCheckCtxt<'p, 'tcx>, UsefulnessReport<'p, 'tcx>), ErrorGuaranteed> {
|
) -> Result<(MatchCheckCtxt<'p, 'tcx>, UsefulnessReport<'p, 'tcx>), ErrorGuaranteed> {
|
||||||
@ -560,7 +560,7 @@ impl<'thir, 'p, 'tcx> MatchVisitor<'thir, 'p, 'tcx> {
|
|||||||
|
|
||||||
fn is_let_irrefutable(
|
fn is_let_irrefutable(
|
||||||
&mut self,
|
&mut self,
|
||||||
pat: &'thir Pat<'tcx>,
|
pat: &'p Pat<'tcx>,
|
||||||
scrut: Option<&Expr<'tcx>>,
|
scrut: Option<&Expr<'tcx>>,
|
||||||
) -> Result<RefutableFlag, ErrorGuaranteed> {
|
) -> Result<RefutableFlag, ErrorGuaranteed> {
|
||||||
let (cx, report) = self.analyze_binding(pat, Refutable, scrut)?;
|
let (cx, report) = self.analyze_binding(pat, Refutable, scrut)?;
|
||||||
@ -575,7 +575,7 @@ impl<'thir, 'p, 'tcx> MatchVisitor<'thir, 'p, 'tcx> {
|
|||||||
#[instrument(level = "trace", skip(self))]
|
#[instrument(level = "trace", skip(self))]
|
||||||
fn check_binding_is_irrefutable(
|
fn check_binding_is_irrefutable(
|
||||||
&mut self,
|
&mut self,
|
||||||
pat: &'thir Pat<'tcx>,
|
pat: &'p Pat<'tcx>,
|
||||||
origin: &str,
|
origin: &str,
|
||||||
scrut: Option<&Expr<'tcx>>,
|
scrut: Option<&Expr<'tcx>>,
|
||||||
sp: Option<Span>,
|
sp: Option<Span>,
|
||||||
@ -677,7 +677,7 @@ impl<'thir, 'p, 'tcx> MatchVisitor<'thir, 'p, 'tcx> {
|
|||||||
/// - `x @ Some(ref mut? y)`.
|
/// - `x @ Some(ref mut? y)`.
|
||||||
///
|
///
|
||||||
/// This analysis is *not* subsumed by NLL.
|
/// This analysis is *not* subsumed by NLL.
|
||||||
fn check_borrow_conflicts_in_at_patterns<'tcx>(cx: &MatchVisitor<'_, '_, 'tcx>, pat: &Pat<'tcx>) {
|
fn check_borrow_conflicts_in_at_patterns<'tcx>(cx: &MatchVisitor<'_, 'tcx>, pat: &Pat<'tcx>) {
|
||||||
// Extract `sub` in `binding @ sub`.
|
// Extract `sub` in `binding @ sub`.
|
||||||
let PatKind::Binding { name, mode, ty, subpattern: Some(box ref sub), .. } = pat.kind else {
|
let PatKind::Binding { name, mode, ty, subpattern: Some(box ref sub), .. } = pat.kind else {
|
||||||
return;
|
return;
|
||||||
@ -772,7 +772,7 @@ fn check_borrow_conflicts_in_at_patterns<'tcx>(cx: &MatchVisitor<'_, '_, 'tcx>,
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn check_for_bindings_named_same_as_variants(
|
fn check_for_bindings_named_same_as_variants(
|
||||||
cx: &MatchVisitor<'_, '_, '_>,
|
cx: &MatchVisitor<'_, '_>,
|
||||||
pat: &Pat<'_>,
|
pat: &Pat<'_>,
|
||||||
rf: RefutableFlag,
|
rf: RefutableFlag,
|
||||||
) {
|
) {
|
||||||
|
@ -399,7 +399,7 @@ impl<'p, 'tcx> RustcMatchCheckCtxt<'p, 'tcx> {
|
|||||||
|
|
||||||
/// Note: the input patterns must have been lowered through
|
/// Note: the input patterns must have been lowered through
|
||||||
/// `rustc_mir_build::thir::pattern::check_match::MatchVisitor::lower_pattern`.
|
/// `rustc_mir_build::thir::pattern::check_match::MatchVisitor::lower_pattern`.
|
||||||
pub fn lower_pat(&self, pat: &Pat<'tcx>) -> DeconstructedPat<'p, 'tcx> {
|
pub fn lower_pat(&self, pat: &'p Pat<'tcx>) -> DeconstructedPat<'p, 'tcx> {
|
||||||
let singleton = |pat| std::slice::from_ref(self.pattern_arena.alloc(pat));
|
let singleton = |pat| std::slice::from_ref(self.pattern_arena.alloc(pat));
|
||||||
let cx = self;
|
let cx = self;
|
||||||
let ctor;
|
let ctor;
|
||||||
|
Loading…
Reference in New Issue
Block a user