about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2024-02-29 16:30:01 +0000
committerEsteban Küber <esteban@kuber.com.ar>2024-03-02 01:53:37 +0000
commit7f97dfe700be69d359eaebf97275285f8a85faf4 (patch)
treee4bdaf2587c2d6fb09cc5de03508e73bfca178fb /compiler
parentd89c2c569aaf509c97469cf7433d26f7f87b40bf (diff)
downloadrust-7f97dfe700be69d359eaebf97275285f8a85faf4.tar.gz
rust-7f97dfe700be69d359eaebf97275285f8a85faf4.zip
Account for unmet `T: !Copy` in E0277 message
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs17
1 files changed, 12 insertions, 5 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 e82e94993d2..06f908f01a9 100644
--- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
+++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
@@ -4773,11 +4773,18 @@ pub(super) fn get_explanation_based_on_obligation<'tcx>(
             Some(desc) => format!(" {desc}"),
             None => String::new(),
         };
-        format!(
-            "{pre_message}the trait `{}` is not implemented for{desc} `{}`{post}",
-            trait_predicate.print_modifiers_and_trait_path(),
-            tcx.short_ty_string(trait_ref.skip_binder().self_ty(), &mut None),
-        )
+        if let ty::ImplPolarity::Positive = trait_predicate.polarity() {
+            format!(
+                "{pre_message}the trait `{}` is not implemented for{desc} `{}`{post}",
+                trait_predicate.print_modifiers_and_trait_path(),
+                tcx.short_ty_string(trait_ref.skip_binder().self_ty(), &mut None),
+            )
+        } else {
+            // "the trait bound `T: !Send` is not satisfied" reads better than "`!Send` is
+            // not implemented for `T`".
+            // FIXME: add note explaining explicit negative trait bounds.
+            format!("{pre_message}the trait bound `{trait_predicate}` is not satisfied{post}")
+        }
     }
 }