@@ -1811,6 +1811,8 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
1811
1811
. iter ( )
1812
1812
. filter ( |param| param. span == span)
1813
1813
. 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.
1814
1816
param
1815
1817
. bounds
1816
1818
. iter ( )
@@ -1827,6 +1829,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
1827
1829
item
1828
1830
@
1829
1831
hir:: Item {
1832
+ // Only suggest indirection for uses of type parameters in ADTs.
1830
1833
kind :
1831
1834
hir:: ItemKind :: Enum ( ..) | hir:: ItemKind :: Struct ( ..) | hir:: ItemKind :: Union ( ..) ,
1832
1835
..
@@ -1838,6 +1841,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
1838
1841
}
1839
1842
_ => { }
1840
1843
} ;
1844
+ // Didn't add an indirection suggestion, so add a general suggestion to relax `Sized`.
1841
1845
let ( span, separator) = match param. bounds {
1842
1846
[ ] => ( span. shrink_to_hi ( ) , ":" ) ,
1843
1847
[ .., bound] => ( bound. span ( ) . shrink_to_hi ( ) , " +" ) ,
@@ -1858,7 +1862,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
1858
1862
) -> bool {
1859
1863
// Suggesting `T: ?Sized` is only valid in an ADT if `T` is only used in a
1860
1864
// 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.
1862
1866
let mut visitor =
1863
1867
FindTypeParam { param : param. name . ident ( ) . name , invalid_spans : vec ! [ ] , nested : false } ;
1864
1868
visitor. visit_item ( item) ;
0 commit comments