@@ -1803,51 +1803,51 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
1803
1803
Some ( generics) => generics,
1804
1804
None => return ,
1805
1805
} ;
1806
- debug ! ( "suggest_unsized_bound_if_applicable: generics.params={:?}" , generics. params) ;
1807
- debug ! (
1808
- "suggest_unsized_bound_if_applicable: generics.where_clause={:?}" ,
1809
- generics. where_clause
1810
- ) ;
1811
- for param in generics. params {
1812
- if param. span != span
1813
- || param. bounds . iter ( ) . any ( |bound| {
1814
- bound. trait_ref ( ) . and_then ( |trait_ref| trait_ref. trait_def_id ( ) )
1815
- == self . tcx . lang_items ( ) . sized_trait ( )
1816
- } )
1817
- {
1818
- continue ;
1819
- }
1820
- debug ! ( "maybe_suggest_unsized_generics: param={:?}" , param) ;
1821
- match node {
1822
- hir:: Node :: Item (
1823
- item
1824
- @
1825
- hir:: Item {
1826
- kind :
1827
- hir:: ItemKind :: Enum ( ..)
1828
- | hir:: ItemKind :: Struct ( ..)
1829
- | hir:: ItemKind :: Union ( ..) ,
1830
- ..
1831
- } ,
1832
- ) => {
1833
- if self . maybe_indirection_for_unsized ( err, item, param) {
1834
- return ;
1835
- }
1806
+ let sized_trait = self . tcx . lang_items ( ) . sized_trait ( ) ;
1807
+ debug ! ( "maybe_suggest_unsized_generics: generics.params={:?}" , generics. params) ;
1808
+ debug ! ( "maybe_suggest_unsized_generics: generics.where_clause={:?}" , generics. where_clause) ;
1809
+ let param = generics
1810
+ . params
1811
+ . iter ( )
1812
+ . filter ( |param| param. span == span)
1813
+ . filter ( |param| {
1814
+ param
1815
+ . bounds
1816
+ . iter ( )
1817
+ . all ( |bound| bound. trait_ref ( ) . and_then ( |tr| tr. trait_def_id ( ) ) != sized_trait)
1818
+ } )
1819
+ . next ( ) ;
1820
+ let param = match param {
1821
+ Some ( param) => param,
1822
+ _ => return ,
1823
+ } ;
1824
+ debug ! ( "maybe_suggest_unsized_generics: param={:?}" , param) ;
1825
+ match node {
1826
+ hir:: Node :: Item (
1827
+ item
1828
+ @
1829
+ hir:: Item {
1830
+ kind :
1831
+ hir:: ItemKind :: Enum ( ..) | hir:: ItemKind :: Struct ( ..) | hir:: ItemKind :: Union ( ..) ,
1832
+ ..
1833
+ } ,
1834
+ ) => {
1835
+ if self . maybe_indirection_for_unsized ( err, item, param) {
1836
+ return ;
1836
1837
}
1837
- _ => { }
1838
1838
}
1839
- let ( span , separator ) = match param . bounds {
1840
- [ ] => ( span . shrink_to_hi ( ) , ":" ) ,
1841
- [ .. , bound ] => ( bound . span ( ) . shrink_to_hi ( ) , " +" ) ,
1842
- } ;
1843
- err . span_suggestion_verbose (
1844
- span ,
1845
- "consider relaxing the implicit `Sized` restriction" ,
1846
- format ! ( "{} ?Sized" , separator ) ,
1847
- Applicability :: MachineApplicable ,
1848
- ) ;
1849
- return ;
1850
- }
1839
+ _ => { }
1840
+ } ;
1841
+ let ( span , separator ) = match param . bounds {
1842
+ [ ] => ( span . shrink_to_hi ( ) , ":" ) ,
1843
+ [ .. , bound ] => ( bound . span ( ) . shrink_to_hi ( ) , " +" ) ,
1844
+ } ;
1845
+ err . span_suggestion_verbose (
1846
+ span ,
1847
+ "consider relaxing the implicit `Sized` restriction" ,
1848
+ format ! ( "{} ?Sized" , separator ) ,
1849
+ Applicability :: MachineApplicable ,
1850
+ ) ;
1851
1851
}
1852
1852
1853
1853
fn maybe_indirection_for_unsized (
@@ -1862,29 +1862,29 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
1862
1862
let mut visitor =
1863
1863
FindTypeParam { param : param. name . ident ( ) . name , invalid_spans : vec ! [ ] , nested : false } ;
1864
1864
visitor. visit_item ( item) ;
1865
- if !visitor. invalid_spans . is_empty ( ) {
1866
- let mut multispan: MultiSpan = param. span . into ( ) ;
1865
+ if visitor. invalid_spans . is_empty ( ) {
1866
+ return false ;
1867
+ }
1868
+ let mut multispan: MultiSpan = param. span . into ( ) ;
1869
+ multispan. push_span_label (
1870
+ param. span ,
1871
+ format ! ( "this could be changed to `{}: ?Sized`..." , param. name. ident( ) ) ,
1872
+ ) ;
1873
+ for sp in visitor. invalid_spans {
1867
1874
multispan. push_span_label (
1868
- param . span ,
1869
- format ! ( "this could be changed to `{}: ?Sized`... " , param. name. ident( ) ) ,
1875
+ sp ,
1876
+ format ! ( "...if indirection were used here: `Box<{}>` " , param. name. ident( ) ) ,
1870
1877
) ;
1871
- for sp in visitor. invalid_spans {
1872
- multispan. push_span_label (
1873
- sp,
1874
- format ! ( "...if indirection were used here: `Box<{}>`" , param. name. ident( ) ) ,
1875
- ) ;
1876
- }
1877
- err. span_help (
1878
- multispan,
1879
- & format ! (
1880
- "you could relax the implicit `Sized` bound on `{T}` if it were \
1881
- used through indirection like `&{T}` or `Box<{T}>`",
1882
- T = param. name. ident( ) ,
1883
- ) ,
1884
- ) ;
1885
- return true ;
1886
1878
}
1887
- false
1879
+ err. span_help (
1880
+ multispan,
1881
+ & format ! (
1882
+ "you could relax the implicit `Sized` bound on `{T}` if it were \
1883
+ used through indirection like `&{T}` or `Box<{T}>`",
1884
+ T = param. name. ident( ) ,
1885
+ ) ,
1886
+ ) ;
1887
+ true
1888
1888
}
1889
1889
1890
1890
fn is_recursive_obligation (
0 commit comments