about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection/src
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2022-08-18 12:16:35 +0000
committerMichael Goulet <michael@errs.io>2022-08-21 02:35:11 +0000
commitd2f54b1990c916c1af15124ce45dbdaa9758f7b2 (patch)
tree39b7ad46e98b2b6ec313140191e53fce38e18870 /compiler/rustc_trait_selection/src
parent2a16a127a0ed1bf961ca7bce40499f6c407d53e2 (diff)
downloadrust-d2f54b1990c916c1af15124ce45dbdaa9758f7b2.tar.gz
rust-d2f54b1990c916c1af15124ce45dbdaa9758f7b2.zip
Adjust messages, address some nits
Diffstat (limited to 'compiler/rustc_trait_selection/src')
-rw-r--r--compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs76
1 files changed, 38 insertions, 38 deletions
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 4561ab0bfe4..803f0dadc02 100644
--- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
+++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
@@ -973,6 +973,23 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
                     || ref_inner_ty_satisfies_pred
                 {
                     if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) {
+                        // We don't want a borrowing suggestion on the fields in structs,
+                        // ```
+                        // struct Foo {
+                        //  the_foos: Vec<Foo>
+                        // }
+                        // ```
+                        if !matches!(
+                            span.ctxt().outer_expn_data().kind,
+                            ExpnKind::Root | ExpnKind::Desugaring(DesugaringKind::ForLoop)
+                        ) {
+                            return false;
+                        }
+                        if snippet.starts_with('&') {
+                            // This is already a literal borrow and the obligation is failing
+                            // somewhere else in the obligation chain. Do not suggest non-sense.
+                            return false;
+                        }
                         // We have a very specific type of error, where just borrowing this argument
                         // might solve the problem. In cases like this, the important part is the
                         // original type obligation, not the last one that failed, which is arbitrary.
@@ -986,50 +1003,33 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
                             err.message =
                                 vec![(rustc_errors::DiagnosticMessage::Str(msg), Style::NoStyle)];
                         }
-                        if snippet.starts_with('&') {
-                            // This is already a literal borrow and the obligation is failing
-                            // somewhere else in the obligation chain. Do not suggest non-sense.
-                            return false;
-                        }
                         err.span_label(
                             span,
-                            &format!(
-                                "expected an implementor of trait `{}`",
+                            format!(
+                                "the trait `{}` is not implemented for `{}`",
                                 old_pred.print_modifiers_and_trait_path(),
+                                old_pred.self_ty().skip_binder(),
                             ),
                         );
 
-                        // This if is to prevent a special edge-case
-                        if matches!(
-                            span.ctxt().outer_expn_data().kind,
-                            ExpnKind::Root | ExpnKind::Desugaring(DesugaringKind::ForLoop)
-                        ) {
-                            // We don't want a borrowing suggestion on the fields in structs,
-                            // ```
-                            // struct Foo {
-                            //  the_foos: Vec<Foo>
-                            // }
-                            // ```
-
-                            if imm_ref_self_ty_satisfies_pred && mut_ref_self_ty_satisfies_pred {
-                                err.span_suggestions(
-                                    span.shrink_to_lo(),
-                                    "consider borrowing here",
-                                    ["&".to_string(), "&mut ".to_string()].into_iter(),
-                                    Applicability::MaybeIncorrect,
-                                );
-                            } else {
-                                let is_mut = mut_ref_self_ty_satisfies_pred || ref_inner_ty_mut;
-                                err.span_suggestion_verbose(
-                                    span.shrink_to_lo(),
-                                    &format!(
-                                        "consider{} borrowing here",
-                                        if is_mut { " mutably" } else { "" }
-                                    ),
-                                    format!("&{}", if is_mut { "mut " } else { "" }),
-                                    Applicability::MaybeIncorrect,
-                                );
-                            }
+                        if imm_ref_self_ty_satisfies_pred && mut_ref_self_ty_satisfies_pred {
+                            err.span_suggestions(
+                                span.shrink_to_lo(),
+                                "consider borrowing here",
+                                ["&".to_string(), "&mut ".to_string()].into_iter(),
+                                Applicability::MaybeIncorrect,
+                            );
+                        } else {
+                            let is_mut = mut_ref_self_ty_satisfies_pred || ref_inner_ty_mut;
+                            err.span_suggestion_verbose(
+                                span.shrink_to_lo(),
+                                &format!(
+                                    "consider{} borrowing here",
+                                    if is_mut { " mutably" } else { "" }
+                                ),
+                                format!("&{}", if is_mut { "mut " } else { "" }),
+                                Applicability::MaybeIncorrect,
+                            );
                         }
                         return true;
                     }