use rustc_ast as ast;
use rustc_data_structures::fx::FxHashMap;
-use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder};
+use rustc_errors::{
+ pluralize, struct_span_err, Applicability, Diagnostic, DiagnosticBuilder, ErrorReported,
+};
use rustc_hir as hir;
use rustc_hir::def::{CtorKind, DefKind, Res};
use rustc_hir::pat_util::EnumerateAndAdjustIterator;
use rustc_hir::{HirId, Pat, PatKind};
use rustc_infer::infer;
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
-use rustc_middle::ty::subst::GenericArg;
use rustc_middle::ty::{self, Adt, BindingMode, Ty, TypeFoldable};
use rustc_session::lint::builtin::NON_EXHAUSTIVE_OMITTED_PATTERNS;
use rustc_span::hygiene::DesugaringKind;
expected: Ty<'tcx>,
actual: Ty<'tcx>,
ti: TopInfo<'tcx>,
- ) -> Option<DiagnosticBuilder<'tcx>> {
+ ) -> Option<DiagnosticBuilder<'tcx, ErrorReported>> {
self.demand_eqtype_with_origin(&self.pattern_cause(ti, cause_span), expected, actual)
}
ty
}
- fn endpoint_has_type(&self, err: &mut DiagnosticBuilder<'_>, span: Span, ty: Ty<'_>) {
+ fn endpoint_has_type(&self, err: &mut Diagnostic, span: Span, ty: Ty<'_>) {
if !ty.references_error() {
err.span_label(span, &format!("this is of type `{}`", ty));
}
fn borrow_pat_suggestion(
&self,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
pat: &Pat<'_>,
inner: &Pat<'_>,
expected: Ty<'tcx>,
}
pub fn check_dereferenceable(&self, span: Span, expected: Ty<'tcx>, inner: &Pat<'_>) -> bool {
- if let PatKind::Binding(..) = inner.kind {
- if let Some(mt) = self.shallow_resolve(expected).builtin_deref(true) {
- if let ty::Dynamic(..) = mt.ty.kind() {
+ if let PatKind::Binding(..) = inner.kind
+ && let Some(mt) = self.shallow_resolve(expected).builtin_deref(true)
+ && let ty::Dynamic(..) = mt.ty.kind()
+ {
// This is "x = SomeTrait" being reduced from
// "let &x = &SomeTrait" or "let box x = Box<SomeTrait>", an error.
let type_str = self.ty_to_string(expected);
err.emit();
return false;
}
- }
- }
true
}
fn maybe_suggest_range_literal(
&self,
- e: &mut DiagnosticBuilder<'_>,
+ e: &mut Diagnostic,
opt_def_id: Option<hir::def_id::DefId>,
ident: Ident,
) -> bool {
fn emit_bad_pat_path<'b>(
&self,
- mut e: DiagnosticBuilder<'_>,
+ mut e: DiagnosticBuilder<'_, ErrorReported>,
pat_span: Span,
res: Res,
pat_res: Res,
if subpats.len() == variant.fields.len()
|| subpats.len() < variant.fields.len() && ddpos.is_some()
{
- let substs = match pat_ty.kind() {
- ty::Adt(_, substs) => substs,
- _ => bug!("unexpected pattern type {:?}", pat_ty),
+ let ty::Adt(_, substs) = pat_ty.kind() else {
+ bug!("unexpected pattern type {:?}", pat_ty);
};
for (i, subpat) in subpats.iter().enumerate_and_adjust(variant.fields.len(), ddpos) {
let field_ty = self.field_ty(subpat.span, &variant.fields[i], substs);
(ty::Adt(_, substs), [field], false) => {
let field_ty = self.field_ty(pat_span, field, substs);
match field_ty.kind() {
- ty::Tuple(_) => field_ty.tuple_fields().count() == subpats.len(),
+ ty::Tuple(fields) => fields.len() == subpats.len(),
_ => false,
}
}
let max_len = cmp::max(expected_len, elements.len());
let element_tys_iter = (0..max_len).map(|_| {
- GenericArg::from(self.next_ty_var(
+ self.next_ty_var(
// FIXME: `MiscVariable` for now -- obtaining the span and name information
// from all tuple elements isn't trivial.
TypeVariableOrigin { kind: TypeVariableOriginKind::TypeInference, span },
- ))
+ )
});
- let element_tys = tcx.mk_substs(element_tys_iter);
+ let element_tys = tcx.mk_type_list(element_tys_iter);
let pat_ty = tcx.mk_ty(ty::Tuple(element_tys));
if let Some(mut err) = self.demand_eqtype_pat_diag(span, expected, pat_ty, ti) {
err.emit();
tcx.mk_tup(element_tys_iter)
} else {
for (i, elem) in elements.iter().enumerate_and_adjust(max_len, ddpos) {
- self.check_pat(elem, element_tys[i].expect_ty(), def_bm, ti);
+ self.check_pat(elem, element_tys[i], def_bm, ti);
}
pat_ty
}
) -> bool {
let tcx = self.tcx;
- let (substs, adt) = match adt_ty.kind() {
- ty::Adt(adt, substs) => (substs, adt),
- _ => span_bug!(pat.span, "struct pattern is not an ADT"),
+ let ty::Adt(adt, substs) = adt_ty.kind() else {
+ span_bug!(pat.span, "struct pattern is not an ADT");
};
// Index the struct fields' types.
variant: &VariantDef,
pat: &'_ Pat<'_>,
fields: &[hir::PatField<'_>],
- ) -> Option<DiagnosticBuilder<'_>> {
+ ) -> Option<DiagnosticBuilder<'_, ErrorReported>> {
// if this is a tuple struct, then all field names will be numbers
// so if any fields in a struct pattern use shorthand syntax, they will
// be invalid identifiers (for example, Foo { 0, 1 }).
inexistent_fields: &[Ident],
unmentioned_fields: &mut Vec<(&ty::FieldDef, Ident)>,
variant: &ty::VariantDef,
- ) -> DiagnosticBuilder<'tcx> {
+ ) -> DiagnosticBuilder<'tcx, ErrorReported> {
let tcx = self.tcx;
let (field_names, t, plural) = if inexistent_fields.len() == 1 {
(format!("a field named `{}`", inexistent_fields[0]), "this", "")
pat: &Pat<'_>,
fields: &'tcx [hir::PatField<'tcx>],
variant: &ty::VariantDef,
- ) -> Option<DiagnosticBuilder<'tcx>> {
+ ) -> Option<DiagnosticBuilder<'tcx, ErrorReported>> {
if let (CtorKind::Fn, PatKind::Struct(qpath, ..)) = (variant.ctor_kind, &pat.kind) {
let path = rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| {
s.print_qpath(qpath, false)
&self,
pat: &Pat<'_>,
fields: &'tcx [hir::PatField<'tcx>],
- ) -> DiagnosticBuilder<'tcx> {
+ ) -> DiagnosticBuilder<'tcx, ErrorReported> {
let mut err = self
.tcx
.sess
unmentioned_fields: &[(&ty::FieldDef, Ident)],
have_inaccessible_fields: bool,
fields: &'tcx [hir::PatField<'tcx>],
- ) -> DiagnosticBuilder<'tcx> {
+ ) -> DiagnosticBuilder<'tcx, ErrorReported> {
let inaccessible = if have_inaccessible_fields { " and inaccessible fields" } else { "" };
let field_names = if unmentioned_fields.len() == 1 {
format!("field `{}`{}", unmentioned_fields[0].1, inaccessible)