about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTaylor Yu <tlyu@mit.edu>2021-06-02 16:06:50 -0500
committerTaylor Yu <tlyu@mit.edu>2021-06-18 17:24:38 -0500
commit3252432c27c8ff14f52ce04fa08c6bb73ce40ebe (patch)
tree321c7b1ae1241e4712c8c0d8f21dc533f5b46f53
parent69f0dc69a45889f58c5e13fabdd8c8eabfd604a1 (diff)
downloadrust-3252432c27c8ff14f52ce04fa08c6bb73ce40ebe.tar.gz
rust-3252432c27c8ff14f52ce04fa08c6bb73ce40ebe.zip
improve comments for unsized suggestions
-rw-r--r--compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs6
1 files changed, 5 insertions, 1 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 1ebdb8ac26c..648cd483bf6 100644
--- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs
+++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs
@@ -1811,6 +1811,8 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
             .iter()
             .filter(|param| param.span == span)
             .filter(|param| {
+                // Check that none of the explicit trait bounds is `Sized`. Assume that an explicit
+                // `Sized` bound is there intentionally and we don't need to suggest relaxing it.
                 param
                     .bounds
                     .iter()
@@ -1827,6 +1829,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
                 item
                 @
                 hir::Item {
+                    // Only suggest indirection for uses of type parameters in ADTs.
                     kind:
                         hir::ItemKind::Enum(..) | hir::ItemKind::Struct(..) | hir::ItemKind::Union(..),
                     ..
@@ -1838,6 +1841,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
             }
             _ => {}
         };
+        // Didn't add an indirection suggestion, so add a general suggestion to relax `Sized`.
         let (span, separator) = match param.bounds {
             [] => (span.shrink_to_hi(), ":"),
             [.., bound] => (bound.span().shrink_to_hi(), " +"),
@@ -1858,7 +1862,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
     ) -> bool {
         // Suggesting `T: ?Sized` is only valid in an ADT if `T` is only used in a
         // borrow. `struct S<'a, T: ?Sized>(&'a T);` is valid, `struct S<T: ?Sized>(T);`
-        // is not.
+        // is not. Look for invalid "bare" parameter uses, and suggest using indirection.
         let mut visitor =
             FindTypeParam { param: param.name.ident().name, invalid_spans: vec![], nested: false };
         visitor.visit_item(item);