From 9835e2ae736235810b4ea1c162ca5e65c547e770 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 18 May 2024 04:49:50 +0200 Subject: Merging upstream version 1.71.1+dfsg1. Signed-off-by: Daniel Baumann --- compiler/rustc_hir_typeck/src/coercion.rs | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'compiler/rustc_hir_typeck/src/coercion.rs') diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index 8fa3bcd68..08c4082e8 100644 --- a/compiler/rustc_hir_typeck/src/coercion.rs +++ b/compiler/rustc_hir_typeck/src/coercion.rs @@ -601,7 +601,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { self.tcx, cause, self.fcx.param_env, - self.tcx.mk_trait_ref(coerce_unsized_did, [coerce_source, coerce_target]) + ty::TraitRef::new(self.tcx, coerce_unsized_did, [coerce_source, coerce_target]) )]; let mut has_unsized_tuple_coercion = false; @@ -707,9 +707,9 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { &self.tcx.sess.parse_sess, sym::trait_upcasting, self.cause.span, - &format!("cannot cast `{sub}` to `{sup}`, trait upcasting coercion is experimental"), + format!("cannot cast `{sub}` to `{sup}`, trait upcasting coercion is experimental"), ); - err.note(&format!("required when coercing `{source}` into `{target}`")); + err.note(format!("required when coercing `{source}` into `{target}`")); err.emit(); } @@ -764,8 +764,11 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { self.tcx, self.cause.clone(), self.param_env, - ty::Binder::dummy( - self.tcx.at(self.cause.span).mk_trait_ref(hir::LangItem::PointerLike, [a]), + ty::TraitRef::from_lang_item( + self.tcx, + hir::LangItem::PointerLike, + self.cause.span, + [a], ), )); @@ -976,7 +979,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// Attempt to coerce an expression to a type, and return the /// adjusted type of the expression, if successful. /// Adjustments are only recorded if the coercion succeeded. - /// The expressions *must not* have any pre-existing adjustments. + /// The expressions *must not* have any preexisting adjustments. pub fn try_coerce( &self, expr: &hir::Expr<'_>, @@ -1340,7 +1343,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { } /// As an optimization, you can create a `CoerceMany` with a - /// pre-existing slice of expressions. In this case, you are + /// preexisting slice of expressions. In this case, you are /// expected to pass each element in the slice to `coerce(...)` in /// order. This is used with arrays in particular to avoid /// needlessly cloning the slice. @@ -1657,7 +1660,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { "the function expects a value to always be returned, but loops might run zero times", ); if MAXITER < ret_exprs.len() { - err.note(&format!( + err.note(format!( "if the loop doesn't execute, {} other values would never get returned", ret_exprs.len() - MAXITER )); @@ -1767,7 +1770,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { { err.span_note( sp, - &format!( + format!( "return type inferred to be `{}` here", expected ), @@ -1811,7 +1814,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { .span_to_snippet(return_sp) .unwrap_or_else(|_| "dyn Trait".to_string()); let mut snippet_iter = snippet.split_whitespace(); - let has_impl = snippet_iter.next().map_or(false, |s| s == "impl"); + let has_impl = snippet_iter.next().is_some_and(|s| s == "impl"); // Only suggest `Box` if `Trait` in `impl Trait` is object safe. let mut is_object_safe = false; if let hir::FnRetTy::Return(ty) = fn_output @@ -1831,7 +1834,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { bound .trait_ref() .and_then(|t| t.trait_def_id()) - .map_or(false, |def_id| { + .is_some_and(|def_id| { fcx.tcx.check_is_object_safe(def_id) }) }) @@ -1864,7 +1867,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { Applicability::MaybeIncorrect, ); } else { - err.help(&format!( + err.help(format!( "if the trait `{}` were object safe, you could return a boxed trait object", &snippet[5..] )); -- cgit v1.2.3