use crate::astconv::AstConv;
use crate::check::FnCtxt;
-use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder};
+use rustc_errors::{struct_span_err, Applicability, Diagnostic, DiagnosticBuilder};
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
// (e.g., in example above, the failure from relating `Vec<T>`
// to the target type), since that should be the least
// confusing.
- let InferOk { value: ty, mut obligations } = match found {
- Some(d) => d,
- None => {
- let err = first_error.expect("coerce_borrowed_pointer had no error");
- debug!("coerce_borrowed_pointer: failed with err = {:?}", err);
- return Err(err);
- }
+ let Some(InferOk { value: ty, mut obligations }) = found else {
+ let err = first_error.expect("coerce_borrowed_pointer had no error");
+ debug!("coerce_borrowed_pointer: failed with err = {:?}", err);
+ return Err(err);
};
if ty == a && mt_a.mutbl == hir::Mutability::Not && autoderef.step_count() == 1 {
// Now apply the autoref. We have to extract the region out of
// the final ref type we got.
- let r_borrow = match ty.kind() {
- ty::Ref(r_borrow, _, _) => r_borrow,
- _ => span_bug!(span, "expected a ref type, got {:?}", ty),
+ let ty::Ref(r_borrow, _, _) = ty.kind() else {
+ span_bug!(span, "expected a ref type, got {:?}", ty);
};
let mutbl = match mutbl_b {
hir::Mutability::Not => AutoBorrowMutability::Not,
// We don't ever need two-phase here since we throw out the result of the coercion
let coerce = Coerce::new(self, cause, AllowTwoPhase::No);
self.probe(|_| {
- let ok = match coerce.coerce(source, target) {
- Ok(ok) => ok,
- _ => return false,
+ let Ok(ok) = coerce.coerce(source, target) else {
+ return false;
};
let mut fcx = traits::FulfillmentContext::new_in_snapshot();
fcx.register_predicate_obligations(self, ok.obligations);
&mut self,
fcx: &FnCtxt<'a, 'tcx>,
cause: &ObligationCause<'tcx>,
- augment_error: &mut dyn FnMut(&mut DiagnosticBuilder<'_>),
+ augment_error: &mut dyn FnMut(&mut Diagnostic),
label_unit_as_expected: bool,
) {
self.coerce_inner(
cause: &ObligationCause<'tcx>,
expression: Option<&'tcx hir::Expr<'tcx>>,
mut expression_ty: Ty<'tcx>,
- augment_error: Option<&mut dyn FnMut(&mut DiagnosticBuilder<'_>)>,
+ augment_error: Option<&mut dyn FnMut(&mut Diagnostic)>,
label_expression_as_expected: bool,
) {
// Incorporate whatever type inference information we have
fn add_impl_trait_explanation<'a>(
&self,
- err: &mut DiagnosticBuilder<'a>,
+ err: &mut Diagnostic,
cause: &ObligationCause<'tcx>,
fcx: &FnCtxt<'a, 'tcx>,
expected: Ty<'tcx>,