@@ -1811,6 +1811,8 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
18111811 . iter ( )
18121812 . filter ( |param| param. span == span)
18131813 . filter ( |param| {
1814+ // Check that none of the explicit trait bounds is `Sized`. Assume that an explicit
1815+ // `Sized` bound is there intentionally and we don't need to suggest relaxing it.
18141816 param
18151817 . bounds
18161818 . iter ( )
@@ -1827,6 +1829,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
18271829 item
18281830 @
18291831 hir:: Item {
1832+ // Only suggest indirection for uses of type parameters in ADTs.
18301833 kind :
18311834 hir:: ItemKind :: Enum ( ..) | hir:: ItemKind :: Struct ( ..) | hir:: ItemKind :: Union ( ..) ,
18321835 ..
@@ -1838,6 +1841,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
18381841 }
18391842 _ => { }
18401843 } ;
1844+ // Didn't add an indirection suggestion, so add a general suggestion to relax `Sized`.
18411845 let ( span, separator) = match param. bounds {
18421846 [ ] => ( span. shrink_to_hi ( ) , ":" ) ,
18431847 [ .., bound] => ( bound. span ( ) . shrink_to_hi ( ) , " +" ) ,
@@ -1858,7 +1862,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
18581862 ) -> bool {
18591863 // Suggesting `T: ?Sized` is only valid in an ADT if `T` is only used in a
18601864 // borrow. `struct S<'a, T: ?Sized>(&'a T);` is valid, `struct S<T: ?Sized>(T);`
1861- // is not.
1865+ // is not. Look for invalid "bare" parameter uses, and suggest using indirection.
18621866 let mut visitor =
18631867 FindTypeParam { param : param. name . ident ( ) . name , invalid_spans : vec ! [ ] , nested : false } ;
18641868 visitor. visit_item ( item) ;
0 commit comments