From c1ccb05ef02f099d480cf18bbe8f3a50dc2ef66a Mon Sep 17 00:00:00 2001 From: long-long-float Date: Sat, 23 Mar 2024 14:34:43 +0900 Subject: [PATCH] Format --- compiler/rustc_hir/src/hir.rs | 5 ++++- compiler/rustc_hir_typeck/src/method/suggest.rs | 5 ++++- .../rustc_infer/src/infer/error_reporting/mod.rs | 3 +-- .../src/traits/error_reporting/type_err_ctxt_ext.rs | 12 ++++++------ 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index b5e1b970f415d..f130255768ac2 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -647,7 +647,10 @@ impl<'hir> Generics<'hir> { /// Returns bounds span for suggestions. /// If the span including lifetime bound needs parentheses, it returns a span to the open parenthese at the second item. /// e.g. `dyn Future + 'static` needs parentheses `(dyn Future) + 'static` - pub fn bounds_span_for_suggestions(&self, param_def_id: LocalDefId) -> Option<(Span, Option)> { + pub fn bounds_span_for_suggestions( + &self, + param_def_id: LocalDefId, + ) -> Option<(Span, Option)> { fn get_inner_ty<'a, 'b>(bound: &'a GenericBound<'b>) -> Option<&'a Ty<'b>> { match bound { GenericBound::Trait(data, _) => { diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index 5eee762e23c65..f9ea8e1922da4 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -3275,7 +3275,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { param.name.ident(), )); let bounds_span = hir_generics.bounds_span_for_suggestions(def_id); - if rcvr_ty.is_ref() && param.is_impl_trait() && let Some((bounds_span, _)) = bounds_span { + if rcvr_ty.is_ref() + && param.is_impl_trait() + && let Some((bounds_span, _)) = bounds_span + { err.multipart_suggestions( msg, candidates.iter().map(|t| { diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index b6801280b54e2..8dfa78ff9489f 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -2403,8 +2403,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { // We do this to avoid suggesting code that ends up as `T: 'a'b`, // instead we suggest `T: 'a + 'b` in that case. let hir_generics = self.tcx.hir().get_generics(scope).unwrap(); - let sugg_span = match hir_generics.bounds_span_for_suggestions(def_id) - { + let sugg_span = match hir_generics.bounds_span_for_suggestions(def_id) { Some((span, open_paren_sp)) => Some((span, true, open_paren_sp)), // If `param` corresponds to `Self`, no usable suggestion span. None if generics.has_self && param.index == 0 => None, diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs index 1a5f293e6dcf7..64cf2c98eb859 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs @@ -2929,12 +2929,12 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { _ => {} }; // Didn't add an indirection suggestion, so add a general suggestion to relax `Sized`. - let (span, separator) = if let Some((s, _)) = generics.bounds_span_for_suggestions(param.def_id) - { - (s, " +") - } else { - (param.name.ident().span.shrink_to_hi(), ":") - }; + let (span, separator) = + if let Some((s, _)) = generics.bounds_span_for_suggestions(param.def_id) { + (s, " +") + } else { + (param.name.ident().span.shrink_to_hi(), ":") + }; err.span_suggestion_verbose( span, "consider relaxing the implicit `Sized` restriction",