@@ -1856,26 +1856,43 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
1856
1856
ObligationCauseCode :: StructInitializerSized => {
1857
1857
err. note ( "structs must have a statically known size to be initialized" ) ;
1858
1858
}
1859
- ObligationCauseCode :: FieldSized { adt_kind : ref item, last } => match * item {
1860
- AdtKind :: Struct => {
1861
- if last {
1862
- err. note (
1863
- "the last field of a packed struct may only have a \
1864
- dynamically sized type if it does not need drop to be run",
1865
- ) ;
1866
- } else {
1867
- err. note (
1868
- "only the last field of a struct may have a dynamically sized type" ,
1869
- ) ;
1859
+ ObligationCauseCode :: FieldSized { adt_kind : ref item, last, span } => {
1860
+ match * item {
1861
+ AdtKind :: Struct => {
1862
+ if last {
1863
+ err. note (
1864
+ "the last field of a packed struct may only have a \
1865
+ dynamically sized type if it does not need drop to be run",
1866
+ ) ;
1867
+ } else {
1868
+ err. note (
1869
+ "only the last field of a struct may have a dynamically sized type" ,
1870
+ ) ;
1871
+ }
1872
+ }
1873
+ AdtKind :: Union => {
1874
+ err. note ( "no field of a union may have a dynamically sized type" ) ;
1875
+ }
1876
+ AdtKind :: Enum => {
1877
+ err. note ( "no field of an enum variant may have a dynamically sized type" ) ;
1870
1878
}
1871
1879
}
1872
- AdtKind :: Union => {
1873
- err. note ( "no field of a union may have a dynamically sized type" ) ;
1874
- }
1875
- AdtKind :: Enum => {
1876
- err. note ( "no field of an enum variant may have a dynamically sized type" ) ;
1877
- }
1878
- } ,
1880
+ err. help ( "change the field's type to have a statically known size" ) ;
1881
+ err. span_suggestion (
1882
+ span. shrink_to_lo ( ) ,
1883
+ "borrowed types always have a statically known size" ,
1884
+ "&" . to_string ( ) ,
1885
+ Applicability :: MachineApplicable ,
1886
+ ) ;
1887
+ err. multipart_suggestion (
1888
+ "heap allocated types always have a statically known size" ,
1889
+ vec ! [
1890
+ ( span. shrink_to_lo( ) , "Box<" . to_string( ) ) ,
1891
+ ( span. shrink_to_hi( ) , ">" . to_string( ) ) ,
1892
+ ] ,
1893
+ Applicability :: MachineApplicable ,
1894
+ ) ;
1895
+ }
1879
1896
ObligationCauseCode :: ConstSized => {
1880
1897
err. note ( "constant expressions must have a statically known size" ) ;
1881
1898
}
0 commit comments