use rustc_trait_selection::traits::ObligationCause;
use rustc_ast::util::parser::PREC_POSTFIX;
-use rustc_errors::{Applicability, DiagnosticBuilder};
+use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, ErrorReported};
use rustc_hir as hir;
use rustc_hir::lang_items::LangItem;
use rustc_hir::{is_range_literal, Node};
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub fn emit_coerce_suggestions(
&self,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
expr: &hir::Expr<'tcx>,
expr_ty: Ty<'tcx>,
expected: Ty<'tcx>,
sp: Span,
expected: Ty<'tcx>,
actual: Ty<'tcx>,
- ) -> Option<DiagnosticBuilder<'tcx>> {
+ ) -> Option<DiagnosticBuilder<'tcx, ErrorReported>> {
self.demand_suptype_with_origin(&self.misc(sp), expected, actual)
}
cause: &ObligationCause<'tcx>,
expected: Ty<'tcx>,
actual: Ty<'tcx>,
- ) -> Option<DiagnosticBuilder<'tcx>> {
+ ) -> Option<DiagnosticBuilder<'tcx, ErrorReported>> {
match self.at(cause, self.param_env).sup(expected, actual) {
Ok(InferOk { obligations, value: () }) => {
self.register_predicates(obligations);
sp: Span,
expected: Ty<'tcx>,
actual: Ty<'tcx>,
- ) -> Option<DiagnosticBuilder<'tcx>> {
+ ) -> Option<DiagnosticBuilder<'tcx, ErrorReported>> {
self.demand_eqtype_with_origin(&self.misc(sp), expected, actual)
}
cause: &ObligationCause<'tcx>,
expected: Ty<'tcx>,
actual: Ty<'tcx>,
- ) -> Option<DiagnosticBuilder<'tcx>> {
+ ) -> Option<DiagnosticBuilder<'tcx, ErrorReported>> {
match self.at(cause, self.param_env).eq(expected, actual) {
Ok(InferOk { obligations, value: () }) => {
self.register_predicates(obligations);
expected: Ty<'tcx>,
expected_ty_expr: Option<&'tcx hir::Expr<'tcx>>,
allow_two_phase: AllowTwoPhase,
- ) -> (Ty<'tcx>, Option<DiagnosticBuilder<'tcx>>) {
+ ) -> (Ty<'tcx>, Option<DiagnosticBuilder<'tcx, ErrorReported>>) {
let expected = self.resolve_vars_with_obligations(expected);
let e = match self.try_coerce(expr, checked_ty, expected, allow_two_phase, None) {
fn annotate_expected_due_to_let_ty(
&self,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
expr: &hir::Expr<'_>,
error: TypeError<'_>,
) {
if !lhs.is_syntactic_place_expr() {
// We already emitted E0070 "invalid left-hand side of assignment", so we
// silence this.
- err.delay_as_bug();
+ err.downgrade_to_delayed_bug();
}
}
_ => {}
/// sole field is of the found type, suggest such variants. (Issue #42764)
fn suggest_compatible_variants(
&self,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
expr: &hir::Expr<'_>,
expected: Ty<'tcx>,
expr_ty: Ty<'tcx>,
match (&expr.kind, expected.kind(), checked_ty.kind()) {
(_, &ty::Ref(_, exp, _), &ty::Ref(_, check, _)) => match (exp.kind(), check.kind()) {
(&ty::Str, &ty::Array(arr, _) | &ty::Slice(arr)) if arr == self.tcx.types.u8 => {
- if let hir::ExprKind::Lit(_) = expr.kind {
- if let Ok(src) = sm.span_to_snippet(sp) {
- if replace_prefix(&src, "b\"", "\"").is_some() {
+ if let hir::ExprKind::Lit(_) = expr.kind
+ && let Ok(src) = sm.span_to_snippet(sp)
+ && replace_prefix(&src, "b\"", "\"").is_some()
+ {
let pos = sp.lo() + BytePos(1);
return Some((
sp.with_hi(pos),
));
}
}
- }
- }
(&ty::Array(arr, _) | &ty::Slice(arr), &ty::Str) if arr == self.tcx.types.u8 => {
- if let hir::ExprKind::Lit(_) = expr.kind {
- if let Ok(src) = sm.span_to_snippet(sp) {
- if replace_prefix(&src, "\"", "b\"").is_some() {
+ if let hir::ExprKind::Lit(_) = expr.kind
+ && let Ok(src) = sm.span_to_snippet(sp)
+ && replace_prefix(&src, "\"", "b\"").is_some()
+ {
return Some((
sp.shrink_to_lo(),
"consider adding a leading `b`",
Applicability::MachineApplicable,
true,
));
- }
- }
+
}
}
_ => {}
pub fn check_for_cast(
&self,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
expr: &hir::Expr<'_>,
checked_ty: Ty<'tcx>,
expected_ty: Ty<'tcx>,
let in_const_context = self.tcx.hir().is_inside_const_context(expr.hir_id);
let suggest_fallible_into_or_lhs_from =
- |err: &mut DiagnosticBuilder<'_>, exp_to_found_is_fallible: bool| {
+ |err: &mut Diagnostic, exp_to_found_is_fallible: bool| {
// If we know the expression the expected type is derived from, we might be able
// to suggest a widening conversion rather than a narrowing one (which may
// panic). For example, given x: u8 and y: u32, if we know the span of "x",
};
let suggest_to_change_suffix_or_into =
- |err: &mut DiagnosticBuilder<'_>,
+ |err: &mut Diagnostic,
found_to_exp_is_fallible: bool,
exp_to_found_is_fallible: bool| {
let exp_is_lhs =
}
// Report the type inferred by the return statement.
- fn report_closure_inferred_return_type(
- &self,
- err: &mut DiagnosticBuilder<'_>,
- expected: Ty<'tcx>,
- ) {
+ fn report_closure_inferred_return_type(&self, err: &mut Diagnostic, expected: Ty<'tcx>) {
if let Some(sp) = self.ret_coercion_span.get() {
// If the closure has an explicit return type annotation, or if
// the closure's return type has been inferred from outside