X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=compiler%2Frustc_typeck%2Fsrc%2Fcheck%2Fcoercion.rs;h=8204a25e9112b71d99cea21425fefa753227178c;hb=02ff9e0aef03d48fdecc2d114311217010ec1d81;hp=3668ecd234c64e1c8b216af4f6d07e653ba8038b;hpb=715cda2e81c769277e63c08a3a9966f8cdb6b3c5;p=rust.git diff --git a/compiler/rustc_typeck/src/check/coercion.rs b/compiler/rustc_typeck/src/check/coercion.rs index 3668ecd234c..ed68bcfe433 100644 --- a/compiler/rustc_typeck/src/check/coercion.rs +++ b/compiler/rustc_typeck/src/check/coercion.rs @@ -37,7 +37,7 @@ 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}; @@ -142,7 +142,7 @@ fn unify_and(&self, a: Ty<'tcx>, b: Ty<'tcx>, f: F) -> CoerceResult<'tcx> where F: FnOnce(Ty<'tcx>) -> Vec>, { - self.unify(&a, &b) + self.unify(a, b) .and_then(|InferOk { value: ty, obligations }| success(f(ty), ty, obligations)) } @@ -429,13 +429,10 @@ fn coerce_borrowed_pointer( // (e.g., in example above, the failure from relating `Vec` // 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 { @@ -461,9 +458,8 @@ fn coerce_borrowed_pointer( // 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, @@ -472,7 +468,7 @@ fn coerce_borrowed_pointer( } }; adjustments.push(Adjustment { - kind: Adjust::Borrow(AutoBorrow::Ref(r_borrow, mutbl)), + kind: Adjust::Borrow(AutoBorrow::Ref(*r_borrow, mutbl)), target: ty, }); @@ -944,9 +940,8 @@ pub fn can_coerce(&self, expr_ty: Ty<'tcx>, target: Ty<'tcx>) -> bool { // 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); @@ -1312,7 +1307,7 @@ pub fn coerce_forced_unit<'a>( &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( @@ -1335,7 +1330,7 @@ pub fn coerce_forced_unit<'a>( 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 @@ -1608,7 +1603,7 @@ fn report_return_mismatched_types<'a>( fn add_impl_trait_explanation<'a>( &self, - err: &mut DiagnosticBuilder<'a>, + err: &mut Diagnostic, cause: &ObligationCause<'tcx>, fcx: &FnCtxt<'a, 'tcx>, expected: Ty<'tcx>,