@@ -1856,26 +1856,43 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
18561856 ObligationCauseCode :: StructInitializerSized => {
18571857 err. note ( "structs must have a statically known size to be initialized" ) ;
18581858 }
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" ) ;
18701878 }
18711879 }
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+ }
18791896 ObligationCauseCode :: ConstSized => {
18801897 err. note ( "constant expressions must have a statically known size" ) ;
18811898 }
0 commit comments