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;
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,
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)