diff options
| author | Stuart Cook <Zalathar@users.noreply.github.com> | 2025-04-11 13:31:46 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-11 13:31:46 +1000 |
| commit | 573ebf011e460d0dbe4ab9e64fc2247ba34bbd5c (patch) | |
| tree | f0a11d654d499222ee7bc8f6a46533e10433b5c1 /compiler/rustc_trait_selection/src | |
| parent | 9a9a0781fa219b7c4d04808a8583c053fa8b12ed (diff) | |
| parent | 8b6ff4a378e2df03db108bcd918a77f8a759334f (diff) | |
| download | rust-573ebf011e460d0dbe4ab9e64fc2247ba34bbd5c.tar.gz rust-573ebf011e460d0dbe4ab9e64fc2247ba34bbd5c.zip | |
Rollup merge of #138998 - rperier:donot_suggest_to_use_impl_trait_in_closure_params, r=Noratrieb
Don't suggest the use of `impl Trait` in closure parameter Fixes #138932
Diffstat (limited to 'compiler/rustc_trait_selection/src')
| -rw-r--r-- | compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs index 3583bc8ad8f..b963e4a2c7c 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs @@ -3018,12 +3018,23 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { [] => span_bug!(ty.span, "trait object with no traits: {ty:?}"), }; let needs_parens = traits.len() != 1; - err.span_suggestion_verbose( - span, - "you can use `impl Trait` as the argument type", - "impl ", - Applicability::MaybeIncorrect, - ); + // Don't recommend impl Trait as a closure argument + if let Some(hir_id) = hir_id + && matches!( + self.tcx.parent_hir_node(hir_id), + hir::Node::Item(hir::Item { + kind: hir::ItemKind::Fn { .. }, + .. + }) + ) + { + err.span_suggestion_verbose( + span, + "you can use `impl Trait` as the argument type", + "impl ", + Applicability::MaybeIncorrect, + ); + } let sugg = if !needs_parens { vec![(span.shrink_to_lo(), format!("&{kw}"))] } else { |
