diff options
| author | León Orell Valerian Liehr <me@fmease.dev> | 2024-04-23 17:25:14 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-23 17:25:14 +0200 |
| commit | 80f2b91b20a445b553b3dd3958624fc6ed1b08a1 (patch) | |
| tree | 49f738142f39c8074971685d98dbbf43625d5d24 /compiler/rustc_trait_selection/src/traits | |
| parent | ad07aa12c99698f810d730d7b5a49704c729651d (diff) | |
| parent | 31e581ec1201aac9a3475b16d2100a3ddd35e2e3 (diff) | |
| download | rust-80f2b91b20a445b553b3dd3958624fc6ed1b08a1.tar.gz rust-80f2b91b20a445b553b3dd3958624fc6ed1b08a1.zip | |
Rollup merge of #120929 - long-long-float:wrap-dyn-in-suggestion, r=fmease
Wrap dyn type with parentheses in suggestion Close #120223 Fix wrong suggestion that is grammatically incorrect. Specifically, I added parentheses to dyn types that need lifetime bound. ``` help: consider adding an explicit lifetime bound | 4 | executor: impl FnOnce(T) -> (dyn Future<Output = ()>) + 'static, | + +++++++++++ ```
Diffstat (limited to 'compiler/rustc_trait_selection/src/traits')
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs | 27 |
1 files changed, 19 insertions, 8 deletions
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 96596de32aa..0e309689680 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 @@ -2938,17 +2938,28 @@ 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, " +") + let (span, separator, open_paren_sp) = + if let Some((s, open_paren_sp)) = generics.bounds_span_for_suggestions(param.def_id) { + (s, " +", open_paren_sp) + } else { + (param.name.ident().span.shrink_to_hi(), ":", None) + }; + + let mut suggs = vec![]; + let suggestion = format!("{separator} ?Sized"); + + if let Some(open_paren_sp) = open_paren_sp { + suggs.push((open_paren_sp, "(".to_string())); + suggs.push((span, format!("){suggestion}"))); } else { - (param.name.ident().span.shrink_to_hi(), ":") - }; - err.span_suggestion_verbose( - span, + suggs.push((span, suggestion)); + } + + err.multipart_suggestion_verbose( "consider relaxing the implicit `Sized` restriction", - format!("{separator} ?Sized"), + suggs, Applicability::MachineApplicable, ); } |
