Perform match checking on THIR.
This commit is contained in:
parent
3b47cdc439
commit
05082f57af
81 changed files with 668 additions and 997 deletions
|
@ -58,6 +58,7 @@ fn mir_build(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> Body<'_
|
|||
ty::WithOptConstParam { did, const_param_did: None } => {
|
||||
tcx.ensure_with_value().thir_check_unsafety(did);
|
||||
tcx.ensure_with_value().thir_abstract_const(did);
|
||||
tcx.ensure_with_value().check_match(did);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,8 @@ use rustc_hir::def::Res;
|
|||
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
|
||||
use rustc_middle::thir::Pat;
|
||||
use rustc_middle::ty::{self, Ty};
|
||||
use rustc_span::{symbol::Ident, Span};
|
||||
use rustc_span::symbol::Symbol;
|
||||
use rustc_span::Span;
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
#[diag(mir_build_unconditional_recursion)]
|
||||
|
@ -534,18 +535,10 @@ pub struct TrailingIrrefutableLetPatterns {
|
|||
#[derive(LintDiagnostic)]
|
||||
#[diag(mir_build_bindings_with_variant_name, code = "E0170")]
|
||||
pub struct BindingsWithVariantName {
|
||||
#[suggestion(code = "{ty_path}::{ident}", applicability = "machine-applicable")]
|
||||
#[suggestion(code = "{ty_path}::{name}", applicability = "machine-applicable")]
|
||||
pub suggestion: Option<Span>,
|
||||
pub ty_path: String,
|
||||
pub ident: Ident,
|
||||
}
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
#[diag(mir_build_irrefutable_let_patterns_generic_let)]
|
||||
#[note]
|
||||
#[help]
|
||||
pub struct IrrefutableLetPatternsGenericLet {
|
||||
pub count: usize,
|
||||
pub name: Symbol,
|
||||
}
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
|
@ -590,7 +583,7 @@ pub struct BorrowOfMovedValue<'tcx> {
|
|||
pub binding_span: Span,
|
||||
#[label(mir_build_value_borrowed_label)]
|
||||
pub conflicts_ref: Vec<Span>,
|
||||
pub name: Ident,
|
||||
pub name: Symbol,
|
||||
pub ty: Ty<'tcx>,
|
||||
#[suggestion(code = "ref ", applicability = "machine-applicable")]
|
||||
pub suggest_borrowing: Option<Span>,
|
||||
|
@ -638,19 +631,19 @@ pub enum Conflict {
|
|||
Mut {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
name: Ident,
|
||||
name: Symbol,
|
||||
},
|
||||
#[label(mir_build_borrow)]
|
||||
Ref {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
name: Ident,
|
||||
name: Symbol,
|
||||
},
|
||||
#[label(mir_build_moved)]
|
||||
Moved {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
name: Ident,
|
||||
name: Symbol,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -54,11 +54,9 @@ pub(super) fn pat_from_hir<'a, 'tcx>(
|
|||
pat: &'tcx hir::Pat<'tcx>,
|
||||
) -> Box<Pat<'tcx>> {
|
||||
let mut pcx = PatCtxt::new(tcx, param_env, typeck_results);
|
||||
pcx.include_lint_checks();
|
||||
let result = pcx.lower_pattern(pat);
|
||||
if !pcx.errors.is_empty() {
|
||||
let msg = format!("encountered errors lowering pattern: {:?}", pcx.errors);
|
||||
tcx.sess.delay_span_bug(pat.span, &msg);
|
||||
}
|
||||
pcx.report_inlining_errors();
|
||||
debug!("pat_from_hir({:?}) = {:?}", pat, result);
|
||||
result
|
||||
}
|
||||
|
@ -77,6 +75,25 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
|
|||
self
|
||||
}
|
||||
|
||||
fn report_inlining_errors(&self) {
|
||||
for error in &self.errors {
|
||||
match *error {
|
||||
PatternError::StaticInPattern(span) => {
|
||||
self.tcx.sess.emit_err(StaticInPattern { span });
|
||||
}
|
||||
PatternError::AssocConstInPattern(span) => {
|
||||
self.tcx.sess.emit_err(AssocConstInPattern { span });
|
||||
}
|
||||
PatternError::ConstParamInPattern(span) => {
|
||||
self.tcx.sess.emit_err(ConstParamInPattern { span });
|
||||
}
|
||||
PatternError::NonConstPath(span) => {
|
||||
self.tcx.sess.emit_err(NonConstPath { span });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn lower_pattern(&mut self, pat: &'tcx hir::Pat<'tcx>) -> Box<Pat<'tcx>> {
|
||||
// When implicit dereferences have been inserted in this pattern, the unadjusted lowered
|
||||
// pattern has the type that results *after* dereferencing. For example, in this code:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue