diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-08-04 21:31:55 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-08-04 21:31:55 +0200 |
| commit | 5054e41b642fb6da0094034e56ae65d98e8bb884 (patch) | |
| tree | 589f4a1b23b3ddd57f448203494035489c6c09e0 /compiler/rustc_trait_selection/src | |
| parent | 03181e0547c1e15a2c0431337b2d5ee00fd0374c (diff) | |
| parent | cde8f06503d06d254aa4191438588ba9b2a36b77 (diff) | |
| download | rust-5054e41b642fb6da0094034e56ae65d98e8bb884.tar.gz rust-5054e41b642fb6da0094034e56ae65d98e8bb884.zip | |
Rollup merge of #113945 - chenyukang:yukang-fix-113447-slice-2, r=cjgillot
Fix wrong span for trait selection failure error reporting Fixes #113447
Diffstat (limited to 'compiler/rustc_trait_selection/src')
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs | 8 |
2 files changed, 13 insertions, 3 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index eae13eb6302..4d85e2b6089 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -2987,6 +2987,14 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { unsatisfied_const: bool, ) { let body_def_id = obligation.cause.body_id; + let span = if let ObligationCauseCode::BinOp { rhs_span: Some(rhs_span), .. } = + obligation.cause.code() + { + *rhs_span + } else { + span + }; + // Try to report a help message if is_fn_trait && let Ok((implemented_kind, params)) = self.type_implements_fn_trait( diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 46c31c77613..bde72c691dc 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -3953,9 +3953,11 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { candidate_impls: &[ImplCandidate<'tcx>], span: Span, ) { - // We can only suggest the slice coersion for function arguments since the suggestion - // would make no sense in turbofish or call - let ObligationCauseCode::FunctionArgumentObligation { .. } = obligation.cause.code() else { + // We can only suggest the slice coersion for function and binary operation arguments, + // since the suggestion would make no sense in turbofish or call + let (ObligationCauseCode::BinOp { .. } + | ObligationCauseCode::FunctionArgumentObligation { .. }) = obligation.cause.code() + else { return; }; |
