diff --git a/mapping.rs b/mapping.rs index b9bfb4b..4610e09 100644 --- a/mapping.rs +++ b/mapping.rs @@ -589,3 +589,349 @@ -Mapping("b75d1f0ce252f4b53f8a97aee0fcf4a785186fef","72e8009185b537083015f43a8e0fd34509ab1938") -Mapping("d6d711dd8f7ad5885294b8e1f0009a23dc1f8b1f","d52acbe37f69a2ebc9d161c479ed628da1cbea4e") -Mapping("8503b3ff822c1ed01c89773d30e4e10b886d77a5","02c1862fb55c6ae4198038b1b317bcdd06e395d1") +-Mapping("c08480fce0f39f5c9c6db6dde0dccb375ca0ab14","16da5d4bb2d65a4d533d1da2a4e0d288d3a474c5") +-Mapping("254f8796b729810846e2b97620032ecaf103db33","0ceeb1be31b52837e270a3349f9c62087ff11985") +-Mapping("06fa27d7c84a21af8449e06f3c50b243c4d5a7ad","e5277c1457d397f22ba18a1d40c1318729becbb4") +-Mapping("64f7de92166f1f7d940575feff57ac33bc384550","0ceeb1be31b52837e270a3349f9c62087ff11985") +-Mapping("874dec25ed4c08d36f17d396b6872ca50313fc8e","c12a75742485dcc3db7b0f374e78f090c323830d") +-Mapping("fb44b4c0eb1d344f84f7bb2c90f28e31a8a180be","e5277c1457d397f22ba18a1d40c1318729becbb4") +-Mapping("521d91c6be76367d966df419677dd187f799b116","cb56b2d1522e83c5bb0613abcf78b686e994df9e") +-Mapping("d8a0dd7ae88023bd09fa4b86c9ca1f6ed8095b43","ebbecac538137fca1c36ceca91337b5ff4d196b5") +-Mapping("e94df4acb4c3f42fdc224a7164b63a99240add1e","4f1e2357447ef7e8066c49560d66c3e18f25d982") +-Mapping("73c78734bae8f2947a4bfdeabebeeb84ccf0b0e1","b5ed39ff10f0e46be6e97b577477e0f60234fa0b") +-Mapping("e2f221c75932de7a29845c8d6f1f73536ad00c41","ebbecac538137fca1c36ceca91337b5ff4d196b5") +-Mapping("daa53a52a2667533d5fe59bfcc5b8614b79c3d31","ebbecac538137fca1c36ceca91337b5ff4d196b5") +-Mapping("c2d381d39d282c0586d50ea7d7a431ffd5ddb3fb","d60fa1d3c21e00bedc0dd94dc2df7e5183c14c48") +-Mapping("a2ec156a5b5d58f2a73bf21b1fe037b6ac1cf5cc","27c8dfddac4c69a6fd399abe537e1007306c58cf") +-Mapping("02cb8f2a4f078025abe6ddba3cff81b383a23973","71120ef1e5cb885ee45e6148970db6ce93ce1aca") +-Mapping("5597ee8a6483238421750fce4eb7031b12852428","5285d35b49e1e8976f2a8d9d2e6f5bd1324016d3") +-Mapping("20c2cba61dc83e612d25ed496025171caa3db30f","ebbecac538137fca1c36ceca91337b5ff4d196b5") +-Mapping("b139669f374eb5024a50eb13f116ff763b1c5935","ebbecac538137fca1c36ceca91337b5ff4d196b5") +-Mapping("0c0c585281740aba4c91cbfd385f5e1fbe313d11","ebbecac538137fca1c36ceca91337b5ff4d196b5") +-Mapping("2bd5993ca25e09b894e4fd6539a2fba64599eee2","5285d35b49e1e8976f2a8d9d2e6f5bd1324016d3") +-Mapping("637ac17c5292ce723430de0e87b92271989e1436","e5277c1457d397f22ba18a1d40c1318729becbb4") +-Mapping("6a1c0637ce44aeea6c60527f4c0e7fb33f2bcd0d","c12a75742485dcc3db7b0f374e78f090c323830d") +-Mapping("934902af61d8024ddd7db290b33a7076dad7b107","e5277c1457d397f22ba18a1d40c1318729becbb4") +-Mapping("f5631d9ac7745dd6eaea2bc6c236d5f8e54e9a18","16da5d4bb2d65a4d533d1da2a4e0d288d3a474c5") +-Mapping("de3d640f59c4fa4a09faf2a8d6b0a812aaa6d6cb","5285d35b49e1e8976f2a8d9d2e6f5bd1324016d3") +-Mapping("7bac68a5d36d18f6ddcf4a3e3bd9f276bb2d18e5","ebbecac538137fca1c36ceca91337b5ff4d196b5") +-Mapping("4b1e39b7b36d677803e40130ea29ee6d300abf6e","ebbecac538137fca1c36ceca91337b5ff4d196b5") +-Mapping("f8d34596ff74da91e0877212a9979cb9ca13eb7e","71120ef1e5cb885ee45e6148970db6ce93ce1aca") +-Mapping("c76f3c374f80e20b612601a3c375666a58ac3971","ebbecac538137fca1c36ceca91337b5ff4d196b5") +-Mapping("f29b4fbd742b8180edb5e06cad0977b08881541b","ebbecac538137fca1c36ceca91337b5ff4d196b5") +-Mapping("bf669d1e3295bc688f71b8c91f48a6beaf895f67","ebbecac538137fca1c36ceca91337b5ff4d196b5") +-Mapping("8c4ad4e9e42f4bcbdbb784692b936c2462061abc","5285d35b49e1e8976f2a8d9d2e6f5bd1324016d3") +-Mapping("d1731801163df1d3a8d4ddfa68adac2ec833ef7f","27c8dfddac4c69a6fd399abe537e1007306c58cf") +-Mapping("6ecad338381cc3b8d56e2df22e5971a598eddd6c","d60fa1d3c21e00bedc0dd94dc2df7e5183c14c48") +-Mapping("da6ab956e1002517803ecd38b904504a1223274b","ebbecac538137fca1c36ceca91337b5ff4d196b5") +-Mapping("ceb2512144d1fc26330e85fb9d41c22ba1866259","ebbecac538137fca1c36ceca91337b5ff4d196b5") +-Mapping("e82261dfbb5feaa2d28d2b138f4aabb2aa52c94b","7cbeddb7b78cc54a52d63ed8556da7121d1d2e68") +-Mapping("cbc4c8380fb92a719ae9be40f9da44ca7e3e2f3f","0b9c686b479ce337581ba9773481ada8dd8f91d6") +-Mapping("8a37c75a3a661385cc607d934c70e86a9eaf5fd7","7cbeddb7b78cc54a52d63ed8556da7121d1d2e68") +-Mapping("60efbdead6b65d7fd8ebfd564c86de4594ef0076","0b9c686b479ce337581ba9773481ada8dd8f91d6") +-Mapping("1d4dbf488a4364413e7b9611866b7a5c75ce566f","7cbeddb7b78cc54a52d63ed8556da7121d1d2e68") +-Mapping("451987d86c89b38ddd8c4c124f1b9b6d4ded6983","b9adc3327ec7d2820ab2db8bb3cc2a0196a8375d") +-Mapping("5205ae8bdc2991eecf3bfbb58ed8f56c0673e738","7cbeddb7b78cc54a52d63ed8556da7121d1d2e68") +-Mapping("0198a1ea45e29af00d92423aa6d2ac876410c3f9","06da917b015a2eceac0e3cca22f9660edef25178") +-Mapping("f960f377fde2a01f64ec6f747725ce41147f46de","14ebca5c1986b55c39b5711c0cb33850afdc0a0c") +-Mapping("f22dca0a1bef4141e75326caacc3cd59f3d5be8e","f22dca0a1bef4141e75326caacc3cd59f3d5be8e") +-Mapping("96d700f1b7bc9c53fa0d11567adb1ed2c1c27e79","379c380a60e7b3adb6c6f595222cbfa2d9160a20") +-Mapping("e40548bc43f2a0375a466c98e174e71561dc98d2","cf9fd6074da321b353a755359fac10cd28ed251d") +-Mapping("2975a3c4befa8ad610da2e3c5f5de351d6d70a2b","271eb8fc5a420280937bb1745f1e7aee7901ad26") +-Mapping("350674b7180a41c8e508d93c6ab8e203b69d3df7","93b6d9e086c6910118a57e4332c9448ab550931f") +-Mapping("e6c5cf923489f4aed6c9e36a170fab9b6179d8da","b9adc3327ec7d2820ab2db8bb3cc2a0196a8375d") +-Mapping("a8c11d216b04abe21a03220b344f1415e1d6ebd1","472ca7159812f8c360697f63454ee7bda1e02570") +-Mapping("88f755f8a84df1d9e6b17cf10c96ae8b93481b2e","f22dca0a1bef4141e75326caacc3cd59f3d5be8e") +-Mapping("8aaae4294b16b8070a52b858364f440873bfc95c","271eb8fc5a420280937bb1745f1e7aee7901ad26") +-Mapping("f4a421ee3cf1259f0750ac7fabd19da1d8551e4c","ee89c088b057affb5bdb96195e107a218b64b1c5") +-Mapping("3c3d3c1777041200bb7ed7a65b6562d62899778c","271eb8fc5a420280937bb1745f1e7aee7901ad26") +-Mapping("e782d790f1b63d82af39248bebe027f92d891bcc","8dbae794b0683668d1b46d2c319ab36dcd9bd96d") +-Mapping("597f432489f12a3f33419daa039ccef11a12c4fd","271eb8fc5a420280937bb1745f1e7aee7901ad26") +-Mapping("b907d966528a6859ec847a2a4d32f092a5be6584","7cbeddb7b78cc54a52d63ed8556da7121d1d2e68") +-Mapping("b68432d560c7c6f1e738b27e49d271a2a778f898","7cbeddb7b78cc54a52d63ed8556da7121d1d2e68") +-Mapping("01cc982e936120acb0424e41de14e42ba2d88c6f","0b9c686b479ce337581ba9773481ada8dd8f91d6") +-Mapping("662c70a59f79919640465b8753f790af822e96c8","0b9c686b479ce337581ba9773481ada8dd8f91d6") +-Mapping("91db9dcf3730207f63b3dfc33b2c438a769b7517","7cbeddb7b78cc54a52d63ed8556da7121d1d2e68") +-Mapping("aaa170bebe31d03e2eea14e8cb06dc2e8891216b","71120ef1e5cb885ee45e6148970db6ce93ce1aca") +-Mapping("5d20ff4d2718c820632b38c1e49d4de648a9810b","271eb8fc5a420280937bb1745f1e7aee7901ad26") +-Mapping("3991285f55a4b7cd92b7ffcdc396a3023076f5cb","271eb8fc5a420280937bb1745f1e7aee7901ad26") +-Mapping("befeeb7c083c9e5edddc86563cc461185d897a13","b6fb3e34117008f7f97094b0f1521116a4e66473") +-Mapping("2a65cbeea78c2c79b1030a0012cdea475104a44f","f22dca0a1bef4141e75326caacc3cd59f3d5be8e") +-Mapping("6e0f1cc1587676b58cfff06bf3a10ea7fba7086e","472ca7159812f8c360697f63454ee7bda1e02570") +-Mapping("33fe1131cadba69d317156847be9a402b89f11bb","271eb8fc5a420280937bb1745f1e7aee7901ad26") +-Mapping("96d1334e567237b1507cd277938e7ae2de75ff51","27c3631d826aaad964f42ee94f26f9e80d658e3f") +-Mapping("bb0896af11bb6b79051d4b794c70f78cd45d080f","5285d35b49e1e8976f2a8d9d2e6f5bd1324016d3") +-Mapping("04fdb44f5ccb6f909cf0f768781afa483e97097c","b9adc3327ec7d2820ab2db8bb3cc2a0196a8375d") +-Mapping("2d3e909e4e68259e15ca2908ff9e854f0a68bbec","cf9fd6074da321b353a755359fac10cd28ed251d") +-Mapping("70f130954d6fd36fe3e77f4b5b33e5af50489288","271eb8fc5a420280937bb1745f1e7aee7901ad26") +-Mapping("fc81e36242ddddb7149a0d1ca44ebce7fb9eef8a","654c5788aa2130acfc89a0883952c6de4bddac95") +-Mapping("ddab10a692aab2e2984b5c826ed9d78a57e94851","14ebca5c1986b55c39b5711c0cb33850afdc0a0c") +-Mapping("8b096314a6381e28834ddb1e662ce90e5b32736b","b9adc3327ec7d2820ab2db8bb3cc2a0196a8375d") +-Mapping("14997d56a550f4aa99fe737593cd2758227afc56","1ed91951c3012e9aabb403d28b902c56cc143907") +-Mapping("0576ac109b1ee40cc3201ac3c9ed58339487140e","c97d3d4dd174e8a80e9d0e55ea6f9a73aca60bf2") +-Mapping("2ab3eba30741652ba538bc2fc2bba9d81a5c84c6","3c9e884dd3bf93b1516d3b5858072b7659c4cfba") +-Mapping("f1e2fa8f0469aac1ea69dd5b6164e1d198d57934","b20bba4f3777fd097539e1f516987e0d9729d710") +-Mapping("6acbb5b65c06d82c867a94c54ce51dab4707ac61","b20bba4f3777fd097539e1f516987e0d9729d710") +-Mapping("94fd0458951a4ff91c03366445f0e2e93b86bd2f","89573b3c8b629507130b1ec8beeaf550fdc0e046") +-Mapping("d09466ceb1374bd0ff1c490bfd50133b8ca67558","1ed91951c3012e9aabb403d28b902c56cc143907") +-Mapping("13c9439925797cd7a65c917d047c07a500d9bfe6","b20bba4f3777fd097539e1f516987e0d9729d710") +-Mapping("36a50c29f6c5c386fba6ab685818755ac55152e5","eca11b99a7d25e4e6573472a16537c1aacb5d5e1") +-Mapping("2f1547c0aa5957b42cc768c00119c6eb7b4262d3","06da917b015a2eceac0e3cca22f9660edef25178") +-Mapping("428943cc290e64187e0698f41853ef316c0a7d03","379c380a60e7b3adb6c6f595222cbfa2d9160a20") +-Mapping("719b0d9849dab698c1ff0630313d068c7d561eae","e1b8898cfb0392f534cc25808a7f6caad36ebbb7") +-Mapping("4a45578bc58ff262864f72680cc02e83f5d2f5b3","fc84f5f837a3e1b9b9bc992dd603d3d968502288") +-Mapping("f49f6e73a8a2dd6ec9f86df9922ccfa2210d9eda","3c9e884dd3bf93b1516d3b5858072b7659c4cfba") +-Mapping("7c19e1eed5418b8c02be65d678417b241ee01a3e","e1b8898cfb0392f534cc25808a7f6caad36ebbb7") +-Mapping("f8673e0ad85e98997faa76fa7edc99c5825f46ee","379c380a60e7b3adb6c6f595222cbfa2d9160a20") +-Mapping("59183180f718fc2212828e180f2f856f0db1bb9c","2a663555ddf36f6b041445894a8c175cd1bc718c") +-Mapping("4591a245c7eec9f70d668982b1383cd2a6854af5","3c9e884dd3bf93b1516d3b5858072b7659c4cfba") +-Mapping("400c2bc5ed292f77c49693320f4eda37bb375e90","b20bba4f3777fd097539e1f516987e0d9729d710") +-Mapping("a3085756edf66459109c4b07948b08fe3e78bc3b","7cbeddb7b78cc54a52d63ed8556da7121d1d2e68") +-Mapping("5bf68db6ecda0dd4788311a41b5c763d35597c96","7cbeddb7b78cc54a52d63ed8556da7121d1d2e68") +-Mapping("f0fdaba04ea7474cd1f66264ef4edb3485a95864","7cbeddb7b78cc54a52d63ed8556da7121d1d2e68") +-Mapping("8afb89493179e52b61a4f8b9c45de1dd7e9d1f3a","7cbeddb7b78cc54a52d63ed8556da7121d1d2e68") +-Mapping("acd3871ba17316419c644e17547887787628ec2f","7cbeddb7b78cc54a52d63ed8556da7121d1d2e68") +-Mapping("6b9b97bd9b704f85f0184f7a213cc4d62bd9654c","b20bba4f3777fd097539e1f516987e0d9729d710") +-Mapping("a2b0f247bf741a1a9729363dda8628a938f1fe58","2a663555ddf36f6b041445894a8c175cd1bc718c") +-Mapping("e68bf8ae15ee6c052d0bcc9252386c5c5ee86de2","e1b8898cfb0392f534cc25808a7f6caad36ebbb7") +-Mapping("53f2165c544cceeafb308b80ace656ed328c1dc2","379c380a60e7b3adb6c6f595222cbfa2d9160a20") +-Mapping("b68fc18c45350e1cdcd83cecf0f12e294e55af56","b20bba4f3777fd097539e1f516987e0d9729d710") +-Mapping("63c75d375d76d0bcc586f9cb5520ced24bc58450","3c9e884dd3bf93b1516d3b5858072b7659c4cfba") +-Mapping("bc44841ad2a2ad5f6c5e67b9e35ed8e7e71d4dc7","e1b8898cfb0392f534cc25808a7f6caad36ebbb7") +-Mapping("f694222887cf31f51e68927716c25736e62f037f","379c380a60e7b3adb6c6f595222cbfa2d9160a20") +-Mapping("6e9b84296223126a0a59bde63a0f97011bb7b0f5","eca11b99a7d25e4e6573472a16537c1aacb5d5e1") +-Mapping("cb2f34dc6d7e83d8bcfef79e0388d49f0c24aca7","89573b3c8b629507130b1ec8beeaf550fdc0e046") +-Mapping("5c875d93855c6d577962b0f74f17374f37b219c9","3c9e884dd3bf93b1516d3b5858072b7659c4cfba") +-Mapping("6bfb46e4ac9a2704f06de1a2ff7a4612cd70c8cb","b20bba4f3777fd097539e1f516987e0d9729d710") +-Mapping("f2302daef3608c09e2b50193a64611b18ced86f3","3c9e884dd3bf93b1516d3b5858072b7659c4cfba") +-Mapping("f37247f885026d29bf26fd4aed6e9135e4f32ebf","b20bba4f3777fd097539e1f516987e0d9729d710") +-Mapping("5aff30734b0e1056b1003459fbb27af199f51822","b20bba4f3777fd097539e1f516987e0d9729d710") +-Mapping("0633c55d2030969d91b57142b8582c53101e6339","c97d3d4dd174e8a80e9d0e55ea6f9a73aca60bf2") +-Mapping("90d36fb5905bbe5004f5b465ea14b53d10dae260","3c9e884dd3bf93b1516d3b5858072b7659c4cfba") +-Mapping("e5f80f2a4f016bf724a1cfb580619d71c8fd39ec","7cbeddb7b78cc54a52d63ed8556da7121d1d2e68") +-Mapping("2f2a11dfc436fc0f401b595f22ed043c46dbebe7","7cbeddb7b78cc54a52d63ed8556da7121d1d2e68") +-Mapping("4a9c58c6bd0e609538053a35685e206f66019820","7cbeddb7b78cc54a52d63ed8556da7121d1d2e68") +-Mapping("a1d4a9503e236b9f49cbdb23d00893201c117b2a","7cbeddb7b78cc54a52d63ed8556da7121d1d2e68") +-Mapping("952f344cdc0bca58d9f6c54dcfbae0890246e886","7cbeddb7b78cc54a52d63ed8556da7121d1d2e68") +-Mapping("990d8aa743b1dda3cc0f68fe09524486261812c6","7cbeddb7b78cc54a52d63ed8556da7121d1d2e68") +-Mapping("1ffb321477d85fb3c95a0be2a0cd89c04dff0d8d","7cbeddb7b78cc54a52d63ed8556da7121d1d2e68") +-Mapping("46880f41b7aeb897b8245474196bba9dc11f0e88","b9adc3327ec7d2820ab2db8bb3cc2a0196a8375d") +-Mapping("57d7cfc3cf50f0c427ad3043ff09eaef20671320","27c8dfddac4c69a6fd399abe537e1007306c58cf") +-Mapping("96064eb61dc703c289fae61bdf90593d3e7b2449","b9adc3327ec7d2820ab2db8bb3cc2a0196a8375d") +-Mapping("f47ec2ad5b6887b3d400aee49e2294bd27733d18","99ed06eb8864e704c4a1871ccda4648273bee4ef") +-Mapping("5af0bb83044c3fb43d59ad5f49ee5ae1a293901f","b9adc3327ec7d2820ab2db8bb3cc2a0196a8375d") +-Mapping("d41f21f11a249ad78990eb9a1ec899ec123c7136","71120ef1e5cb885ee45e6148970db6ce93ce1aca") +-Mapping("e1c6d00574494499f63c1e460ef886768643e7db","e3a8f7db479ce6562bfc312f412b65dc4f3c77d5") +-Mapping("3e6f30ec3e6bda159063fcd126dcb14725fef92d","b9adc3327ec7d2820ab2db8bb3cc2a0196a8375d") +-Mapping("c0bbc3927e28c22edefe6a1353b5ecc95ea9a104","2a663555ddf36f6b041445894a8c175cd1bc718c") +-Mapping("1dceaddfbe163e2d916c904b98923342730ba970","b9adc3327ec7d2820ab2db8bb3cc2a0196a8375d") +-Mapping("ec194646fef1a467073ad74b8b68f6f202cfce97","2a663555ddf36f6b041445894a8c175cd1bc718c") +-Mapping("78ff609d7375ee2a2c6d0222776ac612eb1b75be","b9adc3327ec7d2820ab2db8bb3cc2a0196a8375d") +-Mapping("aadbc459bd97a0325897e2ff94999efbec6a499c","e3a8f7db479ce6562bfc312f412b65dc4f3c77d5") +-Mapping("d5a448b3f47b22c9cb010198bdcc49d4392b090b","31bec788f46c73ab14c72868dc6141141320a058") +-Mapping("4b9b70c394e7f341b4016fce4cbf763d404b26f9","93ad4f2b9c093f204dbd5278c70256f6ec369b32") +-Mapping("9fd3d7899a444fe110ae9277542b306844ecf0c4","0ceeb1be31b52837e270a3349f9c62087ff11985") +-Mapping("686d0ae137b1d66711694903607750ad54f60f69","7cbeddb7b78cc54a52d63ed8556da7121d1d2e68") +-Mapping("866a713258915e6cbb212d135f751a6a8c9e1c0a","4f1e2357447ef7e8066c49560d66c3e18f25d982") +-Mapping("ac3c2288f9f9d977acb46406ba60033d65165a7b","210a2a2b9e5f7bc105897654bfea0f9cc7c8d89f") +-Mapping("80785a547d29519dbdb5781437ec318fb210b980","e5277c1457d397f22ba18a1d40c1318729becbb4") +-Mapping("097c04cf433048585dd9e3f63b30e03cc3509e4b","e3a8f7db479ce6562bfc312f412b65dc4f3c77d5") +-Mapping("b2b7a063af39455d7362524da3123c34c3f4842e","2a663555ddf36f6b041445894a8c175cd1bc718c") +-Mapping("155510e377ae2a8d8ee0dad1a5f809c9062a5526","b9adc3327ec7d2820ab2db8bb3cc2a0196a8375d") +-Mapping("67390c0c312ca2d8649ee7aa1e4bfa823f273857","31bec788f46c73ab14c72868dc6141141320a058") +-Mapping("f381a962550436f74dd6e9021e4df2fdefb96cfa","2a663555ddf36f6b041445894a8c175cd1bc718c") +-Mapping("4bd4e4130ed531a644263db26bf8461704215c77","b9adc3327ec7d2820ab2db8bb3cc2a0196a8375d") +-Mapping("633d75ac17fa1a1bdaf5923895e6d5b7f3040c92","e3a8f7db479ce6562bfc312f412b65dc4f3c77d5") +-Mapping("e7f5d48059aa14cc2808473564deadd72d1e818d","b9adc3327ec7d2820ab2db8bb3cc2a0196a8375d") +-Mapping("96cafc53cfc6667a03c8e77d8e0a2fc96555ff6b","b9adc3327ec7d2820ab2db8bb3cc2a0196a8375d") +-Mapping("e54494727855cd14229f5d456591ed2a2f027c46","99ed06eb8864e704c4a1871ccda4648273bee4ef") +-Mapping("63d66494aff57411bfec1dd2a3a5f1af900feab6","71120ef1e5cb885ee45e6148970db6ce93ce1aca") +-Mapping("b244f61b77c42d7be695afd7901ee4418559e518","99ed06eb8864e704c4a1871ccda4648273bee4ef") +-Mapping("bef62ccddb911b9cd7677717a69348a62cf61f96","b9adc3327ec7d2820ab2db8bb3cc2a0196a8375d") +-Mapping("cae6efc37d70ab7d353e6ab9ce229d59a65ed643","b9adc3327ec7d2820ab2db8bb3cc2a0196a8375d") +-Mapping("65d201f7d682ad921ac6e67ac07f922aa63a8ce4","210a2a2b9e5f7bc105897654bfea0f9cc7c8d89f") +-Mapping("7f3444e1baf0d335b4bf379f845dbc28cdd0509c","7cbeddb7b78cc54a52d63ed8556da7121d1d2e68") +-Mapping("ae544ee1c90afc0f939753014dc5e884cb2749a0","e5277c1457d397f22ba18a1d40c1318729becbb4") +-Mapping("e06c875442e91cc2c597135d1e807a69e73eee26","0ceeb1be31b52837e270a3349f9c62087ff11985") +-Mapping("66363b288141ed2af4b95fb4205a56dce6248363","7cbeddb7b78cc54a52d63ed8556da7121d1d2e68") +-Mapping("7360d6dd678d186d9c9b46311b75ba6840e61aa2","210a2a2b9e5f7bc105897654bfea0f9cc7c8d89f") +-Mapping("54628c8ea844956f3f4f416b82067c634eb09f7b","4f1e2357447ef7e8066c49560d66c3e18f25d982") +-Mapping("960f6046c6d367a48f405dd5c76cc303497edfc5","0ceeb1be31b52837e270a3349f9c62087ff11985") +-Mapping("0b72d48f8e5f3c7cabcf6fcd31474209bff0ab59","93ad4f2b9c093f204dbd5278c70256f6ec369b32") +-Mapping("1cf82fd9c0e8eb9ff29d4165f9824c483bd72f7d","b9adc3327ec7d2820ab2db8bb3cc2a0196a8375d") +-Mapping("b43986184b8f4e0d633e8ae1704f0e19aec30cb2","d60fa1d3c21e00bedc0dd94dc2df7e5183c14c48") +-Mapping("97085f9fb0736b322dc216db3655da780b4d8041","b5ed39ff10f0e46be6e97b577477e0f60234fa0b") +-Mapping("423d8109868c1f926f2cfcc3bff980c3daa515fd","b9adc3327ec7d2820ab2db8bb3cc2a0196a8375d") +-Mapping("03acbd71c977cd63ce5f39ba9b6fe9ffd578785a","ebbecac538137fca1c36ceca91337b5ff4d196b5") +-Mapping("f6fac4225f4ea4881e9146f0a14f2cd36b8ac22f","ebbecac538137fca1c36ceca91337b5ff4d196b5") +-Mapping("4c2be9c97fb60a01c545b8e8fa61e4247ae5c9b2","ebbecac538137fca1c36ceca91337b5ff4d196b5") +-Mapping("8a57831a4b7dfa960110599748f3b7382ae28237","ebbecac538137fca1c36ceca91337b5ff4d196b5") +-Mapping("4efdc04a5d687fce7a63ca339e5c74d8c51e40d2","5285d35b49e1e8976f2a8d9d2e6f5bd1324016d3") +-Mapping("19f8958f827e379be9b0ffc93fca580ec8ffac77","ebbecac538137fca1c36ceca91337b5ff4d196b5") +-Mapping("a04b88d1941644df01fa5e31dd43e0f57c13d938","cb56b2d1522e83c5bb0613abcf78b686e994df9e") +-Mapping("9bd8458c92f7166b827e4eb5cf5effba8c0e615d","0ceeb1be31b52837e270a3349f9c62087ff11985") +-Mapping("056f589fb8bcd70e7caa2bc7b3ede45624bb8e6d","93ad4f2b9c093f204dbd5278c70256f6ec369b32") +-Mapping("1ecf6929dc3b309cdfcb7239260777dab38242b9","0ceeb1be31b52837e270a3349f9c62087ff11985") +-Mapping("79252ff4e25d82f9fe856cb66f127b79cdace163","7cbeddb7b78cc54a52d63ed8556da7121d1d2e68") +-Mapping("188e693b392116c46f746e86f8521f9621fcfd43","16da5d4bb2d65a4d533d1da2a4e0d288d3a474c5") +-Mapping("adf2135adc4a65a78ba053f04c29d7fe0468eb87","cb56b2d1522e83c5bb0613abcf78b686e994df9e") +-Mapping("48fa6f9631868b07309b02f479e2ec523bb58c2b","93ad4f2b9c093f204dbd5278c70256f6ec369b32") +-Mapping("39264539448e7ec5e98067859db71685393a4464","cb56b2d1522e83c5bb0613abcf78b686e994df9e") +-Mapping("517f24025a04e09936a6d07dc5298ca2b9371329","e5277c1457d397f22ba18a1d40c1318729becbb4") +-Mapping("12ed235adc62e63b16bb4f715b143c37a5efa00d","0ceeb1be31b52837e270a3349f9c62087ff11985") +-Mapping("852701ad6df90f4e4cdb11d487373f026f38e5b3","ebbecac538137fca1c36ceca91337b5ff4d196b5") +-Mapping("fddcd316af98583ebebfc40f6a25bec3f4e5fccc","5285d35b49e1e8976f2a8d9d2e6f5bd1324016d3") +-Mapping("01f8e25b15f4ab157c8e7c9c56054df7595ec0e1","ebbecac538137fca1c36ceca91337b5ff4d196b5") +-Mapping("7164a9f151a56316a382d8bc2b15ccf373e129ca","ebbecac538137fca1c36ceca91337b5ff4d196b5") +-Mapping("fc403ad9873ba80765f5a22bae16055c2d95e200","5285d35b49e1e8976f2a8d9d2e6f5bd1324016d3") +-Mapping("8ae730a442cc8af6a487a137ae9ba78f89edbba6","ebbecac538137fca1c36ceca91337b5ff4d196b5") +-Mapping("b2d6ea98b0db53889c5427e5a23cddb3bcb63040","5285d35b49e1e8976f2a8d9d2e6f5bd1324016d3") +-Mapping("7e8ca9f8bd8325398e76bc30ac09aab138bbb127","b5ed39ff10f0e46be6e97b577477e0f60234fa0b") +-Mapping("2fadb0a16c8737a45746e95df9138912590ed8ad","ebbecac538137fca1c36ceca91337b5ff4d196b5") +-Mapping("3edb355b75a2c8315da5942f6a4d40c5d9b5ccbf","b5ed39ff10f0e46be6e97b577477e0f60234fa0b") +-Mapping("75a369c5b11459baa6bf7734eeb6135998a0a7de","ebbecac538137fca1c36ceca91337b5ff4d196b5") +-Mapping("d586d5d2f51489821b471f20959333558c24b129","b9adc3327ec7d2820ab2db8bb3cc2a0196a8375d") +-Mapping("55c984ee5db73db2379024951457d1139db57f24","cb56b2d1522e83c5bb0613abcf78b686e994df9e") +-Mapping("9c9424de51da41fd3d1077ac7810276f8dc746fa","837d6c70233715a0ae8e15c703d40e3046a2f36a") +-Mapping("4f3c7a472b77ba3f3afbc12d004b9d1bbcee7fe7","0ceeb1be31b52837e270a3349f9c62087ff11985") +-Mapping("eeea94c11d02ff62fb011d1afdda9301fdf9726b","93ad4f2b9c093f204dbd5278c70256f6ec369b32") +-Mapping("482a913fb337855072a53c0d602cd19947f45285","16da5d4bb2d65a4d533d1da2a4e0d288d3a474c5") +-Mapping("5508b27145cfb82896ae838e6aca0cd48750796f","cb56b2d1522e83c5bb0613abcf78b686e994df9e") +-Mapping("31f1bc7b40469b9319f1ba610ad8760ebd11c3da","0ceeb1be31b52837e270a3349f9c62087ff11985") +-Mapping("e5f6498d3d5c9dac841009d7b49738923826af75","0ceeb1be31b52837e270a3349f9c62087ff11985") +-Mapping("75af15ee6ca0c12b699a17984b033363cd25e9c3","16da5d4bb2d65a4d533d1da2a4e0d288d3a474c5") +-Mapping("09d6ab90e556bf692ff3f8790d97b3ca4fee94b0","cf9fd6074da321b353a755359fac10cd28ed251d") +-Mapping("c1d2d83ca3b5155468ab96b09a7c54568449b137","93b6d9e086c6910118a57e4332c9448ab550931f") +-Mapping("aa99abeb262307d5e9aa11a792312fd620b7f89a","271eb8fc5a420280937bb1745f1e7aee7901ad26") +-Mapping("13dab66a6f6403f4eee092456f7f8f46199c5859","b9adc3327ec7d2820ab2db8bb3cc2a0196a8375d") +-Mapping("d99a320cba42f661aebfa1293b7b2ec3603dda75","27c3631d826aaad964f42ee94f26f9e80d658e3f") +-Mapping("de9666f123e800d5fc34210f23127aa6a5d6e4ef","b9adc3327ec7d2820ab2db8bb3cc2a0196a8375d") +-Mapping("3de0106789468b211bcc3a25c09c0cf07119186d","379c380a60e7b3adb6c6f595222cbfa2d9160a20") +-Mapping("14b96659e4e9b2f31431df48f47c219957e2666a","14ebca5c1986b55c39b5711c0cb33850afdc0a0c") +-Mapping("a9da8fc9c267c08cfdb8cf5b39da14f154d12939","c0e8cf94103289c424c62ca48e1e3f56e352a84a") +-Mapping("25a42b2ceb46887e9941cec667eac99844dd7ad0","eca11b99a7d25e4e6573472a16537c1aacb5d5e1") +-Mapping("9395f0af789dc007e23dbae5d961c0751ab2dbe7","472ca7159812f8c360697f63454ee7bda1e02570") +-Mapping("e938c2b9aae7e0c37c382e4e22bdc360e9a4f0b6","271eb8fc5a420280937bb1745f1e7aee7901ad26") +-Mapping("0f063aef62cc5c02c4ba1edbf83b82f16853594c","472ca7159812f8c360697f63454ee7bda1e02570") +-Mapping("fb86d604bf65c3becd16180b56267a329cf268d5","2a663555ddf36f6b041445894a8c175cd1bc718c") +-Mapping("a8a2a887d0a65fff6c777f9bcd7b1c0bdfbbddc0","27c3631d826aaad964f42ee94f26f9e80d658e3f") +-Mapping("3e90a12a8a95933604a8b609197fce61bb24a38c","1ed91951c3012e9aabb403d28b902c56cc143907") +-Mapping("6d599337fa7047307ba72786bbabe6b9c9e4daac","271eb8fc5a420280937bb1745f1e7aee7901ad26") +-Mapping("84804c3874a15f55a905c0b53d820372003b0c24","0b9c686b479ce337581ba9773481ada8dd8f91d6") +-Mapping("86a8f1a6374dd558ebdafe061e61720a73ae732c","b81da278623d9dcda1776008612bd42e1922e9c3") +-Mapping("428ea5f6b9e7c6e5ee3294fe9f105e77e89ab407","7cbeddb7b78cc54a52d63ed8556da7121d1d2e68") +-Mapping("f28c7aef7fbff1909c2d0257186cd7a5f0c6aa4b","b81da278623d9dcda1776008612bd42e1922e9c3") +-Mapping("5d0631a6438cf30cac236b7176371663e35c8d07","7cbeddb7b78cc54a52d63ed8556da7121d1d2e68") +-Mapping("967c1f3be1c9ce0469ae9e30659bdf4da5346a9f","7cbeddb7b78cc54a52d63ed8556da7121d1d2e68") +-Mapping("e3bf634e060bc2f8665878288bcea02008ca346e","0b9c686b479ce337581ba9773481ada8dd8f91d6") +-Mapping("a805a2a5ebba2802f432d79874e59c24e398f82a","7cbeddb7b78cc54a52d63ed8556da7121d1d2e68") +-Mapping("8ff4b42064b374bb62043f7729f84b6d979c7667","7cbeddb7b78cc54a52d63ed8556da7121d1d2e68") +-Mapping("1c2e17f4e3a2070a7f703f51e29c1c388ef703b6","472ca7159812f8c360697f63454ee7bda1e02570") +-Mapping("60e825389db3cb7421afb7015b28cb9436c79bba","2a663555ddf36f6b041445894a8c175cd1bc718c") +-Mapping("93c2f055ba443385b7c97b1b81fb179db5c9e065","27c3631d826aaad964f42ee94f26f9e80d658e3f") +-Mapping("31a75a172859d906d8e6a34af4afff9830af495c","271eb8fc5a420280937bb1745f1e7aee7901ad26") +-Mapping("653da4fd006c97625247acd7e076d0782cdc149b","eca11b99a7d25e4e6573472a16537c1aacb5d5e1") +-Mapping("28bcffead74d5e17c6cb1f7de432e37f93a6b50c","472ca7159812f8c360697f63454ee7bda1e02570") +-Mapping("e305df1846a6d985315917ae0c81b74af8b4e641","271eb8fc5a420280937bb1745f1e7aee7901ad26") +-Mapping("adbfec229ce07ff4b2a7bf2d6dec2d13cb224980","27c3631d826aaad964f42ee94f26f9e80d658e3f") +-Mapping("87a436377a7cddd1d4426c9604c48e0aa2ec0b11","c0e8cf94103289c424c62ca48e1e3f56e352a84a") +-Mapping("a7be40c65ae8ace467c9c40b0a22642973e31a13","2a663555ddf36f6b041445894a8c175cd1bc718c") +-Mapping("99da733f7f38ce8fe68453e859b7ac96bf7caa0f","379c380a60e7b3adb6c6f595222cbfa2d9160a20") +-Mapping("15d770400eed9018f18bddf83dd65cb7789280a5","b9adc3327ec7d2820ab2db8bb3cc2a0196a8375d") +-Mapping("e4c66afba5d69356879570aeff22db5a38566a86","379c380a60e7b3adb6c6f595222cbfa2d9160a20") +-Mapping("0ea22717a1e01fa535534b85a5347a7e49fc79de","93b6d9e086c6910118a57e4332c9448ab550931f") +-Mapping("790f4c566d9802dfcadc26398dde2051cfe6ec9f","cf9fd6074da321b353a755359fac10cd28ed251d") +-Mapping("2a0062974a5225847fc43d5522c4dc3718173fe5","7cbeddb7b78cc54a52d63ed8556da7121d1d2e68") +-Mapping("565235ee7e2d978e98b84450e15f673c84123a8a","7cbeddb7b78cc54a52d63ed8556da7121d1d2e68") +-Mapping("ae46aefd5b682b4e4206b91df60760da8483b659","7cbeddb7b78cc54a52d63ed8556da7121d1d2e68") +-Mapping("cd494c1f0915da00a63c03454a96d504afe764ff","0b9c686b479ce337581ba9773481ada8dd8f91d6") +-Mapping("524ad9b9e03656f3fdeb03ed82fe78db3916e566","7cbeddb7b78cc54a52d63ed8556da7121d1d2e68") +-Mapping("f9bfe840f41d00e9712f13fbc635ec3fbe95e8c4","7cbeddb7b78cc54a52d63ed8556da7121d1d2e68") +-Mapping("5230979794db209de492b3f7cc688020b72bc7c6","b81da278623d9dcda1776008612bd42e1922e9c3") +-Mapping("2a1c4eec40527de45b9d9b81672c8b9220d554fc","0b9c686b479ce337581ba9773481ada8dd8f91d6") +-Mapping("71e87be381bd6020645d925c579fa7367167d3d8","7cbeddb7b78cc54a52d63ed8556da7121d1d2e68") +-Mapping("29f48ccf396be031ee8a54e74a3a4e81866c8872","7cbeddb7b78cc54a52d63ed8556da7121d1d2e68") +-Mapping("4ecf12bf0eb8386626ccdb5f721a7183ccc4eba6","7cbeddb7b78cc54a52d63ed8556da7121d1d2e68") +-Mapping("29ffe51e34ec0491806befadc4f820b132b50f9e","7cbeddb7b78cc54a52d63ed8556da7121d1d2e68") +-Mapping("ac5c0848d329663f06c56f732e4414adbec978cf","7cbeddb7b78cc54a52d63ed8556da7121d1d2e68") +-Mapping("edaac35d67bed09260dc0c318acc5212fb66246e","b20bba4f3777fd097539e1f516987e0d9729d710") +-Mapping("82e2f3ec25a316c7536c33a6b6704366b14cbf2a","d3f30c30eaf56b69cf458656c1a84a931d1108a9") +-Mapping("d311571906bd2b22e206b9a84ccb888e248820df","1ed91951c3012e9aabb403d28b902c56cc143907") +-Mapping("551244f05b92f90fe327f8f0a6d9a6e674eaab1b","06da917b015a2eceac0e3cca22f9660edef25178") +-Mapping("3750348daff89741e3153e0e120aa70a45ff5b68","379c380a60e7b3adb6c6f595222cbfa2d9160a20") +-Mapping("63d51e89af33a7cc1c81bbaee335131b7bd00803","3c9e884dd3bf93b1516d3b5858072b7659c4cfba") +-Mapping("4c27fb19ba15a2e45485e601a79914c6280196b0","c97d3d4dd174e8a80e9d0e55ea6f9a73aca60bf2") +-Mapping("b3af09205b9af6026453946feadfd78b61b7a9fc","1ed91951c3012e9aabb403d28b902c56cc143907") +-Mapping("0b9f19dff1347e29bf4362ab5a8fab84b43023b5","b20bba4f3777fd097539e1f516987e0d9729d710") +-Mapping("0f88167f89fffe321590c5148f21b7d51d44388d","d3f30c30eaf56b69cf458656c1a84a931d1108a9") +-Mapping("26b4cb48484382032522384318e70ceb0fbc4a41","e1b8898cfb0392f534cc25808a7f6caad36ebbb7") +-Mapping("8159f389f6cc8ec3e3ea009222d6926da77371ec","379c380a60e7b3adb6c6f595222cbfa2d9160a20") +-Mapping("e4ba1d41e3c2a66215943e43de70f93bb195b1f0","3c9e884dd3bf93b1516d3b5858072b7659c4cfba") +-Mapping("9fefb67669f00c25b476e7a80c9c9300a987d517","eca11b99a7d25e4e6573472a16537c1aacb5d5e1") +-Mapping("20dc0c50704ba1fc8c56a88ae2bf05ddb3e419bc","3c9e884dd3bf93b1516d3b5858072b7659c4cfba") +-Mapping("65204a97d4876b897df0a70c0b9248b57e2bf057","eca11b99a7d25e4e6573472a16537c1aacb5d5e1") +-Mapping("2224a42c353636db6ee53cc3f9b1a968e9d9c1f6","3c9e884dd3bf93b1516d3b5858072b7659c4cfba") +-Mapping("2c8bbf50db0ef90a33f986ba8fc2e1fe129197ff","d3f30c30eaf56b69cf458656c1a84a931d1108a9") +-Mapping("33ef0bad21d6bb646c7c3ab0dbf381ca96c324bf","c97d3d4dd174e8a80e9d0e55ea6f9a73aca60bf2") +-Mapping("ae7fe84e8cf7523f6853d9786e28e9d066d4e5cd","3c9e884dd3bf93b1516d3b5858072b7659c4cfba") +-Mapping("9fae1537462bb10fd17d07816efc17cfe4786806","7cbeddb7b78cc54a52d63ed8556da7121d1d2e68") +-Mapping("ff2ac35db93a80b2de5daa4f280bf1503d62c164","7cbeddb7b78cc54a52d63ed8556da7121d1d2e68") +-Mapping("c2d46037fa6617408155dcba6251d7c4e123b4f5","7cbeddb7b78cc54a52d63ed8556da7121d1d2e68") +-Mapping("aa094a43cc041c8483b7c80fb0ec4be233dd01b7","7cbeddb7b78cc54a52d63ed8556da7121d1d2e68") +-Mapping("41affd03eb169830773cd1b11efda562ab81fad0","7cbeddb7b78cc54a52d63ed8556da7121d1d2e68") +-Mapping("cb20f68d0f9e1c1bf49df22991b5a0d1a43146e8","7cbeddb7b78cc54a52d63ed8556da7121d1d2e68") +-Mapping("79fcc58b24d85743d025fd880fca55748662ed3e","3c9e884dd3bf93b1516d3b5858072b7659c4cfba") +-Mapping("e3428db7c2b1eeb35096e0bf37672397977ff030","379c380a60e7b3adb6c6f595222cbfa2d9160a20") +-Mapping("52e885628e4317aa3f158622435927eb29b812e9","e1b8898cfb0392f534cc25808a7f6caad36ebbb7") +-Mapping("ca79ecd6940e30d4b2466bf378632efcdf5745c7","eca11b99a7d25e4e6573472a16537c1aacb5d5e1") +-Mapping("237bf3244fffef501cf37d4bda00e1fce3fcfb46","d403cd787c98610cf5287301820ad3353b35481d") +-Mapping("4141a4079e3e6b2c4ac104fed042a9b7241467eb","3c9e884dd3bf93b1516d3b5858072b7659c4cfba") +-Mapping("6f93e93af6f823948cc13d2938957757c6486d88","eca11b99a7d25e4e6573472a16537c1aacb5d5e1") +-Mapping("9d71ec1358ac063fe6ff1eaed0ba6ed3cedde610","e1b8898cfb0392f534cc25808a7f6caad36ebbb7") +-Mapping("acd8dd6a50d505057a7d7ad8d0d7a4c2bd274200","379c380a60e7b3adb6c6f595222cbfa2d9160a20") +-Mapping("3bc2ca7e4f8507f82a4c357ee19300166bcd8099","3c9e884dd3bf93b1516d3b5858072b7659c4cfba") +-Mapping("8876906867b2db3c7177d69dd020c40d89177f86","3c9e884dd3bf93b1516d3b5858072b7659c4cfba") +-Mapping("00e03ee57446d47667e5adba77fca8c13bfe7535","b20bba4f3777fd097539e1f516987e0d9729d710") +-Mapping("0c999ed132d67bf2520643e9bd619972cf3888ba","1ed91951c3012e9aabb403d28b902c56cc143907") +-Mapping("fbd34efb32b9efb574899e4335bdc8c6525ac27e","c97d3d4dd174e8a80e9d0e55ea6f9a73aca60bf2") +-Mapping("c82834e2b930619d4143e4dd94fb80888fa190c9","d3f30c30eaf56b69cf458656c1a84a931d1108a9") +-Mapping("cb6d2dfa8923902b0992a1522dc4a45a9d3ba690","3c9e884dd3bf93b1516d3b5858072b7659c4cfba") +-Mapping("21f26849506c141a6760532ca5bdfd8345247fdb","1ed91951c3012e9aabb403d28b902c56cc143907") +-Mapping("3eb4890dfe6db0279fdd3cda19f9643873ae3db9","d3f30c30eaf56b69cf458656c1a84a931d1108a9") +-Mapping("1f57e4841157d5cbd4c4e22018f93bd1801c98c2","b20bba4f3777fd097539e1f516987e0d9729d710") +-Mapping("474e7a6486758ea6fc761893b1a49cd9076fb0ab","379c380a60e7b3adb6c6f595222cbfa2d9160a20") +-Mapping("2d4e34ca8bb1369f7e0eea4cb50e6faa0827a6e5","06da917b015a2eceac0e3cca22f9660edef25178") +-Mapping("33b923fd44c5c5925e635815fce68bdf1f98740f","ea505fd60b09bbfb127c874a27abac52d44bfe00") +-Mapping("a9410cd1af7c1194fbda1457c74b8ab25547e1e6","99ed06eb8864e704c4a1871ccda4648273bee4ef") +-Mapping("77af314083e5acabf9ba5335e47271f35eef2e99","b9adc3327ec7d2820ab2db8bb3cc2a0196a8375d") +-Mapping("147311c5fc62537da8eb9c6f69536bec6719d534","ebbecac538137fca1c36ceca91337b5ff4d196b5") +-Mapping("14f42a732ff9562fb5f07eca5a7f92224dbe8881","b9adc3327ec7d2820ab2db8bb3cc2a0196a8375d") +-Mapping("39e6ba82182b264c94bc62a1284d115b50ff1bd3","71120ef1e5cb885ee45e6148970db6ce93ce1aca") +-Mapping("0b7af2668a80fb2fa720a06ca44aff4dd1e9de38","27c8dfddac4c69a6fd399abe537e1007306c58cf") +-Mapping("d22fa2d87d03d19fdb1359faab9ec5e74eff26b3","d60fa1d3c21e00bedc0dd94dc2df7e5183c14c48") +-Mapping("a66dc8a1489d2818b5e63f18e1464be79da1f137","b9adc3327ec7d2820ab2db8bb3cc2a0196a8375d") +-Mapping("f7202e40f49d2b29635f095a3270a7214e25ce8b","71120ef1e5cb885ee45e6148970db6ce93ce1aca") +-Mapping("02c4c28920ddfdb43e68a363b7fe59ac4c92399c","fb162e69449b423c5aed0d9c39f6c046fa300c30") +-Mapping("9a3392e174a432a5f06c1157befc1ce0fae74bec","99ed06eb8864e704c4a1871ccda4648273bee4ef") +-Mapping("b2028828db7e4870cb6a310f8ad8169ac9ea134d","ea505fd60b09bbfb127c874a27abac52d44bfe00") +-Mapping("b92552d5578e4544006da0dd5e793a19c2149321","d60fa1d3c21e00bedc0dd94dc2df7e5183c14c48") +-Mapping("f99911a4a0bead7dd1f9ef2f90442844434cc391","b9adc3327ec7d2820ab2db8bb3cc2a0196a8375d") +-Mapping("ad610bed83f43158892222a71336bdcaa167909a","210a2a2b9e5f7bc105897654bfea0f9cc7c8d89f") +-Mapping("bd40cbbe1f42bfcc18a823dd46f584127f6578f2","210a2a2b9e5f7bc105897654bfea0f9cc7c8d89f") +-Mapping("68fe5182c967259ef89dbe313e4bf80f45a53e7e","d60fa1d3c21e00bedc0dd94dc2df7e5183c14c48") +-Mapping("7061b2775782bb48c0a70d3c79ec711134396687","71120ef1e5cb885ee45e6148970db6ce93ce1aca") +-Mapping("f66e4697ae286985ddefc53c3a047614568458bb","e3a8f7db479ce6562bfc312f412b65dc4f3c77d5") +-Mapping("424a749a01224239ba2c8850f16007d57db0a242","b9adc3327ec7d2820ab2db8bb3cc2a0196a8375d") +-Mapping("00aae71f503b1ab592f48de47dd30912f3858748","e3a8f7db479ce6562bfc312f412b65dc4f3c77d5") +-Mapping("9eac386342c601b14311b435f2b6d314fc817bb5","2a663555ddf36f6b041445894a8c175cd1bc718c") +-Mapping("d767ee11616390d128853a06f5addb619e79213f","31bec788f46c73ab14c72868dc6141141320a058") +-Mapping("146aa60f3484d8267e085e80611969f387eca068","99ed06eb8864e704c4a1871ccda4648273bee4ef") +-Mapping("3315728c060b73ccf986c63677c1fcd7d92e15c5","27c8dfddac4c69a6fd399abe537e1007306c58cf") +-Mapping("8e2063d02062ee9f088274690a97826333847e17","d60fa1d3c21e00bedc0dd94dc2df7e5183c14c48") +-Mapping("4699283c5b549d1559c198123a67fef498aa6a44","b9adc3327ec7d2820ab2db8bb3cc2a0196a8375d") +-Mapping("2c2e2c57dc2140cfb62a8abb9312b89f02c59f3c","b9adc3327ec7d2820ab2db8bb3cc2a0196a8375d") +-Mapping("c1c3c4e95b69dfeaca5c5db6c622d7f90ad30a54","ebbecac538137fca1c36ceca91337b5ff4d196b5") +-Mapping("eac09088e1a8fc8a293028764e4e84da29469205","99ed06eb8864e704c4a1871ccda4648273bee4ef") +-Mapping("1fa944914c092d728c8307e976a4b447df25bf16","ea505fd60b09bbfb127c874a27abac52d44bfe00") +-Mapping("7e001e5c6c7c090b41416a57d4be412ed3ccd937","115c8a1f095f99dab82da7ab1276c64747ed8fcc") +-Mapping("7219130677c4fe4310c9729cbc0b4c6e9c9b42fc","71120ef1e5cb885ee45e6148970db6ce93ce1aca") diff --git a/patches/06da917b015a2eceac0e3cca22f9660edef25178.patch b/patches/06da917b015a2eceac0e3cca22f9660edef25178.patch new file mode 100644 index 0000000..5f665d1 --- /dev/null +++ b/patches/06da917b015a2eceac0e3cca22f9660edef25178.patch @@ -0,0 +1,1600 @@ +diff --git a/buffered.rs b/buffered.rs +index e26e6d3..c754cf1 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -10,13 +10,13 @@ + + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use io::prelude::*; + +-use cmp; +-use error; +-use fmt; ++use core::cmp; ++use core::fmt; + use io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom}; +-use memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -52,7 +52,6 @@ use memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -76,7 +75,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -97,7 +95,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -130,7 +127,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -151,7 +147,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + + /// Returns a reference to the internally buffered data. +@@ -176,7 +171,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -199,7 +193,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + } + +@@ -208,7 +201,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -228,7 +220,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -251,7 +242,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -271,7 +261,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -281,7 +270,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -387,7 +375,6 @@ impl Seek for BufReader { + /// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -422,7 +409,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -437,7 +423,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -455,7 +440,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -504,7 +488,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -522,7 +505,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Unwraps this `BufWriter`, returning the underlying writer. +@@ -544,7 +526,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -553,7 +534,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -573,7 +553,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -583,7 +562,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -593,7 +571,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -632,7 +609,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -665,23 +641,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -752,7 +718,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -773,7 +738,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -794,7 +758,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -818,7 +781,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -841,7 +803,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -867,7 +828,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -878,7 +838,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -923,7 +882,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index 14f2015..1d60dac 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -10,8 +10,8 @@ + + use io::prelude::*; + +-use core::convert::TryInto; +-use cmp; ++#[cfg(feature="collections")] use core::convert::TryInto; ++use core::cmp; + use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + + /// A `Cursor` wraps an in-memory buffer and provides it with a +@@ -80,7 +80,6 @@ use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -103,7 +102,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -121,7 +119,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -137,7 +134,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -156,7 +152,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -178,7 +173,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -198,11 +192,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -223,17 +215,16 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -244,12 +235,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -262,6 +257,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result, buf: &[u8]) -> io::Result { + let pos: usize = (*pos_mut).try_into().map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -288,7 +284,6 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result Write for Cursor<&'a mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -297,7 +292,7 @@ impl<'a> Write for Cursor<&'a mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl<'a> Write for Cursor<&'a mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) +@@ -305,7 +300,7 @@ impl<'a> Write for Cursor<&'a mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) +@@ -313,8 +308,8 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) +diff --git a/error.rs b/error.rs +index 3e50988..71667ce 100644 +--- a/error.rs ++++ b/error.rs +@@ -8,11 +8,16 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use error; +-use fmt; +-use result; +-use sys; +-use convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -48,7 +53,6 @@ use convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -62,12 +66,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -77,13 +79,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -95,48 +100,35 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + #[non_exhaustive] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -148,10 +140,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -162,15 +152,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -179,7 +166,6 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + } + +@@ -210,7 +196,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + #[inline] + fn from(kind: ErrorKind) -> Error { +@@ -239,14 +224,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -255,24 +239,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -298,7 +264,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -329,7 +294,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -363,12 +327,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(dyn error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -434,12 +397,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -468,8 +430,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -495,10 +456,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -510,22 +470,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -533,24 +489,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- fn cause(&self) -> Option<&dyn error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index fe1179a..452b8b7 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -8,15 +8,18 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use cmp; +-use io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind}; +-use fmt; +-use mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use io::BufRead; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, R: Read + ?Sized> Read for &'a mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -28,11 +31,13 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -43,7 +48,6 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, W: Write + ?Sized> Write for &'a mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -61,12 +65,11 @@ impl<'a, W: Write + ?Sized> Write for &'a mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, S: Seek + ?Sized> Seek for &'a mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -85,7 +88,7 @@ impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -97,11 +100,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -112,7 +117,7 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -130,12 +135,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -161,7 +166,6 @@ impl BufRead for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Read for &'a [u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -207,6 +211,7 @@ impl<'a> Read for &'a [u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -216,7 +221,7 @@ impl<'a> Read for &'a [u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a> BufRead for &'a [u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -230,7 +235,6 @@ impl<'a> BufRead for &'a [u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Write for &'a mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -256,7 +260,7 @@ impl<'a> Write for &'a mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +diff --git a/mod.rs b/mod.rs +index b83f3fb..883fa30 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -267,47 +267,36 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use cmp; +-use fmt; +-use str; +-use memchr; +-use ptr; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::cmp; ++use core::fmt; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++use core::ptr; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl<'a> Drop for Guard<'a> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -332,6 +321,7 @@ impl<'a> Drop for Guard<'a> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -359,10 +349,12 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + read_to_end_with_reservation(r, buf, 32) + } + ++#[cfg(feature="collections")] + fn read_to_end_with_reservation(r: &mut R, + buf: &mut Vec, + reservation_size: usize) -> Result +@@ -469,7 +461,6 @@ fn read_to_end_with_reservation(r: &mut R, + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -526,7 +517,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Determines if this `Read`er can work with buffers of uninitialized +@@ -551,7 +541,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -604,7 +593,7 @@ pub trait Read { + /// file.) + /// + /// [`std::fs::read`]: ../fs/fn.read.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -647,7 +636,7 @@ pub trait Read { + /// reading from a file.) + /// + /// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -710,7 +699,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -762,7 +750,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -799,7 +786,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } +@@ -834,7 +820,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -870,20 +855,17 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -897,21 +879,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -954,7 +933,6 @@ impl Initializer { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this object, returning how many bytes were written. +@@ -1003,7 +981,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Flush this output stream, ensuring that all intermediately buffered +@@ -1029,7 +1006,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this write. +@@ -1062,7 +1038,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1114,7 +1089,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1170,7 +1144,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1200,7 +1173,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1216,7 +1188,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + } + +@@ -1226,29 +1197,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Set the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Set the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Set the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1328,7 +1296,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Fills the internal buffer of this object, returning the buffer contents. + /// +@@ -1373,7 +1341,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1395,7 +1362,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1451,7 +1417,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1510,7 +1475,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1551,7 +1515,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1590,7 +1553,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1602,7 +1564,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1628,7 +1589,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1651,7 +1611,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1678,13 +1637,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1694,7 +1651,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1716,7 +1672,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1743,7 +1699,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -1778,7 +1733,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -1804,7 +1758,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "take_set_limit", since = "1.27.0")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -1829,7 +1782,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -1854,7 +1806,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -1883,13 +1834,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -1906,15 +1855,9 @@ impl Read for Take { + unsafe fn initializer(&self) -> Initializer { + self.inner.initializer() + } +- +- fn read_to_end(&mut self, buf: &mut Vec) -> Result { +- let reservation_size = cmp::min(self.limit, 32) as usize; +- +- read_to_end_with_reservation(self, buf, reservation_size) +- } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -1953,13 +1896,11 @@ fn read_one_byte(reader: &mut dyn Read) -> Option> { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -1975,14 +1916,14 @@ impl Iterator for Bytes { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -2007,13 +1948,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 8772d0f..49d66c9 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -18,7 +18,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 371e5b2..0d643e8 100644 +--- a/util.rs ++++ b/util.rs +@@ -10,9 +10,10 @@ + + #![allow(missing_copy_implementations)] + +-use fmt; +-use io::{self, Read, Initializer, Write, ErrorKind, BufRead}; +-use mem; ++use core::fmt; ++use io::{self, Read, Initializer, Write, ErrorKind}; ++use core::mem; ++#[cfg(feature="collections")] use io::BufRead; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -49,7 +50,6 @@ use mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -78,7 +78,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -98,10 +97,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -111,7 +108,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -119,7 +117,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -132,7 +129,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -149,10 +145,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte: byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -168,7 +162,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -181,7 +174,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -198,10 +190,8 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } +@@ -209,7 +199,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/0b9c686b479ce337581ba9773481ada8dd8f91d6.patch b/patches/0b9c686b479ce337581ba9773481ada8dd8f91d6.patch new file mode 100644 index 0000000..ec54936 --- /dev/null +++ b/patches/0b9c686b479ce337581ba9773481ada8dd8f91d6.patch @@ -0,0 +1,1795 @@ +diff --git a/buffered.rs b/buffered.rs +index ee297d3..452b718 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -10,13 +10,13 @@ + + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use io::prelude::*; + +-use cmp; +-use error; +-use fmt; ++use core::cmp; ++use core::fmt; + use io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom}; +-use memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -52,7 +52,6 @@ use memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -75,7 +74,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -96,7 +94,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -129,7 +126,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -150,36 +146,8 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + +- /// Returns `true` if there are no bytes in the internal buffer. +- /// +- /// # Examples +- // +- /// ```no_run +- /// # #![feature(bufreader_is_empty)] +- /// use std::io::BufReader; +- /// use std::io::BufRead; +- /// use std::fs::File; +- /// +- /// fn main() -> std::io::Result<()> { +- /// let f1 = File::open("log.txt")?; +- /// let mut reader = BufReader::new(f1); +- /// assert!(reader.is_empty()); +- /// +- /// if reader.fill_buf()?.len() > 0 { +- /// assert!(!reader.is_empty()); +- /// } +- /// Ok(()) +- /// } +- /// ``` +- #[unstable(feature = "bufreader_is_empty", issue = "45323", reason = "recently added")] +- #[rustc_deprecated(since = "1.26.0", reason = "use .buffer().is_empty() instead")] +- pub fn is_empty(&self) -> bool { +- self.buffer().is_empty() +- } +- + /// Returns a reference to the internally buffered data. + /// + /// Unlike `fill_buf`, this will not attempt to fill the buffer if it is empty. +@@ -202,7 +170,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -225,7 +192,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + } + +@@ -234,7 +200,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -254,7 +219,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -277,7 +241,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -297,7 +260,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -307,7 +269,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -415,7 +376,6 @@ impl Seek for BufReader { + /// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -450,7 +410,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -464,7 +423,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -482,7 +440,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -531,7 +488,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -549,7 +505,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Unwraps this `BufWriter`, returning the underlying writer. +@@ -571,7 +526,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -580,7 +534,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -600,7 +553,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -610,7 +562,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -620,7 +571,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -659,7 +609,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -692,23 +641,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -766,7 +705,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -787,7 +725,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -808,7 +745,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -832,7 +768,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -855,7 +790,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -881,7 +815,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -892,7 +825,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -937,7 +869,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index 8ac5257..c65ed2a 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -10,7 +10,7 @@ + + use io::prelude::*; + +-use cmp; ++use core::cmp; + use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + + /// A `Cursor` wraps another type and provides it with a +@@ -78,7 +78,6 @@ use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -101,7 +100,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -119,7 +117,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -135,7 +132,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -154,7 +150,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -176,7 +171,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -196,11 +190,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -221,17 +213,16 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -242,12 +233,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -261,6 +256,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result Result { +@@ -271,12 +267,14 @@ fn try_into(n: u64) -> Result { + } + } + ++#[cfg(feature="collections")] + #[cfg(any(target_pointer_width = "64"))] + fn try_into(n: u64) -> Result { + Ok(n as usize) + } + + // Resizing write implementation ++#[cfg(feature="collections")] + fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result { + let pos: usize = try_into(*pos_mut).map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -303,7 +301,6 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result Write for Cursor<&'a mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -312,7 +309,7 @@ impl<'a> Write for Cursor<&'a mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl<'a> Write for Cursor<&'a mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) +@@ -320,7 +317,7 @@ impl<'a> Write for Cursor<&'a mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) +@@ -328,8 +325,8 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) +diff --git a/error.rs b/error.rs +index bdd675e..3acdadf 100644 +--- a/error.rs ++++ b/error.rs +@@ -8,11 +8,16 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use error; +-use fmt; +-use result; +-use sys; +-use convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -48,7 +53,6 @@ use convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -62,12 +66,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -77,13 +79,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -95,47 +100,34 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -147,10 +139,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -161,15 +151,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -178,15 +165,10 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + + /// A marker variant that tells the compiler that users of this enum cannot + /// match it exhaustively. +- #[unstable(feature = "io_error_internals", +- reason = "better expressed through extensible enums that this \ +- enum cannot be exhaustively matched against", +- issue = "0")] + #[doc(hidden)] + __Nonexhaustive, + } +@@ -219,7 +201,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + #[inline] + fn from(kind: ErrorKind) -> Error { +@@ -248,14 +229,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -264,24 +244,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -307,7 +269,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -338,7 +299,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -372,12 +332,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -443,12 +402,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -477,8 +435,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -504,10 +461,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -519,22 +475,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -542,24 +494,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- fn cause(&self) -> Option<&error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index fe1179a..452b8b7 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -8,15 +8,18 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use cmp; +-use io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind}; +-use fmt; +-use mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use io::BufRead; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, R: Read + ?Sized> Read for &'a mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -28,11 +31,13 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -43,7 +48,6 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, W: Write + ?Sized> Write for &'a mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -61,12 +65,11 @@ impl<'a, W: Write + ?Sized> Write for &'a mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, S: Seek + ?Sized> Seek for &'a mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -85,7 +88,7 @@ impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -97,11 +100,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -112,7 +117,7 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -130,12 +135,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -161,7 +166,6 @@ impl BufRead for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Read for &'a [u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -207,6 +211,7 @@ impl<'a> Read for &'a [u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -216,7 +221,7 @@ impl<'a> Read for &'a [u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a> BufRead for &'a [u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -230,7 +235,6 @@ impl<'a> BufRead for &'a [u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Write for &'a mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -256,7 +260,7 @@ impl<'a> Write for &'a mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +diff --git a/mod.rs b/mod.rs +index 2b4644b..fbdb8e6 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -267,50 +267,36 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use cmp; +-use core::str as core_str; +-use error as std_error; +-use fmt; +-use result; +-use str; +-use memchr; +-use ptr; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::cmp; ++use core::fmt; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++use core::ptr; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl<'a> Drop for Guard<'a> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -335,6 +321,7 @@ impl<'a> Drop for Guard<'a> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -362,6 +349,7 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + let start_len = buf.len(); + let mut g = Guard { len: buf.len(), buf: buf }; +@@ -465,7 +453,6 @@ fn read_to_end(r: &mut R, buf: &mut Vec) -> Result + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -522,7 +509,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Determines if this `Read`er can work with buffers of uninitialized +@@ -547,7 +533,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -600,7 +585,7 @@ pub trait Read { + /// file.) + /// + /// [`std::fs::read`]: ../fs/fn.read.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -643,7 +628,7 @@ pub trait Read { + /// reading from a file.) + /// + /// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -706,7 +691,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -758,7 +742,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -795,58 +778,10 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } + +- /// Transforms this `Read` instance to an [`Iterator`] over [`char`]s. +- /// +- /// This adaptor will attempt to interpret this reader as a UTF-8 encoded +- /// sequence of characters. The returned iterator will return [`None`] once +- /// EOF is reached for this reader. Otherwise each element yielded will be a +- /// [`Result`]`<`[`char`]`, E>` where `E` may contain information about what I/O error +- /// occurred or where decoding failed. +- /// +- /// Currently this adaptor will discard intermediate data read, and should +- /// be avoided if this is not desired. +- /// +- /// # Examples +- /// +- /// [`File`]s implement `Read`: +- /// +- /// [`File`]: ../fs/struct.File.html +- /// [`Iterator`]: ../../std/iter/trait.Iterator.html +- /// [`Result`]: ../../std/result/enum.Result.html +- /// [`char`]: ../../std/primitive.char.html +- /// [`None`]: ../../std/option/enum.Option.html#variant.None +- /// +- /// ```no_run +- /// #![feature(io)] +- /// use std::io; +- /// use std::io::prelude::*; +- /// use std::fs::File; +- /// +- /// fn main() -> io::Result<()> { +- /// let mut f = File::open("foo.txt")?; +- /// +- /// for c in f.chars() { +- /// println!("{}", c.unwrap()); +- /// } +- /// Ok(()) +- /// } +- /// ``` +- #[unstable(feature = "io", reason = "the semantics of a partial read/write \ +- of where errors happen is currently \ +- unclear and may change", +- issue = "27802")] +- #[rustc_deprecated(since = "1.27.0", reason = "Use str::from_utf8 instead: +- https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples")] +- #[allow(deprecated)] +- fn chars(self) -> Chars where Self: Sized { +- Chars { inner: self } +- } +- + /// Creates an adaptor which will chain this stream with another. + /// + /// The returned `Read` instance will first read all bytes from this object +@@ -877,7 +812,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -913,20 +847,17 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -940,21 +871,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -997,7 +925,6 @@ impl Initializer { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this object, returning how many bytes were written. +@@ -1046,7 +973,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Flush this output stream, ensuring that all intermediately buffered +@@ -1072,7 +998,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this write. +@@ -1105,7 +1030,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1157,7 +1081,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1213,7 +1136,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1243,7 +1165,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1259,7 +1180,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + } + +@@ -1269,29 +1189,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Set the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Set the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Set the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1371,7 +1288,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Fills the internal buffer of this object, returning the buffer contents. + /// +@@ -1416,7 +1333,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1438,7 +1354,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1494,7 +1409,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1553,7 +1467,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1594,7 +1507,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1633,7 +1545,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1645,7 +1556,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1671,7 +1581,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1694,7 +1603,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1721,13 +1629,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1737,7 +1643,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1759,7 +1664,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1786,7 +1691,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -1821,7 +1725,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -1847,7 +1750,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "take_set_limit", since = "1.27.0")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -1872,7 +1774,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -1897,7 +1798,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -1926,13 +1826,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -1951,7 +1849,7 @@ impl Read for Take { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -1990,13 +1888,11 @@ fn read_one_byte(reader: &mut Read) -> Option> { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -2005,104 +1901,6 @@ impl Iterator for Bytes { + } + } + +-/// An iterator over the `char`s of a reader. +-/// +-/// This struct is generally created by calling [`chars`][chars] on a reader. +-/// Please see the documentation of `chars()` for more details. +-/// +-/// [chars]: trait.Read.html#method.chars +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] +-#[rustc_deprecated(since = "1.27.0", reason = "Use str::from_utf8 instead: +- https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples")] +-#[derive(Debug)] +-#[allow(deprecated)] +-pub struct Chars { +- inner: R, +-} +- +-/// An enumeration of possible errors that can be generated from the `Chars` +-/// adapter. +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] +-#[rustc_deprecated(since = "1.27.0", reason = "Use str::from_utf8 instead: +- https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples")] +-#[derive(Debug)] +-#[allow(deprecated)] +-pub enum CharsError { +- /// Variant representing that the underlying stream was read successfully +- /// but it did not contain valid utf8 data. +- NotUtf8, +- +- /// Variant representing that an I/O error occurred. +- Other(Error), +-} +- +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] +-#[allow(deprecated)] +-impl Iterator for Chars { +- type Item = result::Result; +- +- fn next(&mut self) -> Option> { +- let first_byte = match read_one_byte(&mut self.inner)? { +- Ok(b) => b, +- Err(e) => return Some(Err(CharsError::Other(e))), +- }; +- let width = core_str::utf8_char_width(first_byte); +- if width == 1 { return Some(Ok(first_byte as char)) } +- if width == 0 { return Some(Err(CharsError::NotUtf8)) } +- let mut buf = [first_byte, 0, 0, 0]; +- { +- let mut start = 1; +- while start < width { +- match self.inner.read(&mut buf[start..width]) { +- Ok(0) => return Some(Err(CharsError::NotUtf8)), +- Ok(n) => start += n, +- Err(ref e) if e.kind() == ErrorKind::Interrupted => continue, +- Err(e) => return Some(Err(CharsError::Other(e))), +- } +- } +- } +- Some(match str::from_utf8(&buf[..width]).ok() { +- Some(s) => Ok(s.chars().next().unwrap()), +- None => Err(CharsError::NotUtf8), +- }) +- } +-} +- +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] +-#[allow(deprecated)] +-impl std_error::Error for CharsError { +- fn description(&self) -> &str { +- match *self { +- CharsError::NotUtf8 => "invalid utf8 encoding", +- CharsError::Other(ref e) => std_error::Error::description(e), +- } +- } +- fn cause(&self) -> Option<&std_error::Error> { +- match *self { +- CharsError::NotUtf8 => None, +- CharsError::Other(ref e) => e.cause(), +- } +- } +-} +- +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] +-#[allow(deprecated)] +-impl fmt::Display for CharsError { +- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +- match *self { +- CharsError::NotUtf8 => { +- "byte stream did not contain valid utf8".fmt(f) +- } +- CharsError::Other(ref e) => e.fmt(f), +- } +- } +-} +- + /// An iterator over the contents of an instance of `BufRead` split on a + /// particular byte. + /// +@@ -2110,14 +1908,14 @@ impl fmt::Display for CharsError { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -2142,13 +1940,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 8772d0f..49d66c9 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -18,7 +18,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 195310a..20755b7 100644 +--- a/util.rs ++++ b/util.rs +@@ -10,9 +10,10 @@ + + #![allow(missing_copy_implementations)] + +-use fmt; +-use io::{self, Read, Initializer, Write, ErrorKind, BufRead}; +-use mem; ++use core::fmt; ++use io::{self, Read, Initializer, Write, ErrorKind}; ++use core::mem; ++#[cfg(feature="collections")] use io::BufRead; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -44,7 +45,6 @@ use mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -73,7 +73,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -93,10 +92,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -106,7 +103,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -114,7 +112,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -127,7 +124,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -144,10 +140,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte: byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -163,7 +157,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -176,7 +169,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -193,10 +185,8 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } +@@ -204,7 +194,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/0ceeb1be31b52837e270a3349f9c62087ff11985.patch b/patches/0ceeb1be31b52837e270a3349f9c62087ff11985.patch new file mode 100644 index 0000000..32fda94 --- /dev/null +++ b/patches/0ceeb1be31b52837e270a3349f9c62087ff11985.patch @@ -0,0 +1,1782 @@ +diff --git a/buffered.rs b/buffered.rs +index ee297d3..452b718 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -10,13 +10,13 @@ + + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use io::prelude::*; + +-use cmp; +-use error; +-use fmt; ++use core::cmp; ++use core::fmt; + use io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom}; +-use memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -52,7 +52,6 @@ use memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -75,7 +74,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -96,7 +94,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -129,7 +126,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -150,36 +146,8 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + +- /// Returns `true` if there are no bytes in the internal buffer. +- /// +- /// # Examples +- // +- /// ```no_run +- /// # #![feature(bufreader_is_empty)] +- /// use std::io::BufReader; +- /// use std::io::BufRead; +- /// use std::fs::File; +- /// +- /// fn main() -> std::io::Result<()> { +- /// let f1 = File::open("log.txt")?; +- /// let mut reader = BufReader::new(f1); +- /// assert!(reader.is_empty()); +- /// +- /// if reader.fill_buf()?.len() > 0 { +- /// assert!(!reader.is_empty()); +- /// } +- /// Ok(()) +- /// } +- /// ``` +- #[unstable(feature = "bufreader_is_empty", issue = "45323", reason = "recently added")] +- #[rustc_deprecated(since = "1.26.0", reason = "use .buffer().is_empty() instead")] +- pub fn is_empty(&self) -> bool { +- self.buffer().is_empty() +- } +- + /// Returns a reference to the internally buffered data. + /// + /// Unlike `fill_buf`, this will not attempt to fill the buffer if it is empty. +@@ -202,7 +170,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -225,7 +192,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + } + +@@ -234,7 +200,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -254,7 +219,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -277,7 +241,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -297,7 +260,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -307,7 +269,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -415,7 +376,6 @@ impl Seek for BufReader { + /// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -450,7 +410,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -464,7 +423,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -482,7 +440,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -531,7 +488,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -549,7 +505,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Unwraps this `BufWriter`, returning the underlying writer. +@@ -571,7 +526,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -580,7 +534,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -600,7 +553,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -610,7 +562,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -620,7 +571,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -659,7 +609,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -692,23 +641,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -766,7 +705,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -787,7 +725,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -808,7 +745,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -832,7 +768,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -855,7 +790,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -881,7 +815,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -892,7 +825,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -937,7 +869,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index aadd33b..cd6ae13 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -10,8 +10,8 @@ + + use io::prelude::*; + +-use core::convert::TryInto; +-use cmp; ++#[cfg(feature="collections")] use core::convert::TryInto; ++use core::cmp; + use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + + /// A `Cursor` wraps another type and provides it with a +@@ -79,7 +79,6 @@ use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -102,7 +101,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -120,7 +118,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -136,7 +133,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -155,7 +151,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -177,7 +172,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -197,11 +191,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -222,17 +214,16 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -243,12 +234,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -261,6 +256,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result, buf: &[u8]) -> io::Result { + let pos: usize = (*pos_mut).try_into().map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -287,7 +283,6 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result Write for Cursor<&'a mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -296,7 +291,7 @@ impl<'a> Write for Cursor<&'a mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl<'a> Write for Cursor<&'a mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) +@@ -304,7 +299,7 @@ impl<'a> Write for Cursor<&'a mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) +@@ -312,8 +307,8 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) +diff --git a/error.rs b/error.rs +index bdd675e..3acdadf 100644 +--- a/error.rs ++++ b/error.rs +@@ -8,11 +8,16 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use error; +-use fmt; +-use result; +-use sys; +-use convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -48,7 +53,6 @@ use convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -62,12 +66,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -77,13 +79,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -95,47 +100,34 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -147,10 +139,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -161,15 +151,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -178,15 +165,10 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + + /// A marker variant that tells the compiler that users of this enum cannot + /// match it exhaustively. +- #[unstable(feature = "io_error_internals", +- reason = "better expressed through extensible enums that this \ +- enum cannot be exhaustively matched against", +- issue = "0")] + #[doc(hidden)] + __Nonexhaustive, + } +@@ -219,7 +201,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + #[inline] + fn from(kind: ErrorKind) -> Error { +@@ -248,14 +229,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -264,24 +244,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -307,7 +269,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -338,7 +299,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -372,12 +332,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -443,12 +402,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -477,8 +435,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -504,10 +461,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -519,22 +475,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -542,24 +494,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- fn cause(&self) -> Option<&error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index fe1179a..452b8b7 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -8,15 +8,18 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use cmp; +-use io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind}; +-use fmt; +-use mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use io::BufRead; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, R: Read + ?Sized> Read for &'a mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -28,11 +31,13 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -43,7 +48,6 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, W: Write + ?Sized> Write for &'a mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -61,12 +65,11 @@ impl<'a, W: Write + ?Sized> Write for &'a mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, S: Seek + ?Sized> Seek for &'a mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -85,7 +88,7 @@ impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -97,11 +100,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -112,7 +117,7 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -130,12 +135,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -161,7 +166,6 @@ impl BufRead for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Read for &'a [u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -207,6 +211,7 @@ impl<'a> Read for &'a [u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -216,7 +221,7 @@ impl<'a> Read for &'a [u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a> BufRead for &'a [u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -230,7 +235,6 @@ impl<'a> BufRead for &'a [u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Write for &'a mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -256,7 +260,7 @@ impl<'a> Write for &'a mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +diff --git a/mod.rs b/mod.rs +index 2b4644b..fbdb8e6 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -267,50 +267,36 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use cmp; +-use core::str as core_str; +-use error as std_error; +-use fmt; +-use result; +-use str; +-use memchr; +-use ptr; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::cmp; ++use core::fmt; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++use core::ptr; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl<'a> Drop for Guard<'a> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -335,6 +321,7 @@ impl<'a> Drop for Guard<'a> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -362,6 +349,7 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + let start_len = buf.len(); + let mut g = Guard { len: buf.len(), buf: buf }; +@@ -465,7 +453,6 @@ fn read_to_end(r: &mut R, buf: &mut Vec) -> Result + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -522,7 +509,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Determines if this `Read`er can work with buffers of uninitialized +@@ -547,7 +533,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -600,7 +585,7 @@ pub trait Read { + /// file.) + /// + /// [`std::fs::read`]: ../fs/fn.read.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -643,7 +628,7 @@ pub trait Read { + /// reading from a file.) + /// + /// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -706,7 +691,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -758,7 +742,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -795,58 +778,10 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } + +- /// Transforms this `Read` instance to an [`Iterator`] over [`char`]s. +- /// +- /// This adaptor will attempt to interpret this reader as a UTF-8 encoded +- /// sequence of characters. The returned iterator will return [`None`] once +- /// EOF is reached for this reader. Otherwise each element yielded will be a +- /// [`Result`]`<`[`char`]`, E>` where `E` may contain information about what I/O error +- /// occurred or where decoding failed. +- /// +- /// Currently this adaptor will discard intermediate data read, and should +- /// be avoided if this is not desired. +- /// +- /// # Examples +- /// +- /// [`File`]s implement `Read`: +- /// +- /// [`File`]: ../fs/struct.File.html +- /// [`Iterator`]: ../../std/iter/trait.Iterator.html +- /// [`Result`]: ../../std/result/enum.Result.html +- /// [`char`]: ../../std/primitive.char.html +- /// [`None`]: ../../std/option/enum.Option.html#variant.None +- /// +- /// ```no_run +- /// #![feature(io)] +- /// use std::io; +- /// use std::io::prelude::*; +- /// use std::fs::File; +- /// +- /// fn main() -> io::Result<()> { +- /// let mut f = File::open("foo.txt")?; +- /// +- /// for c in f.chars() { +- /// println!("{}", c.unwrap()); +- /// } +- /// Ok(()) +- /// } +- /// ``` +- #[unstable(feature = "io", reason = "the semantics of a partial read/write \ +- of where errors happen is currently \ +- unclear and may change", +- issue = "27802")] +- #[rustc_deprecated(since = "1.27.0", reason = "Use str::from_utf8 instead: +- https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples")] +- #[allow(deprecated)] +- fn chars(self) -> Chars where Self: Sized { +- Chars { inner: self } +- } +- + /// Creates an adaptor which will chain this stream with another. + /// + /// The returned `Read` instance will first read all bytes from this object +@@ -877,7 +812,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -913,20 +847,17 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -940,21 +871,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -997,7 +925,6 @@ impl Initializer { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this object, returning how many bytes were written. +@@ -1046,7 +973,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Flush this output stream, ensuring that all intermediately buffered +@@ -1072,7 +998,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this write. +@@ -1105,7 +1030,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1157,7 +1081,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1213,7 +1136,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1243,7 +1165,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1259,7 +1180,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + } + +@@ -1269,29 +1189,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Set the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Set the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Set the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1371,7 +1288,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Fills the internal buffer of this object, returning the buffer contents. + /// +@@ -1416,7 +1333,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1438,7 +1354,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1494,7 +1409,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1553,7 +1467,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1594,7 +1507,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1633,7 +1545,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1645,7 +1556,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1671,7 +1581,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1694,7 +1603,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1721,13 +1629,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1737,7 +1643,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1759,7 +1664,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1786,7 +1691,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -1821,7 +1725,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -1847,7 +1750,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "take_set_limit", since = "1.27.0")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -1872,7 +1774,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -1897,7 +1798,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -1926,13 +1826,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -1951,7 +1849,7 @@ impl Read for Take { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -1990,13 +1888,11 @@ fn read_one_byte(reader: &mut Read) -> Option> { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -2005,104 +1901,6 @@ impl Iterator for Bytes { + } + } + +-/// An iterator over the `char`s of a reader. +-/// +-/// This struct is generally created by calling [`chars`][chars] on a reader. +-/// Please see the documentation of `chars()` for more details. +-/// +-/// [chars]: trait.Read.html#method.chars +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] +-#[rustc_deprecated(since = "1.27.0", reason = "Use str::from_utf8 instead: +- https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples")] +-#[derive(Debug)] +-#[allow(deprecated)] +-pub struct Chars { +- inner: R, +-} +- +-/// An enumeration of possible errors that can be generated from the `Chars` +-/// adapter. +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] +-#[rustc_deprecated(since = "1.27.0", reason = "Use str::from_utf8 instead: +- https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples")] +-#[derive(Debug)] +-#[allow(deprecated)] +-pub enum CharsError { +- /// Variant representing that the underlying stream was read successfully +- /// but it did not contain valid utf8 data. +- NotUtf8, +- +- /// Variant representing that an I/O error occurred. +- Other(Error), +-} +- +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] +-#[allow(deprecated)] +-impl Iterator for Chars { +- type Item = result::Result; +- +- fn next(&mut self) -> Option> { +- let first_byte = match read_one_byte(&mut self.inner)? { +- Ok(b) => b, +- Err(e) => return Some(Err(CharsError::Other(e))), +- }; +- let width = core_str::utf8_char_width(first_byte); +- if width == 1 { return Some(Ok(first_byte as char)) } +- if width == 0 { return Some(Err(CharsError::NotUtf8)) } +- let mut buf = [first_byte, 0, 0, 0]; +- { +- let mut start = 1; +- while start < width { +- match self.inner.read(&mut buf[start..width]) { +- Ok(0) => return Some(Err(CharsError::NotUtf8)), +- Ok(n) => start += n, +- Err(ref e) if e.kind() == ErrorKind::Interrupted => continue, +- Err(e) => return Some(Err(CharsError::Other(e))), +- } +- } +- } +- Some(match str::from_utf8(&buf[..width]).ok() { +- Some(s) => Ok(s.chars().next().unwrap()), +- None => Err(CharsError::NotUtf8), +- }) +- } +-} +- +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] +-#[allow(deprecated)] +-impl std_error::Error for CharsError { +- fn description(&self) -> &str { +- match *self { +- CharsError::NotUtf8 => "invalid utf8 encoding", +- CharsError::Other(ref e) => std_error::Error::description(e), +- } +- } +- fn cause(&self) -> Option<&std_error::Error> { +- match *self { +- CharsError::NotUtf8 => None, +- CharsError::Other(ref e) => e.cause(), +- } +- } +-} +- +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] +-#[allow(deprecated)] +-impl fmt::Display for CharsError { +- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +- match *self { +- CharsError::NotUtf8 => { +- "byte stream did not contain valid utf8".fmt(f) +- } +- CharsError::Other(ref e) => e.fmt(f), +- } +- } +-} +- + /// An iterator over the contents of an instance of `BufRead` split on a + /// particular byte. + /// +@@ -2110,14 +1908,14 @@ impl fmt::Display for CharsError { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -2142,13 +1940,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 8772d0f..49d66c9 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -18,7 +18,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 195310a..20755b7 100644 +--- a/util.rs ++++ b/util.rs +@@ -10,9 +10,10 @@ + + #![allow(missing_copy_implementations)] + +-use fmt; +-use io::{self, Read, Initializer, Write, ErrorKind, BufRead}; +-use mem; ++use core::fmt; ++use io::{self, Read, Initializer, Write, ErrorKind}; ++use core::mem; ++#[cfg(feature="collections")] use io::BufRead; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -44,7 +45,6 @@ use mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -73,7 +73,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -93,10 +92,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -106,7 +103,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -114,7 +112,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -127,7 +124,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -144,10 +140,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte: byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -163,7 +157,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -176,7 +169,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -193,10 +185,8 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } +@@ -204,7 +194,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/115c8a1f095f99dab82da7ab1276c64747ed8fcc.patch b/patches/115c8a1f095f99dab82da7ab1276c64747ed8fcc.patch new file mode 100644 index 0000000..967a8e7 --- /dev/null +++ b/patches/115c8a1f095f99dab82da7ab1276c64747ed8fcc.patch @@ -0,0 +1,1868 @@ +diff --git a/buffered.rs b/buffered.rs +index 6383a14..d612c95 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -1,12 +1,12 @@ + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use io::prelude::*; + +-use cmp; +-use error; +-use fmt; ++use core::cmp; ++use core::fmt; + use io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom, IoVec, IoVecMut}; +-use memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -42,7 +42,6 @@ use memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -66,7 +65,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -87,7 +85,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -120,7 +117,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -141,7 +137,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + + /// Returns a reference to the internally buffered data. +@@ -166,7 +161,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -189,7 +183,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + } + +@@ -198,7 +191,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -218,7 +210,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -254,7 +245,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -274,7 +264,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -284,7 +273,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -393,7 +381,6 @@ impl Seek for BufReader { + /// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -428,7 +415,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -443,7 +429,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -461,7 +446,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -510,7 +494,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -528,7 +511,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Returns a reference to the internally buffered data. +@@ -545,7 +527,6 @@ impl BufWriter { + /// // See how many bytes are currently buffered + /// let bytes_buffered = buf_writer.buffer().len(); + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf + } +@@ -569,7 +550,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -578,7 +558,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -614,7 +593,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -624,7 +602,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -634,7 +611,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -673,7 +649,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -706,23 +681,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -793,7 +758,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -814,7 +778,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -835,7 +798,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -859,7 +821,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -882,7 +843,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -908,7 +868,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -919,7 +878,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -964,7 +922,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index 577a115..8813aba 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -1,8 +1,9 @@ + use io::prelude::*; + +-use core::convert::TryInto; +-use cmp; +-use io::{self, Initializer, SeekFrom, Error, ErrorKind, IoVec, IoVecMut}; ++#[cfg(feature="collections")] use core::convert::TryInto; ++use core::cmp; ++use io::{self, Initializer, SeekFrom, Error, ErrorKind}; ++#[cfg(feature="collections")] use io::{IoVec, IoVecMut}; + + /// A `Cursor` wraps an in-memory buffer and provides it with a + /// [`Seek`] implementation. +@@ -70,7 +71,6 @@ use io::{self, Initializer, SeekFrom, Error, ErrorKind, IoVec, IoVecMut}; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -93,7 +93,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -111,7 +110,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -127,7 +125,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -146,7 +143,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -168,7 +164,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -188,11 +183,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -213,14 +206,14 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + ++ #[cfg(feature="collections")] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let mut nread = 0; + for buf in bufs { +@@ -235,7 +228,7 @@ impl Read for Cursor where T: AsRef<[u8]> { + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -246,12 +239,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -263,6 +260,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result, buf: &[u8]) -> io::Result { + let pos: usize = (*pos_mut).try_into().map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -307,6 +306,7 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result, +@@ -320,13 +320,13 @@ fn vec_write_vectored( + Ok(nwritten) + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Cursor<&mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, self.inner, buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + slice_write_vectored(&mut self.pos, self.inner, bufs) +@@ -335,12 +335,13 @@ impl Write for Cursor<&mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl Write for Cursor<&mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) + } + ++ #[cfg(feature="collections")] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + vec_write_vectored(&mut self.pos, self.inner, bufs) + } +@@ -348,12 +349,13 @@ impl Write for Cursor<&mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) + } + ++ #[cfg(feature="collections")] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + vec_write_vectored(&mut self.pos, &mut self.inner, bufs) + } +@@ -361,13 +363,14 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + slice_write_vectored(&mut self.pos, &mut self.inner, bufs) +diff --git a/error.rs b/error.rs +index e9b4f60..31c0ff1 100644 +--- a/error.rs ++++ b/error.rs +@@ -1,8 +1,13 @@ +-use error; +-use fmt; +-use result; +-use sys; +-use convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -38,7 +43,6 @@ use convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -52,12 +56,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -67,13 +69,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -85,48 +90,35 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + #[non_exhaustive] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -138,10 +130,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -152,15 +142,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -169,7 +156,6 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + } + +@@ -200,7 +186,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + /// Converts an [`ErrorKind`] into an [`Error`]. + /// +@@ -245,14 +230,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -261,24 +245,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -304,7 +270,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -335,7 +300,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -369,12 +333,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(dyn error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -440,12 +403,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -474,8 +436,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -501,10 +462,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -516,22 +476,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -539,25 +495,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- #[allow(deprecated)] +- fn cause(&self) -> Option<&dyn error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index aa8db17..aaf1b00 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -1,19 +1,22 @@ +-use cmp; +-use io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind, IoVecMut, +- IoVec}; +-use fmt; +-use mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use io::{BufRead, IoVecMut, IoVec}; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for &mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { + (**self).read(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + (**self).read_vectored(bufs) +@@ -24,11 +27,13 @@ impl Read for &mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -39,11 +44,11 @@ impl Read for &mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for &mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + (**self).write_vectored(bufs) +@@ -62,12 +67,11 @@ impl Write for &mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for &mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for &mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -86,13 +90,14 @@ impl BufRead for &mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { + (**self).read(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + (**self).read_vectored(bufs) +@@ -103,11 +108,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -118,11 +125,12 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + (**self).write_vectored(bufs) +@@ -141,12 +149,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -172,7 +180,6 @@ impl BufRead for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for &[u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -192,6 +199,7 @@ impl Read for &[u8] { + Ok(amt) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let mut nread = 0; +@@ -231,6 +239,7 @@ impl Read for &[u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -240,7 +249,7 @@ impl Read for &[u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for &[u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -254,7 +263,6 @@ impl BufRead for &[u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for &mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -265,6 +273,7 @@ impl Write for &mut [u8] { + Ok(amt) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + let mut nwritten = 0; +@@ -293,7 +302,7 @@ impl Write for &mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -301,6 +310,7 @@ impl Write for Vec { + Ok(buf.len()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + let len = bufs.iter().map(|b| b.len()).sum(); +diff --git a/mod.rs b/mod.rs +index 613ae7a..7fa4bb0 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -257,50 +257,38 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use cmp; +-use fmt; +-use slice; +-use str; +-use memchr; +-use ops::{Deref, DerefMut}; +-use ptr; +-use sys; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::cmp; ++use core::fmt; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++#[cfg(feature="collections")] use core::ops::{Deref, DerefMut}; ++use core::ptr; ++use core::slice; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl Drop for Guard<'_> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -325,6 +313,7 @@ impl Drop for Guard<'_> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -352,10 +341,12 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + read_to_end_with_reservation(r, buf, 32) + } + ++#[cfg(feature="collections")] + fn read_to_end_with_reservation(r: &mut R, + buf: &mut Vec, + reservation_size: usize) -> Result +@@ -462,7 +453,6 @@ fn read_to_end_with_reservation(r: &mut R, + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -519,7 +509,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Like `read`, except that it reads into a slice of buffers. +@@ -530,7 +519,7 @@ pub trait Read { + /// + /// The default implementation simply passes the first nonempty buffer to + /// `read`. +- #[unstable(feature = "iovec", issue = "58452")] ++ #[cfg(feature="collections")] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> Result { + match bufs.iter_mut().find(|b| !b.is_empty()) { + Some(buf) => self.read(buf), +@@ -560,7 +549,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -613,7 +601,7 @@ pub trait Read { + /// file.) + /// + /// [`std::fs::read`]: ../fs/fn.read.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -656,7 +644,7 @@ pub trait Read { + /// reading from a file.) + /// + /// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -719,7 +707,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -771,7 +758,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -808,7 +794,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } +@@ -843,7 +828,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -879,42 +863,77 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + ++#[cfg(feature="collections")] ++pub struct IoVecBuffer<'a>(&'a [u8]); ++ ++#[cfg(feature="collections")] ++impl<'a> IoVecBuffer<'a> { ++ #[inline] ++ pub fn new(buf: &'a [u8]) -> IoVecBuffer<'a> { ++ IoVecBuffer(buf) ++ } ++ ++ #[inline] ++ pub fn as_slice(&self) -> &[u8] { ++ self.0 ++ } ++} ++#[cfg(feature="collections")] ++pub struct IoVecMutBuffer<'a>(&'a mut [u8]); ++ ++#[cfg(feature="collections")] ++impl<'a> IoVecMutBuffer<'a> { ++ #[inline] ++ pub fn new(buf: &'a mut [u8]) -> IoVecMutBuffer<'a> { ++ IoVecMutBuffer(buf) ++ } ++ ++ #[inline] ++ pub fn as_slice(&self) -> &[u8] { ++ self.0 ++ } ++ ++ #[inline] ++ pub fn as_mut_slice(&mut self) -> &mut [u8] { ++ self.0 ++ } ++} ++ + /// A buffer type used with `Read::read_vectored`. + /// + /// It is semantically a wrapper around an `&mut [u8]`, but is guaranteed to be + /// ABI compatible with the `iovec` type on Unix platforms and `WSABUF` on + /// Windows. +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + #[repr(transparent)] +-pub struct IoVecMut<'a>(sys::io::IoVecMut<'a>); ++pub struct IoVecMut<'a>(IoVecMutBuffer<'a>); + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> fmt::Debug for IoVecMut<'a> { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(self.0.as_slice(), fmt) + } + } + ++#[cfg(feature="collections")] + impl<'a> IoVecMut<'a> { + /// Creates a new `IoVecMut` wrapping a byte slice. + /// + /// # Panics + /// + /// Panics on Windows if the slice is larger than 4GB. +- #[unstable(feature = "iovec", issue = "58452")] + #[inline] + pub fn new(buf: &'a mut [u8]) -> IoVecMut<'a> { +- IoVecMut(sys::io::IoVecMut::new(buf)) ++ IoVecMut(IoVecMutBuffer::new(buf)) + } + } + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> Deref for IoVecMut<'a> { + type Target = [u8]; + +@@ -924,7 +943,7 @@ impl<'a> Deref for IoVecMut<'a> { + } + } + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> DerefMut for IoVecMut<'a> { + #[inline] + fn deref_mut(&mut self) -> &mut [u8] { +@@ -937,31 +956,31 @@ impl<'a> DerefMut for IoVecMut<'a> { + /// It is semantically a wrapper around an `&[u8]`, but is guaranteed to be + /// ABI compatible with the `iovec` type on Unix platforms and `WSABUF` on + /// Windows. +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + #[repr(transparent)] +-pub struct IoVec<'a>(sys::io::IoVec<'a>); ++pub struct IoVec<'a>(IoVecBuffer<'a>); + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> fmt::Debug for IoVec<'a> { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(self.0.as_slice(), fmt) + } + } + ++#[cfg(feature="collections")] + impl<'a> IoVec<'a> { + /// Creates a new `IoVec` wrapping a byte slice. + /// + /// # Panics + /// + /// Panics on Windows if the slice is larger than 4GB. +- #[unstable(feature = "iovec", issue = "58452")] + #[inline] + pub fn new(buf: &'a [u8]) -> IoVec<'a> { +- IoVec(sys::io::IoVec::new(buf)) ++ IoVec(IoVecBuffer::new(buf)) + } + } + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> Deref for IoVec<'a> { + type Target = [u8]; + +@@ -972,13 +991,11 @@ impl<'a> Deref for IoVec<'a> { + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -992,21 +1009,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -1049,7 +1063,6 @@ impl Initializer { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this writer, returning how many bytes were written. +@@ -1098,7 +1111,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Like `write`, except that it writes from a slice of buffers. +@@ -1109,7 +1121,7 @@ pub trait Write { + /// + /// The default implementation simply passes the first nonempty buffer to + /// `write`. +- #[unstable(feature = "iovec", issue = "58452")] ++ #[cfg(feature="collections")] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> Result { + match bufs.iter().find(|b| !b.is_empty()) { + Some(buf) => self.write(buf), +@@ -1140,7 +1152,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this writer. +@@ -1173,7 +1184,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1225,7 +1235,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1281,7 +1290,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1311,7 +1319,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1327,7 +1334,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + } + +@@ -1337,29 +1343,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Sets the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Sets the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Sets the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1439,7 +1442,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Returns the contents of the internal buffer, filling it with more data + /// from the inner reader if it is empty. +@@ -1485,7 +1488,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1507,7 +1509,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1563,7 +1564,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1622,7 +1622,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1663,7 +1662,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1702,7 +1700,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1714,7 +1711,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1740,7 +1736,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1763,7 +1758,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1790,13 +1784,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1806,7 +1798,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1818,6 +1809,7 @@ impl Read for Chain { + self.second.read(buf) + } + ++ #[cfg(feature="collections")] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> Result { + if !self.done_first { + match self.first.read_vectored(bufs)? { +@@ -1838,7 +1830,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1865,7 +1857,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -1900,7 +1891,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -1926,7 +1916,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "take_set_limit", since = "1.27.0")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -1951,7 +1940,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -1976,7 +1964,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -2005,13 +1992,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -2028,15 +2013,9 @@ impl Read for Take { + unsafe fn initializer(&self) -> Initializer { + self.inner.initializer() + } +- +- fn read_to_end(&mut self, buf: &mut Vec) -> Result { +- let reservation_size = cmp::min(self.limit, 32) as usize; +- +- read_to_end_with_reservation(self, buf, reservation_size) +- } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -2063,13 +2042,11 @@ impl BufRead for Take { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -2093,14 +2070,14 @@ impl Iterator for Bytes { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -2125,13 +2102,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 2e19edf..66294a3 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -8,7 +8,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 5ce955e..c7d8697 100644 +--- a/util.rs ++++ b/util.rs +@@ -1,8 +1,9 @@ + #![allow(missing_copy_implementations)] + +-use fmt; +-use io::{self, Read, Initializer, Write, ErrorKind, BufRead, IoVec, IoVecMut}; +-use mem; ++use core::fmt; ++use io::{self, Read, Initializer, Write, ErrorKind}; ++use core::mem; ++#[cfg(feature="collections")] use io::{BufRead, IoVec, IoVecMut}; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -39,7 +40,6 @@ use mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -68,7 +68,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -88,10 +87,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -101,7 +98,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -109,7 +107,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -122,7 +119,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -139,10 +135,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -152,6 +146,7 @@ impl Read for Repeat { + Ok(buf.len()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let mut nwritten = 0; +@@ -167,7 +162,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -180,7 +174,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -197,14 +190,13 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + let total_len = bufs.iter().map(|b| b.len()).sum(); +@@ -215,7 +207,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/14ebca5c1986b55c39b5711c0cb33850afdc0a0c.patch b/patches/14ebca5c1986b55c39b5711c0cb33850afdc0a0c.patch new file mode 100644 index 0000000..5cd3760 --- /dev/null +++ b/patches/14ebca5c1986b55c39b5711c0cb33850afdc0a0c.patch @@ -0,0 +1,1611 @@ +diff --git a/buffered.rs b/buffered.rs +index 7aaf89c..c546b8b 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -10,13 +10,13 @@ + + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use io::prelude::*; + +-use cmp; +-use error; +-use fmt; ++use core::cmp; ++use core::fmt; + use io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom}; +-use memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -52,7 +52,6 @@ use memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -76,7 +75,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -97,7 +95,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -130,7 +127,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -151,7 +147,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + + /// Returns a reference to the internally buffered data. +@@ -176,7 +171,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -199,7 +193,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + } + +@@ -208,7 +201,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -228,7 +220,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -251,7 +242,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -271,7 +261,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -281,7 +270,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -390,7 +378,6 @@ impl Seek for BufReader { + /// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -425,7 +412,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -440,7 +426,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -458,7 +443,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -507,7 +491,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -525,7 +508,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Returns a reference to the internally buffered data. +@@ -542,7 +524,6 @@ impl BufWriter { + /// // See how many bytes are currently buffered + /// let bytes_buffered = buf_writer.buffer().len(); + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf + } +@@ -566,7 +547,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -575,7 +555,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -595,7 +574,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -605,7 +583,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -615,7 +592,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -654,7 +630,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -687,23 +662,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -774,7 +739,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -795,7 +759,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -816,7 +779,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -840,7 +802,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -863,7 +824,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -889,7 +849,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -900,7 +859,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -945,7 +903,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index f7a9033..d97489f 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -10,8 +10,8 @@ + + use io::prelude::*; + +-use core::convert::TryInto; +-use cmp; ++#[cfg(feature="collections")] use core::convert::TryInto; ++use core::cmp; + use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + + /// A `Cursor` wraps an in-memory buffer and provides it with a +@@ -80,7 +80,6 @@ use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -103,7 +102,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -121,7 +119,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -137,7 +134,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -156,7 +152,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -178,7 +173,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -198,11 +192,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -223,17 +215,16 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -244,12 +235,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -262,6 +257,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result, buf: &[u8]) -> io::Result { + let pos: usize = (*pos_mut).try_into().map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -288,7 +284,6 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result Write for Cursor<&'a mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -297,7 +292,7 @@ impl<'a> Write for Cursor<&'a mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl<'a> Write for Cursor<&'a mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) +@@ -305,7 +300,7 @@ impl<'a> Write for Cursor<&'a mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) +@@ -313,8 +308,8 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) +diff --git a/error.rs b/error.rs +index 3248523..f1eec94 100644 +--- a/error.rs ++++ b/error.rs +@@ -8,11 +8,16 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use error; +-use fmt; +-use result; +-use sys; +-use convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -48,7 +53,6 @@ use convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -62,12 +66,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -77,13 +79,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -95,48 +100,35 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + #[non_exhaustive] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -148,10 +140,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -162,15 +152,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -179,7 +166,6 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + } + +@@ -210,7 +196,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + /// Converts an [`ErrorKind`] into an [`Error`]. + /// +@@ -255,14 +240,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -271,24 +255,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -314,7 +280,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -345,7 +310,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -379,12 +343,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(dyn error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -450,12 +413,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -484,8 +446,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -511,10 +472,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -526,22 +486,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -549,25 +505,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- #[allow(deprecated)] +- fn cause(&self) -> Option<&dyn error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index fe1179a..452b8b7 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -8,15 +8,18 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use cmp; +-use io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind}; +-use fmt; +-use mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use io::BufRead; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, R: Read + ?Sized> Read for &'a mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -28,11 +31,13 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -43,7 +48,6 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, W: Write + ?Sized> Write for &'a mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -61,12 +65,11 @@ impl<'a, W: Write + ?Sized> Write for &'a mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, S: Seek + ?Sized> Seek for &'a mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -85,7 +88,7 @@ impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -97,11 +100,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -112,7 +117,7 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -130,12 +135,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -161,7 +166,6 @@ impl BufRead for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Read for &'a [u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -207,6 +211,7 @@ impl<'a> Read for &'a [u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -216,7 +221,7 @@ impl<'a> Read for &'a [u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a> BufRead for &'a [u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -230,7 +235,6 @@ impl<'a> BufRead for &'a [u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Write for &'a mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -256,7 +260,7 @@ impl<'a> Write for &'a mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +diff --git a/mod.rs b/mod.rs +index 5137a94..da64ab7 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -267,48 +267,37 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use cmp; +-use fmt; +-use slice; +-use str; +-use memchr; +-use ptr; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::cmp; ++use core::fmt; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++use core::ptr; ++use core::slice; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl<'a> Drop for Guard<'a> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -333,6 +322,7 @@ impl<'a> Drop for Guard<'a> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -360,10 +350,12 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + read_to_end_with_reservation(r, buf, 32) + } + ++#[cfg(feature="collections")] + fn read_to_end_with_reservation(r: &mut R, + buf: &mut Vec, + reservation_size: usize) -> Result +@@ -470,7 +462,6 @@ fn read_to_end_with_reservation(r: &mut R, + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -527,7 +518,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Determines if this `Read`er can work with buffers of uninitialized +@@ -552,7 +542,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -605,7 +594,7 @@ pub trait Read { + /// file.) + /// + /// [`std::fs::read`]: ../fs/fn.read.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -648,7 +637,7 @@ pub trait Read { + /// reading from a file.) + /// + /// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -711,7 +700,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -763,7 +751,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -800,7 +787,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } +@@ -835,7 +821,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -871,20 +856,17 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -898,21 +880,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -955,7 +934,6 @@ impl Initializer { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this object, returning how many bytes were written. +@@ -1004,7 +982,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Flush this output stream, ensuring that all intermediately buffered +@@ -1030,7 +1007,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this write. +@@ -1063,7 +1039,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1115,7 +1090,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1171,7 +1145,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1201,7 +1174,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1217,7 +1189,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + } + +@@ -1227,29 +1198,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Set the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Set the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Set the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1329,7 +1297,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Returns the contents of the internal buffer, filling it with more data + /// from the inner reader if it is empty. +@@ -1375,7 +1343,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1397,7 +1364,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1453,7 +1419,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1512,7 +1477,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1553,7 +1517,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1592,7 +1555,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1604,7 +1566,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1630,7 +1591,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1653,7 +1613,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1680,13 +1639,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1696,7 +1653,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1718,7 +1674,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1745,7 +1701,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -1780,7 +1735,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -1806,7 +1760,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "take_set_limit", since = "1.27.0")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -1831,7 +1784,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -1856,7 +1808,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -1885,13 +1836,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -1908,15 +1857,9 @@ impl Read for Take { + unsafe fn initializer(&self) -> Initializer { + self.inner.initializer() + } +- +- fn read_to_end(&mut self, buf: &mut Vec) -> Result { +- let reservation_size = cmp::min(self.limit, 32) as usize; +- +- read_to_end_with_reservation(self, buf, reservation_size) +- } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -1943,13 +1886,11 @@ impl BufRead for Take { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -1973,14 +1914,14 @@ impl Iterator for Bytes { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -2005,13 +1946,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 8772d0f..49d66c9 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -18,7 +18,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 12995d0..397eef4 100644 +--- a/util.rs ++++ b/util.rs +@@ -10,9 +10,10 @@ + + #![allow(missing_copy_implementations)] + +-use fmt; +-use io::{self, Read, Initializer, Write, ErrorKind, BufRead}; +-use mem; ++use core::fmt; ++use io::{self, Read, Initializer, Write, ErrorKind}; ++use core::mem; ++#[cfg(feature="collections")] use io::BufRead; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -49,7 +50,6 @@ use mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -78,7 +78,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -98,10 +97,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -111,7 +108,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -119,7 +117,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -132,7 +129,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -149,10 +145,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -168,7 +162,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -181,7 +174,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -198,10 +190,8 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } +@@ -209,7 +199,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/16da5d4bb2d65a4d533d1da2a4e0d288d3a474c5.patch b/patches/16da5d4bb2d65a4d533d1da2a4e0d288d3a474c5.patch new file mode 100644 index 0000000..8e4e149 --- /dev/null +++ b/patches/16da5d4bb2d65a4d533d1da2a4e0d288d3a474c5.patch @@ -0,0 +1,1693 @@ +diff --git a/buffered.rs b/buffered.rs +index ccaa19a..c8ff47e 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -10,13 +10,13 @@ + + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use io::prelude::*; + +-use cmp; +-use error; +-use fmt; ++use core::cmp; ++use core::fmt; + use io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom}; +-use memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -46,7 +46,6 @@ use memchr; + /// # Ok(()) + /// # } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -69,7 +68,6 @@ impl BufReader { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -90,7 +88,6 @@ impl BufReader { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -123,7 +120,6 @@ impl BufReader { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -144,35 +140,8 @@ impl BufReader { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + +- /// Returns `true` if there are no bytes in the internal buffer. +- /// +- /// # Examples +- /// ``` +- /// # #![feature(bufreader_is_empty)] +- /// use std::io::BufReader; +- /// use std::io::BufRead; +- /// use std::fs::File; +- /// +- /// # fn foo() -> std::io::Result<()> { +- /// let f1 = File::open("log.txt")?; +- /// let mut reader = BufReader::new(f1); +- /// assert!(reader.is_empty()); +- /// +- /// if reader.fill_buf()?.len() > 0 { +- /// assert!(!reader.is_empty()); +- /// } +- /// # Ok(()) +- /// # } +- /// ``` +- #[unstable(feature = "bufreader_is_empty", issue = "45323", reason = "recently added")] +- #[rustc_deprecated(since = "1.26.0", reason = "use .buffer().is_empty() instead")] +- pub fn is_empty(&self) -> bool { +- self.buffer().is_empty() +- } +- + /// Returns a reference to the internally buffered data. + /// + /// Unlike `fill_buf`, this will not attempt to fill the buffer if it is empty. +@@ -195,7 +164,6 @@ impl BufReader { + /// # Ok(()) + /// # } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -218,7 +186,6 @@ impl BufReader { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + } + +@@ -227,7 +194,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -247,7 +213,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -270,7 +235,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -290,7 +254,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -300,7 +263,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -402,7 +364,6 @@ impl Seek for BufReader { + /// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -437,7 +398,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -451,7 +411,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -469,7 +428,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -518,7 +476,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -536,7 +493,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Unwraps this `BufWriter`, returning the underlying writer. +@@ -558,7 +514,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -567,7 +522,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -587,7 +541,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -597,7 +550,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -607,7 +559,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -646,7 +597,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -679,23 +629,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -753,7 +693,6 @@ impl fmt::Display for IntoInnerError { + /// # Ok(()) + /// # } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -774,7 +713,6 @@ impl LineWriter { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -795,7 +733,6 @@ impl LineWriter { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -819,7 +756,6 @@ impl LineWriter { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -842,7 +778,6 @@ impl LineWriter { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -868,7 +803,6 @@ impl LineWriter { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -879,7 +813,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -924,7 +857,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index 76bcb5f..dcc64c6 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -8,10 +8,11 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + ++use core::prelude::v1::*; + use io::prelude::*; + +-use core::convert::TryInto; +-use cmp; ++#[cfg(feature = "collections")] use core::convert::TryInto; ++use core::cmp; + use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + + /// A `Cursor` wraps another type and provides it with a +@@ -79,7 +80,6 @@ use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -102,7 +102,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -120,7 +119,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -136,7 +134,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -155,7 +152,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -177,7 +173,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -197,11 +192,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -222,17 +215,16 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -243,12 +235,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -261,6 +257,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result, buf: &[u8]) -> io::Result { + let pos: usize = (*pos_mut).try_into().map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -287,7 +284,6 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result Write for Cursor<&'a mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -296,7 +292,7 @@ impl<'a> Write for Cursor<&'a mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl<'a> Write for Cursor<&'a mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) +@@ -304,7 +300,7 @@ impl<'a> Write for Cursor<&'a mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) +@@ -312,8 +308,8 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) +diff --git a/error.rs b/error.rs +index bdd675e..3acdadf 100644 +--- a/error.rs ++++ b/error.rs +@@ -8,11 +8,16 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use error; +-use fmt; +-use result; +-use sys; +-use convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -48,7 +53,6 @@ use convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -62,12 +66,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -77,13 +79,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -95,47 +100,34 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -147,10 +139,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -161,15 +151,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -178,15 +165,10 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + + /// A marker variant that tells the compiler that users of this enum cannot + /// match it exhaustively. +- #[unstable(feature = "io_error_internals", +- reason = "better expressed through extensible enums that this \ +- enum cannot be exhaustively matched against", +- issue = "0")] + #[doc(hidden)] + __Nonexhaustive, + } +@@ -219,7 +201,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + #[inline] + fn from(kind: ErrorKind) -> Error { +@@ -248,14 +229,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -264,24 +244,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -307,7 +269,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -338,7 +299,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -372,12 +332,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -443,12 +402,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -477,8 +435,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -504,10 +461,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -519,22 +475,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -542,24 +494,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- fn cause(&self) -> Option<&error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index fe1179a..452b8b7 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -8,15 +8,18 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use cmp; +-use io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind}; +-use fmt; +-use mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use io::BufRead; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, R: Read + ?Sized> Read for &'a mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -28,11 +31,13 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -43,7 +48,6 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, W: Write + ?Sized> Write for &'a mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -61,12 +65,11 @@ impl<'a, W: Write + ?Sized> Write for &'a mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, S: Seek + ?Sized> Seek for &'a mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -85,7 +88,7 @@ impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -97,11 +100,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -112,7 +117,7 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -130,12 +135,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -161,7 +166,6 @@ impl BufRead for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Read for &'a [u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -207,6 +211,7 @@ impl<'a> Read for &'a [u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -216,7 +221,7 @@ impl<'a> Read for &'a [u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a> BufRead for &'a [u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -230,7 +235,6 @@ impl<'a> BufRead for &'a [u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Write for &'a mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -256,7 +260,7 @@ impl<'a> Write for &'a mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +diff --git a/mod.rs b/mod.rs +index d403bf6..c6c236e 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -268,50 +268,38 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use cmp; ++use core::cmp; + use core::str as core_str; +-use error as std_error; +-use fmt; +-use result; +-use str; +-use memchr; +-use ptr; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::fmt; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++use core::ptr; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl<'a> Drop for Guard<'a> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -336,6 +324,7 @@ impl<'a> Drop for Guard<'a> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -363,6 +352,7 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + let start_len = buf.len(); + let mut g = Guard { len: buf.len(), buf: buf }; +@@ -466,7 +456,6 @@ fn read_to_end(r: &mut R, buf: &mut Vec) -> Result + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -523,7 +512,6 @@ pub trait Read { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Determines if this `Read`er can work with buffers of uninitialized +@@ -548,7 +536,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -596,7 +583,7 @@ pub trait Read { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -634,7 +621,7 @@ pub trait Read { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -697,7 +684,6 @@ pub trait Read { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -749,7 +735,6 @@ pub trait Read { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -786,7 +771,6 @@ pub trait Read { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } +@@ -827,10 +811,6 @@ pub trait Read { + /// # Ok(()) + /// # } + /// ``` +- #[unstable(feature = "io", reason = "the semantics of a partial read/write \ +- of where errors happen is currently \ +- unclear and may change", +- issue = "27802")] + fn chars(self) -> Chars where Self: Sized { + Chars { inner: self } + } +@@ -865,7 +845,6 @@ pub trait Read { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -901,20 +880,17 @@ pub trait Read { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -928,21 +904,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -985,7 +958,6 @@ impl Initializer { + /// # Ok(()) + /// # } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this object, returning how many bytes were written. +@@ -1034,7 +1006,6 @@ pub trait Write { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Flush this output stream, ensuring that all intermediately buffered +@@ -1060,7 +1031,6 @@ pub trait Write { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this write. +@@ -1093,7 +1063,6 @@ pub trait Write { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1145,7 +1114,6 @@ pub trait Write { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1201,7 +1169,6 @@ pub trait Write { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1231,7 +1198,6 @@ pub trait Write { + /// # Ok(()) + /// # } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1247,7 +1213,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + } + +@@ -1257,29 +1222,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Set the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Set the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Set the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1359,7 +1321,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// # } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Fills the internal buffer of this object, returning the buffer contents. + /// +@@ -1404,7 +1366,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1426,7 +1387,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1482,7 +1442,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1541,7 +1500,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1582,7 +1540,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1621,7 +1578,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1633,7 +1589,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1659,7 +1614,6 @@ impl Chain { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1682,7 +1636,6 @@ impl Chain { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1709,13 +1662,11 @@ impl Chain { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1725,7 +1676,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1747,7 +1697,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1774,7 +1724,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -1809,7 +1758,6 @@ impl Take { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -1836,7 +1784,6 @@ impl Take { + /// # Ok(()) + /// # } + /// ``` +- #[unstable(feature = "take_set_limit", issue = "42781")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -1861,7 +1808,6 @@ impl Take { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -1886,7 +1832,6 @@ impl Take { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -1915,13 +1860,11 @@ impl Take { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -1940,7 +1883,7 @@ impl Read for Take { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -1979,13 +1922,11 @@ fn read_one_byte(reader: &mut Read) -> Option> { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -2000,8 +1941,6 @@ impl Iterator for Bytes { + /// Please see the documentation of `chars()` for more details. + /// + /// [chars]: trait.Read.html#method.chars +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] + #[derive(Debug)] + pub struct Chars { + inner: R, +@@ -2010,8 +1949,6 @@ pub struct Chars { + /// An enumeration of possible errors that can be generated from the `Chars` + /// adapter. + #[derive(Debug)] +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] + pub enum CharsError { + /// Variant representing that the underlying stream was read successfully + /// but it did not contain valid utf8 data. +@@ -2021,8 +1958,6 @@ pub enum CharsError { + Other(Error), + } + +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] + impl Iterator for Chars { + type Item = result::Result; + +@@ -2053,25 +1988,6 @@ impl Iterator for Chars { + } + } + +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] +-impl std_error::Error for CharsError { +- fn description(&self) -> &str { +- match *self { +- CharsError::NotUtf8 => "invalid utf8 encoding", +- CharsError::Other(ref e) => std_error::Error::description(e), +- } +- } +- fn cause(&self) -> Option<&std_error::Error> { +- match *self { +- CharsError::NotUtf8 => None, +- CharsError::Other(ref e) => e.cause(), +- } +- } +-} +- +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] + impl fmt::Display for CharsError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match *self { +@@ -2090,14 +2006,14 @@ impl fmt::Display for CharsError { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -2122,13 +2038,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 8772d0f..49d66c9 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -18,7 +18,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 45d281e..0efc3b1 100644 +--- a/util.rs ++++ b/util.rs +@@ -10,9 +10,10 @@ + + #![allow(missing_copy_implementations)] + +-use fmt; +-use io::{self, Read, Initializer, Write, ErrorKind, BufRead}; +-use mem; ++use core::fmt; ++use io::{self, Read, Initializer, Write, ErrorKind}; ++use core::mem; ++#[cfg(feature="collections")] use io::BufRead; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -45,7 +46,6 @@ use mem; + /// # } + /// # foo().unwrap(); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -74,7 +74,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -94,10 +93,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -107,7 +104,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -115,7 +113,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -128,7 +125,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -145,10 +141,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte: byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -164,7 +158,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -177,7 +170,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -194,10 +186,8 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } +@@ -205,7 +195,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/1ed91951c3012e9aabb403d28b902c56cc143907.patch b/patches/1ed91951c3012e9aabb403d28b902c56cc143907.patch new file mode 100644 index 0000000..ddaa74c --- /dev/null +++ b/patches/1ed91951c3012e9aabb403d28b902c56cc143907.patch @@ -0,0 +1,1608 @@ +diff --git a/buffered.rs b/buffered.rs +index 476ee3f..d696d37 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -10,13 +10,13 @@ + + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use io::prelude::*; + +-use cmp; +-use error; +-use fmt; ++use core::cmp; ++use core::fmt; + use io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom}; +-use memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -52,7 +52,6 @@ use memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -76,7 +75,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -97,7 +95,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -130,7 +127,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -151,7 +147,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + + /// Returns a reference to the internally buffered data. +@@ -176,7 +171,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -199,7 +193,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + } + +@@ -208,7 +201,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -228,7 +220,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -251,7 +242,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -271,7 +261,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -281,7 +270,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -387,7 +375,6 @@ impl Seek for BufReader { + /// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -422,7 +409,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -437,7 +423,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -455,7 +440,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -504,7 +488,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -522,7 +505,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Returns a reference to the internally buffered data. +@@ -539,7 +521,6 @@ impl BufWriter { + /// // See how many bytes are currently buffered + /// let bytes_buffered = buf_writer.buffer().len(); + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf + } +@@ -563,7 +544,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -572,7 +552,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -592,7 +571,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -602,7 +580,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -612,7 +589,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -651,7 +627,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -684,23 +659,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -771,7 +736,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -792,7 +756,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -813,7 +776,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -837,7 +799,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -860,7 +821,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -886,7 +846,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -897,7 +856,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -942,7 +900,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index 14f2015..1d60dac 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -10,8 +10,8 @@ + + use io::prelude::*; + +-use core::convert::TryInto; +-use cmp; ++#[cfg(feature="collections")] use core::convert::TryInto; ++use core::cmp; + use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + + /// A `Cursor` wraps an in-memory buffer and provides it with a +@@ -80,7 +80,6 @@ use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -103,7 +102,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -121,7 +119,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -137,7 +134,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -156,7 +152,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -178,7 +173,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -198,11 +192,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -223,17 +215,16 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -244,12 +235,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -262,6 +257,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result, buf: &[u8]) -> io::Result { + let pos: usize = (*pos_mut).try_into().map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -288,7 +284,6 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result Write for Cursor<&'a mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -297,7 +292,7 @@ impl<'a> Write for Cursor<&'a mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl<'a> Write for Cursor<&'a mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) +@@ -305,7 +300,7 @@ impl<'a> Write for Cursor<&'a mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) +@@ -313,8 +308,8 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) +diff --git a/error.rs b/error.rs +index 386de08..4a9559a 100644 +--- a/error.rs ++++ b/error.rs +@@ -8,11 +8,16 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use error; +-use fmt; +-use result; +-use sys; +-use convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -48,7 +53,6 @@ use convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -62,12 +66,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -77,13 +79,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -95,48 +100,35 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + #[non_exhaustive] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -148,10 +140,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -162,15 +152,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -179,7 +166,6 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + } + +@@ -210,7 +196,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + /// Converts an [`ErrorKind`] into an [`Error`]. + /// +@@ -252,14 +237,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -268,24 +252,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -311,7 +277,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -342,7 +307,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -376,12 +340,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(dyn error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -447,12 +410,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -481,8 +443,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -508,10 +469,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -523,22 +483,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -546,24 +502,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- fn cause(&self) -> Option<&dyn error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index fe1179a..452b8b7 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -8,15 +8,18 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use cmp; +-use io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind}; +-use fmt; +-use mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use io::BufRead; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, R: Read + ?Sized> Read for &'a mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -28,11 +31,13 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -43,7 +48,6 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, W: Write + ?Sized> Write for &'a mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -61,12 +65,11 @@ impl<'a, W: Write + ?Sized> Write for &'a mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, S: Seek + ?Sized> Seek for &'a mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -85,7 +88,7 @@ impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -97,11 +100,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -112,7 +117,7 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -130,12 +135,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -161,7 +166,6 @@ impl BufRead for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Read for &'a [u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -207,6 +211,7 @@ impl<'a> Read for &'a [u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -216,7 +221,7 @@ impl<'a> Read for &'a [u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a> BufRead for &'a [u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -230,7 +235,6 @@ impl<'a> BufRead for &'a [u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Write for &'a mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -256,7 +260,7 @@ impl<'a> Write for &'a mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +diff --git a/mod.rs b/mod.rs +index 076524e..0aa9ade 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -267,47 +267,36 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use cmp; +-use fmt; +-use str; +-use memchr; +-use ptr; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::cmp; ++use core::fmt; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++use core::ptr; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl<'a> Drop for Guard<'a> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -332,6 +321,7 @@ impl<'a> Drop for Guard<'a> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -359,10 +349,12 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + read_to_end_with_reservation(r, buf, 32) + } + ++#[cfg(feature="collections")] + fn read_to_end_with_reservation(r: &mut R, + buf: &mut Vec, + reservation_size: usize) -> Result +@@ -469,7 +461,6 @@ fn read_to_end_with_reservation(r: &mut R, + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -526,7 +517,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Determines if this `Read`er can work with buffers of uninitialized +@@ -551,7 +541,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -604,7 +593,7 @@ pub trait Read { + /// file.) + /// + /// [`std::fs::read`]: ../fs/fn.read.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -647,7 +636,7 @@ pub trait Read { + /// reading from a file.) + /// + /// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -710,7 +699,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -762,7 +750,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -799,7 +786,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } +@@ -834,7 +820,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -870,20 +855,17 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -897,21 +879,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -954,7 +933,6 @@ impl Initializer { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this object, returning how many bytes were written. +@@ -1003,7 +981,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Flush this output stream, ensuring that all intermediately buffered +@@ -1029,7 +1006,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this write. +@@ -1062,7 +1038,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1114,7 +1089,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1170,7 +1144,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1200,7 +1173,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1216,7 +1188,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + } + +@@ -1226,29 +1197,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Set the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Set the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Set the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1328,7 +1296,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Returns the contents of the internal buffer, filling it with more data + /// from the inner reader if it is empty. +@@ -1374,7 +1342,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1396,7 +1363,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1452,7 +1418,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1511,7 +1476,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1552,7 +1516,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1591,7 +1554,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1603,7 +1565,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1629,7 +1590,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1652,7 +1612,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1679,13 +1638,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1695,7 +1652,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1717,7 +1673,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1744,7 +1700,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -1779,7 +1734,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -1805,7 +1759,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "take_set_limit", since = "1.27.0")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -1830,7 +1783,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -1855,7 +1807,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -1884,13 +1835,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -1907,15 +1856,9 @@ impl Read for Take { + unsafe fn initializer(&self) -> Initializer { + self.inner.initializer() + } +- +- fn read_to_end(&mut self, buf: &mut Vec) -> Result { +- let reservation_size = cmp::min(self.limit, 32) as usize; +- +- read_to_end_with_reservation(self, buf, reservation_size) +- } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -1954,13 +1897,11 @@ fn read_one_byte(reader: &mut dyn Read) -> Option> { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -1976,14 +1917,14 @@ impl Iterator for Bytes { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -2008,13 +1949,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 8772d0f..49d66c9 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -18,7 +18,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 12995d0..397eef4 100644 +--- a/util.rs ++++ b/util.rs +@@ -10,9 +10,10 @@ + + #![allow(missing_copy_implementations)] + +-use fmt; +-use io::{self, Read, Initializer, Write, ErrorKind, BufRead}; +-use mem; ++use core::fmt; ++use io::{self, Read, Initializer, Write, ErrorKind}; ++use core::mem; ++#[cfg(feature="collections")] use io::BufRead; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -49,7 +50,6 @@ use mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -78,7 +78,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -98,10 +97,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -111,7 +108,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -119,7 +117,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -132,7 +129,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -149,10 +145,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -168,7 +162,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -181,7 +174,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -198,10 +190,8 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } +@@ -209,7 +199,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/210a2a2b9e5f7bc105897654bfea0f9cc7c8d89f.patch b/patches/210a2a2b9e5f7bc105897654bfea0f9cc7c8d89f.patch new file mode 100644 index 0000000..3ba1d2f --- /dev/null +++ b/patches/210a2a2b9e5f7bc105897654bfea0f9cc7c8d89f.patch @@ -0,0 +1,1704 @@ +diff --git a/buffered.rs b/buffered.rs +index d6eac74..e64536c 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -10,13 +10,13 @@ + + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use io::prelude::*; + +-use cmp; +-use error; +-use fmt; ++use core::cmp; ++use core::fmt; + use io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom}; +-use memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -52,7 +52,6 @@ use memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -75,7 +74,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -96,7 +94,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -129,7 +126,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -150,36 +146,8 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + +- /// Returns `true` if there are no bytes in the internal buffer. +- /// +- /// # Examples +- // +- /// ```no_run +- /// # #![feature(bufreader_is_empty)] +- /// use std::io::BufReader; +- /// use std::io::BufRead; +- /// use std::fs::File; +- /// +- /// fn main() -> std::io::Result<()> { +- /// let f1 = File::open("log.txt")?; +- /// let mut reader = BufReader::new(f1); +- /// assert!(reader.is_empty()); +- /// +- /// if reader.fill_buf()?.len() > 0 { +- /// assert!(!reader.is_empty()); +- /// } +- /// Ok(()) +- /// } +- /// ``` +- #[unstable(feature = "bufreader_is_empty", issue = "45323", reason = "recently added")] +- #[rustc_deprecated(since = "1.26.0", reason = "use .buffer().is_empty() instead")] +- pub fn is_empty(&self) -> bool { +- self.buffer().is_empty() +- } +- + /// Returns a reference to the internally buffered data. + /// + /// Unlike `fill_buf`, this will not attempt to fill the buffer if it is empty. +@@ -202,7 +170,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -225,7 +192,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + } + +@@ -234,7 +200,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -254,7 +219,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -277,7 +241,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -297,7 +260,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -307,7 +269,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -415,7 +376,6 @@ impl Seek for BufReader { + /// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -450,7 +410,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -464,7 +423,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -482,7 +440,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -531,7 +488,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -549,7 +505,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Unwraps this `BufWriter`, returning the underlying writer. +@@ -571,7 +526,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -580,7 +534,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -600,7 +553,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -610,7 +562,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -620,7 +571,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -659,7 +609,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -692,23 +641,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -766,7 +705,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -787,7 +725,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -808,7 +745,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -832,7 +768,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -855,7 +790,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -881,7 +815,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -892,7 +825,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -937,7 +869,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index 2673f3c..5b2e073 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -10,7 +10,7 @@ + + use io::prelude::*; + +-use cmp; ++use core::cmp; + use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + + /// A `Cursor` wraps another type and provides it with a +@@ -78,7 +78,6 @@ use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -101,7 +100,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -119,7 +117,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -135,7 +132,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -154,7 +150,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -176,7 +171,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -196,11 +190,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -221,17 +213,16 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -242,12 +233,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -261,6 +256,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result Result { +@@ -271,12 +267,14 @@ fn try_into(n: u64) -> Result { + } + } + ++#[cfg(feature="collections")] + #[cfg(any(target_pointer_width = "64"))] + fn try_into(n: u64) -> Result { + Ok(n as usize) + } + + // Resizing write implementation ++#[cfg(feature="collections")] + fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result { + let pos: usize = try_into(*pos_mut).map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -303,7 +301,6 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result Write for Cursor<&'a mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -312,7 +309,7 @@ impl<'a> Write for Cursor<&'a mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl<'a> Write for Cursor<&'a mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) +@@ -320,7 +317,7 @@ impl<'a> Write for Cursor<&'a mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) +@@ -328,8 +325,8 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) +diff --git a/error.rs b/error.rs +index bdd675e..3acdadf 100644 +--- a/error.rs ++++ b/error.rs +@@ -8,11 +8,16 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use error; +-use fmt; +-use result; +-use sys; +-use convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -48,7 +53,6 @@ use convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -62,12 +66,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -77,13 +79,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -95,47 +100,34 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -147,10 +139,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -161,15 +151,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -178,15 +165,10 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + + /// A marker variant that tells the compiler that users of this enum cannot + /// match it exhaustively. +- #[unstable(feature = "io_error_internals", +- reason = "better expressed through extensible enums that this \ +- enum cannot be exhaustively matched against", +- issue = "0")] + #[doc(hidden)] + __Nonexhaustive, + } +@@ -219,7 +201,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + #[inline] + fn from(kind: ErrorKind) -> Error { +@@ -248,14 +229,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -264,24 +244,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -307,7 +269,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -338,7 +299,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -372,12 +332,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -443,12 +402,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -477,8 +435,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -504,10 +461,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -519,22 +475,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -542,24 +494,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- fn cause(&self) -> Option<&error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index fe1179a..452b8b7 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -8,15 +8,18 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use cmp; +-use io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind}; +-use fmt; +-use mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use io::BufRead; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, R: Read + ?Sized> Read for &'a mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -28,11 +31,13 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -43,7 +48,6 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, W: Write + ?Sized> Write for &'a mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -61,12 +65,11 @@ impl<'a, W: Write + ?Sized> Write for &'a mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, S: Seek + ?Sized> Seek for &'a mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -85,7 +88,7 @@ impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -97,11 +100,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -112,7 +117,7 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -130,12 +135,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -161,7 +166,6 @@ impl BufRead for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Read for &'a [u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -207,6 +211,7 @@ impl<'a> Read for &'a [u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -216,7 +221,7 @@ impl<'a> Read for &'a [u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a> BufRead for &'a [u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -230,7 +235,6 @@ impl<'a> BufRead for &'a [u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Write for &'a mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -256,7 +260,7 @@ impl<'a> Write for &'a mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +diff --git a/mod.rs b/mod.rs +index b02e133..6e4440e 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -267,50 +267,38 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use cmp; ++use core::cmp; + use core::str as core_str; +-use error as std_error; +-use fmt; +-use result; +-use str; +-use memchr; +-use ptr; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::fmt; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++use core::ptr; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl<'a> Drop for Guard<'a> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -335,6 +323,7 @@ impl<'a> Drop for Guard<'a> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -362,6 +351,7 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + let start_len = buf.len(); + let mut g = Guard { len: buf.len(), buf: buf }; +@@ -465,7 +455,6 @@ fn read_to_end(r: &mut R, buf: &mut Vec) -> Result + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -522,7 +511,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Determines if this `Read`er can work with buffers of uninitialized +@@ -547,7 +535,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -600,7 +587,7 @@ pub trait Read { + /// file.) + /// + /// [`std::fs::read`]: ../fs/fn.read.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -643,7 +630,7 @@ pub trait Read { + /// reading from a file.) + /// + /// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -706,7 +693,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -758,7 +744,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -795,7 +780,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } +@@ -836,10 +820,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "io", reason = "the semantics of a partial read/write \ +- of where errors happen is currently \ +- unclear and may change", +- issue = "27802")] + fn chars(self) -> Chars where Self: Sized { + Chars { inner: self } + } +@@ -874,7 +854,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -910,20 +889,17 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -937,21 +913,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -994,7 +967,6 @@ impl Initializer { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this object, returning how many bytes were written. +@@ -1043,7 +1015,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Flush this output stream, ensuring that all intermediately buffered +@@ -1069,7 +1040,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this write. +@@ -1102,7 +1072,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1154,7 +1123,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1210,7 +1178,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1240,7 +1207,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1256,7 +1222,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + } + +@@ -1266,29 +1231,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Set the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Set the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Set the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1368,7 +1330,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Fills the internal buffer of this object, returning the buffer contents. + /// +@@ -1413,7 +1375,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1435,7 +1396,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1491,7 +1451,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1550,7 +1509,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1591,7 +1549,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1630,7 +1587,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1642,7 +1598,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1668,7 +1623,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1691,7 +1645,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1718,13 +1671,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1734,7 +1685,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1756,7 +1706,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1783,7 +1733,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -1818,7 +1767,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -1844,7 +1792,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "take_set_limit", since = "1.27.0")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -1869,7 +1816,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -1894,7 +1840,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -1923,13 +1868,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -1948,7 +1891,7 @@ impl Read for Take { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -1987,13 +1930,11 @@ fn read_one_byte(reader: &mut Read) -> Option> { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -2008,8 +1949,6 @@ impl Iterator for Bytes { + /// Please see the documentation of `chars()` for more details. + /// + /// [chars]: trait.Read.html#method.chars +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] + #[derive(Debug)] + pub struct Chars { + inner: R, +@@ -2018,8 +1957,6 @@ pub struct Chars { + /// An enumeration of possible errors that can be generated from the `Chars` + /// adapter. + #[derive(Debug)] +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] + pub enum CharsError { + /// Variant representing that the underlying stream was read successfully + /// but it did not contain valid utf8 data. +@@ -2029,8 +1966,6 @@ pub enum CharsError { + Other(Error), + } + +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] + impl Iterator for Chars { + type Item = result::Result; + +@@ -2061,25 +1996,6 @@ impl Iterator for Chars { + } + } + +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] +-impl std_error::Error for CharsError { +- fn description(&self) -> &str { +- match *self { +- CharsError::NotUtf8 => "invalid utf8 encoding", +- CharsError::Other(ref e) => std_error::Error::description(e), +- } +- } +- fn cause(&self) -> Option<&std_error::Error> { +- match *self { +- CharsError::NotUtf8 => None, +- CharsError::Other(ref e) => e.cause(), +- } +- } +-} +- +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] + impl fmt::Display for CharsError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match *self { +@@ -2098,14 +2014,14 @@ impl fmt::Display for CharsError { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -2130,13 +2046,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 8772d0f..49d66c9 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -18,7 +18,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 195310a..20755b7 100644 +--- a/util.rs ++++ b/util.rs +@@ -10,9 +10,10 @@ + + #![allow(missing_copy_implementations)] + +-use fmt; +-use io::{self, Read, Initializer, Write, ErrorKind, BufRead}; +-use mem; ++use core::fmt; ++use io::{self, Read, Initializer, Write, ErrorKind}; ++use core::mem; ++#[cfg(feature="collections")] use io::BufRead; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -44,7 +45,6 @@ use mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -73,7 +73,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -93,10 +92,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -106,7 +103,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -114,7 +112,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -127,7 +124,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -144,10 +140,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte: byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -163,7 +157,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -176,7 +169,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -193,10 +185,8 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } +@@ -204,7 +194,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/271eb8fc5a420280937bb1745f1e7aee7901ad26.patch b/patches/271eb8fc5a420280937bb1745f1e7aee7901ad26.patch new file mode 100644 index 0000000..ba1ec33 --- /dev/null +++ b/patches/271eb8fc5a420280937bb1745f1e7aee7901ad26.patch @@ -0,0 +1,1909 @@ +diff --git a/buffered.rs b/buffered.rs +index bf406bb..067523b 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -1,12 +1,12 @@ + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use crate::io::prelude::*; + +-use crate::cmp; +-use crate::error; +-use crate::fmt; ++use core::cmp; ++use core::fmt; + use crate::io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom, IoVec, IoVecMut}; +-use crate::memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -46,7 +46,6 @@ use crate::memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -70,7 +69,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -91,7 +89,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -126,7 +123,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -147,7 +143,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + + /// Returns a reference to the internally buffered data. +@@ -172,7 +167,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -195,7 +189,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + + /// Invalidates all data in the internal buffer. +@@ -211,7 +204,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -231,7 +223,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -269,7 +260,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -289,7 +279,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -299,7 +288,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -408,7 +396,6 @@ impl Seek for BufReader { + /// [`TcpStream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -443,7 +430,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -458,7 +444,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -476,7 +461,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -525,7 +509,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -543,7 +526,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Returns a reference to the internally buffered data. +@@ -560,7 +542,6 @@ impl BufWriter { + /// // See how many bytes are currently buffered + /// let bytes_buffered = buf_writer.buffer().len(); + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf + } +@@ -584,7 +565,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -593,7 +573,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -629,7 +608,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -639,7 +617,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -649,7 +626,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -688,7 +664,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -721,23 +696,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.error().fmt(f) +@@ -808,7 +773,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -829,7 +793,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -850,7 +813,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -874,7 +836,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -897,7 +858,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -923,7 +883,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -934,7 +893,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -979,7 +937,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index 247d45c..f13522d 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -1,9 +1,10 @@ + use crate::io::prelude::*; + +-use crate::cmp; +-use crate::io::{self, Initializer, SeekFrom, Error, ErrorKind, IoVec, IoVecMut}; ++use core::cmp; ++use crate::io::{self, Initializer, SeekFrom, Error, ErrorKind}; ++#[cfg(feature="collections")] use crate::io::{IoVec, IoVecMut}; + +-use core::convert::TryInto; ++#[cfg(feature="collections")] use core::convert::TryInto; + + /// A `Cursor` wraps an in-memory buffer and provides it with a + /// [`Seek`] implementation. +@@ -71,7 +72,6 @@ use core::convert::TryInto; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -94,7 +94,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -112,7 +111,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -128,7 +126,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -147,7 +144,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -169,7 +165,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -189,11 +184,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -222,14 +215,14 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + ++ #[cfg(feature="collections")] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let mut nread = 0; + for buf in bufs { +@@ -244,7 +237,7 @@ impl Read for Cursor where T: AsRef<[u8]> { + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -255,12 +248,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -272,6 +269,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result, buf: &[u8]) -> io::Result { + let pos: usize = (*pos_mut).try_into().map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -316,6 +315,7 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result, +@@ -329,13 +329,13 @@ fn vec_write_vectored( + Ok(nwritten) + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Cursor<&mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, self.inner, buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + slice_write_vectored(&mut self.pos, self.inner, bufs) +@@ -344,12 +344,13 @@ impl Write for Cursor<&mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl Write for Cursor<&mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) + } + ++ #[cfg(feature="collections")] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + vec_write_vectored(&mut self.pos, self.inner, bufs) + } +@@ -357,12 +358,13 @@ impl Write for Cursor<&mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) + } + ++ #[cfg(feature="collections")] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + vec_write_vectored(&mut self.pos, &mut self.inner, bufs) + } +@@ -370,13 +372,14 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + slice_write_vectored(&mut self.pos, &mut self.inner, bufs) +diff --git a/error.rs b/error.rs +index c29a68e..c94d8c5 100644 +--- a/error.rs ++++ b/error.rs +@@ -1,8 +1,13 @@ +-use crate::error; +-use crate::fmt; +-use crate::result; +-use crate::sys; +-use crate::convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -38,7 +43,6 @@ use crate::convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -52,12 +56,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -67,13 +69,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -85,48 +90,35 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + #[non_exhaustive] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -138,10 +130,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -152,15 +142,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -169,7 +156,6 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + } + +@@ -200,7 +186,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + /// Converts an [`ErrorKind`] into an [`Error`]. + /// +@@ -245,14 +230,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -261,24 +245,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -304,7 +270,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -335,7 +300,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -369,12 +333,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(dyn error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -440,12 +403,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -474,8 +436,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -501,10 +462,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -516,22 +476,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -539,33 +495,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- #[allow(deprecated)] +- fn cause(&self) -> Option<&dyn error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +- +- fn source(&self) -> Option<&(dyn error::Error + 'static)> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.source(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index 0eac96f..74d5f66 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -1,19 +1,22 @@ +-use crate::cmp; +-use crate::io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind, IoVecMut, +- IoVec}; +-use crate::fmt; +-use crate::mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use crate::io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use crate::io::{BufRead, IoVecMut, IoVec}; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for &mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { + (**self).read(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + (**self).read_vectored(bufs) +@@ -24,11 +27,13 @@ impl Read for &mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -39,11 +44,11 @@ impl Read for &mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for &mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + (**self).write_vectored(bufs) +@@ -62,12 +67,11 @@ impl Write for &mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for &mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for &mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -86,13 +90,14 @@ impl BufRead for &mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { + (**self).read(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + (**self).read_vectored(bufs) +@@ -103,11 +108,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -118,11 +125,12 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + (**self).write_vectored(bufs) +@@ -141,12 +149,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -186,7 +194,6 @@ impl Write for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for &[u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -206,6 +213,7 @@ impl Read for &[u8] { + Ok(amt) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let mut nread = 0; +@@ -245,6 +253,7 @@ impl Read for &[u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -254,7 +263,7 @@ impl Read for &[u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for &[u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -268,7 +277,6 @@ impl BufRead for &[u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for &mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -279,6 +287,7 @@ impl Write for &mut [u8] { + Ok(amt) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + let mut nwritten = 0; +@@ -307,7 +316,7 @@ impl Write for &mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -315,6 +324,7 @@ impl Write for Vec { + Ok(buf.len()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + let len = bufs.iter().map(|b| b.len()).sum(); +diff --git a/mod.rs b/mod.rs +index 1ce66b9..fad199d 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -257,50 +257,38 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use crate::cmp; +-use crate::fmt; +-use crate::slice; +-use crate::str; +-use crate::memchr; +-use crate::ops::{Deref, DerefMut}; +-use crate::ptr; +-use crate::sys; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::cmp; ++use core::fmt; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++#[cfg(feature="collections")] use core::ops::{Deref, DerefMut}; ++use core::ptr; ++use core::slice; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = crate::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl Drop for Guard<'_> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -325,6 +313,7 @@ impl Drop for Guard<'_> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -352,10 +341,12 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + read_to_end_with_reservation(r, buf, 32) + } + ++#[cfg(feature="collections")] + fn read_to_end_with_reservation(r: &mut R, + buf: &mut Vec, + reservation_size: usize) -> Result +@@ -390,6 +381,7 @@ fn read_to_end_with_reservation(r: &mut R, + ret + } + ++#[cfg(feature="collections")] + pub(crate) fn default_read_vectored(read: F, bufs: &mut [IoVecMut<'_>]) -> Result + where + F: FnOnce(&mut [u8]) -> Result +@@ -401,6 +393,7 @@ where + read(buf) + } + ++#[cfg(feature="collections")] + pub(crate) fn default_write_vectored(write: F, bufs: &[IoVec<'_>]) -> Result + where + F: FnOnce(&[u8]) -> Result +@@ -484,7 +477,6 @@ where + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -543,7 +535,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Like `read`, except that it reads into a slice of buffers. +@@ -554,7 +545,7 @@ pub trait Read { + /// + /// The default implementation calls `read` with either the first nonempty + /// buffer provided, or an empty one if none exists. +- #[unstable(feature = "iovec", issue = "58452")] ++ #[cfg(feature="collections")] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> Result { + default_read_vectored(|b| self.read(b), bufs) + } +@@ -581,7 +572,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -634,7 +624,7 @@ pub trait Read { + /// file.) + /// + /// [`std::fs::read`]: ../fs/fn.read.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -677,7 +667,7 @@ pub trait Read { + /// reading from a file.) + /// + /// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -740,7 +730,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -792,7 +781,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -829,7 +817,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } +@@ -864,7 +851,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -900,42 +886,77 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + ++#[cfg(feature="collections")] ++pub struct IoVecBuffer<'a>(&'a [u8]); ++ ++#[cfg(feature="collections")] ++impl<'a> IoVecBuffer<'a> { ++ #[inline] ++ pub fn new(buf: &'a [u8]) -> IoVecBuffer<'a> { ++ IoVecBuffer(buf) ++ } ++ ++ #[inline] ++ pub fn as_slice(&self) -> &[u8] { ++ self.0 ++ } ++} ++#[cfg(feature="collections")] ++pub struct IoVecMutBuffer<'a>(&'a mut [u8]); ++ ++#[cfg(feature="collections")] ++impl<'a> IoVecMutBuffer<'a> { ++ #[inline] ++ pub fn new(buf: &'a mut [u8]) -> IoVecMutBuffer<'a> { ++ IoVecMutBuffer(buf) ++ } ++ ++ #[inline] ++ pub fn as_slice(&self) -> &[u8] { ++ self.0 ++ } ++ ++ #[inline] ++ pub fn as_mut_slice(&mut self) -> &mut [u8] { ++ self.0 ++ } ++} ++ + /// A buffer type used with `Read::read_vectored`. + /// + /// It is semantically a wrapper around an `&mut [u8]`, but is guaranteed to be + /// ABI compatible with the `iovec` type on Unix platforms and `WSABUF` on + /// Windows. +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + #[repr(transparent)] +-pub struct IoVecMut<'a>(sys::io::IoVecMut<'a>); ++pub struct IoVecMut<'a>(IoVecMutBuffer<'a>); + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> fmt::Debug for IoVecMut<'a> { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::Debug::fmt(self.0.as_slice(), fmt) + } + } + ++#[cfg(feature="collections")] + impl<'a> IoVecMut<'a> { + /// Creates a new `IoVecMut` wrapping a byte slice. + /// + /// # Panics + /// + /// Panics on Windows if the slice is larger than 4GB. +- #[unstable(feature = "iovec", issue = "58452")] + #[inline] + pub fn new(buf: &'a mut [u8]) -> IoVecMut<'a> { +- IoVecMut(sys::io::IoVecMut::new(buf)) ++ IoVecMut(IoVecMutBuffer::new(buf)) + } + } + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> Deref for IoVecMut<'a> { + type Target = [u8]; + +@@ -945,7 +966,7 @@ impl<'a> Deref for IoVecMut<'a> { + } + } + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> DerefMut for IoVecMut<'a> { + #[inline] + fn deref_mut(&mut self) -> &mut [u8] { +@@ -958,31 +979,31 @@ impl<'a> DerefMut for IoVecMut<'a> { + /// It is semantically a wrapper around an `&[u8]`, but is guaranteed to be + /// ABI compatible with the `iovec` type on Unix platforms and `WSABUF` on + /// Windows. +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + #[repr(transparent)] +-pub struct IoVec<'a>(sys::io::IoVec<'a>); ++pub struct IoVec<'a>(IoVecBuffer<'a>); + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> fmt::Debug for IoVec<'a> { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::Debug::fmt(self.0.as_slice(), fmt) + } + } + ++#[cfg(feature="collections")] + impl<'a> IoVec<'a> { + /// Creates a new `IoVec` wrapping a byte slice. + /// + /// # Panics + /// + /// Panics on Windows if the slice is larger than 4GB. +- #[unstable(feature = "iovec", issue = "58452")] + #[inline] + pub fn new(buf: &'a [u8]) -> IoVec<'a> { +- IoVec(sys::io::IoVec::new(buf)) ++ IoVec(IoVecBuffer::new(buf)) + } + } + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> Deref for IoVec<'a> { + type Target = [u8]; + +@@ -993,13 +1014,11 @@ impl<'a> Deref for IoVec<'a> { + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -1013,21 +1032,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -1081,7 +1097,6 @@ impl Initializer { + /// `write` in a loop until its entire input has been written. + /// + /// [`write_all`]: #method.write_all +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this writer, returning how many bytes were written. +@@ -1130,7 +1145,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Like `write`, except that it writes from a slice of buffers. +@@ -1141,7 +1155,7 @@ pub trait Write { + /// + /// The default implementation calls `write` with either the first nonempty + /// buffer provided, or an empty one if none exists. +- #[unstable(feature = "iovec", issue = "58452")] ++ #[cfg(feature="collections")] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> Result { + default_write_vectored(|b| self.write(b), bufs) + } +@@ -1169,7 +1183,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this writer. +@@ -1202,7 +1215,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1254,7 +1266,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments<'_>) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1310,7 +1321,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1340,7 +1350,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1356,7 +1365,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + + /// Returns the length of this stream (in bytes). +@@ -1394,7 +1402,6 @@ pub trait Seek { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "seek_convenience", issue = "59359")] + fn stream_len(&mut self) -> Result { + let old_pos = self.stream_position()?; + let len = self.seek(SeekFrom::End(0))?; +@@ -1433,7 +1440,6 @@ pub trait Seek { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "seek_convenience", issue = "59359")] + fn stream_position(&mut self) -> Result { + self.seek(SeekFrom::Current(0)) + } +@@ -1445,29 +1451,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Sets the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Sets the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Sets the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1547,7 +1550,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Returns the contents of the internal buffer, filling it with more data + /// from the inner reader if it is empty. +@@ -1593,7 +1596,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1615,7 +1617,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1671,7 +1672,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1730,7 +1730,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1771,7 +1770,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1810,7 +1808,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1822,7 +1819,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1848,7 +1844,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1871,7 +1866,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1898,13 +1892,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Chain") +@@ -1914,7 +1906,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1926,6 +1917,7 @@ impl Read for Chain { + self.second.read(buf) + } + ++ #[cfg(feature="collections")] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> Result { + if !self.done_first { + match self.first.read_vectored(bufs)? { +@@ -1946,7 +1938,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1973,7 +1965,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -2008,7 +1999,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -2034,7 +2024,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "take_set_limit", since = "1.27.0")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -2059,7 +2048,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -2084,7 +2072,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -2113,13 +2100,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -2136,15 +2121,9 @@ impl Read for Take { + unsafe fn initializer(&self) -> Initializer { + self.inner.initializer() + } +- +- fn read_to_end(&mut self, buf: &mut Vec) -> Result { +- let reservation_size = cmp::min(self.limit, 32) as usize; +- +- read_to_end_with_reservation(self, buf, reservation_size) +- } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -2171,13 +2150,11 @@ impl BufRead for Take { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -2201,14 +2178,14 @@ impl Iterator for Bytes { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -2233,13 +2210,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 2e19edf..66294a3 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -8,7 +8,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index d2638be..1296fe1 100644 +--- a/util.rs ++++ b/util.rs +@@ -1,8 +1,9 @@ + #![allow(missing_copy_implementations)] + +-use crate::fmt; +-use crate::io::{self, Read, Initializer, Write, ErrorKind, BufRead, IoVec, IoVecMut}; +-use crate::mem; ++use core::fmt; ++use crate::io::{self, Read, Initializer, Write, ErrorKind}; ++#[cfg(feature="collections")] use crate::io::{BufRead, IoVec, IoVecMut}; ++use core::mem; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -39,7 +40,6 @@ use crate::mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -68,7 +68,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -88,10 +87,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -101,7 +98,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -109,7 +107,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.pad("Empty { .. }") +@@ -122,7 +119,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -139,10 +135,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -152,6 +146,7 @@ impl Read for Repeat { + Ok(buf.len()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let mut nwritten = 0; +@@ -167,7 +162,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -180,7 +174,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -197,14 +190,13 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + let total_len = bufs.iter().map(|b| b.len()).sum(); +@@ -215,7 +207,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/27c3631d826aaad964f42ee94f26f9e80d658e3f.patch b/patches/27c3631d826aaad964f42ee94f26f9e80d658e3f.patch new file mode 100644 index 0000000..9115fa0 --- /dev/null +++ b/patches/27c3631d826aaad964f42ee94f26f9e80d658e3f.patch @@ -0,0 +1,1609 @@ +diff --git a/buffered.rs b/buffered.rs +index 7ede050..2359343 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -10,13 +10,13 @@ + + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use io::prelude::*; + +-use cmp; +-use error; +-use fmt; ++use core::cmp; ++use core::fmt; + use io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom}; +-use memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -52,7 +52,6 @@ use memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -76,7 +75,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -97,7 +95,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -130,7 +127,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -151,7 +147,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + + /// Returns a reference to the internally buffered data. +@@ -176,7 +171,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -199,7 +193,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + } + +@@ -208,7 +201,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -228,7 +220,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -251,7 +242,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -271,7 +261,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -281,7 +270,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -387,7 +375,6 @@ impl Seek for BufReader { + /// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -422,7 +409,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -437,7 +423,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -455,7 +440,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -504,7 +488,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -522,7 +505,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Returns a reference to the internally buffered data. +@@ -539,7 +521,6 @@ impl BufWriter { + /// // See how many bytes are currently buffered + /// let bytes_buffered = buf_writer.buffer().len(); + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf + } +@@ -563,7 +544,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -572,7 +552,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -592,7 +571,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -602,7 +580,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -612,7 +589,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -651,7 +627,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -684,23 +659,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -771,7 +736,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -792,7 +756,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -813,7 +776,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -837,7 +799,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -860,7 +821,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -886,7 +846,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -897,7 +856,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -942,7 +900,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index f7a9033..d97489f 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -10,8 +10,8 @@ + + use io::prelude::*; + +-use core::convert::TryInto; +-use cmp; ++#[cfg(feature="collections")] use core::convert::TryInto; ++use core::cmp; + use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + + /// A `Cursor` wraps an in-memory buffer and provides it with a +@@ -80,7 +80,6 @@ use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -103,7 +102,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -121,7 +119,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -137,7 +134,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -156,7 +152,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -178,7 +173,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -198,11 +192,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -223,17 +215,16 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -244,12 +235,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -262,6 +257,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result, buf: &[u8]) -> io::Result { + let pos: usize = (*pos_mut).try_into().map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -288,7 +284,6 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result Write for Cursor<&'a mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -297,7 +292,7 @@ impl<'a> Write for Cursor<&'a mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl<'a> Write for Cursor<&'a mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) +@@ -305,7 +300,7 @@ impl<'a> Write for Cursor<&'a mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) +@@ -313,8 +308,8 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) +diff --git a/error.rs b/error.rs +index d3844eb..b4455e3 100644 +--- a/error.rs ++++ b/error.rs +@@ -8,11 +8,16 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use error; +-use fmt; +-use result; +-use sys; +-use convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -48,7 +53,6 @@ use convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -62,12 +66,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -77,13 +79,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -95,48 +100,35 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + #[non_exhaustive] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -148,10 +140,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -162,15 +152,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -179,7 +166,6 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + } + +@@ -210,7 +196,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + /// Converts an [`ErrorKind`] into an [`Error`]. + /// +@@ -252,14 +237,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -268,24 +252,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -311,7 +277,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -342,7 +307,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -376,12 +340,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(dyn error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -447,12 +410,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -481,8 +443,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -508,10 +469,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -523,22 +483,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -546,25 +502,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- #[allow(deprecated)] +- fn cause(&self) -> Option<&dyn error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index fe1179a..452b8b7 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -8,15 +8,18 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use cmp; +-use io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind}; +-use fmt; +-use mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use io::BufRead; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, R: Read + ?Sized> Read for &'a mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -28,11 +31,13 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -43,7 +48,6 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, W: Write + ?Sized> Write for &'a mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -61,12 +65,11 @@ impl<'a, W: Write + ?Sized> Write for &'a mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, S: Seek + ?Sized> Seek for &'a mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -85,7 +88,7 @@ impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -97,11 +100,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -112,7 +117,7 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -130,12 +135,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -161,7 +166,6 @@ impl BufRead for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Read for &'a [u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -207,6 +211,7 @@ impl<'a> Read for &'a [u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -216,7 +221,7 @@ impl<'a> Read for &'a [u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a> BufRead for &'a [u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -230,7 +235,6 @@ impl<'a> BufRead for &'a [u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Write for &'a mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -256,7 +260,7 @@ impl<'a> Write for &'a mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +diff --git a/mod.rs b/mod.rs +index dc97701..6ea0b47 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -267,47 +267,36 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use cmp; +-use fmt; +-use str; +-use memchr; +-use ptr; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::cmp; ++use core::fmt; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++use core::ptr; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl<'a> Drop for Guard<'a> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -332,6 +321,7 @@ impl<'a> Drop for Guard<'a> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -359,10 +349,12 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + read_to_end_with_reservation(r, buf, 32) + } + ++#[cfg(feature="collections")] + fn read_to_end_with_reservation(r: &mut R, + buf: &mut Vec, + reservation_size: usize) -> Result +@@ -469,7 +461,6 @@ fn read_to_end_with_reservation(r: &mut R, + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -526,7 +517,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Determines if this `Read`er can work with buffers of uninitialized +@@ -551,7 +541,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -604,7 +593,7 @@ pub trait Read { + /// file.) + /// + /// [`std::fs::read`]: ../fs/fn.read.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -647,7 +636,7 @@ pub trait Read { + /// reading from a file.) + /// + /// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -710,7 +699,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -762,7 +750,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -799,7 +786,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } +@@ -834,7 +820,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -870,20 +855,17 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -897,21 +879,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -954,7 +933,6 @@ impl Initializer { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this object, returning how many bytes were written. +@@ -1003,7 +981,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Flush this output stream, ensuring that all intermediately buffered +@@ -1029,7 +1006,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this write. +@@ -1062,7 +1038,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1114,7 +1089,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1170,7 +1144,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1200,7 +1173,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1216,7 +1188,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + } + +@@ -1226,29 +1197,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Set the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Set the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Set the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1328,7 +1296,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Returns the contents of the internal buffer, filling it with more data + /// from the inner reader if it is empty. +@@ -1374,7 +1342,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1396,7 +1363,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1452,7 +1418,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1511,7 +1476,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1552,7 +1516,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1591,7 +1554,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1603,7 +1565,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1629,7 +1590,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1652,7 +1612,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1679,13 +1638,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1695,7 +1652,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1717,7 +1673,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1744,7 +1700,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -1779,7 +1734,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -1805,7 +1759,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "take_set_limit", since = "1.27.0")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -1830,7 +1783,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -1855,7 +1807,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -1884,13 +1835,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -1907,15 +1856,9 @@ impl Read for Take { + unsafe fn initializer(&self) -> Initializer { + self.inner.initializer() + } +- +- fn read_to_end(&mut self, buf: &mut Vec) -> Result { +- let reservation_size = cmp::min(self.limit, 32) as usize; +- +- read_to_end_with_reservation(self, buf, reservation_size) +- } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -1954,13 +1897,11 @@ fn read_one_byte(reader: &mut dyn Read) -> Option> { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -1976,14 +1917,14 @@ impl Iterator for Bytes { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -2008,13 +1949,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 8772d0f..49d66c9 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -18,7 +18,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 12995d0..397eef4 100644 +--- a/util.rs ++++ b/util.rs +@@ -10,9 +10,10 @@ + + #![allow(missing_copy_implementations)] + +-use fmt; +-use io::{self, Read, Initializer, Write, ErrorKind, BufRead}; +-use mem; ++use core::fmt; ++use io::{self, Read, Initializer, Write, ErrorKind}; ++use core::mem; ++#[cfg(feature="collections")] use io::BufRead; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -49,7 +50,6 @@ use mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -78,7 +78,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -98,10 +97,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -111,7 +108,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -119,7 +117,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -132,7 +129,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -149,10 +145,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -168,7 +162,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -181,7 +174,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -198,10 +190,8 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } +@@ -209,7 +199,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/27c8dfddac4c69a6fd399abe537e1007306c58cf.patch b/patches/27c8dfddac4c69a6fd399abe537e1007306c58cf.patch new file mode 100644 index 0000000..5c51a01 --- /dev/null +++ b/patches/27c8dfddac4c69a6fd399abe537e1007306c58cf.patch @@ -0,0 +1,1602 @@ +diff --git a/buffered.rs b/buffered.rs +index 056aa7c..9e294e3 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -1,12 +1,12 @@ + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use io::prelude::*; + +-use cmp; +-use error; +-use fmt; ++use core::cmp; ++use core::fmt; + use io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom}; +-use memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -42,7 +42,6 @@ use memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -66,7 +65,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -87,7 +85,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -120,7 +117,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -141,7 +137,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + + /// Returns a reference to the internally buffered data. +@@ -166,7 +161,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -189,7 +183,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + } + +@@ -198,7 +191,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -218,7 +210,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -241,7 +232,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -261,7 +251,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -271,7 +260,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -380,7 +368,6 @@ impl Seek for BufReader { + /// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -415,7 +402,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -430,7 +416,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -448,7 +433,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -497,7 +481,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -515,7 +498,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Returns a reference to the internally buffered data. +@@ -532,7 +514,6 @@ impl BufWriter { + /// // See how many bytes are currently buffered + /// let bytes_buffered = buf_writer.buffer().len(); + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf + } +@@ -556,7 +537,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -565,7 +545,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -585,7 +564,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -595,7 +573,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -605,7 +582,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -644,7 +620,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -677,23 +652,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -764,7 +729,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -785,7 +749,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -806,7 +769,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -830,7 +792,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -853,7 +814,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -879,7 +839,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -890,7 +849,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -935,7 +893,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index b205f78..3d7e33f 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -1,7 +1,7 @@ + use io::prelude::*; + +-use core::convert::TryInto; +-use cmp; ++#[cfg(feature="collections")] use core::convert::TryInto; ++use core::cmp; + use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + + /// A `Cursor` wraps an in-memory buffer and provides it with a +@@ -70,7 +70,6 @@ use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -93,7 +92,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -111,7 +109,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -127,7 +124,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -146,7 +142,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -168,7 +163,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -188,11 +182,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -213,17 +205,16 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -234,12 +225,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -252,6 +247,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result, buf: &[u8]) -> io::Result { + let pos: usize = (*pos_mut).try_into().map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -278,7 +274,6 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result Write for Cursor<&'a mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -287,7 +282,7 @@ impl<'a> Write for Cursor<&'a mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl<'a> Write for Cursor<&'a mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) +@@ -295,7 +290,7 @@ impl<'a> Write for Cursor<&'a mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) +@@ -303,8 +298,8 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) +diff --git a/error.rs b/error.rs +index e9b4f60..31c0ff1 100644 +--- a/error.rs ++++ b/error.rs +@@ -1,8 +1,13 @@ +-use error; +-use fmt; +-use result; +-use sys; +-use convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -38,7 +43,6 @@ use convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -52,12 +56,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -67,13 +69,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -85,48 +90,35 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + #[non_exhaustive] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -138,10 +130,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -152,15 +142,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -169,7 +156,6 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + } + +@@ -200,7 +186,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + /// Converts an [`ErrorKind`] into an [`Error`]. + /// +@@ -245,14 +230,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -261,24 +245,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -304,7 +270,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -335,7 +300,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -369,12 +333,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(dyn error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -440,12 +403,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -474,8 +436,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -501,10 +462,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -516,22 +476,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -539,25 +495,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- #[allow(deprecated)] +- fn cause(&self) -> Option<&dyn error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index ec75a87..e9d6bf2 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -1,12 +1,15 @@ +-use cmp; +-use io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind}; +-use fmt; +-use mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use io::BufRead; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, R: Read + ?Sized> Read for &'a mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -18,11 +21,13 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -33,7 +38,6 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, W: Write + ?Sized> Write for &'a mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -51,12 +55,11 @@ impl<'a, W: Write + ?Sized> Write for &'a mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, S: Seek + ?Sized> Seek for &'a mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -75,7 +78,7 @@ impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -87,11 +90,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -102,7 +107,7 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -120,12 +125,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -151,7 +156,6 @@ impl BufRead for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Read for &'a [u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -197,6 +201,7 @@ impl<'a> Read for &'a [u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -206,7 +211,7 @@ impl<'a> Read for &'a [u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a> BufRead for &'a [u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -220,7 +225,6 @@ impl<'a> BufRead for &'a [u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Write for &'a mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -246,7 +250,7 @@ impl<'a> Write for &'a mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +diff --git a/mod.rs b/mod.rs +index 28a6fbd..2f5ae43 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -257,48 +257,37 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use cmp; +-use fmt; +-use slice; +-use str; +-use memchr; +-use ptr; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::cmp; ++use core::fmt; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++use core::ptr; ++use core::slice; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl<'a> Drop for Guard<'a> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -323,6 +312,7 @@ impl<'a> Drop for Guard<'a> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -350,10 +340,12 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + read_to_end_with_reservation(r, buf, 32) + } + ++#[cfg(feature="collections")] + fn read_to_end_with_reservation(r: &mut R, + buf: &mut Vec, + reservation_size: usize) -> Result +@@ -460,7 +452,6 @@ fn read_to_end_with_reservation(r: &mut R, + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -517,7 +508,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Determines if this `Read`er can work with buffers of uninitialized +@@ -542,7 +532,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -595,7 +584,7 @@ pub trait Read { + /// file.) + /// + /// [`std::fs::read`]: ../fs/fn.read.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -638,7 +627,7 @@ pub trait Read { + /// reading from a file.) + /// + /// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -701,7 +690,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -753,7 +741,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -790,7 +777,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } +@@ -825,7 +811,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -861,20 +846,17 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -888,21 +870,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -945,7 +924,6 @@ impl Initializer { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this writer, returning how many bytes were written. +@@ -994,7 +972,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Flush this output stream, ensuring that all intermediately buffered +@@ -1020,7 +997,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this writer. +@@ -1053,7 +1029,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1105,7 +1080,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1161,7 +1135,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1191,7 +1164,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1207,7 +1179,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + } + +@@ -1217,29 +1188,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Set the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Set the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Set the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1319,7 +1287,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Returns the contents of the internal buffer, filling it with more data + /// from the inner reader if it is empty. +@@ -1365,7 +1333,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1387,7 +1354,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1443,7 +1409,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1502,7 +1467,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1543,7 +1507,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1582,7 +1545,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1594,7 +1556,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1620,7 +1581,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1643,7 +1603,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1670,13 +1629,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1686,7 +1643,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1708,7 +1664,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1735,7 +1691,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -1770,7 +1725,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -1796,7 +1750,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "take_set_limit", since = "1.27.0")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -1821,7 +1774,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -1846,7 +1798,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -1875,13 +1826,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -1898,15 +1847,9 @@ impl Read for Take { + unsafe fn initializer(&self) -> Initializer { + self.inner.initializer() + } +- +- fn read_to_end(&mut self, buf: &mut Vec) -> Result { +- let reservation_size = cmp::min(self.limit, 32) as usize; +- +- read_to_end_with_reservation(self, buf, reservation_size) +- } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -1933,13 +1876,11 @@ impl BufRead for Take { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -1963,14 +1904,14 @@ impl Iterator for Bytes { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -1995,13 +1936,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 2e19edf..66294a3 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -8,7 +8,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 8df961a..2b08122 100644 +--- a/util.rs ++++ b/util.rs +@@ -1,8 +1,9 @@ + #![allow(missing_copy_implementations)] + +-use fmt; +-use io::{self, Read, Initializer, Write, ErrorKind, BufRead}; +-use mem; ++use core::fmt; ++use io::{self, Read, Initializer, Write, ErrorKind}; ++use core::mem; ++#[cfg(feature="collections")] use io::BufRead; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -39,7 +40,6 @@ use mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -68,7 +68,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -88,10 +87,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -101,7 +98,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -109,7 +107,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -122,7 +119,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -139,10 +135,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -158,7 +152,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -171,7 +164,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -188,10 +180,8 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } +@@ -199,7 +189,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/2a663555ddf36f6b041445894a8c175cd1bc718c.patch b/patches/2a663555ddf36f6b041445894a8c175cd1bc718c.patch new file mode 100644 index 0000000..c17c714 --- /dev/null +++ b/patches/2a663555ddf36f6b041445894a8c175cd1bc718c.patch @@ -0,0 +1,1602 @@ +diff --git a/buffered.rs b/buffered.rs +index 056aa7c..9e294e3 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -1,12 +1,12 @@ + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use io::prelude::*; + +-use cmp; +-use error; +-use fmt; ++use core::cmp; ++use core::fmt; + use io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom}; +-use memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -42,7 +42,6 @@ use memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -66,7 +65,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -87,7 +85,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -120,7 +117,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -141,7 +137,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + + /// Returns a reference to the internally buffered data. +@@ -166,7 +161,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -189,7 +183,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + } + +@@ -198,7 +191,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -218,7 +210,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -241,7 +232,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -261,7 +251,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -271,7 +260,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -380,7 +368,6 @@ impl Seek for BufReader { + /// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -415,7 +402,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -430,7 +416,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -448,7 +433,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -497,7 +481,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -515,7 +498,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Returns a reference to the internally buffered data. +@@ -532,7 +514,6 @@ impl BufWriter { + /// // See how many bytes are currently buffered + /// let bytes_buffered = buf_writer.buffer().len(); + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf + } +@@ -556,7 +537,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -565,7 +545,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -585,7 +564,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -595,7 +573,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -605,7 +582,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -644,7 +620,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -677,23 +652,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -764,7 +729,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -785,7 +749,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -806,7 +769,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -830,7 +792,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -853,7 +814,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -879,7 +839,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -890,7 +849,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -935,7 +893,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index b205f78..3d7e33f 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -1,7 +1,7 @@ + use io::prelude::*; + +-use core::convert::TryInto; +-use cmp; ++#[cfg(feature="collections")] use core::convert::TryInto; ++use core::cmp; + use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + + /// A `Cursor` wraps an in-memory buffer and provides it with a +@@ -70,7 +70,6 @@ use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -93,7 +92,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -111,7 +109,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -127,7 +124,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -146,7 +142,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -168,7 +163,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -188,11 +182,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -213,17 +205,16 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -234,12 +225,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -252,6 +247,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result, buf: &[u8]) -> io::Result { + let pos: usize = (*pos_mut).try_into().map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -278,7 +274,6 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result Write for Cursor<&'a mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -287,7 +282,7 @@ impl<'a> Write for Cursor<&'a mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl<'a> Write for Cursor<&'a mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) +@@ -295,7 +290,7 @@ impl<'a> Write for Cursor<&'a mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) +@@ -303,8 +298,8 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) +diff --git a/error.rs b/error.rs +index e9b4f60..31c0ff1 100644 +--- a/error.rs ++++ b/error.rs +@@ -1,8 +1,13 @@ +-use error; +-use fmt; +-use result; +-use sys; +-use convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -38,7 +43,6 @@ use convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -52,12 +56,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -67,13 +69,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -85,48 +90,35 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + #[non_exhaustive] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -138,10 +130,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -152,15 +142,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -169,7 +156,6 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + } + +@@ -200,7 +186,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + /// Converts an [`ErrorKind`] into an [`Error`]. + /// +@@ -245,14 +230,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -261,24 +245,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -304,7 +270,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -335,7 +300,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -369,12 +333,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(dyn error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -440,12 +403,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -474,8 +436,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -501,10 +462,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -516,22 +476,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -539,25 +495,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- #[allow(deprecated)] +- fn cause(&self) -> Option<&dyn error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index ec75a87..e9d6bf2 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -1,12 +1,15 @@ +-use cmp; +-use io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind}; +-use fmt; +-use mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use io::BufRead; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, R: Read + ?Sized> Read for &'a mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -18,11 +21,13 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -33,7 +38,6 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, W: Write + ?Sized> Write for &'a mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -51,12 +55,11 @@ impl<'a, W: Write + ?Sized> Write for &'a mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, S: Seek + ?Sized> Seek for &'a mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -75,7 +78,7 @@ impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -87,11 +90,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -102,7 +107,7 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -120,12 +125,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -151,7 +156,6 @@ impl BufRead for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Read for &'a [u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -197,6 +201,7 @@ impl<'a> Read for &'a [u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -206,7 +211,7 @@ impl<'a> Read for &'a [u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a> BufRead for &'a [u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -220,7 +225,6 @@ impl<'a> BufRead for &'a [u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Write for &'a mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -246,7 +250,7 @@ impl<'a> Write for &'a mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +diff --git a/mod.rs b/mod.rs +index 040669b..ee4d22c 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -257,48 +257,37 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use cmp; +-use fmt; +-use slice; +-use str; +-use memchr; +-use ptr; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::cmp; ++use core::fmt; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++use core::ptr; ++use core::slice; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl<'a> Drop for Guard<'a> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -323,6 +312,7 @@ impl<'a> Drop for Guard<'a> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -350,10 +340,12 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + read_to_end_with_reservation(r, buf, 32) + } + ++#[cfg(feature="collections")] + fn read_to_end_with_reservation(r: &mut R, + buf: &mut Vec, + reservation_size: usize) -> Result +@@ -460,7 +452,6 @@ fn read_to_end_with_reservation(r: &mut R, + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -517,7 +508,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Determines if this `Read`er can work with buffers of uninitialized +@@ -542,7 +532,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -595,7 +584,7 @@ pub trait Read { + /// file.) + /// + /// [`std::fs::read`]: ../fs/fn.read.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -638,7 +627,7 @@ pub trait Read { + /// reading from a file.) + /// + /// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -701,7 +690,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -753,7 +741,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -790,7 +777,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } +@@ -825,7 +811,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -861,20 +846,17 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -888,21 +870,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -945,7 +924,6 @@ impl Initializer { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this object, returning how many bytes were written. +@@ -994,7 +972,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Flush this output stream, ensuring that all intermediately buffered +@@ -1020,7 +997,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this write. +@@ -1053,7 +1029,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1105,7 +1080,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1161,7 +1135,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1191,7 +1164,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1207,7 +1179,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + } + +@@ -1217,29 +1188,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Set the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Set the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Set the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1319,7 +1287,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Returns the contents of the internal buffer, filling it with more data + /// from the inner reader if it is empty. +@@ -1365,7 +1333,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1387,7 +1354,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1443,7 +1409,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1502,7 +1467,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1543,7 +1507,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1582,7 +1545,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1594,7 +1556,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1620,7 +1581,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1643,7 +1603,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1670,13 +1629,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1686,7 +1643,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1708,7 +1664,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1735,7 +1691,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -1770,7 +1725,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -1796,7 +1750,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "take_set_limit", since = "1.27.0")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -1821,7 +1774,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -1846,7 +1798,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -1875,13 +1826,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -1898,15 +1847,9 @@ impl Read for Take { + unsafe fn initializer(&self) -> Initializer { + self.inner.initializer() + } +- +- fn read_to_end(&mut self, buf: &mut Vec) -> Result { +- let reservation_size = cmp::min(self.limit, 32) as usize; +- +- read_to_end_with_reservation(self, buf, reservation_size) +- } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -1933,13 +1876,11 @@ impl BufRead for Take { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -1963,14 +1904,14 @@ impl Iterator for Bytes { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -1995,13 +1936,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 2e19edf..66294a3 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -8,7 +8,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 8df961a..2b08122 100644 +--- a/util.rs ++++ b/util.rs +@@ -1,8 +1,9 @@ + #![allow(missing_copy_implementations)] + +-use fmt; +-use io::{self, Read, Initializer, Write, ErrorKind, BufRead}; +-use mem; ++use core::fmt; ++use io::{self, Read, Initializer, Write, ErrorKind}; ++use core::mem; ++#[cfg(feature="collections")] use io::BufRead; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -39,7 +40,6 @@ use mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -68,7 +68,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -88,10 +87,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -101,7 +98,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -109,7 +107,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -122,7 +119,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -139,10 +135,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -158,7 +152,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -171,7 +164,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -188,10 +180,8 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } +@@ -199,7 +189,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/31bec788f46c73ab14c72868dc6141141320a058.patch b/patches/31bec788f46c73ab14c72868dc6141141320a058.patch new file mode 100644 index 0000000..c0d3549 --- /dev/null +++ b/patches/31bec788f46c73ab14c72868dc6141141320a058.patch @@ -0,0 +1,1607 @@ +diff --git a/buffered.rs b/buffered.rs +index 03c97de..9618137 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -10,13 +10,13 @@ + + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use io::prelude::*; + +-use cmp; +-use error; +-use fmt; ++use core::cmp; ++use core::fmt; + use io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom}; +-use memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -52,7 +52,6 @@ use memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -76,7 +75,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -97,7 +95,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -130,7 +127,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -151,7 +147,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + + /// Returns a reference to the internally buffered data. +@@ -176,7 +171,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -199,7 +193,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + } + +@@ -208,7 +201,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -228,7 +220,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -251,7 +242,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -271,7 +261,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -281,7 +270,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -389,7 +377,6 @@ impl Seek for BufReader { + /// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -424,7 +411,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -439,7 +425,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -457,7 +442,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -506,7 +490,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -524,7 +507,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Unwraps this `BufWriter`, returning the underlying writer. +@@ -546,7 +528,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -555,7 +536,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -575,7 +555,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -585,7 +564,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -595,7 +573,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -634,7 +611,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -667,23 +643,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -754,7 +720,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -775,7 +740,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -796,7 +760,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -820,7 +783,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -843,7 +805,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -869,7 +830,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -880,7 +840,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -925,7 +884,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index 14f2015..1d60dac 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -10,8 +10,8 @@ + + use io::prelude::*; + +-use core::convert::TryInto; +-use cmp; ++#[cfg(feature="collections")] use core::convert::TryInto; ++use core::cmp; + use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + + /// A `Cursor` wraps an in-memory buffer and provides it with a +@@ -80,7 +80,6 @@ use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -103,7 +102,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -121,7 +119,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -137,7 +134,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -156,7 +152,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -178,7 +173,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -198,11 +192,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -223,17 +215,16 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -244,12 +235,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -262,6 +257,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result, buf: &[u8]) -> io::Result { + let pos: usize = (*pos_mut).try_into().map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -288,7 +284,6 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result Write for Cursor<&'a mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -297,7 +292,7 @@ impl<'a> Write for Cursor<&'a mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl<'a> Write for Cursor<&'a mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) +@@ -305,7 +300,7 @@ impl<'a> Write for Cursor<&'a mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) +@@ -313,8 +308,8 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) +diff --git a/error.rs b/error.rs +index 02a3ce8..3acdadf 100644 +--- a/error.rs ++++ b/error.rs +@@ -8,11 +8,16 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use error; +-use fmt; +-use result; +-use sys; +-use convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -48,7 +53,6 @@ use convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -62,12 +66,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -77,13 +79,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -95,47 +100,34 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -147,10 +139,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -161,15 +151,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -178,15 +165,10 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + + /// A marker variant that tells the compiler that users of this enum cannot + /// match it exhaustively. +- #[unstable(feature = "io_error_internals", +- reason = "better expressed through extensible enums that this \ +- enum cannot be exhaustively matched against", +- issue = "0")] + #[doc(hidden)] + __Nonexhaustive, + } +@@ -219,7 +201,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + #[inline] + fn from(kind: ErrorKind) -> Error { +@@ -248,14 +229,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -264,24 +244,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -307,7 +269,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -338,7 +299,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -372,12 +332,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(dyn error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -443,12 +402,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -477,8 +435,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -504,10 +461,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -519,22 +475,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -542,24 +494,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- fn cause(&self) -> Option<&dyn error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index fe1179a..452b8b7 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -8,15 +8,18 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use cmp; +-use io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind}; +-use fmt; +-use mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use io::BufRead; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, R: Read + ?Sized> Read for &'a mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -28,11 +31,13 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -43,7 +48,6 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, W: Write + ?Sized> Write for &'a mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -61,12 +65,11 @@ impl<'a, W: Write + ?Sized> Write for &'a mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, S: Seek + ?Sized> Seek for &'a mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -85,7 +88,7 @@ impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -97,11 +100,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -112,7 +117,7 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -130,12 +135,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -161,7 +166,6 @@ impl BufRead for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Read for &'a [u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -207,6 +211,7 @@ impl<'a> Read for &'a [u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -216,7 +221,7 @@ impl<'a> Read for &'a [u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a> BufRead for &'a [u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -230,7 +235,6 @@ impl<'a> BufRead for &'a [u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Write for &'a mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -256,7 +260,7 @@ impl<'a> Write for &'a mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +diff --git a/mod.rs b/mod.rs +index b83f3fb..883fa30 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -267,47 +267,36 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use cmp; +-use fmt; +-use str; +-use memchr; +-use ptr; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::cmp; ++use core::fmt; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++use core::ptr; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl<'a> Drop for Guard<'a> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -332,6 +321,7 @@ impl<'a> Drop for Guard<'a> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -359,10 +349,12 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + read_to_end_with_reservation(r, buf, 32) + } + ++#[cfg(feature="collections")] + fn read_to_end_with_reservation(r: &mut R, + buf: &mut Vec, + reservation_size: usize) -> Result +@@ -469,7 +461,6 @@ fn read_to_end_with_reservation(r: &mut R, + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -526,7 +517,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Determines if this `Read`er can work with buffers of uninitialized +@@ -551,7 +541,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -604,7 +593,7 @@ pub trait Read { + /// file.) + /// + /// [`std::fs::read`]: ../fs/fn.read.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -647,7 +636,7 @@ pub trait Read { + /// reading from a file.) + /// + /// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -710,7 +699,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -762,7 +750,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -799,7 +786,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } +@@ -834,7 +820,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -870,20 +855,17 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -897,21 +879,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -954,7 +933,6 @@ impl Initializer { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this object, returning how many bytes were written. +@@ -1003,7 +981,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Flush this output stream, ensuring that all intermediately buffered +@@ -1029,7 +1006,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this write. +@@ -1062,7 +1038,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1114,7 +1089,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1170,7 +1144,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1200,7 +1173,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1216,7 +1188,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + } + +@@ -1226,29 +1197,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Set the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Set the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Set the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1328,7 +1296,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Fills the internal buffer of this object, returning the buffer contents. + /// +@@ -1373,7 +1341,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1395,7 +1362,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1451,7 +1417,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1510,7 +1475,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1551,7 +1515,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1590,7 +1553,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1602,7 +1564,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1628,7 +1589,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1651,7 +1611,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1678,13 +1637,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1694,7 +1651,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1716,7 +1672,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1743,7 +1699,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -1778,7 +1733,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -1804,7 +1758,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "take_set_limit", since = "1.27.0")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -1829,7 +1782,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -1854,7 +1806,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -1883,13 +1834,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -1906,15 +1855,9 @@ impl Read for Take { + unsafe fn initializer(&self) -> Initializer { + self.inner.initializer() + } +- +- fn read_to_end(&mut self, buf: &mut Vec) -> Result { +- let reservation_size = cmp::min(self.limit, 32) as usize; +- +- read_to_end_with_reservation(self, buf, reservation_size) +- } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -1953,13 +1896,11 @@ fn read_one_byte(reader: &mut dyn Read) -> Option> { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -1975,14 +1916,14 @@ impl Iterator for Bytes { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -2007,13 +1948,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 8772d0f..49d66c9 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -18,7 +18,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 33f741d..878fb82 100644 +--- a/util.rs ++++ b/util.rs +@@ -10,9 +10,10 @@ + + #![allow(missing_copy_implementations)] + +-use fmt; +-use io::{self, Read, Initializer, Write, ErrorKind, BufRead}; +-use mem; ++use core::fmt; ++use io::{self, Read, Initializer, Write, ErrorKind}; ++use core::mem; ++#[cfg(feature="collections")] use io::BufRead; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -44,7 +45,6 @@ use mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -73,7 +73,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -93,10 +92,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -106,7 +103,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -114,7 +112,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -127,7 +124,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -144,10 +140,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte: byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -163,7 +157,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -176,7 +169,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -193,10 +185,8 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } +@@ -204,7 +194,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/379c380a60e7b3adb6c6f595222cbfa2d9160a20.patch b/patches/379c380a60e7b3adb6c6f595222cbfa2d9160a20.patch new file mode 100644 index 0000000..d669bb7 --- /dev/null +++ b/patches/379c380a60e7b3adb6c6f595222cbfa2d9160a20.patch @@ -0,0 +1,1909 @@ +diff --git a/buffered.rs b/buffered.rs +index 3370a44..f1f0573 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -1,12 +1,12 @@ + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use crate::io::prelude::*; + +-use crate::cmp; +-use crate::error; +-use crate::fmt; ++use core::cmp; ++use core::fmt; + use crate::io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom, IoVec, IoVecMut}; +-use crate::memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -46,7 +46,6 @@ use crate::memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -70,7 +69,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -91,7 +89,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -126,7 +123,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -147,7 +143,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + + /// Returns a reference to the internally buffered data. +@@ -172,7 +167,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -195,7 +189,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + + /// Invalidates all data in the internal buffer. +@@ -211,7 +204,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -231,7 +223,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -269,7 +260,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -289,7 +279,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -299,7 +288,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -408,7 +396,6 @@ impl Seek for BufReader { + /// [`TcpStream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -443,7 +430,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -458,7 +444,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -476,7 +461,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -525,7 +509,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -543,7 +526,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Returns a reference to the internally buffered data. +@@ -560,7 +542,6 @@ impl BufWriter { + /// // See how many bytes are currently buffered + /// let bytes_buffered = buf_writer.buffer().len(); + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf + } +@@ -584,7 +565,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -593,7 +573,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -629,7 +608,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -639,7 +617,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -649,7 +626,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -688,7 +664,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -721,23 +696,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.error().fmt(f) +@@ -808,7 +773,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -829,7 +793,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -850,7 +813,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -874,7 +836,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -897,7 +858,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -923,7 +883,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -934,7 +893,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -979,7 +937,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index 247d45c..f13522d 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -1,9 +1,10 @@ + use crate::io::prelude::*; + +-use crate::cmp; +-use crate::io::{self, Initializer, SeekFrom, Error, ErrorKind, IoVec, IoVecMut}; ++use core::cmp; ++use crate::io::{self, Initializer, SeekFrom, Error, ErrorKind}; ++#[cfg(feature="collections")] use crate::io::{IoVec, IoVecMut}; + +-use core::convert::TryInto; ++#[cfg(feature="collections")] use core::convert::TryInto; + + /// A `Cursor` wraps an in-memory buffer and provides it with a + /// [`Seek`] implementation. +@@ -71,7 +72,6 @@ use core::convert::TryInto; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -94,7 +94,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -112,7 +111,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -128,7 +126,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -147,7 +144,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -169,7 +165,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -189,11 +184,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -222,14 +215,14 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + ++ #[cfg(feature="collections")] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let mut nread = 0; + for buf in bufs { +@@ -244,7 +237,7 @@ impl Read for Cursor where T: AsRef<[u8]> { + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -255,12 +248,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -272,6 +269,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result, buf: &[u8]) -> io::Result { + let pos: usize = (*pos_mut).try_into().map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -316,6 +315,7 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result, +@@ -329,13 +329,13 @@ fn vec_write_vectored( + Ok(nwritten) + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Cursor<&mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, self.inner, buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + slice_write_vectored(&mut self.pos, self.inner, bufs) +@@ -344,12 +344,13 @@ impl Write for Cursor<&mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl Write for Cursor<&mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) + } + ++ #[cfg(feature="collections")] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + vec_write_vectored(&mut self.pos, self.inner, bufs) + } +@@ -357,12 +358,13 @@ impl Write for Cursor<&mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) + } + ++ #[cfg(feature="collections")] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + vec_write_vectored(&mut self.pos, &mut self.inner, bufs) + } +@@ -370,13 +372,14 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + slice_write_vectored(&mut self.pos, &mut self.inner, bufs) +diff --git a/error.rs b/error.rs +index c29a68e..c94d8c5 100644 +--- a/error.rs ++++ b/error.rs +@@ -1,8 +1,13 @@ +-use crate::error; +-use crate::fmt; +-use crate::result; +-use crate::sys; +-use crate::convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -38,7 +43,6 @@ use crate::convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -52,12 +56,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -67,13 +69,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -85,48 +90,35 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + #[non_exhaustive] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -138,10 +130,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -152,15 +142,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -169,7 +156,6 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + } + +@@ -200,7 +186,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + /// Converts an [`ErrorKind`] into an [`Error`]. + /// +@@ -245,14 +230,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -261,24 +245,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -304,7 +270,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -335,7 +300,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -369,12 +333,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(dyn error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -440,12 +403,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -474,8 +436,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -501,10 +462,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -516,22 +476,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -539,33 +495,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- #[allow(deprecated)] +- fn cause(&self) -> Option<&dyn error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +- +- fn source(&self) -> Option<&(dyn error::Error + 'static)> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.source(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index 0eac96f..74d5f66 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -1,19 +1,22 @@ +-use crate::cmp; +-use crate::io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind, IoVecMut, +- IoVec}; +-use crate::fmt; +-use crate::mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use crate::io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use crate::io::{BufRead, IoVecMut, IoVec}; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for &mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { + (**self).read(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + (**self).read_vectored(bufs) +@@ -24,11 +27,13 @@ impl Read for &mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -39,11 +44,11 @@ impl Read for &mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for &mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + (**self).write_vectored(bufs) +@@ -62,12 +67,11 @@ impl Write for &mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for &mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for &mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -86,13 +90,14 @@ impl BufRead for &mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { + (**self).read(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + (**self).read_vectored(bufs) +@@ -103,11 +108,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -118,11 +125,12 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + (**self).write_vectored(bufs) +@@ -141,12 +149,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -186,7 +194,6 @@ impl Write for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for &[u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -206,6 +213,7 @@ impl Read for &[u8] { + Ok(amt) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let mut nread = 0; +@@ -245,6 +253,7 @@ impl Read for &[u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -254,7 +263,7 @@ impl Read for &[u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for &[u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -268,7 +277,6 @@ impl BufRead for &[u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for &mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -279,6 +287,7 @@ impl Write for &mut [u8] { + Ok(amt) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + let mut nwritten = 0; +@@ -307,7 +316,7 @@ impl Write for &mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -315,6 +324,7 @@ impl Write for Vec { + Ok(buf.len()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + let len = bufs.iter().map(|b| b.len()).sum(); +diff --git a/mod.rs b/mod.rs +index 1ce66b9..fad199d 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -257,50 +257,38 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use crate::cmp; +-use crate::fmt; +-use crate::slice; +-use crate::str; +-use crate::memchr; +-use crate::ops::{Deref, DerefMut}; +-use crate::ptr; +-use crate::sys; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::cmp; ++use core::fmt; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++#[cfg(feature="collections")] use core::ops::{Deref, DerefMut}; ++use core::ptr; ++use core::slice; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = crate::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl Drop for Guard<'_> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -325,6 +313,7 @@ impl Drop for Guard<'_> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -352,10 +341,12 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + read_to_end_with_reservation(r, buf, 32) + } + ++#[cfg(feature="collections")] + fn read_to_end_with_reservation(r: &mut R, + buf: &mut Vec, + reservation_size: usize) -> Result +@@ -390,6 +381,7 @@ fn read_to_end_with_reservation(r: &mut R, + ret + } + ++#[cfg(feature="collections")] + pub(crate) fn default_read_vectored(read: F, bufs: &mut [IoVecMut<'_>]) -> Result + where + F: FnOnce(&mut [u8]) -> Result +@@ -401,6 +393,7 @@ where + read(buf) + } + ++#[cfg(feature="collections")] + pub(crate) fn default_write_vectored(write: F, bufs: &[IoVec<'_>]) -> Result + where + F: FnOnce(&[u8]) -> Result +@@ -484,7 +477,6 @@ where + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -543,7 +535,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Like `read`, except that it reads into a slice of buffers. +@@ -554,7 +545,7 @@ pub trait Read { + /// + /// The default implementation calls `read` with either the first nonempty + /// buffer provided, or an empty one if none exists. +- #[unstable(feature = "iovec", issue = "58452")] ++ #[cfg(feature="collections")] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> Result { + default_read_vectored(|b| self.read(b), bufs) + } +@@ -581,7 +572,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -634,7 +624,7 @@ pub trait Read { + /// file.) + /// + /// [`std::fs::read`]: ../fs/fn.read.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -677,7 +667,7 @@ pub trait Read { + /// reading from a file.) + /// + /// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -740,7 +730,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -792,7 +781,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -829,7 +817,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } +@@ -864,7 +851,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -900,42 +886,77 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + ++#[cfg(feature="collections")] ++pub struct IoVecBuffer<'a>(&'a [u8]); ++ ++#[cfg(feature="collections")] ++impl<'a> IoVecBuffer<'a> { ++ #[inline] ++ pub fn new(buf: &'a [u8]) -> IoVecBuffer<'a> { ++ IoVecBuffer(buf) ++ } ++ ++ #[inline] ++ pub fn as_slice(&self) -> &[u8] { ++ self.0 ++ } ++} ++#[cfg(feature="collections")] ++pub struct IoVecMutBuffer<'a>(&'a mut [u8]); ++ ++#[cfg(feature="collections")] ++impl<'a> IoVecMutBuffer<'a> { ++ #[inline] ++ pub fn new(buf: &'a mut [u8]) -> IoVecMutBuffer<'a> { ++ IoVecMutBuffer(buf) ++ } ++ ++ #[inline] ++ pub fn as_slice(&self) -> &[u8] { ++ self.0 ++ } ++ ++ #[inline] ++ pub fn as_mut_slice(&mut self) -> &mut [u8] { ++ self.0 ++ } ++} ++ + /// A buffer type used with `Read::read_vectored`. + /// + /// It is semantically a wrapper around an `&mut [u8]`, but is guaranteed to be + /// ABI compatible with the `iovec` type on Unix platforms and `WSABUF` on + /// Windows. +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + #[repr(transparent)] +-pub struct IoVecMut<'a>(sys::io::IoVecMut<'a>); ++pub struct IoVecMut<'a>(IoVecMutBuffer<'a>); + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> fmt::Debug for IoVecMut<'a> { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::Debug::fmt(self.0.as_slice(), fmt) + } + } + ++#[cfg(feature="collections")] + impl<'a> IoVecMut<'a> { + /// Creates a new `IoVecMut` wrapping a byte slice. + /// + /// # Panics + /// + /// Panics on Windows if the slice is larger than 4GB. +- #[unstable(feature = "iovec", issue = "58452")] + #[inline] + pub fn new(buf: &'a mut [u8]) -> IoVecMut<'a> { +- IoVecMut(sys::io::IoVecMut::new(buf)) ++ IoVecMut(IoVecMutBuffer::new(buf)) + } + } + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> Deref for IoVecMut<'a> { + type Target = [u8]; + +@@ -945,7 +966,7 @@ impl<'a> Deref for IoVecMut<'a> { + } + } + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> DerefMut for IoVecMut<'a> { + #[inline] + fn deref_mut(&mut self) -> &mut [u8] { +@@ -958,31 +979,31 @@ impl<'a> DerefMut for IoVecMut<'a> { + /// It is semantically a wrapper around an `&[u8]`, but is guaranteed to be + /// ABI compatible with the `iovec` type on Unix platforms and `WSABUF` on + /// Windows. +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + #[repr(transparent)] +-pub struct IoVec<'a>(sys::io::IoVec<'a>); ++pub struct IoVec<'a>(IoVecBuffer<'a>); + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> fmt::Debug for IoVec<'a> { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::Debug::fmt(self.0.as_slice(), fmt) + } + } + ++#[cfg(feature="collections")] + impl<'a> IoVec<'a> { + /// Creates a new `IoVec` wrapping a byte slice. + /// + /// # Panics + /// + /// Panics on Windows if the slice is larger than 4GB. +- #[unstable(feature = "iovec", issue = "58452")] + #[inline] + pub fn new(buf: &'a [u8]) -> IoVec<'a> { +- IoVec(sys::io::IoVec::new(buf)) ++ IoVec(IoVecBuffer::new(buf)) + } + } + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> Deref for IoVec<'a> { + type Target = [u8]; + +@@ -993,13 +1014,11 @@ impl<'a> Deref for IoVec<'a> { + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -1013,21 +1032,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -1081,7 +1097,6 @@ impl Initializer { + /// `write` in a loop until its entire input has been written. + /// + /// [`write_all`]: #method.write_all +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this writer, returning how many bytes were written. +@@ -1130,7 +1145,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Like `write`, except that it writes from a slice of buffers. +@@ -1141,7 +1155,7 @@ pub trait Write { + /// + /// The default implementation calls `write` with either the first nonempty + /// buffer provided, or an empty one if none exists. +- #[unstable(feature = "iovec", issue = "58452")] ++ #[cfg(feature="collections")] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> Result { + default_write_vectored(|b| self.write(b), bufs) + } +@@ -1169,7 +1183,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this writer. +@@ -1202,7 +1215,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1254,7 +1266,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments<'_>) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1310,7 +1321,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1340,7 +1350,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1356,7 +1365,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + + /// Returns the length of this stream (in bytes). +@@ -1394,7 +1402,6 @@ pub trait Seek { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "seek_convenience", issue = "59359")] + fn stream_len(&mut self) -> Result { + let old_pos = self.stream_position()?; + let len = self.seek(SeekFrom::End(0))?; +@@ -1433,7 +1440,6 @@ pub trait Seek { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "seek_convenience", issue = "59359")] + fn stream_position(&mut self) -> Result { + self.seek(SeekFrom::Current(0)) + } +@@ -1445,29 +1451,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Sets the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Sets the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Sets the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1547,7 +1550,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Returns the contents of the internal buffer, filling it with more data + /// from the inner reader if it is empty. +@@ -1593,7 +1596,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1615,7 +1617,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1671,7 +1672,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1730,7 +1730,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1771,7 +1770,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1810,7 +1808,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1822,7 +1819,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1848,7 +1844,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1871,7 +1866,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1898,13 +1892,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Chain") +@@ -1914,7 +1906,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1926,6 +1917,7 @@ impl Read for Chain { + self.second.read(buf) + } + ++ #[cfg(feature="collections")] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> Result { + if !self.done_first { + match self.first.read_vectored(bufs)? { +@@ -1946,7 +1938,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1973,7 +1965,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -2008,7 +1999,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -2034,7 +2024,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "take_set_limit", since = "1.27.0")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -2059,7 +2048,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -2084,7 +2072,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -2113,13 +2100,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -2136,15 +2121,9 @@ impl Read for Take { + unsafe fn initializer(&self) -> Initializer { + self.inner.initializer() + } +- +- fn read_to_end(&mut self, buf: &mut Vec) -> Result { +- let reservation_size = cmp::min(self.limit, 32) as usize; +- +- read_to_end_with_reservation(self, buf, reservation_size) +- } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -2171,13 +2150,11 @@ impl BufRead for Take { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -2201,14 +2178,14 @@ impl Iterator for Bytes { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -2233,13 +2210,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 2e19edf..66294a3 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -8,7 +8,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index d2638be..1296fe1 100644 +--- a/util.rs ++++ b/util.rs +@@ -1,8 +1,9 @@ + #![allow(missing_copy_implementations)] + +-use crate::fmt; +-use crate::io::{self, Read, Initializer, Write, ErrorKind, BufRead, IoVec, IoVecMut}; +-use crate::mem; ++use core::fmt; ++use crate::io::{self, Read, Initializer, Write, ErrorKind}; ++#[cfg(feature="collections")] use crate::io::{BufRead, IoVec, IoVecMut}; ++use core::mem; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -39,7 +40,6 @@ use crate::mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -68,7 +68,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -88,10 +87,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -101,7 +98,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -109,7 +107,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.pad("Empty { .. }") +@@ -122,7 +119,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -139,10 +135,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -152,6 +146,7 @@ impl Read for Repeat { + Ok(buf.len()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let mut nwritten = 0; +@@ -167,7 +162,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -180,7 +174,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -197,14 +190,13 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + let total_len = bufs.iter().map(|b| b.len()).sum(); +@@ -215,7 +207,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/3c9e884dd3bf93b1516d3b5858072b7659c4cfba.patch b/patches/3c9e884dd3bf93b1516d3b5858072b7659c4cfba.patch new file mode 100644 index 0000000..6fd7e21 --- /dev/null +++ b/patches/3c9e884dd3bf93b1516d3b5858072b7659c4cfba.patch @@ -0,0 +1,1600 @@ +diff --git a/buffered.rs b/buffered.rs +index e26e6d3..c754cf1 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -10,13 +10,13 @@ + + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use io::prelude::*; + +-use cmp; +-use error; +-use fmt; ++use core::cmp; ++use core::fmt; + use io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom}; +-use memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -52,7 +52,6 @@ use memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -76,7 +75,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -97,7 +95,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -130,7 +127,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -151,7 +147,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + + /// Returns a reference to the internally buffered data. +@@ -176,7 +171,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -199,7 +193,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + } + +@@ -208,7 +201,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -228,7 +220,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -251,7 +242,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -271,7 +261,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -281,7 +270,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -387,7 +375,6 @@ impl Seek for BufReader { + /// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -422,7 +409,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -437,7 +423,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -455,7 +440,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -504,7 +488,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -522,7 +505,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Unwraps this `BufWriter`, returning the underlying writer. +@@ -544,7 +526,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -553,7 +534,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -573,7 +553,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -583,7 +562,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -593,7 +571,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -632,7 +609,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -665,23 +641,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -752,7 +718,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -773,7 +738,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -794,7 +758,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -818,7 +781,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -841,7 +803,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -867,7 +828,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -878,7 +838,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -923,7 +882,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index 14f2015..1d60dac 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -10,8 +10,8 @@ + + use io::prelude::*; + +-use core::convert::TryInto; +-use cmp; ++#[cfg(feature="collections")] use core::convert::TryInto; ++use core::cmp; + use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + + /// A `Cursor` wraps an in-memory buffer and provides it with a +@@ -80,7 +80,6 @@ use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -103,7 +102,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -121,7 +119,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -137,7 +134,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -156,7 +152,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -178,7 +173,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -198,11 +192,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -223,17 +215,16 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -244,12 +235,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -262,6 +257,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result, buf: &[u8]) -> io::Result { + let pos: usize = (*pos_mut).try_into().map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -288,7 +284,6 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result Write for Cursor<&'a mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -297,7 +292,7 @@ impl<'a> Write for Cursor<&'a mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl<'a> Write for Cursor<&'a mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) +@@ -305,7 +300,7 @@ impl<'a> Write for Cursor<&'a mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) +@@ -313,8 +308,8 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) +diff --git a/error.rs b/error.rs +index 3e50988..71667ce 100644 +--- a/error.rs ++++ b/error.rs +@@ -8,11 +8,16 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use error; +-use fmt; +-use result; +-use sys; +-use convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -48,7 +53,6 @@ use convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -62,12 +66,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -77,13 +79,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -95,48 +100,35 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + #[non_exhaustive] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -148,10 +140,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -162,15 +152,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -179,7 +166,6 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + } + +@@ -210,7 +196,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + #[inline] + fn from(kind: ErrorKind) -> Error { +@@ -239,14 +224,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -255,24 +239,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -298,7 +264,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -329,7 +294,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -363,12 +327,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(dyn error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -434,12 +397,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -468,8 +430,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -495,10 +456,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -510,22 +470,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -533,24 +489,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- fn cause(&self) -> Option<&dyn error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index fe1179a..452b8b7 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -8,15 +8,18 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use cmp; +-use io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind}; +-use fmt; +-use mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use io::BufRead; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, R: Read + ?Sized> Read for &'a mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -28,11 +31,13 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -43,7 +48,6 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, W: Write + ?Sized> Write for &'a mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -61,12 +65,11 @@ impl<'a, W: Write + ?Sized> Write for &'a mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, S: Seek + ?Sized> Seek for &'a mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -85,7 +88,7 @@ impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -97,11 +100,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -112,7 +117,7 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -130,12 +135,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -161,7 +166,6 @@ impl BufRead for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Read for &'a [u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -207,6 +211,7 @@ impl<'a> Read for &'a [u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -216,7 +221,7 @@ impl<'a> Read for &'a [u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a> BufRead for &'a [u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -230,7 +235,6 @@ impl<'a> BufRead for &'a [u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Write for &'a mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -256,7 +260,7 @@ impl<'a> Write for &'a mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +diff --git a/mod.rs b/mod.rs +index 278ee79..ebe2495 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -267,47 +267,36 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use cmp; +-use fmt; +-use str; +-use memchr; +-use ptr; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::cmp; ++use core::fmt; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++use core::ptr; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl<'a> Drop for Guard<'a> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -332,6 +321,7 @@ impl<'a> Drop for Guard<'a> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -359,10 +349,12 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + read_to_end_with_reservation(r, buf, 32) + } + ++#[cfg(feature="collections")] + fn read_to_end_with_reservation(r: &mut R, + buf: &mut Vec, + reservation_size: usize) -> Result +@@ -469,7 +461,6 @@ fn read_to_end_with_reservation(r: &mut R, + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -526,7 +517,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Determines if this `Read`er can work with buffers of uninitialized +@@ -551,7 +541,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -604,7 +593,7 @@ pub trait Read { + /// file.) + /// + /// [`std::fs::read`]: ../fs/fn.read.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -647,7 +636,7 @@ pub trait Read { + /// reading from a file.) + /// + /// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -710,7 +699,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -762,7 +750,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -799,7 +786,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } +@@ -834,7 +820,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -870,20 +855,17 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -897,21 +879,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -954,7 +933,6 @@ impl Initializer { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this object, returning how many bytes were written. +@@ -1003,7 +981,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Flush this output stream, ensuring that all intermediately buffered +@@ -1029,7 +1006,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this write. +@@ -1062,7 +1038,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1114,7 +1089,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1170,7 +1144,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1200,7 +1173,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1216,7 +1188,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + } + +@@ -1226,29 +1197,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Set the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Set the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Set the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1328,7 +1296,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Returns the contents of the internal buffer, filling it with more data + /// from the inner reader if it is empty. +@@ -1374,7 +1342,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1396,7 +1363,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1452,7 +1418,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1511,7 +1476,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1552,7 +1516,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1591,7 +1554,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1603,7 +1565,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1629,7 +1590,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1652,7 +1612,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1679,13 +1638,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1695,7 +1652,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1717,7 +1673,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1744,7 +1700,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -1779,7 +1734,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -1805,7 +1759,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "take_set_limit", since = "1.27.0")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -1830,7 +1783,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -1855,7 +1807,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -1884,13 +1835,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -1907,15 +1856,9 @@ impl Read for Take { + unsafe fn initializer(&self) -> Initializer { + self.inner.initializer() + } +- +- fn read_to_end(&mut self, buf: &mut Vec) -> Result { +- let reservation_size = cmp::min(self.limit, 32) as usize; +- +- read_to_end_with_reservation(self, buf, reservation_size) +- } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -1954,13 +1897,11 @@ fn read_one_byte(reader: &mut dyn Read) -> Option> { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -1976,14 +1917,14 @@ impl Iterator for Bytes { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -2008,13 +1949,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 8772d0f..49d66c9 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -18,7 +18,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 371e5b2..0d643e8 100644 +--- a/util.rs ++++ b/util.rs +@@ -10,9 +10,10 @@ + + #![allow(missing_copy_implementations)] + +-use fmt; +-use io::{self, Read, Initializer, Write, ErrorKind, BufRead}; +-use mem; ++use core::fmt; ++use io::{self, Read, Initializer, Write, ErrorKind}; ++use core::mem; ++#[cfg(feature="collections")] use io::BufRead; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -49,7 +50,6 @@ use mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -78,7 +78,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -98,10 +97,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -111,7 +108,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -119,7 +117,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -132,7 +129,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -149,10 +145,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte: byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -168,7 +162,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -181,7 +174,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -198,10 +190,8 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } +@@ -209,7 +199,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/472ca7159812f8c360697f63454ee7bda1e02570.patch b/patches/472ca7159812f8c360697f63454ee7bda1e02570.patch new file mode 100644 index 0000000..d4840cd --- /dev/null +++ b/patches/472ca7159812f8c360697f63454ee7bda1e02570.patch @@ -0,0 +1,1600 @@ +diff --git a/buffered.rs b/buffered.rs +index 77bc7e9..b78a15a 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -10,13 +10,13 @@ + + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use io::prelude::*; + +-use cmp; +-use error; +-use fmt; ++use core::cmp; ++use core::fmt; + use io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom}; +-use memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -52,7 +52,6 @@ use memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -76,7 +75,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -97,7 +95,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -130,7 +127,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -151,7 +147,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + + /// Returns a reference to the internally buffered data. +@@ -176,7 +171,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -199,7 +193,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + } + +@@ -208,7 +201,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -228,7 +220,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -251,7 +242,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -271,7 +261,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -281,7 +270,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -389,7 +377,6 @@ impl Seek for BufReader { + /// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -424,7 +411,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -439,7 +425,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -457,7 +442,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -506,7 +490,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -524,7 +507,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Unwraps this `BufWriter`, returning the underlying writer. +@@ -546,7 +528,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -555,7 +536,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -575,7 +555,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -585,7 +564,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -595,7 +573,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -634,7 +611,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -667,23 +643,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -754,7 +720,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -775,7 +740,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -796,7 +760,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -820,7 +783,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -843,7 +805,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -869,7 +830,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -880,7 +840,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -925,7 +884,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index 14f2015..1d60dac 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -10,8 +10,8 @@ + + use io::prelude::*; + +-use core::convert::TryInto; +-use cmp; ++#[cfg(feature="collections")] use core::convert::TryInto; ++use core::cmp; + use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + + /// A `Cursor` wraps an in-memory buffer and provides it with a +@@ -80,7 +80,6 @@ use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -103,7 +102,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -121,7 +119,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -137,7 +134,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -156,7 +152,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -178,7 +173,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -198,11 +192,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -223,17 +215,16 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -244,12 +235,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -262,6 +257,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result, buf: &[u8]) -> io::Result { + let pos: usize = (*pos_mut).try_into().map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -288,7 +284,6 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result Write for Cursor<&'a mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -297,7 +292,7 @@ impl<'a> Write for Cursor<&'a mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl<'a> Write for Cursor<&'a mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) +@@ -305,7 +300,7 @@ impl<'a> Write for Cursor<&'a mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) +@@ -313,8 +308,8 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) +diff --git a/error.rs b/error.rs +index 3e50988..71667ce 100644 +--- a/error.rs ++++ b/error.rs +@@ -8,11 +8,16 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use error; +-use fmt; +-use result; +-use sys; +-use convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -48,7 +53,6 @@ use convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -62,12 +66,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -77,13 +79,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -95,48 +100,35 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + #[non_exhaustive] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -148,10 +140,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -162,15 +152,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -179,7 +166,6 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + } + +@@ -210,7 +196,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + #[inline] + fn from(kind: ErrorKind) -> Error { +@@ -239,14 +224,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -255,24 +239,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -298,7 +264,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -329,7 +294,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -363,12 +327,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(dyn error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -434,12 +397,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -468,8 +430,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -495,10 +456,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -510,22 +470,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -533,24 +489,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- fn cause(&self) -> Option<&dyn error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index fe1179a..452b8b7 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -8,15 +8,18 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use cmp; +-use io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind}; +-use fmt; +-use mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use io::BufRead; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, R: Read + ?Sized> Read for &'a mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -28,11 +31,13 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -43,7 +48,6 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, W: Write + ?Sized> Write for &'a mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -61,12 +65,11 @@ impl<'a, W: Write + ?Sized> Write for &'a mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, S: Seek + ?Sized> Seek for &'a mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -85,7 +88,7 @@ impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -97,11 +100,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -112,7 +117,7 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -130,12 +135,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -161,7 +166,6 @@ impl BufRead for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Read for &'a [u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -207,6 +211,7 @@ impl<'a> Read for &'a [u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -216,7 +221,7 @@ impl<'a> Read for &'a [u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a> BufRead for &'a [u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -230,7 +235,6 @@ impl<'a> BufRead for &'a [u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Write for &'a mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -256,7 +260,7 @@ impl<'a> Write for &'a mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +diff --git a/mod.rs b/mod.rs +index b83f3fb..883fa30 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -267,47 +267,36 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use cmp; +-use fmt; +-use str; +-use memchr; +-use ptr; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::cmp; ++use core::fmt; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++use core::ptr; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl<'a> Drop for Guard<'a> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -332,6 +321,7 @@ impl<'a> Drop for Guard<'a> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -359,10 +349,12 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + read_to_end_with_reservation(r, buf, 32) + } + ++#[cfg(feature="collections")] + fn read_to_end_with_reservation(r: &mut R, + buf: &mut Vec, + reservation_size: usize) -> Result +@@ -469,7 +461,6 @@ fn read_to_end_with_reservation(r: &mut R, + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -526,7 +517,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Determines if this `Read`er can work with buffers of uninitialized +@@ -551,7 +541,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -604,7 +593,7 @@ pub trait Read { + /// file.) + /// + /// [`std::fs::read`]: ../fs/fn.read.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -647,7 +636,7 @@ pub trait Read { + /// reading from a file.) + /// + /// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -710,7 +699,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -762,7 +750,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -799,7 +786,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } +@@ -834,7 +820,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -870,20 +855,17 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -897,21 +879,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -954,7 +933,6 @@ impl Initializer { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this object, returning how many bytes were written. +@@ -1003,7 +981,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Flush this output stream, ensuring that all intermediately buffered +@@ -1029,7 +1006,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this write. +@@ -1062,7 +1038,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1114,7 +1089,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1170,7 +1144,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1200,7 +1173,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1216,7 +1188,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + } + +@@ -1226,29 +1197,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Set the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Set the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Set the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1328,7 +1296,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Fills the internal buffer of this object, returning the buffer contents. + /// +@@ -1373,7 +1341,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1395,7 +1362,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1451,7 +1417,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1510,7 +1475,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1551,7 +1515,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1590,7 +1553,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1602,7 +1564,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1628,7 +1589,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1651,7 +1611,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1678,13 +1637,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1694,7 +1651,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1716,7 +1672,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1743,7 +1699,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -1778,7 +1733,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -1804,7 +1758,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "take_set_limit", since = "1.27.0")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -1829,7 +1782,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -1854,7 +1806,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -1883,13 +1834,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -1906,15 +1855,9 @@ impl Read for Take { + unsafe fn initializer(&self) -> Initializer { + self.inner.initializer() + } +- +- fn read_to_end(&mut self, buf: &mut Vec) -> Result { +- let reservation_size = cmp::min(self.limit, 32) as usize; +- +- read_to_end_with_reservation(self, buf, reservation_size) +- } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -1953,13 +1896,11 @@ fn read_one_byte(reader: &mut dyn Read) -> Option> { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -1975,14 +1916,14 @@ impl Iterator for Bytes { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -2007,13 +1948,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 8772d0f..49d66c9 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -18,7 +18,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 33f741d..878fb82 100644 +--- a/util.rs ++++ b/util.rs +@@ -10,9 +10,10 @@ + + #![allow(missing_copy_implementations)] + +-use fmt; +-use io::{self, Read, Initializer, Write, ErrorKind, BufRead}; +-use mem; ++use core::fmt; ++use io::{self, Read, Initializer, Write, ErrorKind}; ++use core::mem; ++#[cfg(feature="collections")] use io::BufRead; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -44,7 +45,6 @@ use mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -73,7 +73,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -93,10 +92,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -106,7 +103,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -114,7 +112,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -127,7 +124,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -144,10 +140,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte: byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -163,7 +157,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -176,7 +169,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -193,10 +185,8 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } +@@ -204,7 +194,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/4f1e2357447ef7e8066c49560d66c3e18f25d982.patch b/patches/4f1e2357447ef7e8066c49560d66c3e18f25d982.patch new file mode 100644 index 0000000..a1cf4dc --- /dev/null +++ b/patches/4f1e2357447ef7e8066c49560d66c3e18f25d982.patch @@ -0,0 +1,1782 @@ +diff --git a/buffered.rs b/buffered.rs +index 2babf50..9ce1884 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -10,13 +10,13 @@ + + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use io::prelude::*; + +-use cmp; +-use error; +-use fmt; ++use core::cmp; ++use core::fmt; + use io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom}; +-use memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -52,7 +52,6 @@ use memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -76,7 +75,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -97,7 +95,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -130,7 +127,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -151,36 +147,8 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + +- /// Returns `true` if there are no bytes in the internal buffer. +- /// +- /// # Examples +- // +- /// ```no_run +- /// # #![feature(bufreader_is_empty)] +- /// use std::io::BufReader; +- /// use std::io::BufRead; +- /// use std::fs::File; +- /// +- /// fn main() -> std::io::Result<()> { +- /// let f1 = File::open("log.txt")?; +- /// let mut reader = BufReader::new(f1); +- /// assert!(reader.is_empty()); +- /// +- /// if reader.fill_buf()?.len() > 0 { +- /// assert!(!reader.is_empty()); +- /// } +- /// Ok(()) +- /// } +- /// ``` +- #[unstable(feature = "bufreader_is_empty", issue = "45323", reason = "recently added")] +- #[rustc_deprecated(since = "1.26.0", reason = "use .buffer().is_empty() instead")] +- pub fn is_empty(&self) -> bool { +- self.buffer().is_empty() +- } +- + /// Returns a reference to the internally buffered data. + /// + /// Unlike `fill_buf`, this will not attempt to fill the buffer if it is empty. +@@ -203,7 +171,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -226,7 +193,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + } + +@@ -235,7 +201,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -255,7 +220,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -278,7 +242,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -298,7 +261,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -308,7 +270,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -416,7 +377,6 @@ impl Seek for BufReader { + /// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -451,7 +411,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -466,7 +425,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -484,7 +442,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -533,7 +490,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -551,7 +507,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Unwraps this `BufWriter`, returning the underlying writer. +@@ -573,7 +528,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -582,7 +536,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -602,7 +555,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -612,7 +564,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -622,7 +573,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -661,7 +611,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -694,23 +643,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -781,7 +720,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -802,7 +740,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -823,7 +760,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -847,7 +783,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -870,7 +805,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -896,7 +830,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -907,7 +840,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -952,7 +884,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index 3622df1..6a4658b 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -10,8 +10,8 @@ + + use io::prelude::*; + +-use core::convert::TryInto; +-use cmp; ++#[cfg(feature="collections")] use core::convert::TryInto; ++use core::cmp; + use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + + /// A `Cursor` wraps an in-memory buffer and provides it with a +@@ -80,7 +80,6 @@ use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -103,7 +102,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -121,7 +119,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -137,7 +134,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -156,7 +152,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -178,7 +173,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -198,11 +192,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -223,17 +215,16 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -244,12 +235,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -262,6 +257,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result, buf: &[u8]) -> io::Result { + let pos: usize = (*pos_mut).try_into().map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -288,7 +284,6 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result Write for Cursor<&'a mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -297,7 +292,7 @@ impl<'a> Write for Cursor<&'a mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl<'a> Write for Cursor<&'a mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) +@@ -305,7 +300,7 @@ impl<'a> Write for Cursor<&'a mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) +@@ -313,8 +308,8 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) +diff --git a/error.rs b/error.rs +index 02a3ce8..3acdadf 100644 +--- a/error.rs ++++ b/error.rs +@@ -8,11 +8,16 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use error; +-use fmt; +-use result; +-use sys; +-use convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -48,7 +53,6 @@ use convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -62,12 +66,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -77,13 +79,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -95,47 +100,34 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -147,10 +139,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -161,15 +151,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -178,15 +165,10 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + + /// A marker variant that tells the compiler that users of this enum cannot + /// match it exhaustively. +- #[unstable(feature = "io_error_internals", +- reason = "better expressed through extensible enums that this \ +- enum cannot be exhaustively matched against", +- issue = "0")] + #[doc(hidden)] + __Nonexhaustive, + } +@@ -219,7 +201,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + #[inline] + fn from(kind: ErrorKind) -> Error { +@@ -248,14 +229,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -264,24 +244,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -307,7 +269,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -338,7 +299,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -372,12 +332,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(dyn error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -443,12 +402,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -477,8 +435,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -504,10 +461,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -519,22 +475,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -542,24 +494,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- fn cause(&self) -> Option<&dyn error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index fe1179a..452b8b7 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -8,15 +8,18 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use cmp; +-use io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind}; +-use fmt; +-use mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use io::BufRead; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, R: Read + ?Sized> Read for &'a mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -28,11 +31,13 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -43,7 +48,6 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, W: Write + ?Sized> Write for &'a mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -61,12 +65,11 @@ impl<'a, W: Write + ?Sized> Write for &'a mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, S: Seek + ?Sized> Seek for &'a mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -85,7 +88,7 @@ impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -97,11 +100,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -112,7 +117,7 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -130,12 +135,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -161,7 +166,6 @@ impl BufRead for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Read for &'a [u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -207,6 +211,7 @@ impl<'a> Read for &'a [u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -216,7 +221,7 @@ impl<'a> Read for &'a [u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a> BufRead for &'a [u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -230,7 +235,6 @@ impl<'a> BufRead for &'a [u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Write for &'a mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -256,7 +260,7 @@ impl<'a> Write for &'a mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +diff --git a/mod.rs b/mod.rs +index 8530487..0966a83 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -267,50 +267,36 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use cmp; +-use core::str as core_str; +-use error as std_error; +-use fmt; +-use result; +-use str; +-use memchr; +-use ptr; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::cmp; ++use core::fmt; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++use core::ptr; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl<'a> Drop for Guard<'a> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -335,6 +321,7 @@ impl<'a> Drop for Guard<'a> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -362,6 +349,7 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + let start_len = buf.len(); + let mut g = Guard { len: buf.len(), buf: buf }; +@@ -465,7 +453,6 @@ fn read_to_end(r: &mut R, buf: &mut Vec) -> Result + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -522,7 +509,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Determines if this `Read`er can work with buffers of uninitialized +@@ -547,7 +533,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -600,7 +585,7 @@ pub trait Read { + /// file.) + /// + /// [`std::fs::read`]: ../fs/fn.read.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -643,7 +628,7 @@ pub trait Read { + /// reading from a file.) + /// + /// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -706,7 +691,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -758,7 +742,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -795,58 +778,10 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } + +- /// Transforms this `Read` instance to an [`Iterator`] over [`char`]s. +- /// +- /// This adaptor will attempt to interpret this reader as a UTF-8 encoded +- /// sequence of characters. The returned iterator will return [`None`] once +- /// EOF is reached for this reader. Otherwise each element yielded will be a +- /// [`Result`]`<`[`char`]`, E>` where `E` may contain information about what I/O error +- /// occurred or where decoding failed. +- /// +- /// Currently this adaptor will discard intermediate data read, and should +- /// be avoided if this is not desired. +- /// +- /// # Examples +- /// +- /// [`File`]s implement `Read`: +- /// +- /// [`File`]: ../fs/struct.File.html +- /// [`Iterator`]: ../../std/iter/trait.Iterator.html +- /// [`Result`]: ../../std/result/enum.Result.html +- /// [`char`]: ../../std/primitive.char.html +- /// [`None`]: ../../std/option/enum.Option.html#variant.None +- /// +- /// ```no_run +- /// #![feature(io)] +- /// use std::io; +- /// use std::io::prelude::*; +- /// use std::fs::File; +- /// +- /// fn main() -> io::Result<()> { +- /// let mut f = File::open("foo.txt")?; +- /// +- /// for c in f.chars() { +- /// println!("{}", c.unwrap()); +- /// } +- /// Ok(()) +- /// } +- /// ``` +- #[unstable(feature = "io", reason = "the semantics of a partial read/write \ +- of where errors happen is currently \ +- unclear and may change", +- issue = "27802")] +- #[rustc_deprecated(since = "1.27.0", reason = "Use str::from_utf8 instead: +- https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples")] +- #[allow(deprecated)] +- fn chars(self) -> Chars where Self: Sized { +- Chars { inner: self } +- } +- + /// Creates an adaptor which will chain this stream with another. + /// + /// The returned `Read` instance will first read all bytes from this object +@@ -877,7 +812,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -913,20 +847,17 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -940,21 +871,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -997,7 +925,6 @@ impl Initializer { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this object, returning how many bytes were written. +@@ -1046,7 +973,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Flush this output stream, ensuring that all intermediately buffered +@@ -1072,7 +998,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this write. +@@ -1105,7 +1030,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1157,7 +1081,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1213,7 +1136,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1243,7 +1165,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1259,7 +1180,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + } + +@@ -1269,29 +1189,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Set the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Set the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Set the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1371,7 +1288,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Fills the internal buffer of this object, returning the buffer contents. + /// +@@ -1416,7 +1333,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1438,7 +1354,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1494,7 +1409,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1553,7 +1467,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1594,7 +1507,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1633,7 +1545,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1645,7 +1556,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1671,7 +1581,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1694,7 +1603,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1721,13 +1629,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1737,7 +1643,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1759,7 +1664,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1786,7 +1691,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -1821,7 +1725,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -1847,7 +1750,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "take_set_limit", since = "1.27.0")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -1872,7 +1774,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -1897,7 +1798,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -1926,13 +1826,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -1951,7 +1849,7 @@ impl Read for Take { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -1990,13 +1888,11 @@ fn read_one_byte(reader: &mut dyn Read) -> Option> { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -2005,104 +1901,6 @@ impl Iterator for Bytes { + } + } + +-/// An iterator over the `char`s of a reader. +-/// +-/// This struct is generally created by calling [`chars`][chars] on a reader. +-/// Please see the documentation of `chars()` for more details. +-/// +-/// [chars]: trait.Read.html#method.chars +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] +-#[rustc_deprecated(since = "1.27.0", reason = "Use str::from_utf8 instead: +- https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples")] +-#[derive(Debug)] +-#[allow(deprecated)] +-pub struct Chars { +- inner: R, +-} +- +-/// An enumeration of possible errors that can be generated from the `Chars` +-/// adapter. +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] +-#[rustc_deprecated(since = "1.27.0", reason = "Use str::from_utf8 instead: +- https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples")] +-#[derive(Debug)] +-#[allow(deprecated)] +-pub enum CharsError { +- /// Variant representing that the underlying stream was read successfully +- /// but it did not contain valid utf8 data. +- NotUtf8, +- +- /// Variant representing that an I/O error occurred. +- Other(Error), +-} +- +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] +-#[allow(deprecated)] +-impl Iterator for Chars { +- type Item = result::Result; +- +- fn next(&mut self) -> Option> { +- let first_byte = match read_one_byte(&mut self.inner)? { +- Ok(b) => b, +- Err(e) => return Some(Err(CharsError::Other(e))), +- }; +- let width = core_str::utf8_char_width(first_byte); +- if width == 1 { return Some(Ok(first_byte as char)) } +- if width == 0 { return Some(Err(CharsError::NotUtf8)) } +- let mut buf = [first_byte, 0, 0, 0]; +- { +- let mut start = 1; +- while start < width { +- match self.inner.read(&mut buf[start..width]) { +- Ok(0) => return Some(Err(CharsError::NotUtf8)), +- Ok(n) => start += n, +- Err(ref e) if e.kind() == ErrorKind::Interrupted => continue, +- Err(e) => return Some(Err(CharsError::Other(e))), +- } +- } +- } +- Some(match str::from_utf8(&buf[..width]).ok() { +- Some(s) => Ok(s.chars().next().unwrap()), +- None => Err(CharsError::NotUtf8), +- }) +- } +-} +- +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] +-#[allow(deprecated)] +-impl std_error::Error for CharsError { +- fn description(&self) -> &str { +- match *self { +- CharsError::NotUtf8 => "invalid utf8 encoding", +- CharsError::Other(ref e) => std_error::Error::description(e), +- } +- } +- fn cause(&self) -> Option<&dyn std_error::Error> { +- match *self { +- CharsError::NotUtf8 => None, +- CharsError::Other(ref e) => e.cause(), +- } +- } +-} +- +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] +-#[allow(deprecated)] +-impl fmt::Display for CharsError { +- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +- match *self { +- CharsError::NotUtf8 => { +- "byte stream did not contain valid utf8".fmt(f) +- } +- CharsError::Other(ref e) => e.fmt(f), +- } +- } +-} +- + /// An iterator over the contents of an instance of `BufRead` split on a + /// particular byte. + /// +@@ -2110,14 +1908,14 @@ impl fmt::Display for CharsError { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -2142,13 +1940,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 8772d0f..49d66c9 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -18,7 +18,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 33f741d..878fb82 100644 +--- a/util.rs ++++ b/util.rs +@@ -10,9 +10,10 @@ + + #![allow(missing_copy_implementations)] + +-use fmt; +-use io::{self, Read, Initializer, Write, ErrorKind, BufRead}; +-use mem; ++use core::fmt; ++use io::{self, Read, Initializer, Write, ErrorKind}; ++use core::mem; ++#[cfg(feature="collections")] use io::BufRead; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -44,7 +45,6 @@ use mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -73,7 +73,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -93,10 +92,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -106,7 +103,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -114,7 +112,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -127,7 +124,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -144,10 +140,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte: byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -163,7 +157,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -176,7 +169,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -193,10 +185,8 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } +@@ -204,7 +194,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/5285d35b49e1e8976f2a8d9d2e6f5bd1324016d3.patch b/patches/5285d35b49e1e8976f2a8d9d2e6f5bd1324016d3.patch new file mode 100644 index 0000000..15e4f73 --- /dev/null +++ b/patches/5285d35b49e1e8976f2a8d9d2e6f5bd1324016d3.patch @@ -0,0 +1,1600 @@ +diff --git a/buffered.rs b/buffered.rs +index e26e6d3..c754cf1 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -10,13 +10,13 @@ + + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use io::prelude::*; + +-use cmp; +-use error; +-use fmt; ++use core::cmp; ++use core::fmt; + use io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom}; +-use memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -52,7 +52,6 @@ use memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -76,7 +75,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -97,7 +95,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -130,7 +127,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -151,7 +147,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + + /// Returns a reference to the internally buffered data. +@@ -176,7 +171,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -199,7 +193,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + } + +@@ -208,7 +201,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -228,7 +220,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -251,7 +242,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -271,7 +261,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -281,7 +270,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -387,7 +375,6 @@ impl Seek for BufReader { + /// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -422,7 +409,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -437,7 +423,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -455,7 +440,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -504,7 +488,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -522,7 +505,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Unwraps this `BufWriter`, returning the underlying writer. +@@ -544,7 +526,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -553,7 +534,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -573,7 +553,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -583,7 +562,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -593,7 +571,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -632,7 +609,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -665,23 +641,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -752,7 +718,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -773,7 +738,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -794,7 +758,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -818,7 +781,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -841,7 +803,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -867,7 +828,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -878,7 +838,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -923,7 +882,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index 14f2015..1d60dac 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -10,8 +10,8 @@ + + use io::prelude::*; + +-use core::convert::TryInto; +-use cmp; ++#[cfg(feature="collections")] use core::convert::TryInto; ++use core::cmp; + use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + + /// A `Cursor` wraps an in-memory buffer and provides it with a +@@ -80,7 +80,6 @@ use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -103,7 +102,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -121,7 +119,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -137,7 +134,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -156,7 +152,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -178,7 +173,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -198,11 +192,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -223,17 +215,16 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -244,12 +235,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -262,6 +257,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result, buf: &[u8]) -> io::Result { + let pos: usize = (*pos_mut).try_into().map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -288,7 +284,6 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result Write for Cursor<&'a mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -297,7 +292,7 @@ impl<'a> Write for Cursor<&'a mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl<'a> Write for Cursor<&'a mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) +@@ -305,7 +300,7 @@ impl<'a> Write for Cursor<&'a mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) +@@ -313,8 +308,8 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) +diff --git a/error.rs b/error.rs +index 3e50988..71667ce 100644 +--- a/error.rs ++++ b/error.rs +@@ -8,11 +8,16 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use error; +-use fmt; +-use result; +-use sys; +-use convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -48,7 +53,6 @@ use convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -62,12 +66,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -77,13 +79,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -95,48 +100,35 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + #[non_exhaustive] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -148,10 +140,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -162,15 +152,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -179,7 +166,6 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + } + +@@ -210,7 +196,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + #[inline] + fn from(kind: ErrorKind) -> Error { +@@ -239,14 +224,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -255,24 +239,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -298,7 +264,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -329,7 +294,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -363,12 +327,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(dyn error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -434,12 +397,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -468,8 +430,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -495,10 +456,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -510,22 +470,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -533,24 +489,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- fn cause(&self) -> Option<&dyn error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index fe1179a..452b8b7 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -8,15 +8,18 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use cmp; +-use io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind}; +-use fmt; +-use mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use io::BufRead; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, R: Read + ?Sized> Read for &'a mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -28,11 +31,13 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -43,7 +48,6 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, W: Write + ?Sized> Write for &'a mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -61,12 +65,11 @@ impl<'a, W: Write + ?Sized> Write for &'a mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, S: Seek + ?Sized> Seek for &'a mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -85,7 +88,7 @@ impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -97,11 +100,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -112,7 +117,7 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -130,12 +135,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -161,7 +166,6 @@ impl BufRead for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Read for &'a [u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -207,6 +211,7 @@ impl<'a> Read for &'a [u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -216,7 +221,7 @@ impl<'a> Read for &'a [u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a> BufRead for &'a [u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -230,7 +235,6 @@ impl<'a> BufRead for &'a [u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Write for &'a mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -256,7 +260,7 @@ impl<'a> Write for &'a mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +diff --git a/mod.rs b/mod.rs +index e263db2..2176464 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -267,47 +267,36 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use cmp; +-use fmt; +-use str; +-use memchr; +-use ptr; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::cmp; ++use core::fmt; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++use core::ptr; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl<'a> Drop for Guard<'a> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -332,6 +321,7 @@ impl<'a> Drop for Guard<'a> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -359,10 +349,12 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + read_to_end_with_reservation(r, buf, 32) + } + ++#[cfg(feature="collections")] + fn read_to_end_with_reservation(r: &mut R, + buf: &mut Vec, + reservation_size: usize) -> Result +@@ -469,7 +461,6 @@ fn read_to_end_with_reservation(r: &mut R, + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -526,7 +517,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Determines if this `Read`er can work with buffers of uninitialized +@@ -551,7 +541,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -604,7 +593,7 @@ pub trait Read { + /// file.) + /// + /// [`std::fs::read`]: ../fs/fn.read.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -647,7 +636,7 @@ pub trait Read { + /// reading from a file.) + /// + /// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -710,7 +699,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -762,7 +750,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -799,7 +786,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } +@@ -834,7 +820,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -870,20 +855,17 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -897,21 +879,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -954,7 +933,6 @@ impl Initializer { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this object, returning how many bytes were written. +@@ -1003,7 +981,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Flush this output stream, ensuring that all intermediately buffered +@@ -1029,7 +1006,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this write. +@@ -1062,7 +1038,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1114,7 +1089,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1170,7 +1144,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1200,7 +1173,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1216,7 +1188,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + } + +@@ -1226,29 +1197,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Set the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Set the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Set the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1328,7 +1296,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Returns the contents of the internal buffer, filling it with more data + /// from the inner reader if it is empty. +@@ -1374,7 +1342,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1396,7 +1363,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1452,7 +1418,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1511,7 +1476,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1552,7 +1516,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1591,7 +1554,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1603,7 +1565,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1629,7 +1590,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1652,7 +1612,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1679,13 +1638,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1695,7 +1652,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1717,7 +1673,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1744,7 +1700,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -1779,7 +1734,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -1805,7 +1759,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "take_set_limit", since = "1.27.0")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -1830,7 +1783,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -1855,7 +1807,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -1884,13 +1835,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -1907,15 +1856,9 @@ impl Read for Take { + unsafe fn initializer(&self) -> Initializer { + self.inner.initializer() + } +- +- fn read_to_end(&mut self, buf: &mut Vec) -> Result { +- let reservation_size = cmp::min(self.limit, 32) as usize; +- +- read_to_end_with_reservation(self, buf, reservation_size) +- } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -1954,13 +1897,11 @@ fn read_one_byte(reader: &mut dyn Read) -> Option> { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -1976,14 +1917,14 @@ impl Iterator for Bytes { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -2008,13 +1949,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 8772d0f..49d66c9 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -18,7 +18,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 371e5b2..0d643e8 100644 +--- a/util.rs ++++ b/util.rs +@@ -10,9 +10,10 @@ + + #![allow(missing_copy_implementations)] + +-use fmt; +-use io::{self, Read, Initializer, Write, ErrorKind, BufRead}; +-use mem; ++use core::fmt; ++use io::{self, Read, Initializer, Write, ErrorKind}; ++use core::mem; ++#[cfg(feature="collections")] use io::BufRead; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -49,7 +50,6 @@ use mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -78,7 +78,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -98,10 +97,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -111,7 +108,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -119,7 +117,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -132,7 +129,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -149,10 +145,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte: byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -168,7 +162,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -181,7 +174,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -198,10 +190,8 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } +@@ -209,7 +199,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/654c5788aa2130acfc89a0883952c6de4bddac95.patch b/patches/654c5788aa2130acfc89a0883952c6de4bddac95.patch new file mode 100644 index 0000000..4d1a7c8 --- /dev/null +++ b/patches/654c5788aa2130acfc89a0883952c6de4bddac95.patch @@ -0,0 +1,1600 @@ +diff --git a/buffered.rs b/buffered.rs +index 77bc7e9..b78a15a 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -10,13 +10,13 @@ + + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use io::prelude::*; + +-use cmp; +-use error; +-use fmt; ++use core::cmp; ++use core::fmt; + use io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom}; +-use memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -52,7 +52,6 @@ use memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -76,7 +75,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -97,7 +95,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -130,7 +127,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -151,7 +147,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + + /// Returns a reference to the internally buffered data. +@@ -176,7 +171,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -199,7 +193,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + } + +@@ -208,7 +201,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -228,7 +220,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -251,7 +242,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -271,7 +261,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -281,7 +270,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -389,7 +377,6 @@ impl Seek for BufReader { + /// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -424,7 +411,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -439,7 +425,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -457,7 +442,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -506,7 +490,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -524,7 +507,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Unwraps this `BufWriter`, returning the underlying writer. +@@ -546,7 +528,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -555,7 +536,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -575,7 +555,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -585,7 +564,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -595,7 +573,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -634,7 +611,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -667,23 +643,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -754,7 +720,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -775,7 +740,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -796,7 +760,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -820,7 +783,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -843,7 +805,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -869,7 +830,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -880,7 +840,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -925,7 +884,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index 14f2015..1d60dac 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -10,8 +10,8 @@ + + use io::prelude::*; + +-use core::convert::TryInto; +-use cmp; ++#[cfg(feature="collections")] use core::convert::TryInto; ++use core::cmp; + use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + + /// A `Cursor` wraps an in-memory buffer and provides it with a +@@ -80,7 +80,6 @@ use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -103,7 +102,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -121,7 +119,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -137,7 +134,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -156,7 +152,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -178,7 +173,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -198,11 +192,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -223,17 +215,16 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -244,12 +235,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -262,6 +257,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result, buf: &[u8]) -> io::Result { + let pos: usize = (*pos_mut).try_into().map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -288,7 +284,6 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result Write for Cursor<&'a mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -297,7 +292,7 @@ impl<'a> Write for Cursor<&'a mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl<'a> Write for Cursor<&'a mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) +@@ -305,7 +300,7 @@ impl<'a> Write for Cursor<&'a mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) +@@ -313,8 +308,8 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) +diff --git a/error.rs b/error.rs +index 3e50988..71667ce 100644 +--- a/error.rs ++++ b/error.rs +@@ -8,11 +8,16 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use error; +-use fmt; +-use result; +-use sys; +-use convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -48,7 +53,6 @@ use convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -62,12 +66,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -77,13 +79,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -95,48 +100,35 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + #[non_exhaustive] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -148,10 +140,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -162,15 +152,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -179,7 +166,6 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + } + +@@ -210,7 +196,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + #[inline] + fn from(kind: ErrorKind) -> Error { +@@ -239,14 +224,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -255,24 +239,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -298,7 +264,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -329,7 +294,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -363,12 +327,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(dyn error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -434,12 +397,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -468,8 +430,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -495,10 +456,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -510,22 +470,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -533,24 +489,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- fn cause(&self) -> Option<&dyn error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index fe1179a..452b8b7 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -8,15 +8,18 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use cmp; +-use io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind}; +-use fmt; +-use mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use io::BufRead; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, R: Read + ?Sized> Read for &'a mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -28,11 +31,13 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -43,7 +48,6 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, W: Write + ?Sized> Write for &'a mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -61,12 +65,11 @@ impl<'a, W: Write + ?Sized> Write for &'a mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, S: Seek + ?Sized> Seek for &'a mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -85,7 +88,7 @@ impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -97,11 +100,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -112,7 +117,7 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -130,12 +135,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -161,7 +166,6 @@ impl BufRead for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Read for &'a [u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -207,6 +211,7 @@ impl<'a> Read for &'a [u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -216,7 +221,7 @@ impl<'a> Read for &'a [u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a> BufRead for &'a [u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -230,7 +235,6 @@ impl<'a> BufRead for &'a [u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Write for &'a mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -256,7 +260,7 @@ impl<'a> Write for &'a mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +diff --git a/mod.rs b/mod.rs +index b83f3fb..883fa30 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -267,47 +267,36 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use cmp; +-use fmt; +-use str; +-use memchr; +-use ptr; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::cmp; ++use core::fmt; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++use core::ptr; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl<'a> Drop for Guard<'a> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -332,6 +321,7 @@ impl<'a> Drop for Guard<'a> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -359,10 +349,12 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + read_to_end_with_reservation(r, buf, 32) + } + ++#[cfg(feature="collections")] + fn read_to_end_with_reservation(r: &mut R, + buf: &mut Vec, + reservation_size: usize) -> Result +@@ -469,7 +461,6 @@ fn read_to_end_with_reservation(r: &mut R, + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -526,7 +517,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Determines if this `Read`er can work with buffers of uninitialized +@@ -551,7 +541,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -604,7 +593,7 @@ pub trait Read { + /// file.) + /// + /// [`std::fs::read`]: ../fs/fn.read.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -647,7 +636,7 @@ pub trait Read { + /// reading from a file.) + /// + /// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -710,7 +699,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -762,7 +750,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -799,7 +786,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } +@@ -834,7 +820,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -870,20 +855,17 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -897,21 +879,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -954,7 +933,6 @@ impl Initializer { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this object, returning how many bytes were written. +@@ -1003,7 +981,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Flush this output stream, ensuring that all intermediately buffered +@@ -1029,7 +1006,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this write. +@@ -1062,7 +1038,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1114,7 +1089,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1170,7 +1144,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1200,7 +1173,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1216,7 +1188,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + } + +@@ -1226,29 +1197,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Set the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Set the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Set the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1328,7 +1296,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Fills the internal buffer of this object, returning the buffer contents. + /// +@@ -1373,7 +1341,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1395,7 +1362,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1451,7 +1417,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1510,7 +1475,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1551,7 +1515,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1590,7 +1553,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1602,7 +1564,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1628,7 +1589,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1651,7 +1611,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1678,13 +1637,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1694,7 +1651,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1716,7 +1672,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1743,7 +1699,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -1778,7 +1733,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -1804,7 +1758,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "take_set_limit", since = "1.27.0")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -1829,7 +1782,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -1854,7 +1806,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -1883,13 +1834,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -1906,15 +1855,9 @@ impl Read for Take { + unsafe fn initializer(&self) -> Initializer { + self.inner.initializer() + } +- +- fn read_to_end(&mut self, buf: &mut Vec) -> Result { +- let reservation_size = cmp::min(self.limit, 32) as usize; +- +- read_to_end_with_reservation(self, buf, reservation_size) +- } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -1953,13 +1896,11 @@ fn read_one_byte(reader: &mut dyn Read) -> Option> { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -1975,14 +1916,14 @@ impl Iterator for Bytes { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -2007,13 +1948,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 8772d0f..49d66c9 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -18,7 +18,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 371e5b2..0d643e8 100644 +--- a/util.rs ++++ b/util.rs +@@ -10,9 +10,10 @@ + + #![allow(missing_copy_implementations)] + +-use fmt; +-use io::{self, Read, Initializer, Write, ErrorKind, BufRead}; +-use mem; ++use core::fmt; ++use io::{self, Read, Initializer, Write, ErrorKind}; ++use core::mem; ++#[cfg(feature="collections")] use io::BufRead; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -49,7 +50,6 @@ use mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -78,7 +78,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -98,10 +97,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -111,7 +108,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -119,7 +117,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -132,7 +129,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -149,10 +145,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte: byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -168,7 +162,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -181,7 +174,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -198,10 +190,8 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } +@@ -209,7 +199,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/71120ef1e5cb885ee45e6148970db6ce93ce1aca.patch b/patches/71120ef1e5cb885ee45e6148970db6ce93ce1aca.patch new file mode 100644 index 0000000..d4840cd --- /dev/null +++ b/patches/71120ef1e5cb885ee45e6148970db6ce93ce1aca.patch @@ -0,0 +1,1600 @@ +diff --git a/buffered.rs b/buffered.rs +index 77bc7e9..b78a15a 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -10,13 +10,13 @@ + + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use io::prelude::*; + +-use cmp; +-use error; +-use fmt; ++use core::cmp; ++use core::fmt; + use io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom}; +-use memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -52,7 +52,6 @@ use memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -76,7 +75,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -97,7 +95,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -130,7 +127,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -151,7 +147,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + + /// Returns a reference to the internally buffered data. +@@ -176,7 +171,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -199,7 +193,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + } + +@@ -208,7 +201,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -228,7 +220,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -251,7 +242,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -271,7 +261,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -281,7 +270,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -389,7 +377,6 @@ impl Seek for BufReader { + /// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -424,7 +411,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -439,7 +425,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -457,7 +442,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -506,7 +490,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -524,7 +507,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Unwraps this `BufWriter`, returning the underlying writer. +@@ -546,7 +528,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -555,7 +536,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -575,7 +555,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -585,7 +564,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -595,7 +573,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -634,7 +611,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -667,23 +643,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -754,7 +720,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -775,7 +740,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -796,7 +760,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -820,7 +783,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -843,7 +805,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -869,7 +830,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -880,7 +840,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -925,7 +884,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index 14f2015..1d60dac 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -10,8 +10,8 @@ + + use io::prelude::*; + +-use core::convert::TryInto; +-use cmp; ++#[cfg(feature="collections")] use core::convert::TryInto; ++use core::cmp; + use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + + /// A `Cursor` wraps an in-memory buffer and provides it with a +@@ -80,7 +80,6 @@ use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -103,7 +102,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -121,7 +119,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -137,7 +134,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -156,7 +152,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -178,7 +173,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -198,11 +192,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -223,17 +215,16 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -244,12 +235,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -262,6 +257,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result, buf: &[u8]) -> io::Result { + let pos: usize = (*pos_mut).try_into().map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -288,7 +284,6 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result Write for Cursor<&'a mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -297,7 +292,7 @@ impl<'a> Write for Cursor<&'a mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl<'a> Write for Cursor<&'a mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) +@@ -305,7 +300,7 @@ impl<'a> Write for Cursor<&'a mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) +@@ -313,8 +308,8 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) +diff --git a/error.rs b/error.rs +index 3e50988..71667ce 100644 +--- a/error.rs ++++ b/error.rs +@@ -8,11 +8,16 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use error; +-use fmt; +-use result; +-use sys; +-use convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -48,7 +53,6 @@ use convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -62,12 +66,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -77,13 +79,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -95,48 +100,35 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + #[non_exhaustive] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -148,10 +140,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -162,15 +152,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -179,7 +166,6 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + } + +@@ -210,7 +196,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + #[inline] + fn from(kind: ErrorKind) -> Error { +@@ -239,14 +224,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -255,24 +239,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -298,7 +264,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -329,7 +294,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -363,12 +327,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(dyn error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -434,12 +397,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -468,8 +430,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -495,10 +456,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -510,22 +470,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -533,24 +489,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- fn cause(&self) -> Option<&dyn error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index fe1179a..452b8b7 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -8,15 +8,18 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use cmp; +-use io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind}; +-use fmt; +-use mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use io::BufRead; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, R: Read + ?Sized> Read for &'a mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -28,11 +31,13 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -43,7 +48,6 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, W: Write + ?Sized> Write for &'a mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -61,12 +65,11 @@ impl<'a, W: Write + ?Sized> Write for &'a mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, S: Seek + ?Sized> Seek for &'a mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -85,7 +88,7 @@ impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -97,11 +100,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -112,7 +117,7 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -130,12 +135,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -161,7 +166,6 @@ impl BufRead for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Read for &'a [u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -207,6 +211,7 @@ impl<'a> Read for &'a [u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -216,7 +221,7 @@ impl<'a> Read for &'a [u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a> BufRead for &'a [u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -230,7 +235,6 @@ impl<'a> BufRead for &'a [u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Write for &'a mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -256,7 +260,7 @@ impl<'a> Write for &'a mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +diff --git a/mod.rs b/mod.rs +index b83f3fb..883fa30 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -267,47 +267,36 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use cmp; +-use fmt; +-use str; +-use memchr; +-use ptr; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::cmp; ++use core::fmt; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++use core::ptr; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl<'a> Drop for Guard<'a> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -332,6 +321,7 @@ impl<'a> Drop for Guard<'a> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -359,10 +349,12 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + read_to_end_with_reservation(r, buf, 32) + } + ++#[cfg(feature="collections")] + fn read_to_end_with_reservation(r: &mut R, + buf: &mut Vec, + reservation_size: usize) -> Result +@@ -469,7 +461,6 @@ fn read_to_end_with_reservation(r: &mut R, + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -526,7 +517,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Determines if this `Read`er can work with buffers of uninitialized +@@ -551,7 +541,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -604,7 +593,7 @@ pub trait Read { + /// file.) + /// + /// [`std::fs::read`]: ../fs/fn.read.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -647,7 +636,7 @@ pub trait Read { + /// reading from a file.) + /// + /// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -710,7 +699,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -762,7 +750,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -799,7 +786,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } +@@ -834,7 +820,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -870,20 +855,17 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -897,21 +879,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -954,7 +933,6 @@ impl Initializer { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this object, returning how many bytes were written. +@@ -1003,7 +981,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Flush this output stream, ensuring that all intermediately buffered +@@ -1029,7 +1006,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this write. +@@ -1062,7 +1038,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1114,7 +1089,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1170,7 +1144,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1200,7 +1173,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1216,7 +1188,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + } + +@@ -1226,29 +1197,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Set the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Set the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Set the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1328,7 +1296,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Fills the internal buffer of this object, returning the buffer contents. + /// +@@ -1373,7 +1341,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1395,7 +1362,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1451,7 +1417,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1510,7 +1475,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1551,7 +1515,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1590,7 +1553,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1602,7 +1564,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1628,7 +1589,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1651,7 +1611,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1678,13 +1637,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1694,7 +1651,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1716,7 +1672,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1743,7 +1699,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -1778,7 +1733,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -1804,7 +1758,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "take_set_limit", since = "1.27.0")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -1829,7 +1782,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -1854,7 +1806,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -1883,13 +1834,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -1906,15 +1855,9 @@ impl Read for Take { + unsafe fn initializer(&self) -> Initializer { + self.inner.initializer() + } +- +- fn read_to_end(&mut self, buf: &mut Vec) -> Result { +- let reservation_size = cmp::min(self.limit, 32) as usize; +- +- read_to_end_with_reservation(self, buf, reservation_size) +- } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -1953,13 +1896,11 @@ fn read_one_byte(reader: &mut dyn Read) -> Option> { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -1975,14 +1916,14 @@ impl Iterator for Bytes { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -2007,13 +1948,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 8772d0f..49d66c9 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -18,7 +18,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 33f741d..878fb82 100644 +--- a/util.rs ++++ b/util.rs +@@ -10,9 +10,10 @@ + + #![allow(missing_copy_implementations)] + +-use fmt; +-use io::{self, Read, Initializer, Write, ErrorKind, BufRead}; +-use mem; ++use core::fmt; ++use io::{self, Read, Initializer, Write, ErrorKind}; ++use core::mem; ++#[cfg(feature="collections")] use io::BufRead; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -44,7 +45,6 @@ use mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -73,7 +73,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -93,10 +92,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -106,7 +103,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -114,7 +112,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -127,7 +124,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -144,10 +140,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte: byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -163,7 +157,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -176,7 +169,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -193,10 +185,8 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } +@@ -204,7 +194,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/7cbeddb7b78cc54a52d63ed8556da7121d1d2e68.patch b/patches/7cbeddb7b78cc54a52d63ed8556da7121d1d2e68.patch new file mode 100644 index 0000000..91edd7d --- /dev/null +++ b/patches/7cbeddb7b78cc54a52d63ed8556da7121d1d2e68.patch @@ -0,0 +1,1795 @@ +diff --git a/buffered.rs b/buffered.rs +index ee297d3..452b718 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -10,13 +10,13 @@ + + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use io::prelude::*; + +-use cmp; +-use error; +-use fmt; ++use core::cmp; ++use core::fmt; + use io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom}; +-use memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -52,7 +52,6 @@ use memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -75,7 +74,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -96,7 +94,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -129,7 +126,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -150,36 +146,8 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + +- /// Returns `true` if there are no bytes in the internal buffer. +- /// +- /// # Examples +- // +- /// ```no_run +- /// # #![feature(bufreader_is_empty)] +- /// use std::io::BufReader; +- /// use std::io::BufRead; +- /// use std::fs::File; +- /// +- /// fn main() -> std::io::Result<()> { +- /// let f1 = File::open("log.txt")?; +- /// let mut reader = BufReader::new(f1); +- /// assert!(reader.is_empty()); +- /// +- /// if reader.fill_buf()?.len() > 0 { +- /// assert!(!reader.is_empty()); +- /// } +- /// Ok(()) +- /// } +- /// ``` +- #[unstable(feature = "bufreader_is_empty", issue = "45323", reason = "recently added")] +- #[rustc_deprecated(since = "1.26.0", reason = "use .buffer().is_empty() instead")] +- pub fn is_empty(&self) -> bool { +- self.buffer().is_empty() +- } +- + /// Returns a reference to the internally buffered data. + /// + /// Unlike `fill_buf`, this will not attempt to fill the buffer if it is empty. +@@ -202,7 +170,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -225,7 +192,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + } + +@@ -234,7 +200,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -254,7 +219,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -277,7 +241,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -297,7 +260,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -307,7 +269,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -415,7 +376,6 @@ impl Seek for BufReader { + /// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -450,7 +410,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -464,7 +423,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -482,7 +440,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -531,7 +488,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -549,7 +505,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Unwraps this `BufWriter`, returning the underlying writer. +@@ -571,7 +526,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -580,7 +534,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -600,7 +553,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -610,7 +562,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -620,7 +571,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -659,7 +609,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -692,23 +641,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -766,7 +705,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -787,7 +725,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -808,7 +745,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -832,7 +768,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -855,7 +790,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -881,7 +815,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -892,7 +825,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -937,7 +869,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index 8ac5257..c65ed2a 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -10,7 +10,7 @@ + + use io::prelude::*; + +-use cmp; ++use core::cmp; + use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + + /// A `Cursor` wraps another type and provides it with a +@@ -78,7 +78,6 @@ use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -101,7 +100,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -119,7 +117,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -135,7 +132,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -154,7 +150,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -176,7 +171,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -196,11 +190,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -221,17 +213,16 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -242,12 +233,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -261,6 +256,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result Result { +@@ -271,12 +267,14 @@ fn try_into(n: u64) -> Result { + } + } + ++#[cfg(feature="collections")] + #[cfg(any(target_pointer_width = "64"))] + fn try_into(n: u64) -> Result { + Ok(n as usize) + } + + // Resizing write implementation ++#[cfg(feature="collections")] + fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result { + let pos: usize = try_into(*pos_mut).map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -303,7 +301,6 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result Write for Cursor<&'a mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -312,7 +309,7 @@ impl<'a> Write for Cursor<&'a mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl<'a> Write for Cursor<&'a mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) +@@ -320,7 +317,7 @@ impl<'a> Write for Cursor<&'a mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) +@@ -328,8 +325,8 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) +diff --git a/error.rs b/error.rs +index bdd675e..3acdadf 100644 +--- a/error.rs ++++ b/error.rs +@@ -8,11 +8,16 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use error; +-use fmt; +-use result; +-use sys; +-use convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -48,7 +53,6 @@ use convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -62,12 +66,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -77,13 +79,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -95,47 +100,34 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -147,10 +139,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -161,15 +151,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -178,15 +165,10 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + + /// A marker variant that tells the compiler that users of this enum cannot + /// match it exhaustively. +- #[unstable(feature = "io_error_internals", +- reason = "better expressed through extensible enums that this \ +- enum cannot be exhaustively matched against", +- issue = "0")] + #[doc(hidden)] + __Nonexhaustive, + } +@@ -219,7 +201,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + #[inline] + fn from(kind: ErrorKind) -> Error { +@@ -248,14 +229,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -264,24 +244,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -307,7 +269,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -338,7 +299,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -372,12 +332,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -443,12 +402,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -477,8 +435,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -504,10 +461,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -519,22 +475,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -542,24 +494,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- fn cause(&self) -> Option<&error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index fe1179a..452b8b7 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -8,15 +8,18 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use cmp; +-use io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind}; +-use fmt; +-use mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use io::BufRead; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, R: Read + ?Sized> Read for &'a mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -28,11 +31,13 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -43,7 +48,6 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, W: Write + ?Sized> Write for &'a mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -61,12 +65,11 @@ impl<'a, W: Write + ?Sized> Write for &'a mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, S: Seek + ?Sized> Seek for &'a mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -85,7 +88,7 @@ impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -97,11 +100,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -112,7 +117,7 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -130,12 +135,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -161,7 +166,6 @@ impl BufRead for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Read for &'a [u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -207,6 +211,7 @@ impl<'a> Read for &'a [u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -216,7 +221,7 @@ impl<'a> Read for &'a [u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a> BufRead for &'a [u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -230,7 +235,6 @@ impl<'a> BufRead for &'a [u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Write for &'a mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -256,7 +260,7 @@ impl<'a> Write for &'a mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +diff --git a/mod.rs b/mod.rs +index eba4e9f..0411b61 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -267,50 +267,36 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use cmp; +-use core::str as core_str; +-use error as std_error; +-use fmt; +-use result; +-use str; +-use memchr; +-use ptr; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::cmp; ++use core::fmt; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++use core::ptr; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl<'a> Drop for Guard<'a> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -335,6 +321,7 @@ impl<'a> Drop for Guard<'a> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -362,6 +349,7 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + let start_len = buf.len(); + let mut g = Guard { len: buf.len(), buf: buf }; +@@ -465,7 +453,6 @@ fn read_to_end(r: &mut R, buf: &mut Vec) -> Result + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -522,7 +509,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Determines if this `Read`er can work with buffers of uninitialized +@@ -547,7 +533,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -600,7 +585,7 @@ pub trait Read { + /// file.) + /// + /// [`std::fs::read`]: ../fs/fn.read.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -643,7 +628,7 @@ pub trait Read { + /// reading from a file.) + /// + /// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -706,7 +691,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -758,7 +742,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -795,58 +778,10 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } + +- /// Transforms this `Read` instance to an [`Iterator`] over [`char`]s. +- /// +- /// This adaptor will attempt to interpret this reader as a UTF-8 encoded +- /// sequence of characters. The returned iterator will return [`None`] once +- /// EOF is reached for this reader. Otherwise each element yielded will be a +- /// [`Result`]`<`[`char`]`, E>` where `E` may contain information about what I/O error +- /// occurred or where decoding failed. +- /// +- /// Currently this adaptor will discard intermediate data read, and should +- /// be avoided if this is not desired. +- /// +- /// # Examples +- /// +- /// [`File`]s implement `Read`: +- /// +- /// [`File`]: ../fs/struct.File.html +- /// [`Iterator`]: ../../std/iter/trait.Iterator.html +- /// [`Result`]: ../../std/result/enum.Result.html +- /// [`char`]: ../../std/primitive.char.html +- /// [`None`]: ../../std/option/enum.Option.html#variant.None +- /// +- /// ```no_run +- /// #![feature(io)] +- /// use std::io; +- /// use std::io::prelude::*; +- /// use std::fs::File; +- /// +- /// fn main() -> io::Result<()> { +- /// let mut f = File::open("foo.txt")?; +- /// +- /// for c in f.chars() { +- /// println!("{}", c.unwrap()); +- /// } +- /// Ok(()) +- /// } +- /// ``` +- #[unstable(feature = "io", reason = "the semantics of a partial read/write \ +- of where errors happen is currently \ +- unclear and may change", +- issue = "27802")] +- #[rustc_deprecated(since = "1.27.0", reason = "Use str::from_utf8 instead: +- https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples")] +- #[allow(deprecated)] +- fn chars(self) -> Chars where Self: Sized { +- Chars { inner: self } +- } +- + /// Creates an adaptor which will chain this stream with another. + /// + /// The returned `Read` instance will first read all bytes from this object +@@ -877,7 +812,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -913,20 +847,17 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -940,21 +871,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -997,7 +925,6 @@ impl Initializer { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this object, returning how many bytes were written. +@@ -1046,7 +973,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Flush this output stream, ensuring that all intermediately buffered +@@ -1072,7 +998,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this write. +@@ -1105,7 +1030,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1157,7 +1081,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1213,7 +1136,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1243,7 +1165,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1259,7 +1180,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + } + +@@ -1269,29 +1189,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Set the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Set the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Set the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1371,7 +1288,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Fills the internal buffer of this object, returning the buffer contents. + /// +@@ -1416,7 +1333,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1438,7 +1354,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1494,7 +1409,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1553,7 +1467,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1594,7 +1507,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1633,7 +1545,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1645,7 +1556,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1671,7 +1581,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1694,7 +1603,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1721,13 +1629,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1737,7 +1643,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1759,7 +1664,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1786,7 +1691,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -1821,7 +1725,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -1847,7 +1750,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "take_set_limit", since = "1.27.0")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -1872,7 +1774,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -1897,7 +1798,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -1926,13 +1826,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -1951,7 +1849,7 @@ impl Read for Take { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -1990,13 +1888,11 @@ fn read_one_byte(reader: &mut Read) -> Option> { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -2005,104 +1901,6 @@ impl Iterator for Bytes { + } + } + +-/// An iterator over the `char`s of a reader. +-/// +-/// This struct is generally created by calling [`chars`][chars] on a reader. +-/// Please see the documentation of `chars()` for more details. +-/// +-/// [chars]: trait.Read.html#method.chars +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] +-#[rustc_deprecated(since = "1.27.0", reason = "Use str::from_utf8 instead: +- https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples")] +-#[derive(Debug)] +-#[allow(deprecated)] +-pub struct Chars { +- inner: R, +-} +- +-/// An enumeration of possible errors that can be generated from the `Chars` +-/// adapter. +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] +-#[rustc_deprecated(since = "1.27.0", reason = "Use str::from_utf8 instead: +- https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples")] +-#[derive(Debug)] +-#[allow(deprecated)] +-pub enum CharsError { +- /// Variant representing that the underlying stream was read successfully +- /// but it did not contain valid utf8 data. +- NotUtf8, +- +- /// Variant representing that an I/O error occurred. +- Other(Error), +-} +- +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] +-#[allow(deprecated)] +-impl Iterator for Chars { +- type Item = result::Result; +- +- fn next(&mut self) -> Option> { +- let first_byte = match read_one_byte(&mut self.inner)? { +- Ok(b) => b, +- Err(e) => return Some(Err(CharsError::Other(e))), +- }; +- let width = core_str::utf8_char_width(first_byte); +- if width == 1 { return Some(Ok(first_byte as char)) } +- if width == 0 { return Some(Err(CharsError::NotUtf8)) } +- let mut buf = [first_byte, 0, 0, 0]; +- { +- let mut start = 1; +- while start < width { +- match self.inner.read(&mut buf[start..width]) { +- Ok(0) => return Some(Err(CharsError::NotUtf8)), +- Ok(n) => start += n, +- Err(ref e) if e.kind() == ErrorKind::Interrupted => continue, +- Err(e) => return Some(Err(CharsError::Other(e))), +- } +- } +- } +- Some(match str::from_utf8(&buf[..width]).ok() { +- Some(s) => Ok(s.chars().next().unwrap()), +- None => Err(CharsError::NotUtf8), +- }) +- } +-} +- +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] +-#[allow(deprecated)] +-impl std_error::Error for CharsError { +- fn description(&self) -> &str { +- match *self { +- CharsError::NotUtf8 => "invalid utf8 encoding", +- CharsError::Other(ref e) => std_error::Error::description(e), +- } +- } +- fn cause(&self) -> Option<&std_error::Error> { +- match *self { +- CharsError::NotUtf8 => None, +- CharsError::Other(ref e) => e.cause(), +- } +- } +-} +- +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] +-#[allow(deprecated)] +-impl fmt::Display for CharsError { +- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +- match *self { +- CharsError::NotUtf8 => { +- "byte stream did not contain valid utf8".fmt(f) +- } +- CharsError::Other(ref e) => e.fmt(f), +- } +- } +-} +- + /// An iterator over the contents of an instance of `BufRead` split on a + /// particular byte. + /// +@@ -2110,14 +1908,14 @@ impl fmt::Display for CharsError { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -2142,13 +1940,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 8772d0f..49d66c9 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -18,7 +18,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 195310a..20755b7 100644 +--- a/util.rs ++++ b/util.rs +@@ -10,9 +10,10 @@ + + #![allow(missing_copy_implementations)] + +-use fmt; +-use io::{self, Read, Initializer, Write, ErrorKind, BufRead}; +-use mem; ++use core::fmt; ++use io::{self, Read, Initializer, Write, ErrorKind}; ++use core::mem; ++#[cfg(feature="collections")] use io::BufRead; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -44,7 +45,6 @@ use mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -73,7 +73,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -93,10 +92,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -106,7 +103,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -114,7 +112,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -127,7 +124,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -144,10 +140,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte: byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -163,7 +157,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -176,7 +169,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -193,10 +185,8 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } +@@ -204,7 +194,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/837d6c70233715a0ae8e15c703d40e3046a2f36a.patch b/patches/837d6c70233715a0ae8e15c703d40e3046a2f36a.patch new file mode 100644 index 0000000..0b25893 --- /dev/null +++ b/patches/837d6c70233715a0ae8e15c703d40e3046a2f36a.patch @@ -0,0 +1,1703 @@ +diff --git a/buffered.rs b/buffered.rs +index ccaa19a..c8ff47e 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -10,13 +10,13 @@ + + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use io::prelude::*; + +-use cmp; +-use error; +-use fmt; ++use core::cmp; ++use core::fmt; + use io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom}; +-use memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -46,7 +46,6 @@ use memchr; + /// # Ok(()) + /// # } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -69,7 +68,6 @@ impl BufReader { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -90,7 +88,6 @@ impl BufReader { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -123,7 +120,6 @@ impl BufReader { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -144,35 +140,8 @@ impl BufReader { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + +- /// Returns `true` if there are no bytes in the internal buffer. +- /// +- /// # Examples +- /// ``` +- /// # #![feature(bufreader_is_empty)] +- /// use std::io::BufReader; +- /// use std::io::BufRead; +- /// use std::fs::File; +- /// +- /// # fn foo() -> std::io::Result<()> { +- /// let f1 = File::open("log.txt")?; +- /// let mut reader = BufReader::new(f1); +- /// assert!(reader.is_empty()); +- /// +- /// if reader.fill_buf()?.len() > 0 { +- /// assert!(!reader.is_empty()); +- /// } +- /// # Ok(()) +- /// # } +- /// ``` +- #[unstable(feature = "bufreader_is_empty", issue = "45323", reason = "recently added")] +- #[rustc_deprecated(since = "1.26.0", reason = "use .buffer().is_empty() instead")] +- pub fn is_empty(&self) -> bool { +- self.buffer().is_empty() +- } +- + /// Returns a reference to the internally buffered data. + /// + /// Unlike `fill_buf`, this will not attempt to fill the buffer if it is empty. +@@ -195,7 +164,6 @@ impl BufReader { + /// # Ok(()) + /// # } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -218,7 +186,6 @@ impl BufReader { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + } + +@@ -227,7 +194,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -247,7 +213,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -270,7 +235,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -290,7 +254,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -300,7 +263,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -402,7 +364,6 @@ impl Seek for BufReader { + /// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -437,7 +398,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -451,7 +411,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -469,7 +428,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -518,7 +476,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -536,7 +493,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Unwraps this `BufWriter`, returning the underlying writer. +@@ -558,7 +514,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -567,7 +522,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -587,7 +541,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -597,7 +550,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -607,7 +559,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -646,7 +597,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -679,23 +629,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -753,7 +693,6 @@ impl fmt::Display for IntoInnerError { + /// # Ok(()) + /// # } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -774,7 +713,6 @@ impl LineWriter { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -795,7 +733,6 @@ impl LineWriter { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -819,7 +756,6 @@ impl LineWriter { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -842,7 +778,6 @@ impl LineWriter { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -868,7 +803,6 @@ impl LineWriter { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -879,7 +813,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -924,7 +857,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index 2673f3c..5b2e073 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -10,7 +10,7 @@ + + use io::prelude::*; + +-use cmp; ++use core::cmp; + use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + + /// A `Cursor` wraps another type and provides it with a +@@ -78,7 +78,6 @@ use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -101,7 +100,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -119,7 +117,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -135,7 +132,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -154,7 +150,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -176,7 +171,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -196,11 +190,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -221,17 +213,16 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -242,12 +233,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -261,6 +256,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result Result { +@@ -271,12 +267,14 @@ fn try_into(n: u64) -> Result { + } + } + ++#[cfg(feature="collections")] + #[cfg(any(target_pointer_width = "64"))] + fn try_into(n: u64) -> Result { + Ok(n as usize) + } + + // Resizing write implementation ++#[cfg(feature="collections")] + fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result { + let pos: usize = try_into(*pos_mut).map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -303,7 +301,6 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result Write for Cursor<&'a mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -312,7 +309,7 @@ impl<'a> Write for Cursor<&'a mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl<'a> Write for Cursor<&'a mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) +@@ -320,7 +317,7 @@ impl<'a> Write for Cursor<&'a mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) +@@ -328,8 +325,8 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) +diff --git a/error.rs b/error.rs +index bdd675e..3acdadf 100644 +--- a/error.rs ++++ b/error.rs +@@ -8,11 +8,16 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use error; +-use fmt; +-use result; +-use sys; +-use convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -48,7 +53,6 @@ use convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -62,12 +66,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -77,13 +79,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -95,47 +100,34 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -147,10 +139,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -161,15 +151,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -178,15 +165,10 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + + /// A marker variant that tells the compiler that users of this enum cannot + /// match it exhaustively. +- #[unstable(feature = "io_error_internals", +- reason = "better expressed through extensible enums that this \ +- enum cannot be exhaustively matched against", +- issue = "0")] + #[doc(hidden)] + __Nonexhaustive, + } +@@ -219,7 +201,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + #[inline] + fn from(kind: ErrorKind) -> Error { +@@ -248,14 +229,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -264,24 +244,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -307,7 +269,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -338,7 +299,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -372,12 +332,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -443,12 +402,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -477,8 +435,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -504,10 +461,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -519,22 +475,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -542,24 +494,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- fn cause(&self) -> Option<&error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index fe1179a..452b8b7 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -8,15 +8,18 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use cmp; +-use io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind}; +-use fmt; +-use mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use io::BufRead; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, R: Read + ?Sized> Read for &'a mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -28,11 +31,13 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -43,7 +48,6 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, W: Write + ?Sized> Write for &'a mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -61,12 +65,11 @@ impl<'a, W: Write + ?Sized> Write for &'a mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, S: Seek + ?Sized> Seek for &'a mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -85,7 +88,7 @@ impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -97,11 +100,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -112,7 +117,7 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -130,12 +135,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -161,7 +166,6 @@ impl BufRead for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Read for &'a [u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -207,6 +211,7 @@ impl<'a> Read for &'a [u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -216,7 +221,7 @@ impl<'a> Read for &'a [u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a> BufRead for &'a [u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -230,7 +235,6 @@ impl<'a> BufRead for &'a [u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Write for &'a mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -256,7 +260,7 @@ impl<'a> Write for &'a mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +diff --git a/mod.rs b/mod.rs +index d403bf6..c6c236e 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -268,50 +268,38 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use cmp; ++use core::cmp; + use core::str as core_str; +-use error as std_error; +-use fmt; +-use result; +-use str; +-use memchr; +-use ptr; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::fmt; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++use core::ptr; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl<'a> Drop for Guard<'a> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -336,6 +324,7 @@ impl<'a> Drop for Guard<'a> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -363,6 +352,7 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + let start_len = buf.len(); + let mut g = Guard { len: buf.len(), buf: buf }; +@@ -466,7 +456,6 @@ fn read_to_end(r: &mut R, buf: &mut Vec) -> Result + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -523,7 +512,6 @@ pub trait Read { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Determines if this `Read`er can work with buffers of uninitialized +@@ -548,7 +536,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -596,7 +583,7 @@ pub trait Read { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -634,7 +621,7 @@ pub trait Read { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -697,7 +684,6 @@ pub trait Read { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -749,7 +735,6 @@ pub trait Read { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -786,7 +771,6 @@ pub trait Read { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } +@@ -827,10 +811,6 @@ pub trait Read { + /// # Ok(()) + /// # } + /// ``` +- #[unstable(feature = "io", reason = "the semantics of a partial read/write \ +- of where errors happen is currently \ +- unclear and may change", +- issue = "27802")] + fn chars(self) -> Chars where Self: Sized { + Chars { inner: self } + } +@@ -865,7 +845,6 @@ pub trait Read { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -901,20 +880,17 @@ pub trait Read { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -928,21 +904,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -985,7 +958,6 @@ impl Initializer { + /// # Ok(()) + /// # } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this object, returning how many bytes were written. +@@ -1034,7 +1006,6 @@ pub trait Write { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Flush this output stream, ensuring that all intermediately buffered +@@ -1060,7 +1031,6 @@ pub trait Write { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this write. +@@ -1093,7 +1063,6 @@ pub trait Write { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1145,7 +1114,6 @@ pub trait Write { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1201,7 +1169,6 @@ pub trait Write { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1231,7 +1198,6 @@ pub trait Write { + /// # Ok(()) + /// # } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1247,7 +1213,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + } + +@@ -1257,29 +1222,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Set the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Set the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Set the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1359,7 +1321,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// # } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Fills the internal buffer of this object, returning the buffer contents. + /// +@@ -1404,7 +1366,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1426,7 +1387,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1482,7 +1442,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1541,7 +1500,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1582,7 +1540,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1621,7 +1578,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1633,7 +1589,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1659,7 +1614,6 @@ impl Chain { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1682,7 +1636,6 @@ impl Chain { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1709,13 +1662,11 @@ impl Chain { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1725,7 +1676,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1747,7 +1697,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1774,7 +1724,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -1809,7 +1758,6 @@ impl Take { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -1836,7 +1784,6 @@ impl Take { + /// # Ok(()) + /// # } + /// ``` +- #[unstable(feature = "take_set_limit", issue = "42781")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -1861,7 +1808,6 @@ impl Take { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -1886,7 +1832,6 @@ impl Take { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -1915,13 +1860,11 @@ impl Take { + /// # Ok(()) + /// # } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -1940,7 +1883,7 @@ impl Read for Take { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -1979,13 +1922,11 @@ fn read_one_byte(reader: &mut Read) -> Option> { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -2000,8 +1941,6 @@ impl Iterator for Bytes { + /// Please see the documentation of `chars()` for more details. + /// + /// [chars]: trait.Read.html#method.chars +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] + #[derive(Debug)] + pub struct Chars { + inner: R, +@@ -2010,8 +1949,6 @@ pub struct Chars { + /// An enumeration of possible errors that can be generated from the `Chars` + /// adapter. + #[derive(Debug)] +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] + pub enum CharsError { + /// Variant representing that the underlying stream was read successfully + /// but it did not contain valid utf8 data. +@@ -2021,8 +1958,6 @@ pub enum CharsError { + Other(Error), + } + +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] + impl Iterator for Chars { + type Item = result::Result; + +@@ -2053,25 +1988,6 @@ impl Iterator for Chars { + } + } + +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] +-impl std_error::Error for CharsError { +- fn description(&self) -> &str { +- match *self { +- CharsError::NotUtf8 => "invalid utf8 encoding", +- CharsError::Other(ref e) => std_error::Error::description(e), +- } +- } +- fn cause(&self) -> Option<&std_error::Error> { +- match *self { +- CharsError::NotUtf8 => None, +- CharsError::Other(ref e) => e.cause(), +- } +- } +-} +- +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] + impl fmt::Display for CharsError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match *self { +@@ -2090,14 +2006,14 @@ impl fmt::Display for CharsError { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -2122,13 +2038,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 8772d0f..49d66c9 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -18,7 +18,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 45d281e..0efc3b1 100644 +--- a/util.rs ++++ b/util.rs +@@ -10,9 +10,10 @@ + + #![allow(missing_copy_implementations)] + +-use fmt; +-use io::{self, Read, Initializer, Write, ErrorKind, BufRead}; +-use mem; ++use core::fmt; ++use io::{self, Read, Initializer, Write, ErrorKind}; ++use core::mem; ++#[cfg(feature="collections")] use io::BufRead; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -45,7 +46,6 @@ use mem; + /// # } + /// # foo().unwrap(); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -74,7 +74,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -94,10 +93,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -107,7 +104,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -115,7 +113,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -128,7 +125,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -145,10 +141,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte: byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -164,7 +158,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -177,7 +170,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -194,10 +186,8 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } +@@ -205,7 +195,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/89573b3c8b629507130b1ec8beeaf550fdc0e046.patch b/patches/89573b3c8b629507130b1ec8beeaf550fdc0e046.patch new file mode 100644 index 0000000..d8d8c15 --- /dev/null +++ b/patches/89573b3c8b629507130b1ec8beeaf550fdc0e046.patch @@ -0,0 +1,1909 @@ +diff --git a/buffered.rs b/buffered.rs +index 4668e3e..4c125bd 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -1,12 +1,12 @@ + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use crate::io::prelude::*; + +-use crate::cmp; +-use crate::error; +-use crate::fmt; ++use core::cmp; ++use core::fmt; + use crate::io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom, IoVec, IoVecMut}; +-use crate::memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -42,7 +42,6 @@ use crate::memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -66,7 +65,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -87,7 +85,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -122,7 +119,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -143,7 +139,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + + /// Returns a reference to the internally buffered data. +@@ -168,7 +163,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -191,7 +185,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + + /// Invalidates all data in the internal buffer. +@@ -207,7 +200,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -227,7 +219,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -265,7 +256,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -285,7 +275,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -295,7 +284,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -404,7 +392,6 @@ impl Seek for BufReader { + /// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -439,7 +426,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -454,7 +440,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -472,7 +457,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -521,7 +505,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -539,7 +522,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Returns a reference to the internally buffered data. +@@ -556,7 +538,6 @@ impl BufWriter { + /// // See how many bytes are currently buffered + /// let bytes_buffered = buf_writer.buffer().len(); + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf + } +@@ -580,7 +561,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -589,7 +569,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -625,7 +604,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -635,7 +613,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -645,7 +622,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -684,7 +660,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -717,23 +692,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -804,7 +769,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -825,7 +789,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -846,7 +809,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -870,7 +832,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -893,7 +854,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -919,7 +879,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -930,7 +889,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -975,7 +933,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index 247d45c..f13522d 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -1,9 +1,10 @@ + use crate::io::prelude::*; + +-use crate::cmp; +-use crate::io::{self, Initializer, SeekFrom, Error, ErrorKind, IoVec, IoVecMut}; ++use core::cmp; ++use crate::io::{self, Initializer, SeekFrom, Error, ErrorKind}; ++#[cfg(feature="collections")] use crate::io::{IoVec, IoVecMut}; + +-use core::convert::TryInto; ++#[cfg(feature="collections")] use core::convert::TryInto; + + /// A `Cursor` wraps an in-memory buffer and provides it with a + /// [`Seek`] implementation. +@@ -71,7 +72,6 @@ use core::convert::TryInto; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -94,7 +94,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -112,7 +111,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -128,7 +126,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -147,7 +144,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -169,7 +165,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -189,11 +184,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -222,14 +215,14 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + ++ #[cfg(feature="collections")] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let mut nread = 0; + for buf in bufs { +@@ -244,7 +237,7 @@ impl Read for Cursor where T: AsRef<[u8]> { + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -255,12 +248,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -272,6 +269,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result, buf: &[u8]) -> io::Result { + let pos: usize = (*pos_mut).try_into().map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -316,6 +315,7 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result, +@@ -329,13 +329,13 @@ fn vec_write_vectored( + Ok(nwritten) + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Cursor<&mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, self.inner, buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + slice_write_vectored(&mut self.pos, self.inner, bufs) +@@ -344,12 +344,13 @@ impl Write for Cursor<&mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl Write for Cursor<&mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) + } + ++ #[cfg(feature="collections")] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + vec_write_vectored(&mut self.pos, self.inner, bufs) + } +@@ -357,12 +358,13 @@ impl Write for Cursor<&mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) + } + ++ #[cfg(feature="collections")] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + vec_write_vectored(&mut self.pos, &mut self.inner, bufs) + } +@@ -370,13 +372,14 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + slice_write_vectored(&mut self.pos, &mut self.inner, bufs) +diff --git a/error.rs b/error.rs +index 614b791..e4ce8b5 100644 +--- a/error.rs ++++ b/error.rs +@@ -1,8 +1,13 @@ +-use crate::error; +-use crate::fmt; +-use crate::result; +-use crate::sys; +-use crate::convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -38,7 +43,6 @@ use crate::convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -52,12 +56,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -67,13 +69,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -85,48 +90,35 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + #[non_exhaustive] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -138,10 +130,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -152,15 +142,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -169,7 +156,6 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + } + +@@ -200,7 +186,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + /// Converts an [`ErrorKind`] into an [`Error`]. + /// +@@ -245,14 +230,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -261,24 +245,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -304,7 +270,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -335,7 +300,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -369,12 +333,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(dyn error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -440,12 +403,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -474,8 +436,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -501,10 +462,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -516,22 +476,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -539,33 +495,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- #[allow(deprecated)] +- fn cause(&self) -> Option<&dyn error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +- +- fn source(&self) -> Option<&(dyn error::Error + 'static)> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.source(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index b286e40..7472d9c 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -1,19 +1,22 @@ +-use crate::cmp; +-use crate::io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind, IoVecMut, +- IoVec}; +-use crate::fmt; +-use crate::mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use crate::io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use crate::io::{BufRead, IoVecMut, IoVec}; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for &mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { + (**self).read(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + (**self).read_vectored(bufs) +@@ -24,11 +27,13 @@ impl Read for &mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -39,11 +44,11 @@ impl Read for &mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for &mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + (**self).write_vectored(bufs) +@@ -62,12 +67,11 @@ impl Write for &mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for &mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for &mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -86,13 +90,14 @@ impl BufRead for &mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { + (**self).read(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + (**self).read_vectored(bufs) +@@ -103,11 +108,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -118,11 +125,12 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + (**self).write_vectored(bufs) +@@ -141,12 +149,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -186,7 +194,6 @@ impl Write for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for &[u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -206,6 +213,7 @@ impl Read for &[u8] { + Ok(amt) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let mut nread = 0; +@@ -245,6 +253,7 @@ impl Read for &[u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -254,7 +263,7 @@ impl Read for &[u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for &[u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -268,7 +277,6 @@ impl BufRead for &[u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for &mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -279,6 +287,7 @@ impl Write for &mut [u8] { + Ok(amt) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + let mut nwritten = 0; +@@ -307,7 +316,7 @@ impl Write for &mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -315,6 +324,7 @@ impl Write for Vec { + Ok(buf.len()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + let len = bufs.iter().map(|b| b.len()).sum(); +diff --git a/mod.rs b/mod.rs +index 4c88fc8..2059b5a 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -257,50 +257,38 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use crate::cmp; +-use crate::fmt; +-use crate::slice; +-use crate::str; +-use crate::memchr; +-use crate::ops::{Deref, DerefMut}; +-use crate::ptr; +-use crate::sys; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::cmp; ++use core::fmt; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++#[cfg(feature="collections")] use core::ops::{Deref, DerefMut}; ++use core::ptr; ++use core::slice; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = crate::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl Drop for Guard<'_> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -325,6 +313,7 @@ impl Drop for Guard<'_> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -352,10 +341,12 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + read_to_end_with_reservation(r, buf, 32) + } + ++#[cfg(feature="collections")] + fn read_to_end_with_reservation(r: &mut R, + buf: &mut Vec, + reservation_size: usize) -> Result +@@ -390,6 +381,7 @@ fn read_to_end_with_reservation(r: &mut R, + ret + } + ++#[cfg(feature="collections")] + pub(crate) fn default_read_vectored(read: F, bufs: &mut [IoVecMut<'_>]) -> Result + where + F: FnOnce(&mut [u8]) -> Result +@@ -401,6 +393,7 @@ where + read(buf) + } + ++#[cfg(feature="collections")] + pub(crate) fn default_write_vectored(write: F, bufs: &[IoVec<'_>]) -> Result + where + F: FnOnce(&[u8]) -> Result +@@ -484,7 +477,6 @@ where + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -541,7 +533,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Like `read`, except that it reads into a slice of buffers. +@@ -552,7 +543,7 @@ pub trait Read { + /// + /// The default implementation calls `read` with either the first nonempty + /// buffer provided, or an empty one if none exists. +- #[unstable(feature = "iovec", issue = "58452")] ++ #[cfg(feature="collections")] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> Result { + default_read_vectored(|b| self.read(b), bufs) + } +@@ -579,7 +570,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -632,7 +622,7 @@ pub trait Read { + /// file.) + /// + /// [`std::fs::read`]: ../fs/fn.read.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -675,7 +665,7 @@ pub trait Read { + /// reading from a file.) + /// + /// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -738,7 +728,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -790,7 +779,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -827,7 +815,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } +@@ -862,7 +849,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -898,42 +884,77 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + ++#[cfg(feature="collections")] ++pub struct IoVecBuffer<'a>(&'a [u8]); ++ ++#[cfg(feature="collections")] ++impl<'a> IoVecBuffer<'a> { ++ #[inline] ++ pub fn new(buf: &'a [u8]) -> IoVecBuffer<'a> { ++ IoVecBuffer(buf) ++ } ++ ++ #[inline] ++ pub fn as_slice(&self) -> &[u8] { ++ self.0 ++ } ++} ++#[cfg(feature="collections")] ++pub struct IoVecMutBuffer<'a>(&'a mut [u8]); ++ ++#[cfg(feature="collections")] ++impl<'a> IoVecMutBuffer<'a> { ++ #[inline] ++ pub fn new(buf: &'a mut [u8]) -> IoVecMutBuffer<'a> { ++ IoVecMutBuffer(buf) ++ } ++ ++ #[inline] ++ pub fn as_slice(&self) -> &[u8] { ++ self.0 ++ } ++ ++ #[inline] ++ pub fn as_mut_slice(&mut self) -> &mut [u8] { ++ self.0 ++ } ++} ++ + /// A buffer type used with `Read::read_vectored`. + /// + /// It is semantically a wrapper around an `&mut [u8]`, but is guaranteed to be + /// ABI compatible with the `iovec` type on Unix platforms and `WSABUF` on + /// Windows. +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + #[repr(transparent)] +-pub struct IoVecMut<'a>(sys::io::IoVecMut<'a>); ++pub struct IoVecMut<'a>(IoVecMutBuffer<'a>); + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> fmt::Debug for IoVecMut<'a> { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(self.0.as_slice(), fmt) + } + } + ++#[cfg(feature="collections")] + impl<'a> IoVecMut<'a> { + /// Creates a new `IoVecMut` wrapping a byte slice. + /// + /// # Panics + /// + /// Panics on Windows if the slice is larger than 4GB. +- #[unstable(feature = "iovec", issue = "58452")] + #[inline] + pub fn new(buf: &'a mut [u8]) -> IoVecMut<'a> { +- IoVecMut(sys::io::IoVecMut::new(buf)) ++ IoVecMut(IoVecMutBuffer::new(buf)) + } + } + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> Deref for IoVecMut<'a> { + type Target = [u8]; + +@@ -943,7 +964,7 @@ impl<'a> Deref for IoVecMut<'a> { + } + } + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> DerefMut for IoVecMut<'a> { + #[inline] + fn deref_mut(&mut self) -> &mut [u8] { +@@ -956,31 +977,31 @@ impl<'a> DerefMut for IoVecMut<'a> { + /// It is semantically a wrapper around an `&[u8]`, but is guaranteed to be + /// ABI compatible with the `iovec` type on Unix platforms and `WSABUF` on + /// Windows. +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + #[repr(transparent)] +-pub struct IoVec<'a>(sys::io::IoVec<'a>); ++pub struct IoVec<'a>(IoVecBuffer<'a>); + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> fmt::Debug for IoVec<'a> { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(self.0.as_slice(), fmt) + } + } + ++#[cfg(feature="collections")] + impl<'a> IoVec<'a> { + /// Creates a new `IoVec` wrapping a byte slice. + /// + /// # Panics + /// + /// Panics on Windows if the slice is larger than 4GB. +- #[unstable(feature = "iovec", issue = "58452")] + #[inline] + pub fn new(buf: &'a [u8]) -> IoVec<'a> { +- IoVec(sys::io::IoVec::new(buf)) ++ IoVec(IoVecBuffer::new(buf)) + } + } + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> Deref for IoVec<'a> { + type Target = [u8]; + +@@ -991,13 +1012,11 @@ impl<'a> Deref for IoVec<'a> { + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -1011,21 +1030,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -1068,7 +1084,6 @@ impl Initializer { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this writer, returning how many bytes were written. +@@ -1117,7 +1132,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Like `write`, except that it writes from a slice of buffers. +@@ -1128,7 +1142,7 @@ pub trait Write { + /// + /// The default implementation calls `write` with either the first nonempty + /// buffer provided, or an empty one if none exists. +- #[unstable(feature = "iovec", issue = "58452")] ++ #[cfg(feature="collections")] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> Result { + default_write_vectored(|b| self.write(b), bufs) + } +@@ -1156,7 +1170,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this writer. +@@ -1189,7 +1202,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1241,7 +1253,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1297,7 +1308,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1327,7 +1337,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1343,7 +1352,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + + /// Returns the length of this stream (in bytes). +@@ -1381,7 +1389,6 @@ pub trait Seek { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "seek_convenience", issue = "0")] + fn stream_len(&mut self) -> Result { + let old_pos = self.stream_position()?; + let len = self.seek(SeekFrom::End(0))?; +@@ -1420,7 +1427,6 @@ pub trait Seek { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "seek_convenience", issue = "0")] + fn stream_position(&mut self) -> Result { + self.seek(SeekFrom::Current(0)) + } +@@ -1432,29 +1438,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Sets the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Sets the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Sets the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1534,7 +1537,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Returns the contents of the internal buffer, filling it with more data + /// from the inner reader if it is empty. +@@ -1580,7 +1583,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1602,7 +1604,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1658,7 +1659,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1717,7 +1717,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1758,7 +1757,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1797,7 +1795,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1809,7 +1806,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1835,7 +1831,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1858,7 +1853,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1885,13 +1879,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1901,7 +1893,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1913,6 +1904,7 @@ impl Read for Chain { + self.second.read(buf) + } + ++ #[cfg(feature="collections")] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> Result { + if !self.done_first { + match self.first.read_vectored(bufs)? { +@@ -1933,7 +1925,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1960,7 +1952,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -1995,7 +1986,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -2021,7 +2011,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "take_set_limit", since = "1.27.0")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -2046,7 +2035,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -2071,7 +2059,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -2100,13 +2087,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -2123,15 +2108,9 @@ impl Read for Take { + unsafe fn initializer(&self) -> Initializer { + self.inner.initializer() + } +- +- fn read_to_end(&mut self, buf: &mut Vec) -> Result { +- let reservation_size = cmp::min(self.limit, 32) as usize; +- +- read_to_end_with_reservation(self, buf, reservation_size) +- } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -2158,13 +2137,11 @@ impl BufRead for Take { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -2188,14 +2165,14 @@ impl Iterator for Bytes { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -2220,13 +2197,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 2e19edf..66294a3 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -8,7 +8,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 6aaf8f1..447ce47 100644 +--- a/util.rs ++++ b/util.rs +@@ -1,8 +1,9 @@ + #![allow(missing_copy_implementations)] + +-use crate::fmt; +-use crate::io::{self, Read, Initializer, Write, ErrorKind, BufRead, IoVec, IoVecMut}; +-use crate::mem; ++use core::fmt; ++use crate::io::{self, Read, Initializer, Write, ErrorKind}; ++#[cfg(feature="collections")] use crate::io::{BufRead, IoVec, IoVecMut}; ++use core::mem; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -39,7 +40,6 @@ use crate::mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -68,7 +68,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -88,10 +87,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -101,7 +98,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -109,7 +107,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -122,7 +119,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -139,10 +135,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -152,6 +146,7 @@ impl Read for Repeat { + Ok(buf.len()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let mut nwritten = 0; +@@ -167,7 +162,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -180,7 +174,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -197,14 +190,13 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + let total_len = bufs.iter().map(|b| b.len()).sum(); +@@ -215,7 +207,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/8dbae794b0683668d1b46d2c319ab36dcd9bd96d.patch b/patches/8dbae794b0683668d1b46d2c319ab36dcd9bd96d.patch new file mode 100644 index 0000000..2c0afce --- /dev/null +++ b/patches/8dbae794b0683668d1b46d2c319ab36dcd9bd96d.patch @@ -0,0 +1,1909 @@ +diff --git a/buffered.rs b/buffered.rs +index 441f6b9..540d4aa 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -1,12 +1,12 @@ + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use crate::io::prelude::*; + +-use crate::cmp; +-use crate::error; +-use crate::fmt; ++use core::cmp; ++use core::fmt; + use crate::io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom, IoVec, IoVecMut}; +-use crate::memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -46,7 +46,6 @@ use crate::memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -70,7 +69,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -91,7 +89,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -126,7 +123,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -147,7 +143,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + + /// Returns a reference to the internally buffered data. +@@ -172,7 +167,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -195,7 +189,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + + /// Invalidates all data in the internal buffer. +@@ -211,7 +204,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -231,7 +223,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -269,7 +260,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -289,7 +279,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -299,7 +288,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -408,7 +396,6 @@ impl Seek for BufReader { + /// [`TcpStream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -443,7 +430,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -458,7 +444,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -476,7 +461,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -525,7 +509,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -543,7 +526,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Returns a reference to the internally buffered data. +@@ -560,7 +542,6 @@ impl BufWriter { + /// // See how many bytes are currently buffered + /// let bytes_buffered = buf_writer.buffer().len(); + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf + } +@@ -584,7 +565,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -593,7 +573,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -629,7 +608,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -639,7 +617,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -649,7 +626,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -688,7 +664,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -721,23 +696,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -808,7 +773,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -829,7 +793,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -850,7 +813,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -874,7 +836,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -897,7 +858,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -923,7 +883,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -934,7 +893,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -979,7 +937,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index 247d45c..f13522d 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -1,9 +1,10 @@ + use crate::io::prelude::*; + +-use crate::cmp; +-use crate::io::{self, Initializer, SeekFrom, Error, ErrorKind, IoVec, IoVecMut}; ++use core::cmp; ++use crate::io::{self, Initializer, SeekFrom, Error, ErrorKind}; ++#[cfg(feature="collections")] use crate::io::{IoVec, IoVecMut}; + +-use core::convert::TryInto; ++#[cfg(feature="collections")] use core::convert::TryInto; + + /// A `Cursor` wraps an in-memory buffer and provides it with a + /// [`Seek`] implementation. +@@ -71,7 +72,6 @@ use core::convert::TryInto; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -94,7 +94,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -112,7 +111,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -128,7 +126,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -147,7 +144,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -169,7 +165,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -189,11 +184,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -222,14 +215,14 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + ++ #[cfg(feature="collections")] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let mut nread = 0; + for buf in bufs { +@@ -244,7 +237,7 @@ impl Read for Cursor where T: AsRef<[u8]> { + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -255,12 +248,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -272,6 +269,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result, buf: &[u8]) -> io::Result { + let pos: usize = (*pos_mut).try_into().map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -316,6 +315,7 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result, +@@ -329,13 +329,13 @@ fn vec_write_vectored( + Ok(nwritten) + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Cursor<&mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, self.inner, buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + slice_write_vectored(&mut self.pos, self.inner, bufs) +@@ -344,12 +344,13 @@ impl Write for Cursor<&mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl Write for Cursor<&mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) + } + ++ #[cfg(feature="collections")] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + vec_write_vectored(&mut self.pos, self.inner, bufs) + } +@@ -357,12 +358,13 @@ impl Write for Cursor<&mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) + } + ++ #[cfg(feature="collections")] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + vec_write_vectored(&mut self.pos, &mut self.inner, bufs) + } +@@ -370,13 +372,14 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + slice_write_vectored(&mut self.pos, &mut self.inner, bufs) +diff --git a/error.rs b/error.rs +index 614b791..e4ce8b5 100644 +--- a/error.rs ++++ b/error.rs +@@ -1,8 +1,13 @@ +-use crate::error; +-use crate::fmt; +-use crate::result; +-use crate::sys; +-use crate::convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -38,7 +43,6 @@ use crate::convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -52,12 +56,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -67,13 +69,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -85,48 +90,35 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + #[non_exhaustive] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -138,10 +130,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -152,15 +142,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -169,7 +156,6 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + } + +@@ -200,7 +186,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + /// Converts an [`ErrorKind`] into an [`Error`]. + /// +@@ -245,14 +230,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -261,24 +245,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -304,7 +270,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -335,7 +300,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -369,12 +333,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(dyn error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -440,12 +403,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -474,8 +436,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -501,10 +462,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -516,22 +476,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -539,33 +495,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- #[allow(deprecated)] +- fn cause(&self) -> Option<&dyn error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +- +- fn source(&self) -> Option<&(dyn error::Error + 'static)> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.source(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index b286e40..7472d9c 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -1,19 +1,22 @@ +-use crate::cmp; +-use crate::io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind, IoVecMut, +- IoVec}; +-use crate::fmt; +-use crate::mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use crate::io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use crate::io::{BufRead, IoVecMut, IoVec}; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for &mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { + (**self).read(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + (**self).read_vectored(bufs) +@@ -24,11 +27,13 @@ impl Read for &mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -39,11 +44,11 @@ impl Read for &mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for &mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + (**self).write_vectored(bufs) +@@ -62,12 +67,11 @@ impl Write for &mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for &mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for &mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -86,13 +90,14 @@ impl BufRead for &mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { + (**self).read(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + (**self).read_vectored(bufs) +@@ -103,11 +108,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -118,11 +125,12 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + (**self).write_vectored(bufs) +@@ -141,12 +149,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -186,7 +194,6 @@ impl Write for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for &[u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -206,6 +213,7 @@ impl Read for &[u8] { + Ok(amt) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let mut nread = 0; +@@ -245,6 +253,7 @@ impl Read for &[u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -254,7 +263,7 @@ impl Read for &[u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for &[u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -268,7 +277,6 @@ impl BufRead for &[u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for &mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -279,6 +287,7 @@ impl Write for &mut [u8] { + Ok(amt) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + let mut nwritten = 0; +@@ -307,7 +316,7 @@ impl Write for &mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -315,6 +324,7 @@ impl Write for Vec { + Ok(buf.len()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + let len = bufs.iter().map(|b| b.len()).sum(); +diff --git a/mod.rs b/mod.rs +index 14c850b..eaa3481 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -257,50 +257,38 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use crate::cmp; +-use crate::fmt; +-use crate::slice; +-use crate::str; +-use crate::memchr; +-use crate::ops::{Deref, DerefMut}; +-use crate::ptr; +-use crate::sys; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::cmp; ++use core::fmt; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++#[cfg(feature="collections")] use core::ops::{Deref, DerefMut}; ++use core::ptr; ++use core::slice; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = crate::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl Drop for Guard<'_> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -325,6 +313,7 @@ impl Drop for Guard<'_> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -352,10 +341,12 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + read_to_end_with_reservation(r, buf, 32) + } + ++#[cfg(feature="collections")] + fn read_to_end_with_reservation(r: &mut R, + buf: &mut Vec, + reservation_size: usize) -> Result +@@ -390,6 +381,7 @@ fn read_to_end_with_reservation(r: &mut R, + ret + } + ++#[cfg(feature="collections")] + pub(crate) fn default_read_vectored(read: F, bufs: &mut [IoVecMut<'_>]) -> Result + where + F: FnOnce(&mut [u8]) -> Result +@@ -401,6 +393,7 @@ where + read(buf) + } + ++#[cfg(feature="collections")] + pub(crate) fn default_write_vectored(write: F, bufs: &[IoVec<'_>]) -> Result + where + F: FnOnce(&[u8]) -> Result +@@ -484,7 +477,6 @@ where + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -541,7 +533,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Like `read`, except that it reads into a slice of buffers. +@@ -552,7 +543,7 @@ pub trait Read { + /// + /// The default implementation calls `read` with either the first nonempty + /// buffer provided, or an empty one if none exists. +- #[unstable(feature = "iovec", issue = "58452")] ++ #[cfg(feature="collections")] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> Result { + default_read_vectored(|b| self.read(b), bufs) + } +@@ -579,7 +570,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -632,7 +622,7 @@ pub trait Read { + /// file.) + /// + /// [`std::fs::read`]: ../fs/fn.read.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -675,7 +665,7 @@ pub trait Read { + /// reading from a file.) + /// + /// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -738,7 +728,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -790,7 +779,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -827,7 +815,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } +@@ -862,7 +849,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -898,42 +884,77 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + ++#[cfg(feature="collections")] ++pub struct IoVecBuffer<'a>(&'a [u8]); ++ ++#[cfg(feature="collections")] ++impl<'a> IoVecBuffer<'a> { ++ #[inline] ++ pub fn new(buf: &'a [u8]) -> IoVecBuffer<'a> { ++ IoVecBuffer(buf) ++ } ++ ++ #[inline] ++ pub fn as_slice(&self) -> &[u8] { ++ self.0 ++ } ++} ++#[cfg(feature="collections")] ++pub struct IoVecMutBuffer<'a>(&'a mut [u8]); ++ ++#[cfg(feature="collections")] ++impl<'a> IoVecMutBuffer<'a> { ++ #[inline] ++ pub fn new(buf: &'a mut [u8]) -> IoVecMutBuffer<'a> { ++ IoVecMutBuffer(buf) ++ } ++ ++ #[inline] ++ pub fn as_slice(&self) -> &[u8] { ++ self.0 ++ } ++ ++ #[inline] ++ pub fn as_mut_slice(&mut self) -> &mut [u8] { ++ self.0 ++ } ++} ++ + /// A buffer type used with `Read::read_vectored`. + /// + /// It is semantically a wrapper around an `&mut [u8]`, but is guaranteed to be + /// ABI compatible with the `iovec` type on Unix platforms and `WSABUF` on + /// Windows. +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + #[repr(transparent)] +-pub struct IoVecMut<'a>(sys::io::IoVecMut<'a>); ++pub struct IoVecMut<'a>(IoVecMutBuffer<'a>); + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> fmt::Debug for IoVecMut<'a> { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(self.0.as_slice(), fmt) + } + } + ++#[cfg(feature="collections")] + impl<'a> IoVecMut<'a> { + /// Creates a new `IoVecMut` wrapping a byte slice. + /// + /// # Panics + /// + /// Panics on Windows if the slice is larger than 4GB. +- #[unstable(feature = "iovec", issue = "58452")] + #[inline] + pub fn new(buf: &'a mut [u8]) -> IoVecMut<'a> { +- IoVecMut(sys::io::IoVecMut::new(buf)) ++ IoVecMut(IoVecMutBuffer::new(buf)) + } + } + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> Deref for IoVecMut<'a> { + type Target = [u8]; + +@@ -943,7 +964,7 @@ impl<'a> Deref for IoVecMut<'a> { + } + } + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> DerefMut for IoVecMut<'a> { + #[inline] + fn deref_mut(&mut self) -> &mut [u8] { +@@ -956,31 +977,31 @@ impl<'a> DerefMut for IoVecMut<'a> { + /// It is semantically a wrapper around an `&[u8]`, but is guaranteed to be + /// ABI compatible with the `iovec` type on Unix platforms and `WSABUF` on + /// Windows. +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + #[repr(transparent)] +-pub struct IoVec<'a>(sys::io::IoVec<'a>); ++pub struct IoVec<'a>(IoVecBuffer<'a>); + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> fmt::Debug for IoVec<'a> { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(self.0.as_slice(), fmt) + } + } + ++#[cfg(feature="collections")] + impl<'a> IoVec<'a> { + /// Creates a new `IoVec` wrapping a byte slice. + /// + /// # Panics + /// + /// Panics on Windows if the slice is larger than 4GB. +- #[unstable(feature = "iovec", issue = "58452")] + #[inline] + pub fn new(buf: &'a [u8]) -> IoVec<'a> { +- IoVec(sys::io::IoVec::new(buf)) ++ IoVec(IoVecBuffer::new(buf)) + } + } + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> Deref for IoVec<'a> { + type Target = [u8]; + +@@ -991,13 +1012,11 @@ impl<'a> Deref for IoVec<'a> { + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -1011,21 +1030,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -1068,7 +1084,6 @@ impl Initializer { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this writer, returning how many bytes were written. +@@ -1117,7 +1132,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Like `write`, except that it writes from a slice of buffers. +@@ -1128,7 +1142,7 @@ pub trait Write { + /// + /// The default implementation calls `write` with either the first nonempty + /// buffer provided, or an empty one if none exists. +- #[unstable(feature = "iovec", issue = "58452")] ++ #[cfg(feature="collections")] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> Result { + default_write_vectored(|b| self.write(b), bufs) + } +@@ -1156,7 +1170,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this writer. +@@ -1189,7 +1202,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1241,7 +1253,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1297,7 +1308,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1327,7 +1337,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1343,7 +1352,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + + /// Returns the length of this stream (in bytes). +@@ -1381,7 +1389,6 @@ pub trait Seek { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "seek_convenience", issue = "59359")] + fn stream_len(&mut self) -> Result { + let old_pos = self.stream_position()?; + let len = self.seek(SeekFrom::End(0))?; +@@ -1420,7 +1427,6 @@ pub trait Seek { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "seek_convenience", issue = "59359")] + fn stream_position(&mut self) -> Result { + self.seek(SeekFrom::Current(0)) + } +@@ -1432,29 +1438,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Sets the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Sets the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Sets the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1534,7 +1537,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Returns the contents of the internal buffer, filling it with more data + /// from the inner reader if it is empty. +@@ -1580,7 +1583,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1602,7 +1604,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1658,7 +1659,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1717,7 +1717,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1758,7 +1757,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1797,7 +1795,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1809,7 +1806,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1835,7 +1831,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1858,7 +1853,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1885,13 +1879,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1901,7 +1893,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1913,6 +1904,7 @@ impl Read for Chain { + self.second.read(buf) + } + ++ #[cfg(feature="collections")] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> Result { + if !self.done_first { + match self.first.read_vectored(bufs)? { +@@ -1933,7 +1925,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1960,7 +1952,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -1995,7 +1986,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -2021,7 +2011,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "take_set_limit", since = "1.27.0")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -2046,7 +2035,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -2071,7 +2059,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -2100,13 +2087,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -2123,15 +2108,9 @@ impl Read for Take { + unsafe fn initializer(&self) -> Initializer { + self.inner.initializer() + } +- +- fn read_to_end(&mut self, buf: &mut Vec) -> Result { +- let reservation_size = cmp::min(self.limit, 32) as usize; +- +- read_to_end_with_reservation(self, buf, reservation_size) +- } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -2158,13 +2137,11 @@ impl BufRead for Take { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -2188,14 +2165,14 @@ impl Iterator for Bytes { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -2220,13 +2197,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 2e19edf..66294a3 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -8,7 +8,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 6aaf8f1..447ce47 100644 +--- a/util.rs ++++ b/util.rs +@@ -1,8 +1,9 @@ + #![allow(missing_copy_implementations)] + +-use crate::fmt; +-use crate::io::{self, Read, Initializer, Write, ErrorKind, BufRead, IoVec, IoVecMut}; +-use crate::mem; ++use core::fmt; ++use crate::io::{self, Read, Initializer, Write, ErrorKind}; ++#[cfg(feature="collections")] use crate::io::{BufRead, IoVec, IoVecMut}; ++use core::mem; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -39,7 +40,6 @@ use crate::mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -68,7 +68,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -88,10 +87,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -101,7 +98,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -109,7 +107,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -122,7 +119,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -139,10 +135,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -152,6 +146,7 @@ impl Read for Repeat { + Ok(buf.len()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let mut nwritten = 0; +@@ -167,7 +162,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -180,7 +174,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -197,14 +190,13 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + let total_len = bufs.iter().map(|b| b.len()).sum(); +@@ -215,7 +207,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/93ad4f2b9c093f204dbd5278c70256f6ec369b32.patch b/patches/93ad4f2b9c093f204dbd5278c70256f6ec369b32.patch new file mode 100644 index 0000000..91f4743 --- /dev/null +++ b/patches/93ad4f2b9c093f204dbd5278c70256f6ec369b32.patch @@ -0,0 +1,1704 @@ +diff --git a/buffered.rs b/buffered.rs +index d6eac74..e64536c 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -10,13 +10,13 @@ + + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use io::prelude::*; + +-use cmp; +-use error; +-use fmt; ++use core::cmp; ++use core::fmt; + use io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom}; +-use memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -52,7 +52,6 @@ use memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -75,7 +74,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -96,7 +94,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -129,7 +126,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -150,36 +146,8 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + +- /// Returns `true` if there are no bytes in the internal buffer. +- /// +- /// # Examples +- // +- /// ```no_run +- /// # #![feature(bufreader_is_empty)] +- /// use std::io::BufReader; +- /// use std::io::BufRead; +- /// use std::fs::File; +- /// +- /// fn main() -> std::io::Result<()> { +- /// let f1 = File::open("log.txt")?; +- /// let mut reader = BufReader::new(f1); +- /// assert!(reader.is_empty()); +- /// +- /// if reader.fill_buf()?.len() > 0 { +- /// assert!(!reader.is_empty()); +- /// } +- /// Ok(()) +- /// } +- /// ``` +- #[unstable(feature = "bufreader_is_empty", issue = "45323", reason = "recently added")] +- #[rustc_deprecated(since = "1.26.0", reason = "use .buffer().is_empty() instead")] +- pub fn is_empty(&self) -> bool { +- self.buffer().is_empty() +- } +- + /// Returns a reference to the internally buffered data. + /// + /// Unlike `fill_buf`, this will not attempt to fill the buffer if it is empty. +@@ -202,7 +170,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -225,7 +192,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + } + +@@ -234,7 +200,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -254,7 +219,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -277,7 +241,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -297,7 +260,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -307,7 +269,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -415,7 +376,6 @@ impl Seek for BufReader { + /// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -450,7 +410,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -464,7 +423,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -482,7 +440,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -531,7 +488,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -549,7 +505,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Unwraps this `BufWriter`, returning the underlying writer. +@@ -571,7 +526,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -580,7 +534,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -600,7 +553,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -610,7 +562,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -620,7 +571,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -659,7 +609,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -692,23 +641,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -766,7 +705,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -787,7 +725,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -808,7 +745,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -832,7 +768,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -855,7 +790,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -881,7 +815,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -892,7 +825,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -937,7 +869,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index 2673f3c..5b2e073 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -10,7 +10,7 @@ + + use io::prelude::*; + +-use cmp; ++use core::cmp; + use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + + /// A `Cursor` wraps another type and provides it with a +@@ -78,7 +78,6 @@ use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -101,7 +100,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -119,7 +117,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -135,7 +132,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -154,7 +150,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -176,7 +171,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -196,11 +190,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -221,17 +213,16 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -242,12 +233,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -261,6 +256,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result Result { +@@ -271,12 +267,14 @@ fn try_into(n: u64) -> Result { + } + } + ++#[cfg(feature="collections")] + #[cfg(any(target_pointer_width = "64"))] + fn try_into(n: u64) -> Result { + Ok(n as usize) + } + + // Resizing write implementation ++#[cfg(feature="collections")] + fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result { + let pos: usize = try_into(*pos_mut).map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -303,7 +301,6 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result Write for Cursor<&'a mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -312,7 +309,7 @@ impl<'a> Write for Cursor<&'a mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl<'a> Write for Cursor<&'a mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) +@@ -320,7 +317,7 @@ impl<'a> Write for Cursor<&'a mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) +@@ -328,8 +325,8 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) +diff --git a/error.rs b/error.rs +index bdd675e..3acdadf 100644 +--- a/error.rs ++++ b/error.rs +@@ -8,11 +8,16 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use error; +-use fmt; +-use result; +-use sys; +-use convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -48,7 +53,6 @@ use convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -62,12 +66,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -77,13 +79,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -95,47 +100,34 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -147,10 +139,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -161,15 +151,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -178,15 +165,10 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + + /// A marker variant that tells the compiler that users of this enum cannot + /// match it exhaustively. +- #[unstable(feature = "io_error_internals", +- reason = "better expressed through extensible enums that this \ +- enum cannot be exhaustively matched against", +- issue = "0")] + #[doc(hidden)] + __Nonexhaustive, + } +@@ -219,7 +201,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + #[inline] + fn from(kind: ErrorKind) -> Error { +@@ -248,14 +229,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -264,24 +244,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -307,7 +269,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -338,7 +299,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -372,12 +332,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -443,12 +402,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -477,8 +435,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -504,10 +461,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -519,22 +475,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -542,24 +494,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- fn cause(&self) -> Option<&error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index fe1179a..452b8b7 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -8,15 +8,18 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use cmp; +-use io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind}; +-use fmt; +-use mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use io::BufRead; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, R: Read + ?Sized> Read for &'a mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -28,11 +31,13 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -43,7 +48,6 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, W: Write + ?Sized> Write for &'a mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -61,12 +65,11 @@ impl<'a, W: Write + ?Sized> Write for &'a mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, S: Seek + ?Sized> Seek for &'a mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -85,7 +88,7 @@ impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -97,11 +100,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -112,7 +117,7 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -130,12 +135,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -161,7 +166,6 @@ impl BufRead for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Read for &'a [u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -207,6 +211,7 @@ impl<'a> Read for &'a [u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -216,7 +221,7 @@ impl<'a> Read for &'a [u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a> BufRead for &'a [u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -230,7 +235,6 @@ impl<'a> BufRead for &'a [u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Write for &'a mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -256,7 +260,7 @@ impl<'a> Write for &'a mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +diff --git a/mod.rs b/mod.rs +index 3b8c42d..b9f5664 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -267,50 +267,38 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use cmp; ++use core::cmp; + use core::str as core_str; +-use error as std_error; +-use fmt; +-use result; +-use str; +-use memchr; +-use ptr; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::fmt; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++use core::ptr; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl<'a> Drop for Guard<'a> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -335,6 +323,7 @@ impl<'a> Drop for Guard<'a> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -362,6 +351,7 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + let start_len = buf.len(); + let mut g = Guard { len: buf.len(), buf: buf }; +@@ -465,7 +455,6 @@ fn read_to_end(r: &mut R, buf: &mut Vec) -> Result + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -522,7 +511,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Determines if this `Read`er can work with buffers of uninitialized +@@ -547,7 +535,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -600,7 +587,7 @@ pub trait Read { + /// file.) + /// + /// [`std::fs::read`]: ../fs/fn.read.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -643,7 +630,7 @@ pub trait Read { + /// reading from a file.) + /// + /// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -706,7 +693,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -758,7 +744,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -795,7 +780,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } +@@ -836,10 +820,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "io", reason = "the semantics of a partial read/write \ +- of where errors happen is currently \ +- unclear and may change", +- issue = "27802")] + fn chars(self) -> Chars where Self: Sized { + Chars { inner: self } + } +@@ -874,7 +854,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -910,20 +889,17 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -937,21 +913,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -994,7 +967,6 @@ impl Initializer { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this object, returning how many bytes were written. +@@ -1043,7 +1015,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Flush this output stream, ensuring that all intermediately buffered +@@ -1069,7 +1040,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this write. +@@ -1102,7 +1072,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1154,7 +1123,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1210,7 +1178,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1240,7 +1207,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1256,7 +1222,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + } + +@@ -1266,29 +1231,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Set the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Set the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Set the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1368,7 +1330,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Fills the internal buffer of this object, returning the buffer contents. + /// +@@ -1413,7 +1375,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1435,7 +1396,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1491,7 +1451,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1550,7 +1509,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1591,7 +1549,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1630,7 +1587,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1642,7 +1598,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1668,7 +1623,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1691,7 +1645,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1718,13 +1671,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1734,7 +1685,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1756,7 +1706,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1783,7 +1733,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -1818,7 +1767,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -1845,7 +1793,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "take_set_limit", issue = "42781")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -1870,7 +1817,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -1895,7 +1841,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -1924,13 +1869,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -1949,7 +1892,7 @@ impl Read for Take { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -1988,13 +1931,11 @@ fn read_one_byte(reader: &mut Read) -> Option> { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -2009,8 +1950,6 @@ impl Iterator for Bytes { + /// Please see the documentation of `chars()` for more details. + /// + /// [chars]: trait.Read.html#method.chars +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] + #[derive(Debug)] + pub struct Chars { + inner: R, +@@ -2019,8 +1958,6 @@ pub struct Chars { + /// An enumeration of possible errors that can be generated from the `Chars` + /// adapter. + #[derive(Debug)] +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] + pub enum CharsError { + /// Variant representing that the underlying stream was read successfully + /// but it did not contain valid utf8 data. +@@ -2030,8 +1967,6 @@ pub enum CharsError { + Other(Error), + } + +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] + impl Iterator for Chars { + type Item = result::Result; + +@@ -2062,25 +1997,6 @@ impl Iterator for Chars { + } + } + +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] +-impl std_error::Error for CharsError { +- fn description(&self) -> &str { +- match *self { +- CharsError::NotUtf8 => "invalid utf8 encoding", +- CharsError::Other(ref e) => std_error::Error::description(e), +- } +- } +- fn cause(&self) -> Option<&std_error::Error> { +- match *self { +- CharsError::NotUtf8 => None, +- CharsError::Other(ref e) => e.cause(), +- } +- } +-} +- +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] + impl fmt::Display for CharsError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match *self { +@@ -2099,14 +2015,14 @@ impl fmt::Display for CharsError { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -2131,13 +2047,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 8772d0f..49d66c9 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -18,7 +18,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 195310a..20755b7 100644 +--- a/util.rs ++++ b/util.rs +@@ -10,9 +10,10 @@ + + #![allow(missing_copy_implementations)] + +-use fmt; +-use io::{self, Read, Initializer, Write, ErrorKind, BufRead}; +-use mem; ++use core::fmt; ++use io::{self, Read, Initializer, Write, ErrorKind}; ++use core::mem; ++#[cfg(feature="collections")] use io::BufRead; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -44,7 +45,6 @@ use mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -73,7 +73,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -93,10 +92,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -106,7 +103,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -114,7 +112,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -127,7 +124,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -144,10 +140,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte: byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -163,7 +157,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -176,7 +169,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -193,10 +185,8 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } +@@ -204,7 +194,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/93b6d9e086c6910118a57e4332c9448ab550931f.patch b/patches/93b6d9e086c6910118a57e4332c9448ab550931f.patch new file mode 100644 index 0000000..1137a47 --- /dev/null +++ b/patches/93b6d9e086c6910118a57e4332c9448ab550931f.patch @@ -0,0 +1,1869 @@ +diff --git a/buffered.rs b/buffered.rs +index 559a54d..bd888d2 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -1,12 +1,12 @@ + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use crate::io::prelude::*; + +-use crate::cmp; +-use crate::error; +-use crate::fmt; ++use core::cmp; ++use core::fmt; + use crate::io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom, IoVec, IoVecMut}; +-use crate::memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -42,7 +42,6 @@ use crate::memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -66,7 +65,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -87,7 +85,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -120,7 +117,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -141,7 +137,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + + /// Returns a reference to the internally buffered data. +@@ -166,7 +161,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -189,7 +183,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + } + +@@ -198,7 +191,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -218,7 +210,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -254,7 +245,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -274,7 +264,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -284,7 +273,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -393,7 +381,6 @@ impl Seek for BufReader { + /// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -428,7 +415,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -443,7 +429,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -461,7 +446,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -510,7 +494,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -528,7 +511,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Returns a reference to the internally buffered data. +@@ -545,7 +527,6 @@ impl BufWriter { + /// // See how many bytes are currently buffered + /// let bytes_buffered = buf_writer.buffer().len(); + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf + } +@@ -569,7 +550,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -578,7 +558,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -614,7 +593,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -624,7 +602,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -634,7 +611,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -673,7 +649,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -706,23 +681,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -793,7 +758,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -814,7 +778,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -835,7 +798,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -859,7 +821,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -882,7 +843,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -908,7 +868,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -919,7 +878,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -964,7 +922,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index 873da08..3d39e57 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -1,9 +1,10 @@ + use crate::io::prelude::*; + +-use crate::cmp; +-use crate::io::{self, Initializer, SeekFrom, Error, ErrorKind, IoVec, IoVecMut}; ++use core::cmp; ++use crate::io::{self, Initializer, SeekFrom, Error, ErrorKind}; ++#[cfg(feature="collections")] use crate::io::{IoVec, IoVecMut}; + +-use core::convert::TryInto; ++#[cfg(feature="collections")] use core::convert::TryInto; + + /// A `Cursor` wraps an in-memory buffer and provides it with a + /// [`Seek`] implementation. +@@ -71,7 +72,6 @@ use core::convert::TryInto; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -94,7 +94,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -112,7 +111,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -128,7 +126,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -147,7 +144,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -169,7 +165,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -189,11 +184,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -214,14 +207,14 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + ++ #[cfg(feature="collections")] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let mut nread = 0; + for buf in bufs { +@@ -236,7 +229,7 @@ impl Read for Cursor where T: AsRef<[u8]> { + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -247,12 +240,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -264,6 +261,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result, buf: &[u8]) -> io::Result { + let pos: usize = (*pos_mut).try_into().map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -308,6 +307,7 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result, +@@ -321,13 +321,13 @@ fn vec_write_vectored( + Ok(nwritten) + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Cursor<&mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, self.inner, buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + slice_write_vectored(&mut self.pos, self.inner, bufs) +@@ -336,12 +336,13 @@ impl Write for Cursor<&mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl Write for Cursor<&mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) + } + ++ #[cfg(feature="collections")] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + vec_write_vectored(&mut self.pos, self.inner, bufs) + } +@@ -349,12 +350,13 @@ impl Write for Cursor<&mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) + } + ++ #[cfg(feature="collections")] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + vec_write_vectored(&mut self.pos, &mut self.inner, bufs) + } +@@ -362,13 +364,14 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + slice_write_vectored(&mut self.pos, &mut self.inner, bufs) +diff --git a/error.rs b/error.rs +index fdc5625..e4ce8b5 100644 +--- a/error.rs ++++ b/error.rs +@@ -1,8 +1,13 @@ +-use crate::error; +-use crate::fmt; +-use crate::result; +-use crate::sys; +-use crate::convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -38,7 +43,6 @@ use crate::convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -52,12 +56,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -67,13 +69,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -85,48 +90,35 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + #[non_exhaustive] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -138,10 +130,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -152,15 +142,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -169,7 +156,6 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + } + +@@ -200,7 +186,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + /// Converts an [`ErrorKind`] into an [`Error`]. + /// +@@ -245,14 +230,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -261,24 +245,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -304,7 +270,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -335,7 +300,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -369,12 +333,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(dyn error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -440,12 +403,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -474,8 +436,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -501,10 +462,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -516,22 +476,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -539,25 +495,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- #[allow(deprecated)] +- fn cause(&self) -> Option<&dyn error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index bd3d0a4..c44cc70 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -1,19 +1,22 @@ +-use crate::cmp; +-use crate::io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind, IoVecMut, +- IoVec}; +-use crate::fmt; +-use crate::mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use crate::io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use crate::io::{BufRead, IoVecMut, IoVec}; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for &mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { + (**self).read(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + (**self).read_vectored(bufs) +@@ -24,11 +27,13 @@ impl Read for &mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -39,11 +44,11 @@ impl Read for &mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for &mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + (**self).write_vectored(bufs) +@@ -62,12 +67,11 @@ impl Write for &mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for &mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for &mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -86,13 +90,14 @@ impl BufRead for &mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { + (**self).read(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + (**self).read_vectored(bufs) +@@ -103,11 +108,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -118,11 +125,12 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + (**self).write_vectored(bufs) +@@ -141,12 +149,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -172,7 +180,6 @@ impl BufRead for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for &[u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -192,6 +199,7 @@ impl Read for &[u8] { + Ok(amt) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let mut nread = 0; +@@ -231,6 +239,7 @@ impl Read for &[u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -240,7 +249,7 @@ impl Read for &[u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for &[u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -254,7 +263,6 @@ impl BufRead for &[u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for &mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -265,6 +273,7 @@ impl Write for &mut [u8] { + Ok(amt) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + let mut nwritten = 0; +@@ -293,7 +302,7 @@ impl Write for &mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -301,6 +310,7 @@ impl Write for Vec { + Ok(buf.len()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + let len = bufs.iter().map(|b| b.len()).sum(); +diff --git a/mod.rs b/mod.rs +index e3e2754..400eca6 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -257,50 +257,38 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use crate::cmp; +-use crate::fmt; +-use crate::slice; +-use crate::str; +-use crate::memchr; +-use crate::ops::{Deref, DerefMut}; +-use crate::ptr; +-use crate::sys; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::cmp; ++use core::fmt; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++#[cfg(feature="collections")] use core::ops::{Deref, DerefMut}; ++use core::ptr; ++use core::slice; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = crate::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl Drop for Guard<'_> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -325,6 +313,7 @@ impl Drop for Guard<'_> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -352,10 +341,12 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + read_to_end_with_reservation(r, buf, 32) + } + ++#[cfg(feature="collections")] + fn read_to_end_with_reservation(r: &mut R, + buf: &mut Vec, + reservation_size: usize) -> Result +@@ -462,7 +453,6 @@ fn read_to_end_with_reservation(r: &mut R, + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -519,7 +509,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Like `read`, except that it reads into a slice of buffers. +@@ -530,7 +519,7 @@ pub trait Read { + /// + /// The default implementation simply passes the first nonempty buffer to + /// `read`. +- #[unstable(feature = "iovec", issue = "58452")] ++ #[cfg(feature="collections")] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> Result { + match bufs.iter_mut().find(|b| !b.is_empty()) { + Some(buf) => self.read(buf), +@@ -560,7 +549,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -613,7 +601,7 @@ pub trait Read { + /// file.) + /// + /// [`std::fs::read`]: ../fs/fn.read.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -656,7 +644,7 @@ pub trait Read { + /// reading from a file.) + /// + /// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -719,7 +707,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -771,7 +758,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -808,7 +794,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } +@@ -843,7 +828,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -879,42 +863,77 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + ++#[cfg(feature="collections")] ++pub struct IoVecBuffer<'a>(&'a [u8]); ++ ++#[cfg(feature="collections")] ++impl<'a> IoVecBuffer<'a> { ++ #[inline] ++ pub fn new(buf: &'a [u8]) -> IoVecBuffer<'a> { ++ IoVecBuffer(buf) ++ } ++ ++ #[inline] ++ pub fn as_slice(&self) -> &[u8] { ++ self.0 ++ } ++} ++#[cfg(feature="collections")] ++pub struct IoVecMutBuffer<'a>(&'a mut [u8]); ++ ++#[cfg(feature="collections")] ++impl<'a> IoVecMutBuffer<'a> { ++ #[inline] ++ pub fn new(buf: &'a mut [u8]) -> IoVecMutBuffer<'a> { ++ IoVecMutBuffer(buf) ++ } ++ ++ #[inline] ++ pub fn as_slice(&self) -> &[u8] { ++ self.0 ++ } ++ ++ #[inline] ++ pub fn as_mut_slice(&mut self) -> &mut [u8] { ++ self.0 ++ } ++} ++ + /// A buffer type used with `Read::read_vectored`. + /// + /// It is semantically a wrapper around an `&mut [u8]`, but is guaranteed to be + /// ABI compatible with the `iovec` type on Unix platforms and `WSABUF` on + /// Windows. +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + #[repr(transparent)] +-pub struct IoVecMut<'a>(sys::io::IoVecMut<'a>); ++pub struct IoVecMut<'a>(IoVecMutBuffer<'a>); + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> fmt::Debug for IoVecMut<'a> { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(self.0.as_slice(), fmt) + } + } + ++#[cfg(feature="collections")] + impl<'a> IoVecMut<'a> { + /// Creates a new `IoVecMut` wrapping a byte slice. + /// + /// # Panics + /// + /// Panics on Windows if the slice is larger than 4GB. +- #[unstable(feature = "iovec", issue = "58452")] + #[inline] + pub fn new(buf: &'a mut [u8]) -> IoVecMut<'a> { +- IoVecMut(sys::io::IoVecMut::new(buf)) ++ IoVecMut(IoVecMutBuffer::new(buf)) + } + } + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> Deref for IoVecMut<'a> { + type Target = [u8]; + +@@ -924,7 +943,7 @@ impl<'a> Deref for IoVecMut<'a> { + } + } + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> DerefMut for IoVecMut<'a> { + #[inline] + fn deref_mut(&mut self) -> &mut [u8] { +@@ -937,31 +956,31 @@ impl<'a> DerefMut for IoVecMut<'a> { + /// It is semantically a wrapper around an `&[u8]`, but is guaranteed to be + /// ABI compatible with the `iovec` type on Unix platforms and `WSABUF` on + /// Windows. +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + #[repr(transparent)] +-pub struct IoVec<'a>(sys::io::IoVec<'a>); ++pub struct IoVec<'a>(IoVecBuffer<'a>); + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> fmt::Debug for IoVec<'a> { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(self.0.as_slice(), fmt) + } + } + ++#[cfg(feature="collections")] + impl<'a> IoVec<'a> { + /// Creates a new `IoVec` wrapping a byte slice. + /// + /// # Panics + /// + /// Panics on Windows if the slice is larger than 4GB. +- #[unstable(feature = "iovec", issue = "58452")] + #[inline] + pub fn new(buf: &'a [u8]) -> IoVec<'a> { +- IoVec(sys::io::IoVec::new(buf)) ++ IoVec(IoVecBuffer::new(buf)) + } + } + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> Deref for IoVec<'a> { + type Target = [u8]; + +@@ -972,13 +991,11 @@ impl<'a> Deref for IoVec<'a> { + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -992,21 +1009,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -1049,7 +1063,6 @@ impl Initializer { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this writer, returning how many bytes were written. +@@ -1098,7 +1111,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Like `write`, except that it writes from a slice of buffers. +@@ -1109,7 +1121,7 @@ pub trait Write { + /// + /// The default implementation simply passes the first nonempty buffer to + /// `write`. +- #[unstable(feature = "iovec", issue = "58452")] ++ #[cfg(feature="collections")] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> Result { + match bufs.iter().find(|b| !b.is_empty()) { + Some(buf) => self.write(buf), +@@ -1140,7 +1152,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this writer. +@@ -1173,7 +1184,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1225,7 +1235,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1281,7 +1290,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1311,7 +1319,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1327,7 +1334,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + } + +@@ -1337,29 +1343,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Sets the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Sets the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Sets the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1439,7 +1442,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Returns the contents of the internal buffer, filling it with more data + /// from the inner reader if it is empty. +@@ -1485,7 +1488,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1507,7 +1509,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1563,7 +1564,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1622,7 +1622,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1663,7 +1662,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1702,7 +1700,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1714,7 +1711,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1740,7 +1736,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1763,7 +1758,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1790,13 +1784,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1806,7 +1798,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1818,6 +1809,7 @@ impl Read for Chain { + self.second.read(buf) + } + ++ #[cfg(feature="collections")] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> Result { + if !self.done_first { + match self.first.read_vectored(bufs)? { +@@ -1838,7 +1830,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1865,7 +1857,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -1900,7 +1891,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -1926,7 +1916,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "take_set_limit", since = "1.27.0")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -1951,7 +1940,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -1976,7 +1964,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -2005,13 +1992,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -2028,15 +2013,9 @@ impl Read for Take { + unsafe fn initializer(&self) -> Initializer { + self.inner.initializer() + } +- +- fn read_to_end(&mut self, buf: &mut Vec) -> Result { +- let reservation_size = cmp::min(self.limit, 32) as usize; +- +- read_to_end_with_reservation(self, buf, reservation_size) +- } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -2063,13 +2042,11 @@ impl BufRead for Take { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -2093,14 +2070,14 @@ impl Iterator for Bytes { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -2125,13 +2102,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 2e19edf..66294a3 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -8,7 +8,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 6aaf8f1..447ce47 100644 +--- a/util.rs ++++ b/util.rs +@@ -1,8 +1,9 @@ + #![allow(missing_copy_implementations)] + +-use crate::fmt; +-use crate::io::{self, Read, Initializer, Write, ErrorKind, BufRead, IoVec, IoVecMut}; +-use crate::mem; ++use core::fmt; ++use crate::io::{self, Read, Initializer, Write, ErrorKind}; ++#[cfg(feature="collections")] use crate::io::{BufRead, IoVec, IoVecMut}; ++use core::mem; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -39,7 +40,6 @@ use crate::mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -68,7 +68,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -88,10 +87,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -101,7 +98,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -109,7 +107,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -122,7 +119,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -139,10 +135,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -152,6 +146,7 @@ impl Read for Repeat { + Ok(buf.len()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let mut nwritten = 0; +@@ -167,7 +162,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -180,7 +174,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -197,14 +190,13 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + let total_len = bufs.iter().map(|b| b.len()).sum(); +@@ -215,7 +207,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/99ed06eb8864e704c4a1871ccda4648273bee4ef.patch b/patches/99ed06eb8864e704c4a1871ccda4648273bee4ef.patch new file mode 100644 index 0000000..2c010f1 --- /dev/null +++ b/patches/99ed06eb8864e704c4a1871ccda4648273bee4ef.patch @@ -0,0 +1,1602 @@ +diff --git a/buffered.rs b/buffered.rs +index 0615cd5..a46bf20 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -1,12 +1,12 @@ + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use io::prelude::*; + +-use cmp; +-use error; +-use fmt; ++use core::cmp; ++use core::fmt; + use io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom}; +-use memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -42,7 +42,6 @@ use memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -66,7 +65,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -87,7 +85,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -120,7 +117,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -141,7 +137,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + + /// Returns a reference to the internally buffered data. +@@ -166,7 +161,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -189,7 +183,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + } + +@@ -198,7 +191,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -218,7 +210,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -241,7 +232,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -261,7 +251,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -271,7 +260,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -380,7 +368,6 @@ impl Seek for BufReader { + /// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -415,7 +402,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -430,7 +416,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -448,7 +433,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -497,7 +481,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -515,7 +498,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Returns a reference to the internally buffered data. +@@ -532,7 +514,6 @@ impl BufWriter { + /// // See how many bytes are currently buffered + /// let bytes_buffered = buf_writer.buffer().len(); + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf + } +@@ -556,7 +537,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -565,7 +545,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -585,7 +564,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -595,7 +573,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -605,7 +582,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -644,7 +620,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -677,23 +652,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -764,7 +729,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -785,7 +749,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -806,7 +769,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -830,7 +792,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -853,7 +814,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -879,7 +839,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -890,7 +849,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -935,7 +893,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index b205f78..3d7e33f 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -1,7 +1,7 @@ + use io::prelude::*; + +-use core::convert::TryInto; +-use cmp; ++#[cfg(feature="collections")] use core::convert::TryInto; ++use core::cmp; + use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + + /// A `Cursor` wraps an in-memory buffer and provides it with a +@@ -70,7 +70,6 @@ use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -93,7 +92,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -111,7 +109,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -127,7 +124,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -146,7 +142,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -168,7 +163,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -188,11 +182,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -213,17 +205,16 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -234,12 +225,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -252,6 +247,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result, buf: &[u8]) -> io::Result { + let pos: usize = (*pos_mut).try_into().map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -278,7 +274,6 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result Write for Cursor<&'a mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -287,7 +282,7 @@ impl<'a> Write for Cursor<&'a mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl<'a> Write for Cursor<&'a mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) +@@ -295,7 +290,7 @@ impl<'a> Write for Cursor<&'a mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) +@@ -303,8 +298,8 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) +diff --git a/error.rs b/error.rs +index e9b4f60..31c0ff1 100644 +--- a/error.rs ++++ b/error.rs +@@ -1,8 +1,13 @@ +-use error; +-use fmt; +-use result; +-use sys; +-use convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -38,7 +43,6 @@ use convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -52,12 +56,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -67,13 +69,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -85,48 +90,35 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + #[non_exhaustive] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -138,10 +130,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -152,15 +142,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -169,7 +156,6 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + } + +@@ -200,7 +186,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + /// Converts an [`ErrorKind`] into an [`Error`]. + /// +@@ -245,14 +230,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -261,24 +245,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -304,7 +270,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -335,7 +300,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -369,12 +333,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(dyn error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -440,12 +403,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -474,8 +436,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -501,10 +462,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -516,22 +476,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -539,25 +495,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- #[allow(deprecated)] +- fn cause(&self) -> Option<&dyn error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index ec75a87..e9d6bf2 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -1,12 +1,15 @@ +-use cmp; +-use io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind}; +-use fmt; +-use mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use io::BufRead; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, R: Read + ?Sized> Read for &'a mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -18,11 +21,13 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -33,7 +38,6 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, W: Write + ?Sized> Write for &'a mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -51,12 +55,11 @@ impl<'a, W: Write + ?Sized> Write for &'a mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, S: Seek + ?Sized> Seek for &'a mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -75,7 +78,7 @@ impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -87,11 +90,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -102,7 +107,7 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -120,12 +125,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -151,7 +156,6 @@ impl BufRead for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Read for &'a [u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -197,6 +201,7 @@ impl<'a> Read for &'a [u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -206,7 +211,7 @@ impl<'a> Read for &'a [u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a> BufRead for &'a [u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -220,7 +225,6 @@ impl<'a> BufRead for &'a [u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Write for &'a mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -246,7 +250,7 @@ impl<'a> Write for &'a mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +diff --git a/mod.rs b/mod.rs +index c0570ae..f10d775 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -257,48 +257,37 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use cmp; +-use fmt; +-use slice; +-use str; +-use memchr; +-use ptr; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::cmp; ++use core::fmt; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++use core::ptr; ++use core::slice; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl<'a> Drop for Guard<'a> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -323,6 +312,7 @@ impl<'a> Drop for Guard<'a> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -350,10 +340,12 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + read_to_end_with_reservation(r, buf, 32) + } + ++#[cfg(feature="collections")] + fn read_to_end_with_reservation(r: &mut R, + buf: &mut Vec, + reservation_size: usize) -> Result +@@ -460,7 +452,6 @@ fn read_to_end_with_reservation(r: &mut R, + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -517,7 +508,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Determines if this `Read`er can work with buffers of uninitialized +@@ -542,7 +532,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -595,7 +584,7 @@ pub trait Read { + /// file.) + /// + /// [`std::fs::read`]: ../fs/fn.read.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -638,7 +627,7 @@ pub trait Read { + /// reading from a file.) + /// + /// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -701,7 +690,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -753,7 +741,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -790,7 +777,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } +@@ -825,7 +811,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -861,20 +846,17 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -888,21 +870,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -945,7 +924,6 @@ impl Initializer { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this writer, returning how many bytes were written. +@@ -994,7 +972,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Flush this output stream, ensuring that all intermediately buffered +@@ -1020,7 +997,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this writer. +@@ -1053,7 +1029,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1105,7 +1080,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1161,7 +1135,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1191,7 +1164,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1207,7 +1179,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + } + +@@ -1217,29 +1188,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Sets the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Sets the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Sets the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1319,7 +1287,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Returns the contents of the internal buffer, filling it with more data + /// from the inner reader if it is empty. +@@ -1365,7 +1333,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1387,7 +1354,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1443,7 +1409,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1502,7 +1467,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1543,7 +1507,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1582,7 +1545,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1594,7 +1556,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1620,7 +1581,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1643,7 +1603,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1670,13 +1629,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1686,7 +1643,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1708,7 +1664,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1735,7 +1691,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -1770,7 +1725,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -1796,7 +1750,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "take_set_limit", since = "1.27.0")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -1821,7 +1774,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -1846,7 +1798,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -1875,13 +1826,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -1898,15 +1847,9 @@ impl Read for Take { + unsafe fn initializer(&self) -> Initializer { + self.inner.initializer() + } +- +- fn read_to_end(&mut self, buf: &mut Vec) -> Result { +- let reservation_size = cmp::min(self.limit, 32) as usize; +- +- read_to_end_with_reservation(self, buf, reservation_size) +- } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -1933,13 +1876,11 @@ impl BufRead for Take { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -1963,14 +1904,14 @@ impl Iterator for Bytes { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -1995,13 +1936,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 2e19edf..66294a3 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -8,7 +8,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 8df961a..2b08122 100644 +--- a/util.rs ++++ b/util.rs +@@ -1,8 +1,9 @@ + #![allow(missing_copy_implementations)] + +-use fmt; +-use io::{self, Read, Initializer, Write, ErrorKind, BufRead}; +-use mem; ++use core::fmt; ++use io::{self, Read, Initializer, Write, ErrorKind}; ++use core::mem; ++#[cfg(feature="collections")] use io::BufRead; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -39,7 +40,6 @@ use mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -68,7 +68,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -88,10 +87,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -101,7 +98,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -109,7 +107,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -122,7 +119,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -139,10 +135,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -158,7 +152,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -171,7 +164,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -188,10 +180,8 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } +@@ -199,7 +189,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/b20bba4f3777fd097539e1f516987e0d9729d710.patch b/patches/b20bba4f3777fd097539e1f516987e0d9729d710.patch new file mode 100644 index 0000000..5235ec4 --- /dev/null +++ b/patches/b20bba4f3777fd097539e1f516987e0d9729d710.patch @@ -0,0 +1,1608 @@ +diff --git a/buffered.rs b/buffered.rs +index 476ee3f..d696d37 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -10,13 +10,13 @@ + + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use io::prelude::*; + +-use cmp; +-use error; +-use fmt; ++use core::cmp; ++use core::fmt; + use io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom}; +-use memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -52,7 +52,6 @@ use memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -76,7 +75,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -97,7 +95,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -130,7 +127,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -151,7 +147,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + + /// Returns a reference to the internally buffered data. +@@ -176,7 +171,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -199,7 +193,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + } + +@@ -208,7 +201,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -228,7 +220,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -251,7 +242,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -271,7 +261,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -281,7 +270,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -387,7 +375,6 @@ impl Seek for BufReader { + /// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -422,7 +409,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -437,7 +423,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -455,7 +440,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -504,7 +488,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -522,7 +505,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Returns a reference to the internally buffered data. +@@ -539,7 +521,6 @@ impl BufWriter { + /// // See how many bytes are currently buffered + /// let bytes_buffered = buf_writer.buffer().len(); + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf + } +@@ -563,7 +544,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -572,7 +552,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -592,7 +571,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -602,7 +580,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -612,7 +589,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -651,7 +627,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -684,23 +659,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -771,7 +736,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -792,7 +756,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -813,7 +776,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -837,7 +799,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -860,7 +821,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -886,7 +846,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -897,7 +856,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -942,7 +900,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index 14f2015..1d60dac 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -10,8 +10,8 @@ + + use io::prelude::*; + +-use core::convert::TryInto; +-use cmp; ++#[cfg(feature="collections")] use core::convert::TryInto; ++use core::cmp; + use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + + /// A `Cursor` wraps an in-memory buffer and provides it with a +@@ -80,7 +80,6 @@ use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -103,7 +102,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -121,7 +119,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -137,7 +134,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -156,7 +152,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -178,7 +173,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -198,11 +192,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -223,17 +215,16 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -244,12 +235,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -262,6 +257,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result, buf: &[u8]) -> io::Result { + let pos: usize = (*pos_mut).try_into().map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -288,7 +284,6 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result Write for Cursor<&'a mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -297,7 +292,7 @@ impl<'a> Write for Cursor<&'a mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl<'a> Write for Cursor<&'a mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) +@@ -305,7 +300,7 @@ impl<'a> Write for Cursor<&'a mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) +@@ -313,8 +308,8 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) +diff --git a/error.rs b/error.rs +index 386de08..4a9559a 100644 +--- a/error.rs ++++ b/error.rs +@@ -8,11 +8,16 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use error; +-use fmt; +-use result; +-use sys; +-use convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -48,7 +53,6 @@ use convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -62,12 +66,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -77,13 +79,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -95,48 +100,35 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + #[non_exhaustive] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -148,10 +140,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -162,15 +152,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -179,7 +166,6 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + } + +@@ -210,7 +196,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + /// Converts an [`ErrorKind`] into an [`Error`]. + /// +@@ -252,14 +237,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -268,24 +252,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -311,7 +277,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -342,7 +307,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -376,12 +340,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(dyn error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -447,12 +410,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -481,8 +443,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -508,10 +469,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -523,22 +483,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -546,24 +502,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- fn cause(&self) -> Option<&dyn error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index fe1179a..452b8b7 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -8,15 +8,18 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use cmp; +-use io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind}; +-use fmt; +-use mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use io::BufRead; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, R: Read + ?Sized> Read for &'a mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -28,11 +31,13 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -43,7 +48,6 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, W: Write + ?Sized> Write for &'a mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -61,12 +65,11 @@ impl<'a, W: Write + ?Sized> Write for &'a mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, S: Seek + ?Sized> Seek for &'a mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -85,7 +88,7 @@ impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -97,11 +100,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -112,7 +117,7 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -130,12 +135,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -161,7 +166,6 @@ impl BufRead for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Read for &'a [u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -207,6 +211,7 @@ impl<'a> Read for &'a [u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -216,7 +221,7 @@ impl<'a> Read for &'a [u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a> BufRead for &'a [u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -230,7 +235,6 @@ impl<'a> BufRead for &'a [u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Write for &'a mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -256,7 +260,7 @@ impl<'a> Write for &'a mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +diff --git a/mod.rs b/mod.rs +index e263db2..2176464 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -267,47 +267,36 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use cmp; +-use fmt; +-use str; +-use memchr; +-use ptr; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::cmp; ++use core::fmt; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++use core::ptr; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl<'a> Drop for Guard<'a> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -332,6 +321,7 @@ impl<'a> Drop for Guard<'a> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -359,10 +349,12 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + read_to_end_with_reservation(r, buf, 32) + } + ++#[cfg(feature="collections")] + fn read_to_end_with_reservation(r: &mut R, + buf: &mut Vec, + reservation_size: usize) -> Result +@@ -469,7 +461,6 @@ fn read_to_end_with_reservation(r: &mut R, + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -526,7 +517,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Determines if this `Read`er can work with buffers of uninitialized +@@ -551,7 +541,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -604,7 +593,7 @@ pub trait Read { + /// file.) + /// + /// [`std::fs::read`]: ../fs/fn.read.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -647,7 +636,7 @@ pub trait Read { + /// reading from a file.) + /// + /// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -710,7 +699,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -762,7 +750,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -799,7 +786,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } +@@ -834,7 +820,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -870,20 +855,17 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -897,21 +879,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -954,7 +933,6 @@ impl Initializer { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this object, returning how many bytes were written. +@@ -1003,7 +981,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Flush this output stream, ensuring that all intermediately buffered +@@ -1029,7 +1006,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this write. +@@ -1062,7 +1038,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1114,7 +1089,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1170,7 +1144,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1200,7 +1173,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1216,7 +1188,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + } + +@@ -1226,29 +1197,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Set the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Set the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Set the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1328,7 +1296,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Returns the contents of the internal buffer, filling it with more data + /// from the inner reader if it is empty. +@@ -1374,7 +1342,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1396,7 +1363,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1452,7 +1418,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1511,7 +1476,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1552,7 +1516,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1591,7 +1554,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1603,7 +1565,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1629,7 +1590,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1652,7 +1612,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1679,13 +1638,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1695,7 +1652,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1717,7 +1673,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1744,7 +1700,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -1779,7 +1734,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -1805,7 +1759,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "take_set_limit", since = "1.27.0")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -1830,7 +1783,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -1855,7 +1807,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -1884,13 +1835,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -1907,15 +1856,9 @@ impl Read for Take { + unsafe fn initializer(&self) -> Initializer { + self.inner.initializer() + } +- +- fn read_to_end(&mut self, buf: &mut Vec) -> Result { +- let reservation_size = cmp::min(self.limit, 32) as usize; +- +- read_to_end_with_reservation(self, buf, reservation_size) +- } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -1954,13 +1897,11 @@ fn read_one_byte(reader: &mut dyn Read) -> Option> { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -1976,14 +1917,14 @@ impl Iterator for Bytes { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -2008,13 +1949,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 8772d0f..49d66c9 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -18,7 +18,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 12995d0..397eef4 100644 +--- a/util.rs ++++ b/util.rs +@@ -10,9 +10,10 @@ + + #![allow(missing_copy_implementations)] + +-use fmt; +-use io::{self, Read, Initializer, Write, ErrorKind, BufRead}; +-use mem; ++use core::fmt; ++use io::{self, Read, Initializer, Write, ErrorKind}; ++use core::mem; ++#[cfg(feature="collections")] use io::BufRead; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -49,7 +50,6 @@ use mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -78,7 +78,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -98,10 +97,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -111,7 +108,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -119,7 +117,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -132,7 +129,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -149,10 +145,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -168,7 +162,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -181,7 +174,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -198,10 +190,8 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } +@@ -209,7 +199,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/b5ed39ff10f0e46be6e97b577477e0f60234fa0b.patch b/patches/b5ed39ff10f0e46be6e97b577477e0f60234fa0b.patch new file mode 100644 index 0000000..c0d3549 --- /dev/null +++ b/patches/b5ed39ff10f0e46be6e97b577477e0f60234fa0b.patch @@ -0,0 +1,1607 @@ +diff --git a/buffered.rs b/buffered.rs +index 03c97de..9618137 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -10,13 +10,13 @@ + + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use io::prelude::*; + +-use cmp; +-use error; +-use fmt; ++use core::cmp; ++use core::fmt; + use io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom}; +-use memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -52,7 +52,6 @@ use memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -76,7 +75,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -97,7 +95,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -130,7 +127,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -151,7 +147,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + + /// Returns a reference to the internally buffered data. +@@ -176,7 +171,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -199,7 +193,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + } + +@@ -208,7 +201,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -228,7 +220,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -251,7 +242,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -271,7 +261,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -281,7 +270,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -389,7 +377,6 @@ impl Seek for BufReader { + /// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -424,7 +411,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -439,7 +425,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -457,7 +442,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -506,7 +490,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -524,7 +507,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Unwraps this `BufWriter`, returning the underlying writer. +@@ -546,7 +528,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -555,7 +536,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -575,7 +555,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -585,7 +564,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -595,7 +573,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -634,7 +611,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -667,23 +643,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -754,7 +720,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -775,7 +740,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -796,7 +760,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -820,7 +783,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -843,7 +805,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -869,7 +830,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -880,7 +840,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -925,7 +884,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index 14f2015..1d60dac 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -10,8 +10,8 @@ + + use io::prelude::*; + +-use core::convert::TryInto; +-use cmp; ++#[cfg(feature="collections")] use core::convert::TryInto; ++use core::cmp; + use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + + /// A `Cursor` wraps an in-memory buffer and provides it with a +@@ -80,7 +80,6 @@ use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -103,7 +102,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -121,7 +119,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -137,7 +134,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -156,7 +152,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -178,7 +173,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -198,11 +192,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -223,17 +215,16 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -244,12 +235,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -262,6 +257,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result, buf: &[u8]) -> io::Result { + let pos: usize = (*pos_mut).try_into().map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -288,7 +284,6 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result Write for Cursor<&'a mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -297,7 +292,7 @@ impl<'a> Write for Cursor<&'a mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl<'a> Write for Cursor<&'a mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) +@@ -305,7 +300,7 @@ impl<'a> Write for Cursor<&'a mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) +@@ -313,8 +308,8 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) +diff --git a/error.rs b/error.rs +index 02a3ce8..3acdadf 100644 +--- a/error.rs ++++ b/error.rs +@@ -8,11 +8,16 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use error; +-use fmt; +-use result; +-use sys; +-use convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -48,7 +53,6 @@ use convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -62,12 +66,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -77,13 +79,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -95,47 +100,34 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -147,10 +139,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -161,15 +151,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -178,15 +165,10 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + + /// A marker variant that tells the compiler that users of this enum cannot + /// match it exhaustively. +- #[unstable(feature = "io_error_internals", +- reason = "better expressed through extensible enums that this \ +- enum cannot be exhaustively matched against", +- issue = "0")] + #[doc(hidden)] + __Nonexhaustive, + } +@@ -219,7 +201,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + #[inline] + fn from(kind: ErrorKind) -> Error { +@@ -248,14 +229,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -264,24 +244,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -307,7 +269,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -338,7 +299,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -372,12 +332,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(dyn error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -443,12 +402,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -477,8 +435,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -504,10 +461,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -519,22 +475,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -542,24 +494,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- fn cause(&self) -> Option<&dyn error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index fe1179a..452b8b7 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -8,15 +8,18 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use cmp; +-use io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind}; +-use fmt; +-use mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use io::BufRead; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, R: Read + ?Sized> Read for &'a mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -28,11 +31,13 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -43,7 +48,6 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, W: Write + ?Sized> Write for &'a mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -61,12 +65,11 @@ impl<'a, W: Write + ?Sized> Write for &'a mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, S: Seek + ?Sized> Seek for &'a mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -85,7 +88,7 @@ impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -97,11 +100,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -112,7 +117,7 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -130,12 +135,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -161,7 +166,6 @@ impl BufRead for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Read for &'a [u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -207,6 +211,7 @@ impl<'a> Read for &'a [u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -216,7 +221,7 @@ impl<'a> Read for &'a [u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a> BufRead for &'a [u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -230,7 +235,6 @@ impl<'a> BufRead for &'a [u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Write for &'a mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -256,7 +260,7 @@ impl<'a> Write for &'a mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +diff --git a/mod.rs b/mod.rs +index b83f3fb..883fa30 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -267,47 +267,36 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use cmp; +-use fmt; +-use str; +-use memchr; +-use ptr; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::cmp; ++use core::fmt; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++use core::ptr; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl<'a> Drop for Guard<'a> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -332,6 +321,7 @@ impl<'a> Drop for Guard<'a> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -359,10 +349,12 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + read_to_end_with_reservation(r, buf, 32) + } + ++#[cfg(feature="collections")] + fn read_to_end_with_reservation(r: &mut R, + buf: &mut Vec, + reservation_size: usize) -> Result +@@ -469,7 +461,6 @@ fn read_to_end_with_reservation(r: &mut R, + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -526,7 +517,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Determines if this `Read`er can work with buffers of uninitialized +@@ -551,7 +541,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -604,7 +593,7 @@ pub trait Read { + /// file.) + /// + /// [`std::fs::read`]: ../fs/fn.read.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -647,7 +636,7 @@ pub trait Read { + /// reading from a file.) + /// + /// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -710,7 +699,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -762,7 +750,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -799,7 +786,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } +@@ -834,7 +820,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -870,20 +855,17 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -897,21 +879,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -954,7 +933,6 @@ impl Initializer { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this object, returning how many bytes were written. +@@ -1003,7 +981,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Flush this output stream, ensuring that all intermediately buffered +@@ -1029,7 +1006,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this write. +@@ -1062,7 +1038,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1114,7 +1089,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1170,7 +1144,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1200,7 +1173,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1216,7 +1188,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + } + +@@ -1226,29 +1197,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Set the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Set the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Set the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1328,7 +1296,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Fills the internal buffer of this object, returning the buffer contents. + /// +@@ -1373,7 +1341,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1395,7 +1362,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1451,7 +1417,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1510,7 +1475,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1551,7 +1515,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1590,7 +1553,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1602,7 +1564,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1628,7 +1589,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1651,7 +1611,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1678,13 +1637,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1694,7 +1651,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1716,7 +1672,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1743,7 +1699,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -1778,7 +1733,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -1804,7 +1758,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "take_set_limit", since = "1.27.0")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -1829,7 +1782,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -1854,7 +1806,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -1883,13 +1834,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -1906,15 +1855,9 @@ impl Read for Take { + unsafe fn initializer(&self) -> Initializer { + self.inner.initializer() + } +- +- fn read_to_end(&mut self, buf: &mut Vec) -> Result { +- let reservation_size = cmp::min(self.limit, 32) as usize; +- +- read_to_end_with_reservation(self, buf, reservation_size) +- } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -1953,13 +1896,11 @@ fn read_one_byte(reader: &mut dyn Read) -> Option> { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -1975,14 +1916,14 @@ impl Iterator for Bytes { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -2007,13 +1948,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 8772d0f..49d66c9 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -18,7 +18,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 33f741d..878fb82 100644 +--- a/util.rs ++++ b/util.rs +@@ -10,9 +10,10 @@ + + #![allow(missing_copy_implementations)] + +-use fmt; +-use io::{self, Read, Initializer, Write, ErrorKind, BufRead}; +-use mem; ++use core::fmt; ++use io::{self, Read, Initializer, Write, ErrorKind}; ++use core::mem; ++#[cfg(feature="collections")] use io::BufRead; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -44,7 +45,6 @@ use mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -73,7 +73,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -93,10 +92,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -106,7 +103,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -114,7 +112,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -127,7 +124,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -144,10 +140,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte: byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -163,7 +157,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -176,7 +169,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -193,10 +185,8 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } +@@ -204,7 +194,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/b6fb3e34117008f7f97094b0f1521116a4e66473.patch b/patches/b6fb3e34117008f7f97094b0f1521116a4e66473.patch new file mode 100644 index 0000000..7b7f3de --- /dev/null +++ b/patches/b6fb3e34117008f7f97094b0f1521116a4e66473.patch @@ -0,0 +1,1909 @@ +diff --git a/buffered.rs b/buffered.rs +index 441f6b9..540d4aa 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -1,12 +1,12 @@ + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use crate::io::prelude::*; + +-use crate::cmp; +-use crate::error; +-use crate::fmt; ++use core::cmp; ++use core::fmt; + use crate::io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom, IoVec, IoVecMut}; +-use crate::memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -46,7 +46,6 @@ use crate::memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -70,7 +69,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -91,7 +89,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -126,7 +123,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -147,7 +143,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + + /// Returns a reference to the internally buffered data. +@@ -172,7 +167,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -195,7 +189,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + + /// Invalidates all data in the internal buffer. +@@ -211,7 +204,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -231,7 +223,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -269,7 +260,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -289,7 +279,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -299,7 +288,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -408,7 +396,6 @@ impl Seek for BufReader { + /// [`TcpStream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -443,7 +430,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -458,7 +444,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -476,7 +461,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -525,7 +509,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -543,7 +526,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Returns a reference to the internally buffered data. +@@ -560,7 +542,6 @@ impl BufWriter { + /// // See how many bytes are currently buffered + /// let bytes_buffered = buf_writer.buffer().len(); + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf + } +@@ -584,7 +565,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -593,7 +573,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -629,7 +608,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -639,7 +617,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -649,7 +626,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -688,7 +664,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -721,23 +696,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -808,7 +773,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -829,7 +793,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -850,7 +813,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -874,7 +836,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -897,7 +858,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -923,7 +883,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -934,7 +893,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -979,7 +937,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index 247d45c..f13522d 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -1,9 +1,10 @@ + use crate::io::prelude::*; + +-use crate::cmp; +-use crate::io::{self, Initializer, SeekFrom, Error, ErrorKind, IoVec, IoVecMut}; ++use core::cmp; ++use crate::io::{self, Initializer, SeekFrom, Error, ErrorKind}; ++#[cfg(feature="collections")] use crate::io::{IoVec, IoVecMut}; + +-use core::convert::TryInto; ++#[cfg(feature="collections")] use core::convert::TryInto; + + /// A `Cursor` wraps an in-memory buffer and provides it with a + /// [`Seek`] implementation. +@@ -71,7 +72,6 @@ use core::convert::TryInto; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -94,7 +94,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -112,7 +111,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -128,7 +126,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -147,7 +144,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -169,7 +165,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -189,11 +184,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -222,14 +215,14 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + ++ #[cfg(feature="collections")] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let mut nread = 0; + for buf in bufs { +@@ -244,7 +237,7 @@ impl Read for Cursor where T: AsRef<[u8]> { + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -255,12 +248,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -272,6 +269,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result, buf: &[u8]) -> io::Result { + let pos: usize = (*pos_mut).try_into().map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -316,6 +315,7 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result, +@@ -329,13 +329,13 @@ fn vec_write_vectored( + Ok(nwritten) + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Cursor<&mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, self.inner, buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + slice_write_vectored(&mut self.pos, self.inner, bufs) +@@ -344,12 +344,13 @@ impl Write for Cursor<&mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl Write for Cursor<&mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) + } + ++ #[cfg(feature="collections")] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + vec_write_vectored(&mut self.pos, self.inner, bufs) + } +@@ -357,12 +358,13 @@ impl Write for Cursor<&mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) + } + ++ #[cfg(feature="collections")] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + vec_write_vectored(&mut self.pos, &mut self.inner, bufs) + } +@@ -370,13 +372,14 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + slice_write_vectored(&mut self.pos, &mut self.inner, bufs) +diff --git a/error.rs b/error.rs +index 614b791..e4ce8b5 100644 +--- a/error.rs ++++ b/error.rs +@@ -1,8 +1,13 @@ +-use crate::error; +-use crate::fmt; +-use crate::result; +-use crate::sys; +-use crate::convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -38,7 +43,6 @@ use crate::convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -52,12 +56,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -67,13 +69,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -85,48 +90,35 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + #[non_exhaustive] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -138,10 +130,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -152,15 +142,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -169,7 +156,6 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + } + +@@ -200,7 +186,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + /// Converts an [`ErrorKind`] into an [`Error`]. + /// +@@ -245,14 +230,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -261,24 +245,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -304,7 +270,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -335,7 +300,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -369,12 +333,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(dyn error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -440,12 +403,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -474,8 +436,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -501,10 +462,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -516,22 +476,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -539,33 +495,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- #[allow(deprecated)] +- fn cause(&self) -> Option<&dyn error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +- +- fn source(&self) -> Option<&(dyn error::Error + 'static)> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.source(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index b286e40..7472d9c 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -1,19 +1,22 @@ +-use crate::cmp; +-use crate::io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind, IoVecMut, +- IoVec}; +-use crate::fmt; +-use crate::mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use crate::io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use crate::io::{BufRead, IoVecMut, IoVec}; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for &mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { + (**self).read(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + (**self).read_vectored(bufs) +@@ -24,11 +27,13 @@ impl Read for &mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -39,11 +44,11 @@ impl Read for &mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for &mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + (**self).write_vectored(bufs) +@@ -62,12 +67,11 @@ impl Write for &mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for &mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for &mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -86,13 +90,14 @@ impl BufRead for &mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { + (**self).read(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + (**self).read_vectored(bufs) +@@ -103,11 +108,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -118,11 +125,12 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + (**self).write_vectored(bufs) +@@ -141,12 +149,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -186,7 +194,6 @@ impl Write for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for &[u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -206,6 +213,7 @@ impl Read for &[u8] { + Ok(amt) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let mut nread = 0; +@@ -245,6 +253,7 @@ impl Read for &[u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -254,7 +263,7 @@ impl Read for &[u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for &[u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -268,7 +277,6 @@ impl BufRead for &[u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for &mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -279,6 +287,7 @@ impl Write for &mut [u8] { + Ok(amt) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + let mut nwritten = 0; +@@ -307,7 +316,7 @@ impl Write for &mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -315,6 +324,7 @@ impl Write for Vec { + Ok(buf.len()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + let len = bufs.iter().map(|b| b.len()).sum(); +diff --git a/mod.rs b/mod.rs +index 14a16f3..07792b7 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -257,50 +257,38 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use crate::cmp; +-use crate::fmt; +-use crate::slice; +-use crate::str; +-use crate::memchr; +-use crate::ops::{Deref, DerefMut}; +-use crate::ptr; +-use crate::sys; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::cmp; ++use core::fmt; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++#[cfg(feature="collections")] use core::ops::{Deref, DerefMut}; ++use core::ptr; ++use core::slice; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = crate::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl Drop for Guard<'_> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -325,6 +313,7 @@ impl Drop for Guard<'_> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -352,10 +341,12 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + read_to_end_with_reservation(r, buf, 32) + } + ++#[cfg(feature="collections")] + fn read_to_end_with_reservation(r: &mut R, + buf: &mut Vec, + reservation_size: usize) -> Result +@@ -390,6 +381,7 @@ fn read_to_end_with_reservation(r: &mut R, + ret + } + ++#[cfg(feature="collections")] + pub(crate) fn default_read_vectored(read: F, bufs: &mut [IoVecMut<'_>]) -> Result + where + F: FnOnce(&mut [u8]) -> Result +@@ -401,6 +393,7 @@ where + read(buf) + } + ++#[cfg(feature="collections")] + pub(crate) fn default_write_vectored(write: F, bufs: &[IoVec<'_>]) -> Result + where + F: FnOnce(&[u8]) -> Result +@@ -484,7 +477,6 @@ where + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -543,7 +535,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Like `read`, except that it reads into a slice of buffers. +@@ -554,7 +545,7 @@ pub trait Read { + /// + /// The default implementation calls `read` with either the first nonempty + /// buffer provided, or an empty one if none exists. +- #[unstable(feature = "iovec", issue = "58452")] ++ #[cfg(feature="collections")] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> Result { + default_read_vectored(|b| self.read(b), bufs) + } +@@ -581,7 +572,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -634,7 +624,7 @@ pub trait Read { + /// file.) + /// + /// [`std::fs::read`]: ../fs/fn.read.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -677,7 +667,7 @@ pub trait Read { + /// reading from a file.) + /// + /// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -740,7 +730,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -792,7 +781,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -829,7 +817,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } +@@ -864,7 +851,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -900,42 +886,77 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + ++#[cfg(feature="collections")] ++pub struct IoVecBuffer<'a>(&'a [u8]); ++ ++#[cfg(feature="collections")] ++impl<'a> IoVecBuffer<'a> { ++ #[inline] ++ pub fn new(buf: &'a [u8]) -> IoVecBuffer<'a> { ++ IoVecBuffer(buf) ++ } ++ ++ #[inline] ++ pub fn as_slice(&self) -> &[u8] { ++ self.0 ++ } ++} ++#[cfg(feature="collections")] ++pub struct IoVecMutBuffer<'a>(&'a mut [u8]); ++ ++#[cfg(feature="collections")] ++impl<'a> IoVecMutBuffer<'a> { ++ #[inline] ++ pub fn new(buf: &'a mut [u8]) -> IoVecMutBuffer<'a> { ++ IoVecMutBuffer(buf) ++ } ++ ++ #[inline] ++ pub fn as_slice(&self) -> &[u8] { ++ self.0 ++ } ++ ++ #[inline] ++ pub fn as_mut_slice(&mut self) -> &mut [u8] { ++ self.0 ++ } ++} ++ + /// A buffer type used with `Read::read_vectored`. + /// + /// It is semantically a wrapper around an `&mut [u8]`, but is guaranteed to be + /// ABI compatible with the `iovec` type on Unix platforms and `WSABUF` on + /// Windows. +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + #[repr(transparent)] +-pub struct IoVecMut<'a>(sys::io::IoVecMut<'a>); ++pub struct IoVecMut<'a>(IoVecMutBuffer<'a>); + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> fmt::Debug for IoVecMut<'a> { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(self.0.as_slice(), fmt) + } + } + ++#[cfg(feature="collections")] + impl<'a> IoVecMut<'a> { + /// Creates a new `IoVecMut` wrapping a byte slice. + /// + /// # Panics + /// + /// Panics on Windows if the slice is larger than 4GB. +- #[unstable(feature = "iovec", issue = "58452")] + #[inline] + pub fn new(buf: &'a mut [u8]) -> IoVecMut<'a> { +- IoVecMut(sys::io::IoVecMut::new(buf)) ++ IoVecMut(IoVecMutBuffer::new(buf)) + } + } + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> Deref for IoVecMut<'a> { + type Target = [u8]; + +@@ -945,7 +966,7 @@ impl<'a> Deref for IoVecMut<'a> { + } + } + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> DerefMut for IoVecMut<'a> { + #[inline] + fn deref_mut(&mut self) -> &mut [u8] { +@@ -958,31 +979,31 @@ impl<'a> DerefMut for IoVecMut<'a> { + /// It is semantically a wrapper around an `&[u8]`, but is guaranteed to be + /// ABI compatible with the `iovec` type on Unix platforms and `WSABUF` on + /// Windows. +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + #[repr(transparent)] +-pub struct IoVec<'a>(sys::io::IoVec<'a>); ++pub struct IoVec<'a>(IoVecBuffer<'a>); + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> fmt::Debug for IoVec<'a> { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(self.0.as_slice(), fmt) + } + } + ++#[cfg(feature="collections")] + impl<'a> IoVec<'a> { + /// Creates a new `IoVec` wrapping a byte slice. + /// + /// # Panics + /// + /// Panics on Windows if the slice is larger than 4GB. +- #[unstable(feature = "iovec", issue = "58452")] + #[inline] + pub fn new(buf: &'a [u8]) -> IoVec<'a> { +- IoVec(sys::io::IoVec::new(buf)) ++ IoVec(IoVecBuffer::new(buf)) + } + } + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> Deref for IoVec<'a> { + type Target = [u8]; + +@@ -993,13 +1014,11 @@ impl<'a> Deref for IoVec<'a> { + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -1013,21 +1032,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -1081,7 +1097,6 @@ impl Initializer { + /// `write` in a loop until its entire input has been written. + /// + /// [`write_all`]: #method.write_all +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this writer, returning how many bytes were written. +@@ -1130,7 +1145,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Like `write`, except that it writes from a slice of buffers. +@@ -1141,7 +1155,7 @@ pub trait Write { + /// + /// The default implementation calls `write` with either the first nonempty + /// buffer provided, or an empty one if none exists. +- #[unstable(feature = "iovec", issue = "58452")] ++ #[cfg(feature="collections")] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> Result { + default_write_vectored(|b| self.write(b), bufs) + } +@@ -1169,7 +1183,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this writer. +@@ -1202,7 +1215,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1254,7 +1266,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1310,7 +1321,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1340,7 +1350,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1356,7 +1365,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + + /// Returns the length of this stream (in bytes). +@@ -1394,7 +1402,6 @@ pub trait Seek { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "seek_convenience", issue = "59359")] + fn stream_len(&mut self) -> Result { + let old_pos = self.stream_position()?; + let len = self.seek(SeekFrom::End(0))?; +@@ -1433,7 +1440,6 @@ pub trait Seek { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "seek_convenience", issue = "59359")] + fn stream_position(&mut self) -> Result { + self.seek(SeekFrom::Current(0)) + } +@@ -1445,29 +1451,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Sets the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Sets the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Sets the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1547,7 +1550,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Returns the contents of the internal buffer, filling it with more data + /// from the inner reader if it is empty. +@@ -1593,7 +1596,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1615,7 +1617,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1671,7 +1672,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1730,7 +1730,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1771,7 +1770,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1810,7 +1808,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1822,7 +1819,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1848,7 +1844,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1871,7 +1866,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1898,13 +1892,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1914,7 +1906,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1926,6 +1917,7 @@ impl Read for Chain { + self.second.read(buf) + } + ++ #[cfg(feature="collections")] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> Result { + if !self.done_first { + match self.first.read_vectored(bufs)? { +@@ -1946,7 +1938,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1973,7 +1965,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -2008,7 +1999,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -2034,7 +2024,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "take_set_limit", since = "1.27.0")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -2059,7 +2048,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -2084,7 +2072,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -2113,13 +2100,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -2136,15 +2121,9 @@ impl Read for Take { + unsafe fn initializer(&self) -> Initializer { + self.inner.initializer() + } +- +- fn read_to_end(&mut self, buf: &mut Vec) -> Result { +- let reservation_size = cmp::min(self.limit, 32) as usize; +- +- read_to_end_with_reservation(self, buf, reservation_size) +- } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -2171,13 +2150,11 @@ impl BufRead for Take { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -2201,14 +2178,14 @@ impl Iterator for Bytes { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -2233,13 +2210,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 2e19edf..66294a3 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -8,7 +8,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 6aaf8f1..447ce47 100644 +--- a/util.rs ++++ b/util.rs +@@ -1,8 +1,9 @@ + #![allow(missing_copy_implementations)] + +-use crate::fmt; +-use crate::io::{self, Read, Initializer, Write, ErrorKind, BufRead, IoVec, IoVecMut}; +-use crate::mem; ++use core::fmt; ++use crate::io::{self, Read, Initializer, Write, ErrorKind}; ++#[cfg(feature="collections")] use crate::io::{BufRead, IoVec, IoVecMut}; ++use core::mem; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -39,7 +40,6 @@ use crate::mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -68,7 +68,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -88,10 +87,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -101,7 +98,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -109,7 +107,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -122,7 +119,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -139,10 +135,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -152,6 +146,7 @@ impl Read for Repeat { + Ok(buf.len()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let mut nwritten = 0; +@@ -167,7 +162,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -180,7 +174,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -197,14 +190,13 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + let total_len = bufs.iter().map(|b| b.len()).sum(); +@@ -215,7 +207,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/b81da278623d9dcda1776008612bd42e1922e9c3.patch b/patches/b81da278623d9dcda1776008612bd42e1922e9c3.patch new file mode 100644 index 0000000..91edd7d --- /dev/null +++ b/patches/b81da278623d9dcda1776008612bd42e1922e9c3.patch @@ -0,0 +1,1795 @@ +diff --git a/buffered.rs b/buffered.rs +index ee297d3..452b718 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -10,13 +10,13 @@ + + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use io::prelude::*; + +-use cmp; +-use error; +-use fmt; ++use core::cmp; ++use core::fmt; + use io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom}; +-use memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -52,7 +52,6 @@ use memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -75,7 +74,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -96,7 +94,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -129,7 +126,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -150,36 +146,8 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + +- /// Returns `true` if there are no bytes in the internal buffer. +- /// +- /// # Examples +- // +- /// ```no_run +- /// # #![feature(bufreader_is_empty)] +- /// use std::io::BufReader; +- /// use std::io::BufRead; +- /// use std::fs::File; +- /// +- /// fn main() -> std::io::Result<()> { +- /// let f1 = File::open("log.txt")?; +- /// let mut reader = BufReader::new(f1); +- /// assert!(reader.is_empty()); +- /// +- /// if reader.fill_buf()?.len() > 0 { +- /// assert!(!reader.is_empty()); +- /// } +- /// Ok(()) +- /// } +- /// ``` +- #[unstable(feature = "bufreader_is_empty", issue = "45323", reason = "recently added")] +- #[rustc_deprecated(since = "1.26.0", reason = "use .buffer().is_empty() instead")] +- pub fn is_empty(&self) -> bool { +- self.buffer().is_empty() +- } +- + /// Returns a reference to the internally buffered data. + /// + /// Unlike `fill_buf`, this will not attempt to fill the buffer if it is empty. +@@ -202,7 +170,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -225,7 +192,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + } + +@@ -234,7 +200,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -254,7 +219,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -277,7 +241,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -297,7 +260,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -307,7 +269,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -415,7 +376,6 @@ impl Seek for BufReader { + /// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -450,7 +410,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -464,7 +423,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -482,7 +440,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -531,7 +488,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -549,7 +505,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Unwraps this `BufWriter`, returning the underlying writer. +@@ -571,7 +526,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -580,7 +534,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -600,7 +553,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -610,7 +562,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -620,7 +571,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -659,7 +609,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -692,23 +641,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -766,7 +705,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -787,7 +725,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -808,7 +745,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -832,7 +768,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -855,7 +790,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -881,7 +815,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -892,7 +825,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -937,7 +869,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index 8ac5257..c65ed2a 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -10,7 +10,7 @@ + + use io::prelude::*; + +-use cmp; ++use core::cmp; + use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + + /// A `Cursor` wraps another type and provides it with a +@@ -78,7 +78,6 @@ use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -101,7 +100,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -119,7 +117,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -135,7 +132,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -154,7 +150,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -176,7 +171,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -196,11 +190,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -221,17 +213,16 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -242,12 +233,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -261,6 +256,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result Result { +@@ -271,12 +267,14 @@ fn try_into(n: u64) -> Result { + } + } + ++#[cfg(feature="collections")] + #[cfg(any(target_pointer_width = "64"))] + fn try_into(n: u64) -> Result { + Ok(n as usize) + } + + // Resizing write implementation ++#[cfg(feature="collections")] + fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result { + let pos: usize = try_into(*pos_mut).map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -303,7 +301,6 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result Write for Cursor<&'a mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -312,7 +309,7 @@ impl<'a> Write for Cursor<&'a mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl<'a> Write for Cursor<&'a mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) +@@ -320,7 +317,7 @@ impl<'a> Write for Cursor<&'a mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) +@@ -328,8 +325,8 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) +diff --git a/error.rs b/error.rs +index bdd675e..3acdadf 100644 +--- a/error.rs ++++ b/error.rs +@@ -8,11 +8,16 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use error; +-use fmt; +-use result; +-use sys; +-use convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -48,7 +53,6 @@ use convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -62,12 +66,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -77,13 +79,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -95,47 +100,34 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -147,10 +139,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -161,15 +151,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -178,15 +165,10 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + + /// A marker variant that tells the compiler that users of this enum cannot + /// match it exhaustively. +- #[unstable(feature = "io_error_internals", +- reason = "better expressed through extensible enums that this \ +- enum cannot be exhaustively matched against", +- issue = "0")] + #[doc(hidden)] + __Nonexhaustive, + } +@@ -219,7 +201,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + #[inline] + fn from(kind: ErrorKind) -> Error { +@@ -248,14 +229,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -264,24 +244,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -307,7 +269,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -338,7 +299,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -372,12 +332,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -443,12 +402,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -477,8 +435,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -504,10 +461,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -519,22 +475,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -542,24 +494,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- fn cause(&self) -> Option<&error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index fe1179a..452b8b7 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -8,15 +8,18 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use cmp; +-use io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind}; +-use fmt; +-use mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use io::BufRead; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, R: Read + ?Sized> Read for &'a mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -28,11 +31,13 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -43,7 +48,6 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, W: Write + ?Sized> Write for &'a mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -61,12 +65,11 @@ impl<'a, W: Write + ?Sized> Write for &'a mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, S: Seek + ?Sized> Seek for &'a mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -85,7 +88,7 @@ impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -97,11 +100,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -112,7 +117,7 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -130,12 +135,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -161,7 +166,6 @@ impl BufRead for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Read for &'a [u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -207,6 +211,7 @@ impl<'a> Read for &'a [u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -216,7 +221,7 @@ impl<'a> Read for &'a [u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a> BufRead for &'a [u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -230,7 +235,6 @@ impl<'a> BufRead for &'a [u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Write for &'a mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -256,7 +260,7 @@ impl<'a> Write for &'a mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +diff --git a/mod.rs b/mod.rs +index eba4e9f..0411b61 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -267,50 +267,36 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use cmp; +-use core::str as core_str; +-use error as std_error; +-use fmt; +-use result; +-use str; +-use memchr; +-use ptr; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::cmp; ++use core::fmt; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++use core::ptr; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl<'a> Drop for Guard<'a> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -335,6 +321,7 @@ impl<'a> Drop for Guard<'a> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -362,6 +349,7 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + let start_len = buf.len(); + let mut g = Guard { len: buf.len(), buf: buf }; +@@ -465,7 +453,6 @@ fn read_to_end(r: &mut R, buf: &mut Vec) -> Result + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -522,7 +509,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Determines if this `Read`er can work with buffers of uninitialized +@@ -547,7 +533,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -600,7 +585,7 @@ pub trait Read { + /// file.) + /// + /// [`std::fs::read`]: ../fs/fn.read.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -643,7 +628,7 @@ pub trait Read { + /// reading from a file.) + /// + /// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -706,7 +691,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -758,7 +742,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -795,58 +778,10 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } + +- /// Transforms this `Read` instance to an [`Iterator`] over [`char`]s. +- /// +- /// This adaptor will attempt to interpret this reader as a UTF-8 encoded +- /// sequence of characters. The returned iterator will return [`None`] once +- /// EOF is reached for this reader. Otherwise each element yielded will be a +- /// [`Result`]`<`[`char`]`, E>` where `E` may contain information about what I/O error +- /// occurred or where decoding failed. +- /// +- /// Currently this adaptor will discard intermediate data read, and should +- /// be avoided if this is not desired. +- /// +- /// # Examples +- /// +- /// [`File`]s implement `Read`: +- /// +- /// [`File`]: ../fs/struct.File.html +- /// [`Iterator`]: ../../std/iter/trait.Iterator.html +- /// [`Result`]: ../../std/result/enum.Result.html +- /// [`char`]: ../../std/primitive.char.html +- /// [`None`]: ../../std/option/enum.Option.html#variant.None +- /// +- /// ```no_run +- /// #![feature(io)] +- /// use std::io; +- /// use std::io::prelude::*; +- /// use std::fs::File; +- /// +- /// fn main() -> io::Result<()> { +- /// let mut f = File::open("foo.txt")?; +- /// +- /// for c in f.chars() { +- /// println!("{}", c.unwrap()); +- /// } +- /// Ok(()) +- /// } +- /// ``` +- #[unstable(feature = "io", reason = "the semantics of a partial read/write \ +- of where errors happen is currently \ +- unclear and may change", +- issue = "27802")] +- #[rustc_deprecated(since = "1.27.0", reason = "Use str::from_utf8 instead: +- https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples")] +- #[allow(deprecated)] +- fn chars(self) -> Chars where Self: Sized { +- Chars { inner: self } +- } +- + /// Creates an adaptor which will chain this stream with another. + /// + /// The returned `Read` instance will first read all bytes from this object +@@ -877,7 +812,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -913,20 +847,17 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -940,21 +871,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -997,7 +925,6 @@ impl Initializer { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this object, returning how many bytes were written. +@@ -1046,7 +973,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Flush this output stream, ensuring that all intermediately buffered +@@ -1072,7 +998,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this write. +@@ -1105,7 +1030,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1157,7 +1081,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1213,7 +1136,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1243,7 +1165,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1259,7 +1180,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + } + +@@ -1269,29 +1189,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Set the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Set the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Set the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1371,7 +1288,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Fills the internal buffer of this object, returning the buffer contents. + /// +@@ -1416,7 +1333,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1438,7 +1354,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1494,7 +1409,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1553,7 +1467,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1594,7 +1507,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1633,7 +1545,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1645,7 +1556,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1671,7 +1581,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1694,7 +1603,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1721,13 +1629,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1737,7 +1643,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1759,7 +1664,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1786,7 +1691,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -1821,7 +1725,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -1847,7 +1750,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "take_set_limit", since = "1.27.0")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -1872,7 +1774,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -1897,7 +1798,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -1926,13 +1826,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -1951,7 +1849,7 @@ impl Read for Take { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -1990,13 +1888,11 @@ fn read_one_byte(reader: &mut Read) -> Option> { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -2005,104 +1901,6 @@ impl Iterator for Bytes { + } + } + +-/// An iterator over the `char`s of a reader. +-/// +-/// This struct is generally created by calling [`chars`][chars] on a reader. +-/// Please see the documentation of `chars()` for more details. +-/// +-/// [chars]: trait.Read.html#method.chars +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] +-#[rustc_deprecated(since = "1.27.0", reason = "Use str::from_utf8 instead: +- https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples")] +-#[derive(Debug)] +-#[allow(deprecated)] +-pub struct Chars { +- inner: R, +-} +- +-/// An enumeration of possible errors that can be generated from the `Chars` +-/// adapter. +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] +-#[rustc_deprecated(since = "1.27.0", reason = "Use str::from_utf8 instead: +- https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples")] +-#[derive(Debug)] +-#[allow(deprecated)] +-pub enum CharsError { +- /// Variant representing that the underlying stream was read successfully +- /// but it did not contain valid utf8 data. +- NotUtf8, +- +- /// Variant representing that an I/O error occurred. +- Other(Error), +-} +- +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] +-#[allow(deprecated)] +-impl Iterator for Chars { +- type Item = result::Result; +- +- fn next(&mut self) -> Option> { +- let first_byte = match read_one_byte(&mut self.inner)? { +- Ok(b) => b, +- Err(e) => return Some(Err(CharsError::Other(e))), +- }; +- let width = core_str::utf8_char_width(first_byte); +- if width == 1 { return Some(Ok(first_byte as char)) } +- if width == 0 { return Some(Err(CharsError::NotUtf8)) } +- let mut buf = [first_byte, 0, 0, 0]; +- { +- let mut start = 1; +- while start < width { +- match self.inner.read(&mut buf[start..width]) { +- Ok(0) => return Some(Err(CharsError::NotUtf8)), +- Ok(n) => start += n, +- Err(ref e) if e.kind() == ErrorKind::Interrupted => continue, +- Err(e) => return Some(Err(CharsError::Other(e))), +- } +- } +- } +- Some(match str::from_utf8(&buf[..width]).ok() { +- Some(s) => Ok(s.chars().next().unwrap()), +- None => Err(CharsError::NotUtf8), +- }) +- } +-} +- +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] +-#[allow(deprecated)] +-impl std_error::Error for CharsError { +- fn description(&self) -> &str { +- match *self { +- CharsError::NotUtf8 => "invalid utf8 encoding", +- CharsError::Other(ref e) => std_error::Error::description(e), +- } +- } +- fn cause(&self) -> Option<&std_error::Error> { +- match *self { +- CharsError::NotUtf8 => None, +- CharsError::Other(ref e) => e.cause(), +- } +- } +-} +- +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] +-#[allow(deprecated)] +-impl fmt::Display for CharsError { +- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +- match *self { +- CharsError::NotUtf8 => { +- "byte stream did not contain valid utf8".fmt(f) +- } +- CharsError::Other(ref e) => e.fmt(f), +- } +- } +-} +- + /// An iterator over the contents of an instance of `BufRead` split on a + /// particular byte. + /// +@@ -2110,14 +1908,14 @@ impl fmt::Display for CharsError { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -2142,13 +1940,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 8772d0f..49d66c9 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -18,7 +18,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 195310a..20755b7 100644 +--- a/util.rs ++++ b/util.rs +@@ -10,9 +10,10 @@ + + #![allow(missing_copy_implementations)] + +-use fmt; +-use io::{self, Read, Initializer, Write, ErrorKind, BufRead}; +-use mem; ++use core::fmt; ++use io::{self, Read, Initializer, Write, ErrorKind}; ++use core::mem; ++#[cfg(feature="collections")] use io::BufRead; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -44,7 +45,6 @@ use mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -73,7 +73,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -93,10 +92,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -106,7 +103,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -114,7 +112,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -127,7 +124,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -144,10 +140,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte: byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -163,7 +157,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -176,7 +169,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -193,10 +185,8 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } +@@ -204,7 +194,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/b9adc3327ec7d2820ab2db8bb3cc2a0196a8375d.patch b/patches/b9adc3327ec7d2820ab2db8bb3cc2a0196a8375d.patch new file mode 100644 index 0000000..cb1f7d6 --- /dev/null +++ b/patches/b9adc3327ec7d2820ab2db8bb3cc2a0196a8375d.patch @@ -0,0 +1,1600 @@ +diff --git a/buffered.rs b/buffered.rs +index e26e6d3..c754cf1 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -10,13 +10,13 @@ + + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use io::prelude::*; + +-use cmp; +-use error; +-use fmt; ++use core::cmp; ++use core::fmt; + use io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom}; +-use memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -52,7 +52,6 @@ use memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -76,7 +75,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -97,7 +95,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -130,7 +127,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -151,7 +147,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + + /// Returns a reference to the internally buffered data. +@@ -176,7 +171,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -199,7 +193,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + } + +@@ -208,7 +201,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -228,7 +220,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -251,7 +242,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -271,7 +261,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -281,7 +270,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -387,7 +375,6 @@ impl Seek for BufReader { + /// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -422,7 +409,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -437,7 +423,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -455,7 +440,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -504,7 +488,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -522,7 +505,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Unwraps this `BufWriter`, returning the underlying writer. +@@ -544,7 +526,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -553,7 +534,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -573,7 +553,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -583,7 +562,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -593,7 +571,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -632,7 +609,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -665,23 +641,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -752,7 +718,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -773,7 +738,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -794,7 +758,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -818,7 +781,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -841,7 +803,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -867,7 +828,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -878,7 +838,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -923,7 +882,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index 14f2015..1d60dac 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -10,8 +10,8 @@ + + use io::prelude::*; + +-use core::convert::TryInto; +-use cmp; ++#[cfg(feature="collections")] use core::convert::TryInto; ++use core::cmp; + use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + + /// A `Cursor` wraps an in-memory buffer and provides it with a +@@ -80,7 +80,6 @@ use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -103,7 +102,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -121,7 +119,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -137,7 +134,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -156,7 +152,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -178,7 +173,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -198,11 +192,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -223,17 +215,16 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -244,12 +235,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -262,6 +257,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result, buf: &[u8]) -> io::Result { + let pos: usize = (*pos_mut).try_into().map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -288,7 +284,6 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result Write for Cursor<&'a mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -297,7 +292,7 @@ impl<'a> Write for Cursor<&'a mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl<'a> Write for Cursor<&'a mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) +@@ -305,7 +300,7 @@ impl<'a> Write for Cursor<&'a mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) +@@ -313,8 +308,8 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) +diff --git a/error.rs b/error.rs +index 386de08..4a9559a 100644 +--- a/error.rs ++++ b/error.rs +@@ -8,11 +8,16 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use error; +-use fmt; +-use result; +-use sys; +-use convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -48,7 +53,6 @@ use convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -62,12 +66,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -77,13 +79,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -95,48 +100,35 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + #[non_exhaustive] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -148,10 +140,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -162,15 +152,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -179,7 +166,6 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + } + +@@ -210,7 +196,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + /// Converts an [`ErrorKind`] into an [`Error`]. + /// +@@ -252,14 +237,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -268,24 +252,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -311,7 +277,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -342,7 +307,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -376,12 +340,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(dyn error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -447,12 +410,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -481,8 +443,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -508,10 +469,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -523,22 +483,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -546,24 +502,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- fn cause(&self) -> Option<&dyn error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index fe1179a..452b8b7 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -8,15 +8,18 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use cmp; +-use io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind}; +-use fmt; +-use mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use io::BufRead; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, R: Read + ?Sized> Read for &'a mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -28,11 +31,13 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -43,7 +48,6 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, W: Write + ?Sized> Write for &'a mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -61,12 +65,11 @@ impl<'a, W: Write + ?Sized> Write for &'a mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, S: Seek + ?Sized> Seek for &'a mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -85,7 +88,7 @@ impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -97,11 +100,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -112,7 +117,7 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -130,12 +135,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -161,7 +166,6 @@ impl BufRead for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Read for &'a [u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -207,6 +211,7 @@ impl<'a> Read for &'a [u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -216,7 +221,7 @@ impl<'a> Read for &'a [u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a> BufRead for &'a [u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -230,7 +235,6 @@ impl<'a> BufRead for &'a [u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Write for &'a mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -256,7 +260,7 @@ impl<'a> Write for &'a mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +diff --git a/mod.rs b/mod.rs +index e263db2..2176464 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -267,47 +267,36 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use cmp; +-use fmt; +-use str; +-use memchr; +-use ptr; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::cmp; ++use core::fmt; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++use core::ptr; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl<'a> Drop for Guard<'a> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -332,6 +321,7 @@ impl<'a> Drop for Guard<'a> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -359,10 +349,12 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + read_to_end_with_reservation(r, buf, 32) + } + ++#[cfg(feature="collections")] + fn read_to_end_with_reservation(r: &mut R, + buf: &mut Vec, + reservation_size: usize) -> Result +@@ -469,7 +461,6 @@ fn read_to_end_with_reservation(r: &mut R, + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -526,7 +517,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Determines if this `Read`er can work with buffers of uninitialized +@@ -551,7 +541,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -604,7 +593,7 @@ pub trait Read { + /// file.) + /// + /// [`std::fs::read`]: ../fs/fn.read.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -647,7 +636,7 @@ pub trait Read { + /// reading from a file.) + /// + /// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -710,7 +699,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -762,7 +750,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -799,7 +786,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } +@@ -834,7 +820,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -870,20 +855,17 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -897,21 +879,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -954,7 +933,6 @@ impl Initializer { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this object, returning how many bytes were written. +@@ -1003,7 +981,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Flush this output stream, ensuring that all intermediately buffered +@@ -1029,7 +1006,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this write. +@@ -1062,7 +1038,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1114,7 +1089,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1170,7 +1144,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1200,7 +1173,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1216,7 +1188,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + } + +@@ -1226,29 +1197,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Set the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Set the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Set the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1328,7 +1296,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Returns the contents of the internal buffer, filling it with more data + /// from the inner reader if it is empty. +@@ -1374,7 +1342,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1396,7 +1363,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1452,7 +1418,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1511,7 +1476,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1552,7 +1516,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1591,7 +1554,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1603,7 +1565,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1629,7 +1590,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1652,7 +1612,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1679,13 +1638,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1695,7 +1652,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1717,7 +1673,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1744,7 +1700,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -1779,7 +1734,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -1805,7 +1759,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "take_set_limit", since = "1.27.0")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -1830,7 +1783,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -1855,7 +1807,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -1884,13 +1835,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -1907,15 +1856,9 @@ impl Read for Take { + unsafe fn initializer(&self) -> Initializer { + self.inner.initializer() + } +- +- fn read_to_end(&mut self, buf: &mut Vec) -> Result { +- let reservation_size = cmp::min(self.limit, 32) as usize; +- +- read_to_end_with_reservation(self, buf, reservation_size) +- } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -1954,13 +1897,11 @@ fn read_one_byte(reader: &mut dyn Read) -> Option> { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -1976,14 +1917,14 @@ impl Iterator for Bytes { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -2008,13 +1949,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 8772d0f..49d66c9 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -18,7 +18,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 371e5b2..0d643e8 100644 +--- a/util.rs ++++ b/util.rs +@@ -10,9 +10,10 @@ + + #![allow(missing_copy_implementations)] + +-use fmt; +-use io::{self, Read, Initializer, Write, ErrorKind, BufRead}; +-use mem; ++use core::fmt; ++use io::{self, Read, Initializer, Write, ErrorKind}; ++use core::mem; ++#[cfg(feature="collections")] use io::BufRead; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -49,7 +50,6 @@ use mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -78,7 +78,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -98,10 +97,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -111,7 +108,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -119,7 +117,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -132,7 +129,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -149,10 +145,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte: byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -168,7 +162,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -181,7 +174,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -198,10 +190,8 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } +@@ -209,7 +199,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/c0e8cf94103289c424c62ca48e1e3f56e352a84a.patch b/patches/c0e8cf94103289c424c62ca48e1e3f56e352a84a.patch new file mode 100644 index 0000000..10c4dee --- /dev/null +++ b/patches/c0e8cf94103289c424c62ca48e1e3f56e352a84a.patch @@ -0,0 +1,1869 @@ +diff --git a/buffered.rs b/buffered.rs +index 559a54d..bd888d2 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -1,12 +1,12 @@ + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use crate::io::prelude::*; + +-use crate::cmp; +-use crate::error; +-use crate::fmt; ++use core::cmp; ++use core::fmt; + use crate::io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom, IoVec, IoVecMut}; +-use crate::memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -42,7 +42,6 @@ use crate::memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -66,7 +65,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -87,7 +85,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -120,7 +117,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -141,7 +137,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + + /// Returns a reference to the internally buffered data. +@@ -166,7 +161,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -189,7 +183,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + } + +@@ -198,7 +191,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -218,7 +210,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -254,7 +245,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -274,7 +264,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -284,7 +273,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -393,7 +381,6 @@ impl Seek for BufReader { + /// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -428,7 +415,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -443,7 +429,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -461,7 +446,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -510,7 +494,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -528,7 +511,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Returns a reference to the internally buffered data. +@@ -545,7 +527,6 @@ impl BufWriter { + /// // See how many bytes are currently buffered + /// let bytes_buffered = buf_writer.buffer().len(); + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf + } +@@ -569,7 +550,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -578,7 +558,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -614,7 +593,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -624,7 +602,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -634,7 +611,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -673,7 +649,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -706,23 +681,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -793,7 +758,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -814,7 +778,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -835,7 +798,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -859,7 +821,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -882,7 +843,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -908,7 +868,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -919,7 +878,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -964,7 +922,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index 873da08..3d39e57 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -1,9 +1,10 @@ + use crate::io::prelude::*; + +-use crate::cmp; +-use crate::io::{self, Initializer, SeekFrom, Error, ErrorKind, IoVec, IoVecMut}; ++use core::cmp; ++use crate::io::{self, Initializer, SeekFrom, Error, ErrorKind}; ++#[cfg(feature="collections")] use crate::io::{IoVec, IoVecMut}; + +-use core::convert::TryInto; ++#[cfg(feature="collections")] use core::convert::TryInto; + + /// A `Cursor` wraps an in-memory buffer and provides it with a + /// [`Seek`] implementation. +@@ -71,7 +72,6 @@ use core::convert::TryInto; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -94,7 +94,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -112,7 +111,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -128,7 +126,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -147,7 +144,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -169,7 +165,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -189,11 +184,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -214,14 +207,14 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + ++ #[cfg(feature="collections")] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let mut nread = 0; + for buf in bufs { +@@ -236,7 +229,7 @@ impl Read for Cursor where T: AsRef<[u8]> { + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -247,12 +240,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -264,6 +261,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result, buf: &[u8]) -> io::Result { + let pos: usize = (*pos_mut).try_into().map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -308,6 +307,7 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result, +@@ -321,13 +321,13 @@ fn vec_write_vectored( + Ok(nwritten) + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Cursor<&mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, self.inner, buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + slice_write_vectored(&mut self.pos, self.inner, bufs) +@@ -336,12 +336,13 @@ impl Write for Cursor<&mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl Write for Cursor<&mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) + } + ++ #[cfg(feature="collections")] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + vec_write_vectored(&mut self.pos, self.inner, bufs) + } +@@ -349,12 +350,13 @@ impl Write for Cursor<&mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) + } + ++ #[cfg(feature="collections")] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + vec_write_vectored(&mut self.pos, &mut self.inner, bufs) + } +@@ -362,13 +364,14 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + slice_write_vectored(&mut self.pos, &mut self.inner, bufs) +diff --git a/error.rs b/error.rs +index fdc5625..e4ce8b5 100644 +--- a/error.rs ++++ b/error.rs +@@ -1,8 +1,13 @@ +-use crate::error; +-use crate::fmt; +-use crate::result; +-use crate::sys; +-use crate::convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -38,7 +43,6 @@ use crate::convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -52,12 +56,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -67,13 +69,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -85,48 +90,35 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + #[non_exhaustive] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -138,10 +130,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -152,15 +142,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -169,7 +156,6 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + } + +@@ -200,7 +186,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + /// Converts an [`ErrorKind`] into an [`Error`]. + /// +@@ -245,14 +230,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -261,24 +245,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -304,7 +270,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -335,7 +300,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -369,12 +333,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(dyn error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -440,12 +403,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -474,8 +436,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -501,10 +462,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -516,22 +476,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -539,25 +495,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- #[allow(deprecated)] +- fn cause(&self) -> Option<&dyn error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index b286e40..7472d9c 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -1,19 +1,22 @@ +-use crate::cmp; +-use crate::io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind, IoVecMut, +- IoVec}; +-use crate::fmt; +-use crate::mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use crate::io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use crate::io::{BufRead, IoVecMut, IoVec}; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for &mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { + (**self).read(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + (**self).read_vectored(bufs) +@@ -24,11 +27,13 @@ impl Read for &mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -39,11 +44,11 @@ impl Read for &mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for &mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + (**self).write_vectored(bufs) +@@ -62,12 +67,11 @@ impl Write for &mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for &mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for &mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -86,13 +90,14 @@ impl BufRead for &mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { + (**self).read(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + (**self).read_vectored(bufs) +@@ -103,11 +108,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -118,11 +125,12 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + (**self).write_vectored(bufs) +@@ -141,12 +149,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -186,7 +194,6 @@ impl Write for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for &[u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -206,6 +213,7 @@ impl Read for &[u8] { + Ok(amt) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let mut nread = 0; +@@ -245,6 +253,7 @@ impl Read for &[u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -254,7 +263,7 @@ impl Read for &[u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for &[u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -268,7 +277,6 @@ impl BufRead for &[u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for &mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -279,6 +287,7 @@ impl Write for &mut [u8] { + Ok(amt) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + let mut nwritten = 0; +@@ -307,7 +316,7 @@ impl Write for &mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -315,6 +324,7 @@ impl Write for Vec { + Ok(buf.len()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + let len = bufs.iter().map(|b| b.len()).sum(); +diff --git a/mod.rs b/mod.rs +index e3e2754..400eca6 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -257,50 +257,38 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use crate::cmp; +-use crate::fmt; +-use crate::slice; +-use crate::str; +-use crate::memchr; +-use crate::ops::{Deref, DerefMut}; +-use crate::ptr; +-use crate::sys; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::cmp; ++use core::fmt; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++#[cfg(feature="collections")] use core::ops::{Deref, DerefMut}; ++use core::ptr; ++use core::slice; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = crate::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl Drop for Guard<'_> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -325,6 +313,7 @@ impl Drop for Guard<'_> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -352,10 +341,12 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + read_to_end_with_reservation(r, buf, 32) + } + ++#[cfg(feature="collections")] + fn read_to_end_with_reservation(r: &mut R, + buf: &mut Vec, + reservation_size: usize) -> Result +@@ -462,7 +453,6 @@ fn read_to_end_with_reservation(r: &mut R, + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -519,7 +509,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Like `read`, except that it reads into a slice of buffers. +@@ -530,7 +519,7 @@ pub trait Read { + /// + /// The default implementation simply passes the first nonempty buffer to + /// `read`. +- #[unstable(feature = "iovec", issue = "58452")] ++ #[cfg(feature="collections")] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> Result { + match bufs.iter_mut().find(|b| !b.is_empty()) { + Some(buf) => self.read(buf), +@@ -560,7 +549,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -613,7 +601,7 @@ pub trait Read { + /// file.) + /// + /// [`std::fs::read`]: ../fs/fn.read.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -656,7 +644,7 @@ pub trait Read { + /// reading from a file.) + /// + /// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -719,7 +707,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -771,7 +758,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -808,7 +794,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } +@@ -843,7 +828,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -879,42 +863,77 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + ++#[cfg(feature="collections")] ++pub struct IoVecBuffer<'a>(&'a [u8]); ++ ++#[cfg(feature="collections")] ++impl<'a> IoVecBuffer<'a> { ++ #[inline] ++ pub fn new(buf: &'a [u8]) -> IoVecBuffer<'a> { ++ IoVecBuffer(buf) ++ } ++ ++ #[inline] ++ pub fn as_slice(&self) -> &[u8] { ++ self.0 ++ } ++} ++#[cfg(feature="collections")] ++pub struct IoVecMutBuffer<'a>(&'a mut [u8]); ++ ++#[cfg(feature="collections")] ++impl<'a> IoVecMutBuffer<'a> { ++ #[inline] ++ pub fn new(buf: &'a mut [u8]) -> IoVecMutBuffer<'a> { ++ IoVecMutBuffer(buf) ++ } ++ ++ #[inline] ++ pub fn as_slice(&self) -> &[u8] { ++ self.0 ++ } ++ ++ #[inline] ++ pub fn as_mut_slice(&mut self) -> &mut [u8] { ++ self.0 ++ } ++} ++ + /// A buffer type used with `Read::read_vectored`. + /// + /// It is semantically a wrapper around an `&mut [u8]`, but is guaranteed to be + /// ABI compatible with the `iovec` type on Unix platforms and `WSABUF` on + /// Windows. +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + #[repr(transparent)] +-pub struct IoVecMut<'a>(sys::io::IoVecMut<'a>); ++pub struct IoVecMut<'a>(IoVecMutBuffer<'a>); + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> fmt::Debug for IoVecMut<'a> { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(self.0.as_slice(), fmt) + } + } + ++#[cfg(feature="collections")] + impl<'a> IoVecMut<'a> { + /// Creates a new `IoVecMut` wrapping a byte slice. + /// + /// # Panics + /// + /// Panics on Windows if the slice is larger than 4GB. +- #[unstable(feature = "iovec", issue = "58452")] + #[inline] + pub fn new(buf: &'a mut [u8]) -> IoVecMut<'a> { +- IoVecMut(sys::io::IoVecMut::new(buf)) ++ IoVecMut(IoVecMutBuffer::new(buf)) + } + } + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> Deref for IoVecMut<'a> { + type Target = [u8]; + +@@ -924,7 +943,7 @@ impl<'a> Deref for IoVecMut<'a> { + } + } + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> DerefMut for IoVecMut<'a> { + #[inline] + fn deref_mut(&mut self) -> &mut [u8] { +@@ -937,31 +956,31 @@ impl<'a> DerefMut for IoVecMut<'a> { + /// It is semantically a wrapper around an `&[u8]`, but is guaranteed to be + /// ABI compatible with the `iovec` type on Unix platforms and `WSABUF` on + /// Windows. +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + #[repr(transparent)] +-pub struct IoVec<'a>(sys::io::IoVec<'a>); ++pub struct IoVec<'a>(IoVecBuffer<'a>); + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> fmt::Debug for IoVec<'a> { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(self.0.as_slice(), fmt) + } + } + ++#[cfg(feature="collections")] + impl<'a> IoVec<'a> { + /// Creates a new `IoVec` wrapping a byte slice. + /// + /// # Panics + /// + /// Panics on Windows if the slice is larger than 4GB. +- #[unstable(feature = "iovec", issue = "58452")] + #[inline] + pub fn new(buf: &'a [u8]) -> IoVec<'a> { +- IoVec(sys::io::IoVec::new(buf)) ++ IoVec(IoVecBuffer::new(buf)) + } + } + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> Deref for IoVec<'a> { + type Target = [u8]; + +@@ -972,13 +991,11 @@ impl<'a> Deref for IoVec<'a> { + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -992,21 +1009,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -1049,7 +1063,6 @@ impl Initializer { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this writer, returning how many bytes were written. +@@ -1098,7 +1111,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Like `write`, except that it writes from a slice of buffers. +@@ -1109,7 +1121,7 @@ pub trait Write { + /// + /// The default implementation simply passes the first nonempty buffer to + /// `write`. +- #[unstable(feature = "iovec", issue = "58452")] ++ #[cfg(feature="collections")] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> Result { + match bufs.iter().find(|b| !b.is_empty()) { + Some(buf) => self.write(buf), +@@ -1140,7 +1152,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this writer. +@@ -1173,7 +1184,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1225,7 +1235,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1281,7 +1290,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1311,7 +1319,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1327,7 +1334,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + } + +@@ -1337,29 +1343,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Sets the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Sets the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Sets the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1439,7 +1442,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Returns the contents of the internal buffer, filling it with more data + /// from the inner reader if it is empty. +@@ -1485,7 +1488,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1507,7 +1509,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1563,7 +1564,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1622,7 +1622,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1663,7 +1662,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1702,7 +1700,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1714,7 +1711,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1740,7 +1736,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1763,7 +1758,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1790,13 +1784,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1806,7 +1798,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1818,6 +1809,7 @@ impl Read for Chain { + self.second.read(buf) + } + ++ #[cfg(feature="collections")] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> Result { + if !self.done_first { + match self.first.read_vectored(bufs)? { +@@ -1838,7 +1830,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1865,7 +1857,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -1900,7 +1891,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -1926,7 +1916,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "take_set_limit", since = "1.27.0")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -1951,7 +1940,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -1976,7 +1964,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -2005,13 +1992,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -2028,15 +2013,9 @@ impl Read for Take { + unsafe fn initializer(&self) -> Initializer { + self.inner.initializer() + } +- +- fn read_to_end(&mut self, buf: &mut Vec) -> Result { +- let reservation_size = cmp::min(self.limit, 32) as usize; +- +- read_to_end_with_reservation(self, buf, reservation_size) +- } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -2063,13 +2042,11 @@ impl BufRead for Take { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -2093,14 +2070,14 @@ impl Iterator for Bytes { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -2125,13 +2102,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 2e19edf..66294a3 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -8,7 +8,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 6aaf8f1..447ce47 100644 +--- a/util.rs ++++ b/util.rs +@@ -1,8 +1,9 @@ + #![allow(missing_copy_implementations)] + +-use crate::fmt; +-use crate::io::{self, Read, Initializer, Write, ErrorKind, BufRead, IoVec, IoVecMut}; +-use crate::mem; ++use core::fmt; ++use crate::io::{self, Read, Initializer, Write, ErrorKind}; ++#[cfg(feature="collections")] use crate::io::{BufRead, IoVec, IoVecMut}; ++use core::mem; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -39,7 +40,6 @@ use crate::mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -68,7 +68,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -88,10 +87,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -101,7 +98,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -109,7 +107,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -122,7 +119,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -139,10 +135,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -152,6 +146,7 @@ impl Read for Repeat { + Ok(buf.len()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let mut nwritten = 0; +@@ -167,7 +162,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -180,7 +174,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -197,14 +190,13 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + let total_len = bufs.iter().map(|b| b.len()).sum(); +@@ -215,7 +207,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/c12a75742485dcc3db7b0f374e78f090c323830d.patch b/patches/c12a75742485dcc3db7b0f374e78f090c323830d.patch new file mode 100644 index 0000000..25c0671 --- /dev/null +++ b/patches/c12a75742485dcc3db7b0f374e78f090c323830d.patch @@ -0,0 +1,1782 @@ +diff --git a/buffered.rs b/buffered.rs +index 1895696..848290e 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -10,13 +10,13 @@ + + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use io::prelude::*; + +-use cmp; +-use error; +-use fmt; ++use core::cmp; ++use core::fmt; + use io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom}; +-use memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -52,7 +52,6 @@ use memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -75,7 +74,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -96,7 +94,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -129,7 +126,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -150,36 +146,8 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + +- /// Returns `true` if there are no bytes in the internal buffer. +- /// +- /// # Examples +- // +- /// ```no_run +- /// # #![feature(bufreader_is_empty)] +- /// use std::io::BufReader; +- /// use std::io::BufRead; +- /// use std::fs::File; +- /// +- /// fn main() -> std::io::Result<()> { +- /// let f1 = File::open("log.txt")?; +- /// let mut reader = BufReader::new(f1); +- /// assert!(reader.is_empty()); +- /// +- /// if reader.fill_buf()?.len() > 0 { +- /// assert!(!reader.is_empty()); +- /// } +- /// Ok(()) +- /// } +- /// ``` +- #[unstable(feature = "bufreader_is_empty", issue = "45323", reason = "recently added")] +- #[rustc_deprecated(since = "1.26.0", reason = "use .buffer().is_empty() instead")] +- pub fn is_empty(&self) -> bool { +- self.buffer().is_empty() +- } +- + /// Returns a reference to the internally buffered data. + /// + /// Unlike `fill_buf`, this will not attempt to fill the buffer if it is empty. +@@ -202,7 +170,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -225,7 +192,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + } + +@@ -234,7 +200,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -254,7 +219,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -277,7 +241,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -297,7 +260,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -307,7 +269,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -415,7 +376,6 @@ impl Seek for BufReader { + /// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -450,7 +410,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -464,7 +423,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -482,7 +440,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -531,7 +488,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -549,7 +505,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Unwraps this `BufWriter`, returning the underlying writer. +@@ -571,7 +526,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -580,7 +534,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -600,7 +553,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -610,7 +562,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -620,7 +571,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -659,7 +609,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -692,23 +641,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -779,7 +718,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -800,7 +738,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -821,7 +758,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -845,7 +781,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -868,7 +803,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -894,7 +828,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -905,7 +838,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -950,7 +882,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index aadd33b..cd6ae13 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -10,8 +10,8 @@ + + use io::prelude::*; + +-use core::convert::TryInto; +-use cmp; ++#[cfg(feature="collections")] use core::convert::TryInto; ++use core::cmp; + use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + + /// A `Cursor` wraps another type and provides it with a +@@ -79,7 +79,6 @@ use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -102,7 +101,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -120,7 +118,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -136,7 +133,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -155,7 +151,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -177,7 +172,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -197,11 +191,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -222,17 +214,16 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -243,12 +234,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -261,6 +256,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result, buf: &[u8]) -> io::Result { + let pos: usize = (*pos_mut).try_into().map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -287,7 +283,6 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result Write for Cursor<&'a mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -296,7 +291,7 @@ impl<'a> Write for Cursor<&'a mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl<'a> Write for Cursor<&'a mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) +@@ -304,7 +299,7 @@ impl<'a> Write for Cursor<&'a mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) +@@ -312,8 +307,8 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) +diff --git a/error.rs b/error.rs +index bdd675e..3acdadf 100644 +--- a/error.rs ++++ b/error.rs +@@ -8,11 +8,16 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use error; +-use fmt; +-use result; +-use sys; +-use convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -48,7 +53,6 @@ use convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -62,12 +66,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -77,13 +79,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -95,47 +100,34 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -147,10 +139,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -161,15 +151,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -178,15 +165,10 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + + /// A marker variant that tells the compiler that users of this enum cannot + /// match it exhaustively. +- #[unstable(feature = "io_error_internals", +- reason = "better expressed through extensible enums that this \ +- enum cannot be exhaustively matched against", +- issue = "0")] + #[doc(hidden)] + __Nonexhaustive, + } +@@ -219,7 +201,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + #[inline] + fn from(kind: ErrorKind) -> Error { +@@ -248,14 +229,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -264,24 +244,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -307,7 +269,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -338,7 +299,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -372,12 +332,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -443,12 +402,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -477,8 +435,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -504,10 +461,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -519,22 +475,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -542,24 +494,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- fn cause(&self) -> Option<&error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index fe1179a..452b8b7 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -8,15 +8,18 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use cmp; +-use io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind}; +-use fmt; +-use mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use io::BufRead; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, R: Read + ?Sized> Read for &'a mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -28,11 +31,13 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -43,7 +48,6 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, W: Write + ?Sized> Write for &'a mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -61,12 +65,11 @@ impl<'a, W: Write + ?Sized> Write for &'a mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, S: Seek + ?Sized> Seek for &'a mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -85,7 +88,7 @@ impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -97,11 +100,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -112,7 +117,7 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -130,12 +135,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -161,7 +166,6 @@ impl BufRead for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Read for &'a [u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -207,6 +211,7 @@ impl<'a> Read for &'a [u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -216,7 +221,7 @@ impl<'a> Read for &'a [u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a> BufRead for &'a [u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -230,7 +235,6 @@ impl<'a> BufRead for &'a [u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Write for &'a mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -256,7 +260,7 @@ impl<'a> Write for &'a mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +diff --git a/mod.rs b/mod.rs +index 2b4644b..fbdb8e6 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -267,50 +267,36 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use cmp; +-use core::str as core_str; +-use error as std_error; +-use fmt; +-use result; +-use str; +-use memchr; +-use ptr; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::cmp; ++use core::fmt; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++use core::ptr; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl<'a> Drop for Guard<'a> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -335,6 +321,7 @@ impl<'a> Drop for Guard<'a> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -362,6 +349,7 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + let start_len = buf.len(); + let mut g = Guard { len: buf.len(), buf: buf }; +@@ -465,7 +453,6 @@ fn read_to_end(r: &mut R, buf: &mut Vec) -> Result + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -522,7 +509,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Determines if this `Read`er can work with buffers of uninitialized +@@ -547,7 +533,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -600,7 +585,7 @@ pub trait Read { + /// file.) + /// + /// [`std::fs::read`]: ../fs/fn.read.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -643,7 +628,7 @@ pub trait Read { + /// reading from a file.) + /// + /// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -706,7 +691,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -758,7 +742,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -795,58 +778,10 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } + +- /// Transforms this `Read` instance to an [`Iterator`] over [`char`]s. +- /// +- /// This adaptor will attempt to interpret this reader as a UTF-8 encoded +- /// sequence of characters. The returned iterator will return [`None`] once +- /// EOF is reached for this reader. Otherwise each element yielded will be a +- /// [`Result`]`<`[`char`]`, E>` where `E` may contain information about what I/O error +- /// occurred or where decoding failed. +- /// +- /// Currently this adaptor will discard intermediate data read, and should +- /// be avoided if this is not desired. +- /// +- /// # Examples +- /// +- /// [`File`]s implement `Read`: +- /// +- /// [`File`]: ../fs/struct.File.html +- /// [`Iterator`]: ../../std/iter/trait.Iterator.html +- /// [`Result`]: ../../std/result/enum.Result.html +- /// [`char`]: ../../std/primitive.char.html +- /// [`None`]: ../../std/option/enum.Option.html#variant.None +- /// +- /// ```no_run +- /// #![feature(io)] +- /// use std::io; +- /// use std::io::prelude::*; +- /// use std::fs::File; +- /// +- /// fn main() -> io::Result<()> { +- /// let mut f = File::open("foo.txt")?; +- /// +- /// for c in f.chars() { +- /// println!("{}", c.unwrap()); +- /// } +- /// Ok(()) +- /// } +- /// ``` +- #[unstable(feature = "io", reason = "the semantics of a partial read/write \ +- of where errors happen is currently \ +- unclear and may change", +- issue = "27802")] +- #[rustc_deprecated(since = "1.27.0", reason = "Use str::from_utf8 instead: +- https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples")] +- #[allow(deprecated)] +- fn chars(self) -> Chars where Self: Sized { +- Chars { inner: self } +- } +- + /// Creates an adaptor which will chain this stream with another. + /// + /// The returned `Read` instance will first read all bytes from this object +@@ -877,7 +812,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -913,20 +847,17 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -940,21 +871,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -997,7 +925,6 @@ impl Initializer { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this object, returning how many bytes were written. +@@ -1046,7 +973,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Flush this output stream, ensuring that all intermediately buffered +@@ -1072,7 +998,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this write. +@@ -1105,7 +1030,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1157,7 +1081,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1213,7 +1136,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1243,7 +1165,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1259,7 +1180,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + } + +@@ -1269,29 +1189,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Set the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Set the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Set the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1371,7 +1288,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Fills the internal buffer of this object, returning the buffer contents. + /// +@@ -1416,7 +1333,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1438,7 +1354,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1494,7 +1409,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1553,7 +1467,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1594,7 +1507,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1633,7 +1545,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1645,7 +1556,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1671,7 +1581,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1694,7 +1603,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1721,13 +1629,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1737,7 +1643,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1759,7 +1664,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1786,7 +1691,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -1821,7 +1725,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -1847,7 +1750,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "take_set_limit", since = "1.27.0")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -1872,7 +1774,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -1897,7 +1798,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -1926,13 +1826,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -1951,7 +1849,7 @@ impl Read for Take { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -1990,13 +1888,11 @@ fn read_one_byte(reader: &mut Read) -> Option> { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -2005,104 +1901,6 @@ impl Iterator for Bytes { + } + } + +-/// An iterator over the `char`s of a reader. +-/// +-/// This struct is generally created by calling [`chars`][chars] on a reader. +-/// Please see the documentation of `chars()` for more details. +-/// +-/// [chars]: trait.Read.html#method.chars +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] +-#[rustc_deprecated(since = "1.27.0", reason = "Use str::from_utf8 instead: +- https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples")] +-#[derive(Debug)] +-#[allow(deprecated)] +-pub struct Chars { +- inner: R, +-} +- +-/// An enumeration of possible errors that can be generated from the `Chars` +-/// adapter. +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] +-#[rustc_deprecated(since = "1.27.0", reason = "Use str::from_utf8 instead: +- https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples")] +-#[derive(Debug)] +-#[allow(deprecated)] +-pub enum CharsError { +- /// Variant representing that the underlying stream was read successfully +- /// but it did not contain valid utf8 data. +- NotUtf8, +- +- /// Variant representing that an I/O error occurred. +- Other(Error), +-} +- +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] +-#[allow(deprecated)] +-impl Iterator for Chars { +- type Item = result::Result; +- +- fn next(&mut self) -> Option> { +- let first_byte = match read_one_byte(&mut self.inner)? { +- Ok(b) => b, +- Err(e) => return Some(Err(CharsError::Other(e))), +- }; +- let width = core_str::utf8_char_width(first_byte); +- if width == 1 { return Some(Ok(first_byte as char)) } +- if width == 0 { return Some(Err(CharsError::NotUtf8)) } +- let mut buf = [first_byte, 0, 0, 0]; +- { +- let mut start = 1; +- while start < width { +- match self.inner.read(&mut buf[start..width]) { +- Ok(0) => return Some(Err(CharsError::NotUtf8)), +- Ok(n) => start += n, +- Err(ref e) if e.kind() == ErrorKind::Interrupted => continue, +- Err(e) => return Some(Err(CharsError::Other(e))), +- } +- } +- } +- Some(match str::from_utf8(&buf[..width]).ok() { +- Some(s) => Ok(s.chars().next().unwrap()), +- None => Err(CharsError::NotUtf8), +- }) +- } +-} +- +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] +-#[allow(deprecated)] +-impl std_error::Error for CharsError { +- fn description(&self) -> &str { +- match *self { +- CharsError::NotUtf8 => "invalid utf8 encoding", +- CharsError::Other(ref e) => std_error::Error::description(e), +- } +- } +- fn cause(&self) -> Option<&std_error::Error> { +- match *self { +- CharsError::NotUtf8 => None, +- CharsError::Other(ref e) => e.cause(), +- } +- } +-} +- +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] +-#[allow(deprecated)] +-impl fmt::Display for CharsError { +- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +- match *self { +- CharsError::NotUtf8 => { +- "byte stream did not contain valid utf8".fmt(f) +- } +- CharsError::Other(ref e) => e.fmt(f), +- } +- } +-} +- + /// An iterator over the contents of an instance of `BufRead` split on a + /// particular byte. + /// +@@ -2110,14 +1908,14 @@ impl fmt::Display for CharsError { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -2142,13 +1940,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 8772d0f..49d66c9 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -18,7 +18,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 195310a..20755b7 100644 +--- a/util.rs ++++ b/util.rs +@@ -10,9 +10,10 @@ + + #![allow(missing_copy_implementations)] + +-use fmt; +-use io::{self, Read, Initializer, Write, ErrorKind, BufRead}; +-use mem; ++use core::fmt; ++use io::{self, Read, Initializer, Write, ErrorKind}; ++use core::mem; ++#[cfg(feature="collections")] use io::BufRead; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -44,7 +45,6 @@ use mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -73,7 +73,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -93,10 +92,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -106,7 +103,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -114,7 +112,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -127,7 +124,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -144,10 +140,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte: byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -163,7 +157,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -176,7 +169,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -193,10 +185,8 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } +@@ -204,7 +194,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/c97d3d4dd174e8a80e9d0e55ea6f9a73aca60bf2.patch b/patches/c97d3d4dd174e8a80e9d0e55ea6f9a73aca60bf2.patch new file mode 100644 index 0000000..17ddb2f --- /dev/null +++ b/patches/c97d3d4dd174e8a80e9d0e55ea6f9a73aca60bf2.patch @@ -0,0 +1,1909 @@ +diff --git a/buffered.rs b/buffered.rs +index 4668e3e..4c125bd 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -1,12 +1,12 @@ + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use crate::io::prelude::*; + +-use crate::cmp; +-use crate::error; +-use crate::fmt; ++use core::cmp; ++use core::fmt; + use crate::io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom, IoVec, IoVecMut}; +-use crate::memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -42,7 +42,6 @@ use crate::memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -66,7 +65,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -87,7 +85,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -122,7 +119,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -143,7 +139,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + + /// Returns a reference to the internally buffered data. +@@ -168,7 +163,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -191,7 +185,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + + /// Invalidates all data in the internal buffer. +@@ -207,7 +200,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -227,7 +219,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -265,7 +256,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -285,7 +275,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -295,7 +284,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -404,7 +392,6 @@ impl Seek for BufReader { + /// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -439,7 +426,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -454,7 +440,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -472,7 +457,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -521,7 +505,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -539,7 +522,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Returns a reference to the internally buffered data. +@@ -556,7 +538,6 @@ impl BufWriter { + /// // See how many bytes are currently buffered + /// let bytes_buffered = buf_writer.buffer().len(); + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf + } +@@ -580,7 +561,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -589,7 +569,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -625,7 +604,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -635,7 +613,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -645,7 +622,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -684,7 +660,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -717,23 +692,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -804,7 +769,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -825,7 +789,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -846,7 +809,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -870,7 +832,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -893,7 +854,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -919,7 +879,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -930,7 +889,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -975,7 +933,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index 247d45c..f13522d 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -1,9 +1,10 @@ + use crate::io::prelude::*; + +-use crate::cmp; +-use crate::io::{self, Initializer, SeekFrom, Error, ErrorKind, IoVec, IoVecMut}; ++use core::cmp; ++use crate::io::{self, Initializer, SeekFrom, Error, ErrorKind}; ++#[cfg(feature="collections")] use crate::io::{IoVec, IoVecMut}; + +-use core::convert::TryInto; ++#[cfg(feature="collections")] use core::convert::TryInto; + + /// A `Cursor` wraps an in-memory buffer and provides it with a + /// [`Seek`] implementation. +@@ -71,7 +72,6 @@ use core::convert::TryInto; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -94,7 +94,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -112,7 +111,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -128,7 +126,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -147,7 +144,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -169,7 +165,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -189,11 +184,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -222,14 +215,14 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + ++ #[cfg(feature="collections")] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let mut nread = 0; + for buf in bufs { +@@ -244,7 +237,7 @@ impl Read for Cursor where T: AsRef<[u8]> { + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -255,12 +248,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -272,6 +269,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result, buf: &[u8]) -> io::Result { + let pos: usize = (*pos_mut).try_into().map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -316,6 +315,7 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result, +@@ -329,13 +329,13 @@ fn vec_write_vectored( + Ok(nwritten) + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Cursor<&mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, self.inner, buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + slice_write_vectored(&mut self.pos, self.inner, bufs) +@@ -344,12 +344,13 @@ impl Write for Cursor<&mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl Write for Cursor<&mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) + } + ++ #[cfg(feature="collections")] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + vec_write_vectored(&mut self.pos, self.inner, bufs) + } +@@ -357,12 +358,13 @@ impl Write for Cursor<&mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) + } + ++ #[cfg(feature="collections")] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + vec_write_vectored(&mut self.pos, &mut self.inner, bufs) + } +@@ -370,13 +372,14 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + slice_write_vectored(&mut self.pos, &mut self.inner, bufs) +diff --git a/error.rs b/error.rs +index 614b791..e4ce8b5 100644 +--- a/error.rs ++++ b/error.rs +@@ -1,8 +1,13 @@ +-use crate::error; +-use crate::fmt; +-use crate::result; +-use crate::sys; +-use crate::convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -38,7 +43,6 @@ use crate::convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -52,12 +56,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -67,13 +69,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -85,48 +90,35 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + #[non_exhaustive] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -138,10 +130,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -152,15 +142,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -169,7 +156,6 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + } + +@@ -200,7 +186,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + /// Converts an [`ErrorKind`] into an [`Error`]. + /// +@@ -245,14 +230,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -261,24 +245,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -304,7 +270,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -335,7 +300,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -369,12 +333,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(dyn error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -440,12 +403,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -474,8 +436,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -501,10 +462,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -516,22 +476,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -539,33 +495,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- #[allow(deprecated)] +- fn cause(&self) -> Option<&dyn error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +- +- fn source(&self) -> Option<&(dyn error::Error + 'static)> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.source(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index b286e40..7472d9c 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -1,19 +1,22 @@ +-use crate::cmp; +-use crate::io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind, IoVecMut, +- IoVec}; +-use crate::fmt; +-use crate::mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use crate::io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use crate::io::{BufRead, IoVecMut, IoVec}; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for &mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { + (**self).read(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + (**self).read_vectored(bufs) +@@ -24,11 +27,13 @@ impl Read for &mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -39,11 +44,11 @@ impl Read for &mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for &mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + (**self).write_vectored(bufs) +@@ -62,12 +67,11 @@ impl Write for &mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for &mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for &mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -86,13 +90,14 @@ impl BufRead for &mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { + (**self).read(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + (**self).read_vectored(bufs) +@@ -103,11 +108,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -118,11 +125,12 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + (**self).write_vectored(bufs) +@@ -141,12 +149,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -186,7 +194,6 @@ impl Write for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for &[u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -206,6 +213,7 @@ impl Read for &[u8] { + Ok(amt) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let mut nread = 0; +@@ -245,6 +253,7 @@ impl Read for &[u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -254,7 +263,7 @@ impl Read for &[u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for &[u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -268,7 +277,6 @@ impl BufRead for &[u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for &mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -279,6 +287,7 @@ impl Write for &mut [u8] { + Ok(amt) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + let mut nwritten = 0; +@@ -307,7 +316,7 @@ impl Write for &mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -315,6 +324,7 @@ impl Write for Vec { + Ok(buf.len()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + let len = bufs.iter().map(|b| b.len()).sum(); +diff --git a/mod.rs b/mod.rs +index 7147b64..2059b5a 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -257,50 +257,38 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use crate::cmp; +-use crate::fmt; +-use crate::slice; +-use crate::str; +-use crate::memchr; +-use crate::ops::{Deref, DerefMut}; +-use crate::ptr; +-use crate::sys; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::cmp; ++use core::fmt; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++#[cfg(feature="collections")] use core::ops::{Deref, DerefMut}; ++use core::ptr; ++use core::slice; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = crate::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl Drop for Guard<'_> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -325,6 +313,7 @@ impl Drop for Guard<'_> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -352,10 +341,12 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + read_to_end_with_reservation(r, buf, 32) + } + ++#[cfg(feature="collections")] + fn read_to_end_with_reservation(r: &mut R, + buf: &mut Vec, + reservation_size: usize) -> Result +@@ -390,6 +381,7 @@ fn read_to_end_with_reservation(r: &mut R, + ret + } + ++#[cfg(feature="collections")] + pub(crate) fn default_read_vectored(read: F, bufs: &mut [IoVecMut<'_>]) -> Result + where + F: FnOnce(&mut [u8]) -> Result +@@ -401,6 +393,7 @@ where + read(buf) + } + ++#[cfg(feature="collections")] + pub(crate) fn default_write_vectored(write: F, bufs: &[IoVec<'_>]) -> Result + where + F: FnOnce(&[u8]) -> Result +@@ -484,7 +477,6 @@ where + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -541,7 +533,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Like `read`, except that it reads into a slice of buffers. +@@ -552,7 +543,7 @@ pub trait Read { + /// + /// The default implementation calls `read` with either the first nonempty + /// buffer provided, or an empty one if none exists. +- #[unstable(feature = "iovec", issue = "58452")] ++ #[cfg(feature="collections")] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> Result { + default_read_vectored(|b| self.read(b), bufs) + } +@@ -579,7 +570,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -632,7 +622,7 @@ pub trait Read { + /// file.) + /// + /// [`std::fs::read`]: ../fs/fn.read.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -675,7 +665,7 @@ pub trait Read { + /// reading from a file.) + /// + /// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -738,7 +728,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -790,7 +779,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -827,7 +815,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } +@@ -862,7 +849,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -898,42 +884,77 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + ++#[cfg(feature="collections")] ++pub struct IoVecBuffer<'a>(&'a [u8]); ++ ++#[cfg(feature="collections")] ++impl<'a> IoVecBuffer<'a> { ++ #[inline] ++ pub fn new(buf: &'a [u8]) -> IoVecBuffer<'a> { ++ IoVecBuffer(buf) ++ } ++ ++ #[inline] ++ pub fn as_slice(&self) -> &[u8] { ++ self.0 ++ } ++} ++#[cfg(feature="collections")] ++pub struct IoVecMutBuffer<'a>(&'a mut [u8]); ++ ++#[cfg(feature="collections")] ++impl<'a> IoVecMutBuffer<'a> { ++ #[inline] ++ pub fn new(buf: &'a mut [u8]) -> IoVecMutBuffer<'a> { ++ IoVecMutBuffer(buf) ++ } ++ ++ #[inline] ++ pub fn as_slice(&self) -> &[u8] { ++ self.0 ++ } ++ ++ #[inline] ++ pub fn as_mut_slice(&mut self) -> &mut [u8] { ++ self.0 ++ } ++} ++ + /// A buffer type used with `Read::read_vectored`. + /// + /// It is semantically a wrapper around an `&mut [u8]`, but is guaranteed to be + /// ABI compatible with the `iovec` type on Unix platforms and `WSABUF` on + /// Windows. +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + #[repr(transparent)] +-pub struct IoVecMut<'a>(sys::io::IoVecMut<'a>); ++pub struct IoVecMut<'a>(IoVecMutBuffer<'a>); + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> fmt::Debug for IoVecMut<'a> { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(self.0.as_slice(), fmt) + } + } + ++#[cfg(feature="collections")] + impl<'a> IoVecMut<'a> { + /// Creates a new `IoVecMut` wrapping a byte slice. + /// + /// # Panics + /// + /// Panics on Windows if the slice is larger than 4GB. +- #[unstable(feature = "iovec", issue = "58452")] + #[inline] + pub fn new(buf: &'a mut [u8]) -> IoVecMut<'a> { +- IoVecMut(sys::io::IoVecMut::new(buf)) ++ IoVecMut(IoVecMutBuffer::new(buf)) + } + } + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> Deref for IoVecMut<'a> { + type Target = [u8]; + +@@ -943,7 +964,7 @@ impl<'a> Deref for IoVecMut<'a> { + } + } + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> DerefMut for IoVecMut<'a> { + #[inline] + fn deref_mut(&mut self) -> &mut [u8] { +@@ -956,31 +977,31 @@ impl<'a> DerefMut for IoVecMut<'a> { + /// It is semantically a wrapper around an `&[u8]`, but is guaranteed to be + /// ABI compatible with the `iovec` type on Unix platforms and `WSABUF` on + /// Windows. +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + #[repr(transparent)] +-pub struct IoVec<'a>(sys::io::IoVec<'a>); ++pub struct IoVec<'a>(IoVecBuffer<'a>); + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> fmt::Debug for IoVec<'a> { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(self.0.as_slice(), fmt) + } + } + ++#[cfg(feature="collections")] + impl<'a> IoVec<'a> { + /// Creates a new `IoVec` wrapping a byte slice. + /// + /// # Panics + /// + /// Panics on Windows if the slice is larger than 4GB. +- #[unstable(feature = "iovec", issue = "58452")] + #[inline] + pub fn new(buf: &'a [u8]) -> IoVec<'a> { +- IoVec(sys::io::IoVec::new(buf)) ++ IoVec(IoVecBuffer::new(buf)) + } + } + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> Deref for IoVec<'a> { + type Target = [u8]; + +@@ -991,13 +1012,11 @@ impl<'a> Deref for IoVec<'a> { + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -1011,21 +1030,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -1068,7 +1084,6 @@ impl Initializer { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this writer, returning how many bytes were written. +@@ -1117,7 +1132,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Like `write`, except that it writes from a slice of buffers. +@@ -1128,7 +1142,7 @@ pub trait Write { + /// + /// The default implementation calls `write` with either the first nonempty + /// buffer provided, or an empty one if none exists. +- #[unstable(feature = "iovec", issue = "58452")] ++ #[cfg(feature="collections")] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> Result { + default_write_vectored(|b| self.write(b), bufs) + } +@@ -1156,7 +1170,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this writer. +@@ -1189,7 +1202,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1241,7 +1253,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1297,7 +1308,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1327,7 +1337,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1343,7 +1352,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + + /// Returns the length of this stream (in bytes). +@@ -1381,7 +1389,6 @@ pub trait Seek { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "seek_convenience", issue = "59359")] + fn stream_len(&mut self) -> Result { + let old_pos = self.stream_position()?; + let len = self.seek(SeekFrom::End(0))?; +@@ -1420,7 +1427,6 @@ pub trait Seek { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "seek_convenience", issue = "59359")] + fn stream_position(&mut self) -> Result { + self.seek(SeekFrom::Current(0)) + } +@@ -1432,29 +1438,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Sets the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Sets the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Sets the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1534,7 +1537,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Returns the contents of the internal buffer, filling it with more data + /// from the inner reader if it is empty. +@@ -1580,7 +1583,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1602,7 +1604,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1658,7 +1659,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1717,7 +1717,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1758,7 +1757,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1797,7 +1795,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1809,7 +1806,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1835,7 +1831,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1858,7 +1853,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1885,13 +1879,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1901,7 +1893,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1913,6 +1904,7 @@ impl Read for Chain { + self.second.read(buf) + } + ++ #[cfg(feature="collections")] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> Result { + if !self.done_first { + match self.first.read_vectored(bufs)? { +@@ -1933,7 +1925,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1960,7 +1952,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -1995,7 +1986,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -2021,7 +2011,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "take_set_limit", since = "1.27.0")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -2046,7 +2035,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -2071,7 +2059,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -2100,13 +2087,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -2123,15 +2108,9 @@ impl Read for Take { + unsafe fn initializer(&self) -> Initializer { + self.inner.initializer() + } +- +- fn read_to_end(&mut self, buf: &mut Vec) -> Result { +- let reservation_size = cmp::min(self.limit, 32) as usize; +- +- read_to_end_with_reservation(self, buf, reservation_size) +- } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -2158,13 +2137,11 @@ impl BufRead for Take { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -2188,14 +2165,14 @@ impl Iterator for Bytes { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -2220,13 +2197,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 2e19edf..66294a3 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -8,7 +8,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 6aaf8f1..447ce47 100644 +--- a/util.rs ++++ b/util.rs +@@ -1,8 +1,9 @@ + #![allow(missing_copy_implementations)] + +-use crate::fmt; +-use crate::io::{self, Read, Initializer, Write, ErrorKind, BufRead, IoVec, IoVecMut}; +-use crate::mem; ++use core::fmt; ++use crate::io::{self, Read, Initializer, Write, ErrorKind}; ++#[cfg(feature="collections")] use crate::io::{BufRead, IoVec, IoVecMut}; ++use core::mem; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -39,7 +40,6 @@ use crate::mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -68,7 +68,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -88,10 +87,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -101,7 +98,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -109,7 +107,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -122,7 +119,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -139,10 +135,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -152,6 +146,7 @@ impl Read for Repeat { + Ok(buf.len()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let mut nwritten = 0; +@@ -167,7 +162,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -180,7 +174,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -197,14 +190,13 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + let total_len = bufs.iter().map(|b| b.len()).sum(); +@@ -215,7 +207,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/cf9fd6074da321b353a755359fac10cd28ed251d.patch b/patches/cf9fd6074da321b353a755359fac10cd28ed251d.patch new file mode 100644 index 0000000..bda73be --- /dev/null +++ b/patches/cf9fd6074da321b353a755359fac10cd28ed251d.patch @@ -0,0 +1,1611 @@ +diff --git a/buffered.rs b/buffered.rs +index 7ede050..2359343 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -10,13 +10,13 @@ + + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use io::prelude::*; + +-use cmp; +-use error; +-use fmt; ++use core::cmp; ++use core::fmt; + use io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom}; +-use memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -52,7 +52,6 @@ use memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -76,7 +75,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -97,7 +95,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -130,7 +127,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -151,7 +147,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + + /// Returns a reference to the internally buffered data. +@@ -176,7 +171,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -199,7 +193,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + } + +@@ -208,7 +201,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -228,7 +220,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -251,7 +242,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -271,7 +261,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -281,7 +270,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -387,7 +375,6 @@ impl Seek for BufReader { + /// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -422,7 +409,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -437,7 +423,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -455,7 +440,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -504,7 +488,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -522,7 +505,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Returns a reference to the internally buffered data. +@@ -539,7 +521,6 @@ impl BufWriter { + /// // See how many bytes are currently buffered + /// let bytes_buffered = buf_writer.buffer().len(); + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf + } +@@ -563,7 +544,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -572,7 +552,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -592,7 +571,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -602,7 +580,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -612,7 +589,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -651,7 +627,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -684,23 +659,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -771,7 +736,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -792,7 +756,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -813,7 +776,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -837,7 +799,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -860,7 +821,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -886,7 +846,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -897,7 +856,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -942,7 +900,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index f7a9033..d97489f 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -10,8 +10,8 @@ + + use io::prelude::*; + +-use core::convert::TryInto; +-use cmp; ++#[cfg(feature="collections")] use core::convert::TryInto; ++use core::cmp; + use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + + /// A `Cursor` wraps an in-memory buffer and provides it with a +@@ -80,7 +80,6 @@ use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -103,7 +102,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -121,7 +119,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -137,7 +134,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -156,7 +152,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -178,7 +173,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -198,11 +192,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -223,17 +215,16 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -244,12 +235,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -262,6 +257,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result, buf: &[u8]) -> io::Result { + let pos: usize = (*pos_mut).try_into().map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -288,7 +284,6 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result Write for Cursor<&'a mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -297,7 +292,7 @@ impl<'a> Write for Cursor<&'a mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl<'a> Write for Cursor<&'a mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) +@@ -305,7 +300,7 @@ impl<'a> Write for Cursor<&'a mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) +@@ -313,8 +308,8 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) +diff --git a/error.rs b/error.rs +index d3844eb..b4455e3 100644 +--- a/error.rs ++++ b/error.rs +@@ -8,11 +8,16 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use error; +-use fmt; +-use result; +-use sys; +-use convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -48,7 +53,6 @@ use convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -62,12 +66,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -77,13 +79,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -95,48 +100,35 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + #[non_exhaustive] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -148,10 +140,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -162,15 +152,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -179,7 +166,6 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + } + +@@ -210,7 +196,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + /// Converts an [`ErrorKind`] into an [`Error`]. + /// +@@ -252,14 +237,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -268,24 +252,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -311,7 +277,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -342,7 +307,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -376,12 +340,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(dyn error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -447,12 +410,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -481,8 +443,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -508,10 +469,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -523,22 +483,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -546,25 +502,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- #[allow(deprecated)] +- fn cause(&self) -> Option<&dyn error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index fe1179a..452b8b7 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -8,15 +8,18 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use cmp; +-use io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind}; +-use fmt; +-use mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use io::BufRead; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, R: Read + ?Sized> Read for &'a mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -28,11 +31,13 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -43,7 +48,6 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, W: Write + ?Sized> Write for &'a mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -61,12 +65,11 @@ impl<'a, W: Write + ?Sized> Write for &'a mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, S: Seek + ?Sized> Seek for &'a mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -85,7 +88,7 @@ impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -97,11 +100,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -112,7 +117,7 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -130,12 +135,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -161,7 +166,6 @@ impl BufRead for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Read for &'a [u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -207,6 +211,7 @@ impl<'a> Read for &'a [u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -216,7 +221,7 @@ impl<'a> Read for &'a [u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a> BufRead for &'a [u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -230,7 +235,6 @@ impl<'a> BufRead for &'a [u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Write for &'a mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -256,7 +260,7 @@ impl<'a> Write for &'a mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +diff --git a/mod.rs b/mod.rs +index 5137a94..da64ab7 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -267,48 +267,37 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use cmp; +-use fmt; +-use slice; +-use str; +-use memchr; +-use ptr; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::cmp; ++use core::fmt; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++use core::ptr; ++use core::slice; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl<'a> Drop for Guard<'a> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -333,6 +322,7 @@ impl<'a> Drop for Guard<'a> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -360,10 +350,12 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + read_to_end_with_reservation(r, buf, 32) + } + ++#[cfg(feature="collections")] + fn read_to_end_with_reservation(r: &mut R, + buf: &mut Vec, + reservation_size: usize) -> Result +@@ -470,7 +462,6 @@ fn read_to_end_with_reservation(r: &mut R, + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -527,7 +518,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Determines if this `Read`er can work with buffers of uninitialized +@@ -552,7 +542,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -605,7 +594,7 @@ pub trait Read { + /// file.) + /// + /// [`std::fs::read`]: ../fs/fn.read.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -648,7 +637,7 @@ pub trait Read { + /// reading from a file.) + /// + /// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -711,7 +700,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -763,7 +751,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -800,7 +787,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } +@@ -835,7 +821,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -871,20 +856,17 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -898,21 +880,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -955,7 +934,6 @@ impl Initializer { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this object, returning how many bytes were written. +@@ -1004,7 +982,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Flush this output stream, ensuring that all intermediately buffered +@@ -1030,7 +1007,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this write. +@@ -1063,7 +1039,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1115,7 +1090,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1171,7 +1145,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1201,7 +1174,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1217,7 +1189,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + } + +@@ -1227,29 +1198,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Set the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Set the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Set the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1329,7 +1297,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Returns the contents of the internal buffer, filling it with more data + /// from the inner reader if it is empty. +@@ -1375,7 +1343,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1397,7 +1364,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1453,7 +1419,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1512,7 +1477,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1553,7 +1517,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1592,7 +1555,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1604,7 +1566,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1630,7 +1591,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1653,7 +1613,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1680,13 +1639,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1696,7 +1653,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1718,7 +1674,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1745,7 +1701,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -1780,7 +1735,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -1806,7 +1760,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "take_set_limit", since = "1.27.0")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -1831,7 +1784,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -1856,7 +1808,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -1885,13 +1836,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -1908,15 +1857,9 @@ impl Read for Take { + unsafe fn initializer(&self) -> Initializer { + self.inner.initializer() + } +- +- fn read_to_end(&mut self, buf: &mut Vec) -> Result { +- let reservation_size = cmp::min(self.limit, 32) as usize; +- +- read_to_end_with_reservation(self, buf, reservation_size) +- } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -1943,13 +1886,11 @@ impl BufRead for Take { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -1973,14 +1914,14 @@ impl Iterator for Bytes { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -2005,13 +1946,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 8772d0f..49d66c9 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -18,7 +18,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 12995d0..397eef4 100644 +--- a/util.rs ++++ b/util.rs +@@ -10,9 +10,10 @@ + + #![allow(missing_copy_implementations)] + +-use fmt; +-use io::{self, Read, Initializer, Write, ErrorKind, BufRead}; +-use mem; ++use core::fmt; ++use io::{self, Read, Initializer, Write, ErrorKind}; ++use core::mem; ++#[cfg(feature="collections")] use io::BufRead; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -49,7 +50,6 @@ use mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -78,7 +78,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -98,10 +97,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -111,7 +108,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -119,7 +117,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -132,7 +129,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -149,10 +145,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -168,7 +162,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -181,7 +174,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -198,10 +190,8 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } +@@ -209,7 +199,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/d3f30c30eaf56b69cf458656c1a84a931d1108a9.patch b/patches/d3f30c30eaf56b69cf458656c1a84a931d1108a9.patch new file mode 100644 index 0000000..cfd6bbd --- /dev/null +++ b/patches/d3f30c30eaf56b69cf458656c1a84a931d1108a9.patch @@ -0,0 +1,1893 @@ +diff --git a/buffered.rs b/buffered.rs +index a14c10d..3e78c01 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -1,12 +1,12 @@ + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use crate::io::prelude::*; + +-use crate::cmp; +-use crate::error; +-use crate::fmt; ++use core::cmp; ++use core::fmt; + use crate::io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom, IoVec, IoVecMut}; +-use crate::memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -42,7 +42,6 @@ use crate::memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -66,7 +65,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -87,7 +85,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -122,7 +119,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -143,7 +139,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + + /// Returns a reference to the internally buffered data. +@@ -168,7 +163,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -191,7 +185,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + } + +@@ -200,7 +193,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -220,7 +212,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -256,7 +247,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -276,7 +266,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -286,7 +275,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -395,7 +383,6 @@ impl Seek for BufReader { + /// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -430,7 +417,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -445,7 +431,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -463,7 +448,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -512,7 +496,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -530,7 +513,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Returns a reference to the internally buffered data. +@@ -547,7 +529,6 @@ impl BufWriter { + /// // See how many bytes are currently buffered + /// let bytes_buffered = buf_writer.buffer().len(); + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf + } +@@ -571,7 +552,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -580,7 +560,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -616,7 +595,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -626,7 +604,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -636,7 +613,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -675,7 +651,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -708,23 +683,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -795,7 +760,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -816,7 +780,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -837,7 +800,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -861,7 +823,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -884,7 +845,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -910,7 +870,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -921,7 +880,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -966,7 +924,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index 873da08..3d39e57 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -1,9 +1,10 @@ + use crate::io::prelude::*; + +-use crate::cmp; +-use crate::io::{self, Initializer, SeekFrom, Error, ErrorKind, IoVec, IoVecMut}; ++use core::cmp; ++use crate::io::{self, Initializer, SeekFrom, Error, ErrorKind}; ++#[cfg(feature="collections")] use crate::io::{IoVec, IoVecMut}; + +-use core::convert::TryInto; ++#[cfg(feature="collections")] use core::convert::TryInto; + + /// A `Cursor` wraps an in-memory buffer and provides it with a + /// [`Seek`] implementation. +@@ -71,7 +72,6 @@ use core::convert::TryInto; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -94,7 +94,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -112,7 +111,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -128,7 +126,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -147,7 +144,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -169,7 +165,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -189,11 +184,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -214,14 +207,14 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + ++ #[cfg(feature="collections")] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let mut nread = 0; + for buf in bufs { +@@ -236,7 +229,7 @@ impl Read for Cursor where T: AsRef<[u8]> { + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -247,12 +240,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -264,6 +261,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result, buf: &[u8]) -> io::Result { + let pos: usize = (*pos_mut).try_into().map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -308,6 +307,7 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result, +@@ -321,13 +321,13 @@ fn vec_write_vectored( + Ok(nwritten) + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Cursor<&mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, self.inner, buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + slice_write_vectored(&mut self.pos, self.inner, bufs) +@@ -336,12 +336,13 @@ impl Write for Cursor<&mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl Write for Cursor<&mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) + } + ++ #[cfg(feature="collections")] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + vec_write_vectored(&mut self.pos, self.inner, bufs) + } +@@ -349,12 +350,13 @@ impl Write for Cursor<&mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) + } + ++ #[cfg(feature="collections")] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + vec_write_vectored(&mut self.pos, &mut self.inner, bufs) + } +@@ -362,13 +364,14 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + slice_write_vectored(&mut self.pos, &mut self.inner, bufs) +diff --git a/error.rs b/error.rs +index 614b791..e4ce8b5 100644 +--- a/error.rs ++++ b/error.rs +@@ -1,8 +1,13 @@ +-use crate::error; +-use crate::fmt; +-use crate::result; +-use crate::sys; +-use crate::convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -38,7 +43,6 @@ use crate::convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -52,12 +56,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -67,13 +69,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -85,48 +90,35 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + #[non_exhaustive] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -138,10 +130,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -152,15 +142,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -169,7 +156,6 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + } + +@@ -200,7 +186,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + /// Converts an [`ErrorKind`] into an [`Error`]. + /// +@@ -245,14 +230,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -261,24 +245,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -304,7 +270,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -335,7 +300,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -369,12 +333,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(dyn error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -440,12 +403,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -474,8 +436,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -501,10 +462,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -516,22 +476,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -539,33 +495,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- #[allow(deprecated)] +- fn cause(&self) -> Option<&dyn error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +- +- fn source(&self) -> Option<&(dyn error::Error + 'static)> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.source(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index b286e40..7472d9c 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -1,19 +1,22 @@ +-use crate::cmp; +-use crate::io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind, IoVecMut, +- IoVec}; +-use crate::fmt; +-use crate::mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use crate::io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use crate::io::{BufRead, IoVecMut, IoVec}; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for &mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { + (**self).read(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + (**self).read_vectored(bufs) +@@ -24,11 +27,13 @@ impl Read for &mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -39,11 +44,11 @@ impl Read for &mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for &mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + (**self).write_vectored(bufs) +@@ -62,12 +67,11 @@ impl Write for &mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for &mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for &mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -86,13 +90,14 @@ impl BufRead for &mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { + (**self).read(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + (**self).read_vectored(bufs) +@@ -103,11 +108,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -118,11 +125,12 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + (**self).write_vectored(bufs) +@@ -141,12 +149,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -186,7 +194,6 @@ impl Write for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for &[u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -206,6 +213,7 @@ impl Read for &[u8] { + Ok(amt) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let mut nread = 0; +@@ -245,6 +253,7 @@ impl Read for &[u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -254,7 +263,7 @@ impl Read for &[u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for &[u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -268,7 +277,6 @@ impl BufRead for &[u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for &mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -279,6 +287,7 @@ impl Write for &mut [u8] { + Ok(amt) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + let mut nwritten = 0; +@@ -307,7 +316,7 @@ impl Write for &mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -315,6 +324,7 @@ impl Write for Vec { + Ok(buf.len()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + let len = bufs.iter().map(|b| b.len()).sum(); +diff --git a/mod.rs b/mod.rs +index 1a2152a..85652f4 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -257,50 +257,38 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use crate::cmp; +-use crate::fmt; +-use crate::slice; +-use crate::str; +-use crate::memchr; +-use crate::ops::{Deref, DerefMut}; +-use crate::ptr; +-use crate::sys; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::cmp; ++use core::fmt; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++#[cfg(feature="collections")] use core::ops::{Deref, DerefMut}; ++use core::ptr; ++use core::slice; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = crate::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl Drop for Guard<'_> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -325,6 +313,7 @@ impl Drop for Guard<'_> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -352,10 +341,12 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + read_to_end_with_reservation(r, buf, 32) + } + ++#[cfg(feature="collections")] + fn read_to_end_with_reservation(r: &mut R, + buf: &mut Vec, + reservation_size: usize) -> Result +@@ -390,6 +381,7 @@ fn read_to_end_with_reservation(r: &mut R, + ret + } + ++#[cfg(feature="collections")] + pub(crate) fn default_read_vectored(read: F, bufs: &mut [IoVecMut<'_>]) -> Result + where + F: FnOnce(&mut [u8]) -> Result +@@ -401,6 +393,7 @@ where + read(buf) + } + ++#[cfg(feature="collections")] + pub(crate) fn default_write_vectored(write: F, bufs: &[IoVec<'_>]) -> Result + where + F: FnOnce(&[u8]) -> Result +@@ -484,7 +477,6 @@ where + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -541,7 +533,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Like `read`, except that it reads into a slice of buffers. +@@ -552,7 +543,7 @@ pub trait Read { + /// + /// The default implementation calls `read` with either the first nonempty + /// buffer provided, or an empty one if none exists. +- #[unstable(feature = "iovec", issue = "58452")] ++ #[cfg(feature="collections")] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> Result { + default_read_vectored(|b| self.read(b), bufs) + } +@@ -579,7 +570,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -632,7 +622,7 @@ pub trait Read { + /// file.) + /// + /// [`std::fs::read`]: ../fs/fn.read.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -675,7 +665,7 @@ pub trait Read { + /// reading from a file.) + /// + /// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -738,7 +728,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -790,7 +779,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -827,7 +815,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } +@@ -862,7 +849,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -898,42 +884,77 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + ++#[cfg(feature="collections")] ++pub struct IoVecBuffer<'a>(&'a [u8]); ++ ++#[cfg(feature="collections")] ++impl<'a> IoVecBuffer<'a> { ++ #[inline] ++ pub fn new(buf: &'a [u8]) -> IoVecBuffer<'a> { ++ IoVecBuffer(buf) ++ } ++ ++ #[inline] ++ pub fn as_slice(&self) -> &[u8] { ++ self.0 ++ } ++} ++#[cfg(feature="collections")] ++pub struct IoVecMutBuffer<'a>(&'a mut [u8]); ++ ++#[cfg(feature="collections")] ++impl<'a> IoVecMutBuffer<'a> { ++ #[inline] ++ pub fn new(buf: &'a mut [u8]) -> IoVecMutBuffer<'a> { ++ IoVecMutBuffer(buf) ++ } ++ ++ #[inline] ++ pub fn as_slice(&self) -> &[u8] { ++ self.0 ++ } ++ ++ #[inline] ++ pub fn as_mut_slice(&mut self) -> &mut [u8] { ++ self.0 ++ } ++} ++ + /// A buffer type used with `Read::read_vectored`. + /// + /// It is semantically a wrapper around an `&mut [u8]`, but is guaranteed to be + /// ABI compatible with the `iovec` type on Unix platforms and `WSABUF` on + /// Windows. +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + #[repr(transparent)] +-pub struct IoVecMut<'a>(sys::io::IoVecMut<'a>); ++pub struct IoVecMut<'a>(IoVecMutBuffer<'a>); + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> fmt::Debug for IoVecMut<'a> { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(self.0.as_slice(), fmt) + } + } + ++#[cfg(feature="collections")] + impl<'a> IoVecMut<'a> { + /// Creates a new `IoVecMut` wrapping a byte slice. + /// + /// # Panics + /// + /// Panics on Windows if the slice is larger than 4GB. +- #[unstable(feature = "iovec", issue = "58452")] + #[inline] + pub fn new(buf: &'a mut [u8]) -> IoVecMut<'a> { +- IoVecMut(sys::io::IoVecMut::new(buf)) ++ IoVecMut(IoVecMutBuffer::new(buf)) + } + } + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> Deref for IoVecMut<'a> { + type Target = [u8]; + +@@ -943,7 +964,7 @@ impl<'a> Deref for IoVecMut<'a> { + } + } + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> DerefMut for IoVecMut<'a> { + #[inline] + fn deref_mut(&mut self) -> &mut [u8] { +@@ -956,31 +977,31 @@ impl<'a> DerefMut for IoVecMut<'a> { + /// It is semantically a wrapper around an `&[u8]`, but is guaranteed to be + /// ABI compatible with the `iovec` type on Unix platforms and `WSABUF` on + /// Windows. +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + #[repr(transparent)] +-pub struct IoVec<'a>(sys::io::IoVec<'a>); ++pub struct IoVec<'a>(IoVecBuffer<'a>); + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> fmt::Debug for IoVec<'a> { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(self.0.as_slice(), fmt) + } + } + ++#[cfg(feature="collections")] + impl<'a> IoVec<'a> { + /// Creates a new `IoVec` wrapping a byte slice. + /// + /// # Panics + /// + /// Panics on Windows if the slice is larger than 4GB. +- #[unstable(feature = "iovec", issue = "58452")] + #[inline] + pub fn new(buf: &'a [u8]) -> IoVec<'a> { +- IoVec(sys::io::IoVec::new(buf)) ++ IoVec(IoVecBuffer::new(buf)) + } + } + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> Deref for IoVec<'a> { + type Target = [u8]; + +@@ -991,13 +1012,11 @@ impl<'a> Deref for IoVec<'a> { + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -1011,21 +1030,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -1068,7 +1084,6 @@ impl Initializer { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this writer, returning how many bytes were written. +@@ -1117,7 +1132,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Like `write`, except that it writes from a slice of buffers. +@@ -1128,7 +1142,7 @@ pub trait Write { + /// + /// The default implementation calls `write` with either the first nonempty + /// buffer provided, or an empty one if none exists. +- #[unstable(feature = "iovec", issue = "58452")] ++ #[cfg(feature="collections")] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> Result { + default_write_vectored(|b| self.write(b), bufs) + } +@@ -1156,7 +1170,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this writer. +@@ -1189,7 +1202,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1241,7 +1253,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1297,7 +1308,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1327,7 +1337,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1343,7 +1352,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + } + +@@ -1353,29 +1361,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Sets the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Sets the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Sets the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1455,7 +1460,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Returns the contents of the internal buffer, filling it with more data + /// from the inner reader if it is empty. +@@ -1501,7 +1506,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1523,7 +1527,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1579,7 +1582,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1638,7 +1640,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1679,7 +1680,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1718,7 +1718,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1730,7 +1729,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1756,7 +1754,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1779,7 +1776,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1806,13 +1802,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1822,7 +1816,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1834,6 +1827,7 @@ impl Read for Chain { + self.second.read(buf) + } + ++ #[cfg(feature="collections")] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> Result { + if !self.done_first { + match self.first.read_vectored(bufs)? { +@@ -1854,7 +1848,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1881,7 +1875,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -1916,7 +1909,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -1942,7 +1934,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "take_set_limit", since = "1.27.0")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -1967,7 +1958,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -1992,7 +1982,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -2021,13 +2010,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -2044,15 +2031,9 @@ impl Read for Take { + unsafe fn initializer(&self) -> Initializer { + self.inner.initializer() + } +- +- fn read_to_end(&mut self, buf: &mut Vec) -> Result { +- let reservation_size = cmp::min(self.limit, 32) as usize; +- +- read_to_end_with_reservation(self, buf, reservation_size) +- } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -2079,13 +2060,11 @@ impl BufRead for Take { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -2109,14 +2088,14 @@ impl Iterator for Bytes { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -2141,13 +2120,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 2e19edf..66294a3 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -8,7 +8,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 6aaf8f1..447ce47 100644 +--- a/util.rs ++++ b/util.rs +@@ -1,8 +1,9 @@ + #![allow(missing_copy_implementations)] + +-use crate::fmt; +-use crate::io::{self, Read, Initializer, Write, ErrorKind, BufRead, IoVec, IoVecMut}; +-use crate::mem; ++use core::fmt; ++use crate::io::{self, Read, Initializer, Write, ErrorKind}; ++#[cfg(feature="collections")] use crate::io::{BufRead, IoVec, IoVecMut}; ++use core::mem; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -39,7 +40,6 @@ use crate::mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -68,7 +68,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -88,10 +87,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -101,7 +98,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -109,7 +107,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -122,7 +119,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -139,10 +135,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -152,6 +146,7 @@ impl Read for Repeat { + Ok(buf.len()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let mut nwritten = 0; +@@ -167,7 +162,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -180,7 +174,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -197,14 +190,13 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + let total_len = bufs.iter().map(|b| b.len()).sum(); +@@ -215,7 +207,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/d403cd787c98610cf5287301820ad3353b35481d.patch b/patches/d403cd787c98610cf5287301820ad3353b35481d.patch new file mode 100644 index 0000000..4dd0e56 --- /dev/null +++ b/patches/d403cd787c98610cf5287301820ad3353b35481d.patch @@ -0,0 +1,1909 @@ +diff --git a/buffered.rs b/buffered.rs +index 441f6b9..540d4aa 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -1,12 +1,12 @@ + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use crate::io::prelude::*; + +-use crate::cmp; +-use crate::error; +-use crate::fmt; ++use core::cmp; ++use core::fmt; + use crate::io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom, IoVec, IoVecMut}; +-use crate::memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -46,7 +46,6 @@ use crate::memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -70,7 +69,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -91,7 +89,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -126,7 +123,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -147,7 +143,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + + /// Returns a reference to the internally buffered data. +@@ -172,7 +167,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -195,7 +189,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + + /// Invalidates all data in the internal buffer. +@@ -211,7 +204,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -231,7 +223,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -269,7 +260,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -289,7 +279,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -299,7 +288,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -408,7 +396,6 @@ impl Seek for BufReader { + /// [`TcpStream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -443,7 +430,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -458,7 +444,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -476,7 +461,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -525,7 +509,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -543,7 +526,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Returns a reference to the internally buffered data. +@@ -560,7 +542,6 @@ impl BufWriter { + /// // See how many bytes are currently buffered + /// let bytes_buffered = buf_writer.buffer().len(); + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf + } +@@ -584,7 +565,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -593,7 +573,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -629,7 +608,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -639,7 +617,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -649,7 +626,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -688,7 +664,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -721,23 +696,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -808,7 +773,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -829,7 +793,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -850,7 +813,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -874,7 +836,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -897,7 +858,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -923,7 +883,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -934,7 +893,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -979,7 +937,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index 247d45c..f13522d 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -1,9 +1,10 @@ + use crate::io::prelude::*; + +-use crate::cmp; +-use crate::io::{self, Initializer, SeekFrom, Error, ErrorKind, IoVec, IoVecMut}; ++use core::cmp; ++use crate::io::{self, Initializer, SeekFrom, Error, ErrorKind}; ++#[cfg(feature="collections")] use crate::io::{IoVec, IoVecMut}; + +-use core::convert::TryInto; ++#[cfg(feature="collections")] use core::convert::TryInto; + + /// A `Cursor` wraps an in-memory buffer and provides it with a + /// [`Seek`] implementation. +@@ -71,7 +72,6 @@ use core::convert::TryInto; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -94,7 +94,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -112,7 +111,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -128,7 +126,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -147,7 +144,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -169,7 +165,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -189,11 +184,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -222,14 +215,14 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + ++ #[cfg(feature="collections")] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let mut nread = 0; + for buf in bufs { +@@ -244,7 +237,7 @@ impl Read for Cursor where T: AsRef<[u8]> { + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -255,12 +248,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -272,6 +269,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result, buf: &[u8]) -> io::Result { + let pos: usize = (*pos_mut).try_into().map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -316,6 +315,7 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result, +@@ -329,13 +329,13 @@ fn vec_write_vectored( + Ok(nwritten) + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Cursor<&mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, self.inner, buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + slice_write_vectored(&mut self.pos, self.inner, bufs) +@@ -344,12 +344,13 @@ impl Write for Cursor<&mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl Write for Cursor<&mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) + } + ++ #[cfg(feature="collections")] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + vec_write_vectored(&mut self.pos, self.inner, bufs) + } +@@ -357,12 +358,13 @@ impl Write for Cursor<&mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) + } + ++ #[cfg(feature="collections")] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + vec_write_vectored(&mut self.pos, &mut self.inner, bufs) + } +@@ -370,13 +372,14 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + slice_write_vectored(&mut self.pos, &mut self.inner, bufs) +diff --git a/error.rs b/error.rs +index 614b791..e4ce8b5 100644 +--- a/error.rs ++++ b/error.rs +@@ -1,8 +1,13 @@ +-use crate::error; +-use crate::fmt; +-use crate::result; +-use crate::sys; +-use crate::convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -38,7 +43,6 @@ use crate::convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -52,12 +56,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -67,13 +69,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -85,48 +90,35 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + #[non_exhaustive] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -138,10 +130,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -152,15 +142,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -169,7 +156,6 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + } + +@@ -200,7 +186,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + /// Converts an [`ErrorKind`] into an [`Error`]. + /// +@@ -245,14 +230,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -261,24 +245,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -304,7 +270,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -335,7 +300,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -369,12 +333,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(dyn error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -440,12 +403,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -474,8 +436,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -501,10 +462,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -516,22 +476,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -539,33 +495,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- #[allow(deprecated)] +- fn cause(&self) -> Option<&dyn error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +- +- fn source(&self) -> Option<&(dyn error::Error + 'static)> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.source(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index b286e40..7472d9c 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -1,19 +1,22 @@ +-use crate::cmp; +-use crate::io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind, IoVecMut, +- IoVec}; +-use crate::fmt; +-use crate::mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use crate::io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use crate::io::{BufRead, IoVecMut, IoVec}; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for &mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { + (**self).read(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + (**self).read_vectored(bufs) +@@ -24,11 +27,13 @@ impl Read for &mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -39,11 +44,11 @@ impl Read for &mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for &mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + (**self).write_vectored(bufs) +@@ -62,12 +67,11 @@ impl Write for &mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for &mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for &mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -86,13 +90,14 @@ impl BufRead for &mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { + (**self).read(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + (**self).read_vectored(bufs) +@@ -103,11 +108,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -118,11 +125,12 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + (**self).write_vectored(bufs) +@@ -141,12 +149,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -186,7 +194,6 @@ impl Write for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for &[u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -206,6 +213,7 @@ impl Read for &[u8] { + Ok(amt) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let mut nread = 0; +@@ -245,6 +253,7 @@ impl Read for &[u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -254,7 +263,7 @@ impl Read for &[u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for &[u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -268,7 +277,6 @@ impl BufRead for &[u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for &mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -279,6 +287,7 @@ impl Write for &mut [u8] { + Ok(amt) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + let mut nwritten = 0; +@@ -307,7 +316,7 @@ impl Write for &mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -315,6 +324,7 @@ impl Write for Vec { + Ok(buf.len()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + let len = bufs.iter().map(|b| b.len()).sum(); +diff --git a/mod.rs b/mod.rs +index 7147b64..2059b5a 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -257,50 +257,38 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use crate::cmp; +-use crate::fmt; +-use crate::slice; +-use crate::str; +-use crate::memchr; +-use crate::ops::{Deref, DerefMut}; +-use crate::ptr; +-use crate::sys; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::cmp; ++use core::fmt; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++#[cfg(feature="collections")] use core::ops::{Deref, DerefMut}; ++use core::ptr; ++use core::slice; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = crate::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl Drop for Guard<'_> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -325,6 +313,7 @@ impl Drop for Guard<'_> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -352,10 +341,12 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + read_to_end_with_reservation(r, buf, 32) + } + ++#[cfg(feature="collections")] + fn read_to_end_with_reservation(r: &mut R, + buf: &mut Vec, + reservation_size: usize) -> Result +@@ -390,6 +381,7 @@ fn read_to_end_with_reservation(r: &mut R, + ret + } + ++#[cfg(feature="collections")] + pub(crate) fn default_read_vectored(read: F, bufs: &mut [IoVecMut<'_>]) -> Result + where + F: FnOnce(&mut [u8]) -> Result +@@ -401,6 +393,7 @@ where + read(buf) + } + ++#[cfg(feature="collections")] + pub(crate) fn default_write_vectored(write: F, bufs: &[IoVec<'_>]) -> Result + where + F: FnOnce(&[u8]) -> Result +@@ -484,7 +477,6 @@ where + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -541,7 +533,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Like `read`, except that it reads into a slice of buffers. +@@ -552,7 +543,7 @@ pub trait Read { + /// + /// The default implementation calls `read` with either the first nonempty + /// buffer provided, or an empty one if none exists. +- #[unstable(feature = "iovec", issue = "58452")] ++ #[cfg(feature="collections")] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> Result { + default_read_vectored(|b| self.read(b), bufs) + } +@@ -579,7 +570,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -632,7 +622,7 @@ pub trait Read { + /// file.) + /// + /// [`std::fs::read`]: ../fs/fn.read.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -675,7 +665,7 @@ pub trait Read { + /// reading from a file.) + /// + /// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -738,7 +728,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -790,7 +779,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -827,7 +815,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } +@@ -862,7 +849,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -898,42 +884,77 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + ++#[cfg(feature="collections")] ++pub struct IoVecBuffer<'a>(&'a [u8]); ++ ++#[cfg(feature="collections")] ++impl<'a> IoVecBuffer<'a> { ++ #[inline] ++ pub fn new(buf: &'a [u8]) -> IoVecBuffer<'a> { ++ IoVecBuffer(buf) ++ } ++ ++ #[inline] ++ pub fn as_slice(&self) -> &[u8] { ++ self.0 ++ } ++} ++#[cfg(feature="collections")] ++pub struct IoVecMutBuffer<'a>(&'a mut [u8]); ++ ++#[cfg(feature="collections")] ++impl<'a> IoVecMutBuffer<'a> { ++ #[inline] ++ pub fn new(buf: &'a mut [u8]) -> IoVecMutBuffer<'a> { ++ IoVecMutBuffer(buf) ++ } ++ ++ #[inline] ++ pub fn as_slice(&self) -> &[u8] { ++ self.0 ++ } ++ ++ #[inline] ++ pub fn as_mut_slice(&mut self) -> &mut [u8] { ++ self.0 ++ } ++} ++ + /// A buffer type used with `Read::read_vectored`. + /// + /// It is semantically a wrapper around an `&mut [u8]`, but is guaranteed to be + /// ABI compatible with the `iovec` type on Unix platforms and `WSABUF` on + /// Windows. +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + #[repr(transparent)] +-pub struct IoVecMut<'a>(sys::io::IoVecMut<'a>); ++pub struct IoVecMut<'a>(IoVecMutBuffer<'a>); + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> fmt::Debug for IoVecMut<'a> { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(self.0.as_slice(), fmt) + } + } + ++#[cfg(feature="collections")] + impl<'a> IoVecMut<'a> { + /// Creates a new `IoVecMut` wrapping a byte slice. + /// + /// # Panics + /// + /// Panics on Windows if the slice is larger than 4GB. +- #[unstable(feature = "iovec", issue = "58452")] + #[inline] + pub fn new(buf: &'a mut [u8]) -> IoVecMut<'a> { +- IoVecMut(sys::io::IoVecMut::new(buf)) ++ IoVecMut(IoVecMutBuffer::new(buf)) + } + } + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> Deref for IoVecMut<'a> { + type Target = [u8]; + +@@ -943,7 +964,7 @@ impl<'a> Deref for IoVecMut<'a> { + } + } + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> DerefMut for IoVecMut<'a> { + #[inline] + fn deref_mut(&mut self) -> &mut [u8] { +@@ -956,31 +977,31 @@ impl<'a> DerefMut for IoVecMut<'a> { + /// It is semantically a wrapper around an `&[u8]`, but is guaranteed to be + /// ABI compatible with the `iovec` type on Unix platforms and `WSABUF` on + /// Windows. +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + #[repr(transparent)] +-pub struct IoVec<'a>(sys::io::IoVec<'a>); ++pub struct IoVec<'a>(IoVecBuffer<'a>); + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> fmt::Debug for IoVec<'a> { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(self.0.as_slice(), fmt) + } + } + ++#[cfg(feature="collections")] + impl<'a> IoVec<'a> { + /// Creates a new `IoVec` wrapping a byte slice. + /// + /// # Panics + /// + /// Panics on Windows if the slice is larger than 4GB. +- #[unstable(feature = "iovec", issue = "58452")] + #[inline] + pub fn new(buf: &'a [u8]) -> IoVec<'a> { +- IoVec(sys::io::IoVec::new(buf)) ++ IoVec(IoVecBuffer::new(buf)) + } + } + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> Deref for IoVec<'a> { + type Target = [u8]; + +@@ -991,13 +1012,11 @@ impl<'a> Deref for IoVec<'a> { + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -1011,21 +1030,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -1068,7 +1084,6 @@ impl Initializer { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this writer, returning how many bytes were written. +@@ -1117,7 +1132,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Like `write`, except that it writes from a slice of buffers. +@@ -1128,7 +1142,7 @@ pub trait Write { + /// + /// The default implementation calls `write` with either the first nonempty + /// buffer provided, or an empty one if none exists. +- #[unstable(feature = "iovec", issue = "58452")] ++ #[cfg(feature="collections")] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> Result { + default_write_vectored(|b| self.write(b), bufs) + } +@@ -1156,7 +1170,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this writer. +@@ -1189,7 +1202,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1241,7 +1253,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1297,7 +1308,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1327,7 +1337,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1343,7 +1352,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + + /// Returns the length of this stream (in bytes). +@@ -1381,7 +1389,6 @@ pub trait Seek { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "seek_convenience", issue = "59359")] + fn stream_len(&mut self) -> Result { + let old_pos = self.stream_position()?; + let len = self.seek(SeekFrom::End(0))?; +@@ -1420,7 +1427,6 @@ pub trait Seek { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "seek_convenience", issue = "59359")] + fn stream_position(&mut self) -> Result { + self.seek(SeekFrom::Current(0)) + } +@@ -1432,29 +1438,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Sets the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Sets the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Sets the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1534,7 +1537,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Returns the contents of the internal buffer, filling it with more data + /// from the inner reader if it is empty. +@@ -1580,7 +1583,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1602,7 +1604,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1658,7 +1659,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1717,7 +1717,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1758,7 +1757,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1797,7 +1795,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1809,7 +1806,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1835,7 +1831,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1858,7 +1853,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1885,13 +1879,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1901,7 +1893,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1913,6 +1904,7 @@ impl Read for Chain { + self.second.read(buf) + } + ++ #[cfg(feature="collections")] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> Result { + if !self.done_first { + match self.first.read_vectored(bufs)? { +@@ -1933,7 +1925,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1960,7 +1952,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -1995,7 +1986,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -2021,7 +2011,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "take_set_limit", since = "1.27.0")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -2046,7 +2035,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -2071,7 +2059,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -2100,13 +2087,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -2123,15 +2108,9 @@ impl Read for Take { + unsafe fn initializer(&self) -> Initializer { + self.inner.initializer() + } +- +- fn read_to_end(&mut self, buf: &mut Vec) -> Result { +- let reservation_size = cmp::min(self.limit, 32) as usize; +- +- read_to_end_with_reservation(self, buf, reservation_size) +- } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -2158,13 +2137,11 @@ impl BufRead for Take { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -2188,14 +2165,14 @@ impl Iterator for Bytes { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -2220,13 +2197,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 2e19edf..66294a3 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -8,7 +8,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 6aaf8f1..447ce47 100644 +--- a/util.rs ++++ b/util.rs +@@ -1,8 +1,9 @@ + #![allow(missing_copy_implementations)] + +-use crate::fmt; +-use crate::io::{self, Read, Initializer, Write, ErrorKind, BufRead, IoVec, IoVecMut}; +-use crate::mem; ++use core::fmt; ++use crate::io::{self, Read, Initializer, Write, ErrorKind}; ++#[cfg(feature="collections")] use crate::io::{BufRead, IoVec, IoVecMut}; ++use core::mem; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -39,7 +40,6 @@ use crate::mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -68,7 +68,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -88,10 +87,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -101,7 +98,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -109,7 +107,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -122,7 +119,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -139,10 +135,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -152,6 +146,7 @@ impl Read for Repeat { + Ok(buf.len()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let mut nwritten = 0; +@@ -167,7 +162,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -180,7 +174,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -197,14 +190,13 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + let total_len = bufs.iter().map(|b| b.len()).sum(); +@@ -215,7 +207,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/d60fa1d3c21e00bedc0dd94dc2df7e5183c14c48.patch b/patches/d60fa1d3c21e00bedc0dd94dc2df7e5183c14c48.patch new file mode 100644 index 0000000..e60d32f --- /dev/null +++ b/patches/d60fa1d3c21e00bedc0dd94dc2df7e5183c14c48.patch @@ -0,0 +1,1602 @@ +diff --git a/buffered.rs b/buffered.rs +index 056aa7c..9e294e3 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -1,12 +1,12 @@ + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use io::prelude::*; + +-use cmp; +-use error; +-use fmt; ++use core::cmp; ++use core::fmt; + use io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom}; +-use memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -42,7 +42,6 @@ use memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -66,7 +65,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -87,7 +85,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -120,7 +117,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -141,7 +137,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + + /// Returns a reference to the internally buffered data. +@@ -166,7 +161,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -189,7 +183,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + } + +@@ -198,7 +191,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -218,7 +210,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -241,7 +232,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -261,7 +251,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -271,7 +260,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -380,7 +368,6 @@ impl Seek for BufReader { + /// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -415,7 +402,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -430,7 +416,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -448,7 +433,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -497,7 +481,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -515,7 +498,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Returns a reference to the internally buffered data. +@@ -532,7 +514,6 @@ impl BufWriter { + /// // See how many bytes are currently buffered + /// let bytes_buffered = buf_writer.buffer().len(); + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf + } +@@ -556,7 +537,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -565,7 +545,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -585,7 +564,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -595,7 +573,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -605,7 +582,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -644,7 +620,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -677,23 +652,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -764,7 +729,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -785,7 +749,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -806,7 +769,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -830,7 +792,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -853,7 +814,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -879,7 +839,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -890,7 +849,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -935,7 +893,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index b205f78..3d7e33f 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -1,7 +1,7 @@ + use io::prelude::*; + +-use core::convert::TryInto; +-use cmp; ++#[cfg(feature="collections")] use core::convert::TryInto; ++use core::cmp; + use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + + /// A `Cursor` wraps an in-memory buffer and provides it with a +@@ -70,7 +70,6 @@ use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -93,7 +92,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -111,7 +109,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -127,7 +124,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -146,7 +142,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -168,7 +163,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -188,11 +182,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -213,17 +205,16 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -234,12 +225,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -252,6 +247,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result, buf: &[u8]) -> io::Result { + let pos: usize = (*pos_mut).try_into().map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -278,7 +274,6 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result Write for Cursor<&'a mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -287,7 +282,7 @@ impl<'a> Write for Cursor<&'a mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl<'a> Write for Cursor<&'a mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) +@@ -295,7 +290,7 @@ impl<'a> Write for Cursor<&'a mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) +@@ -303,8 +298,8 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) +diff --git a/error.rs b/error.rs +index e9b4f60..31c0ff1 100644 +--- a/error.rs ++++ b/error.rs +@@ -1,8 +1,13 @@ +-use error; +-use fmt; +-use result; +-use sys; +-use convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -38,7 +43,6 @@ use convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -52,12 +56,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -67,13 +69,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -85,48 +90,35 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + #[non_exhaustive] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -138,10 +130,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -152,15 +142,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -169,7 +156,6 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + } + +@@ -200,7 +186,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + /// Converts an [`ErrorKind`] into an [`Error`]. + /// +@@ -245,14 +230,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -261,24 +245,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -304,7 +270,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -335,7 +300,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -369,12 +333,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(dyn error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -440,12 +403,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -474,8 +436,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -501,10 +462,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -516,22 +476,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -539,25 +495,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- #[allow(deprecated)] +- fn cause(&self) -> Option<&dyn error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index ec75a87..e9d6bf2 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -1,12 +1,15 @@ +-use cmp; +-use io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind}; +-use fmt; +-use mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use io::BufRead; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, R: Read + ?Sized> Read for &'a mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -18,11 +21,13 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -33,7 +38,6 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, W: Write + ?Sized> Write for &'a mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -51,12 +55,11 @@ impl<'a, W: Write + ?Sized> Write for &'a mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, S: Seek + ?Sized> Seek for &'a mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -75,7 +78,7 @@ impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -87,11 +90,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -102,7 +107,7 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -120,12 +125,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -151,7 +156,6 @@ impl BufRead for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Read for &'a [u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -197,6 +201,7 @@ impl<'a> Read for &'a [u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -206,7 +211,7 @@ impl<'a> Read for &'a [u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a> BufRead for &'a [u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -220,7 +225,6 @@ impl<'a> BufRead for &'a [u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Write for &'a mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -246,7 +250,7 @@ impl<'a> Write for &'a mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +diff --git a/mod.rs b/mod.rs +index 0991957..010e352 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -257,48 +257,37 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use cmp; +-use fmt; +-use slice; +-use str; +-use memchr; +-use ptr; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::cmp; ++use core::fmt; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++use core::ptr; ++use core::slice; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl<'a> Drop for Guard<'a> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -323,6 +312,7 @@ impl<'a> Drop for Guard<'a> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -350,10 +340,12 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + read_to_end_with_reservation(r, buf, 32) + } + ++#[cfg(feature="collections")] + fn read_to_end_with_reservation(r: &mut R, + buf: &mut Vec, + reservation_size: usize) -> Result +@@ -460,7 +452,6 @@ fn read_to_end_with_reservation(r: &mut R, + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -517,7 +508,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Determines if this `Read`er can work with buffers of uninitialized +@@ -542,7 +532,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -595,7 +584,7 @@ pub trait Read { + /// file.) + /// + /// [`std::fs::read`]: ../fs/fn.read.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -638,7 +627,7 @@ pub trait Read { + /// reading from a file.) + /// + /// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -701,7 +690,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -753,7 +741,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -790,7 +777,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } +@@ -825,7 +811,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -861,20 +846,17 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -888,21 +870,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -945,7 +924,6 @@ impl Initializer { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this writer, returning how many bytes were written. +@@ -994,7 +972,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Flush this output stream, ensuring that all intermediately buffered +@@ -1020,7 +997,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this writer. +@@ -1053,7 +1029,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1105,7 +1080,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1161,7 +1135,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1191,7 +1164,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1207,7 +1179,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + } + +@@ -1217,29 +1188,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Set the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Set the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Set the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1319,7 +1287,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Returns the contents of the internal buffer, filling it with more data + /// from the inner reader if it is empty. +@@ -1365,7 +1333,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1387,7 +1354,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1443,7 +1409,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1502,7 +1467,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1543,7 +1507,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1582,7 +1545,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1594,7 +1556,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1620,7 +1581,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1643,7 +1603,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1670,13 +1629,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1686,7 +1643,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1708,7 +1664,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1735,7 +1691,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -1770,7 +1725,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -1796,7 +1750,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "take_set_limit", since = "1.27.0")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -1821,7 +1774,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -1846,7 +1798,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -1875,13 +1826,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -1898,15 +1847,9 @@ impl Read for Take { + unsafe fn initializer(&self) -> Initializer { + self.inner.initializer() + } +- +- fn read_to_end(&mut self, buf: &mut Vec) -> Result { +- let reservation_size = cmp::min(self.limit, 32) as usize; +- +- read_to_end_with_reservation(self, buf, reservation_size) +- } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -1933,13 +1876,11 @@ impl BufRead for Take { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -1963,14 +1904,14 @@ impl Iterator for Bytes { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -1995,13 +1936,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 2e19edf..66294a3 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -8,7 +8,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 8df961a..2b08122 100644 +--- a/util.rs ++++ b/util.rs +@@ -1,8 +1,9 @@ + #![allow(missing_copy_implementations)] + +-use fmt; +-use io::{self, Read, Initializer, Write, ErrorKind, BufRead}; +-use mem; ++use core::fmt; ++use io::{self, Read, Initializer, Write, ErrorKind}; ++use core::mem; ++#[cfg(feature="collections")] use io::BufRead; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -39,7 +40,6 @@ use mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -68,7 +68,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -88,10 +87,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -101,7 +98,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -109,7 +107,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -122,7 +119,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -139,10 +135,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -158,7 +152,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -171,7 +164,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -188,10 +180,8 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } +@@ -199,7 +189,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/e1b8898cfb0392f534cc25808a7f6caad36ebbb7.patch b/patches/e1b8898cfb0392f534cc25808a7f6caad36ebbb7.patch new file mode 100644 index 0000000..54d5cc6 --- /dev/null +++ b/patches/e1b8898cfb0392f534cc25808a7f6caad36ebbb7.patch @@ -0,0 +1,1877 @@ +diff --git a/buffered.rs b/buffered.rs +index a14c10d..3e78c01 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -1,12 +1,12 @@ + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use crate::io::prelude::*; + +-use crate::cmp; +-use crate::error; +-use crate::fmt; ++use core::cmp; ++use core::fmt; + use crate::io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom, IoVec, IoVecMut}; +-use crate::memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -42,7 +42,6 @@ use crate::memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -66,7 +65,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -87,7 +85,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -122,7 +119,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -143,7 +139,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + + /// Returns a reference to the internally buffered data. +@@ -168,7 +163,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -191,7 +185,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + } + +@@ -200,7 +193,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -220,7 +212,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -256,7 +247,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -276,7 +266,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -286,7 +275,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -395,7 +383,6 @@ impl Seek for BufReader { + /// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -430,7 +417,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -445,7 +431,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -463,7 +448,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -512,7 +496,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -530,7 +513,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Returns a reference to the internally buffered data. +@@ -547,7 +529,6 @@ impl BufWriter { + /// // See how many bytes are currently buffered + /// let bytes_buffered = buf_writer.buffer().len(); + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf + } +@@ -571,7 +552,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -580,7 +560,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -616,7 +595,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -626,7 +604,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -636,7 +613,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -675,7 +651,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -708,23 +683,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -795,7 +760,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -816,7 +780,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -837,7 +800,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -861,7 +823,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -884,7 +845,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -910,7 +870,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -921,7 +880,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -966,7 +924,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index 873da08..3d39e57 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -1,9 +1,10 @@ + use crate::io::prelude::*; + +-use crate::cmp; +-use crate::io::{self, Initializer, SeekFrom, Error, ErrorKind, IoVec, IoVecMut}; ++use core::cmp; ++use crate::io::{self, Initializer, SeekFrom, Error, ErrorKind}; ++#[cfg(feature="collections")] use crate::io::{IoVec, IoVecMut}; + +-use core::convert::TryInto; ++#[cfg(feature="collections")] use core::convert::TryInto; + + /// A `Cursor` wraps an in-memory buffer and provides it with a + /// [`Seek`] implementation. +@@ -71,7 +72,6 @@ use core::convert::TryInto; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -94,7 +94,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -112,7 +111,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -128,7 +126,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -147,7 +144,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -169,7 +165,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -189,11 +184,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -214,14 +207,14 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + ++ #[cfg(feature="collections")] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let mut nread = 0; + for buf in bufs { +@@ -236,7 +229,7 @@ impl Read for Cursor where T: AsRef<[u8]> { + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -247,12 +240,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -264,6 +261,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result, buf: &[u8]) -> io::Result { + let pos: usize = (*pos_mut).try_into().map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -308,6 +307,7 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result, +@@ -321,13 +321,13 @@ fn vec_write_vectored( + Ok(nwritten) + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Cursor<&mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, self.inner, buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + slice_write_vectored(&mut self.pos, self.inner, bufs) +@@ -336,12 +336,13 @@ impl Write for Cursor<&mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl Write for Cursor<&mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) + } + ++ #[cfg(feature="collections")] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + vec_write_vectored(&mut self.pos, self.inner, bufs) + } +@@ -349,12 +350,13 @@ impl Write for Cursor<&mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) + } + ++ #[cfg(feature="collections")] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + vec_write_vectored(&mut self.pos, &mut self.inner, bufs) + } +@@ -362,13 +364,14 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + slice_write_vectored(&mut self.pos, &mut self.inner, bufs) +diff --git a/error.rs b/error.rs +index 614b791..e4ce8b5 100644 +--- a/error.rs ++++ b/error.rs +@@ -1,8 +1,13 @@ +-use crate::error; +-use crate::fmt; +-use crate::result; +-use crate::sys; +-use crate::convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -38,7 +43,6 @@ use crate::convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -52,12 +56,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -67,13 +69,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -85,48 +90,35 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + #[non_exhaustive] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -138,10 +130,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -152,15 +142,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -169,7 +156,6 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + } + +@@ -200,7 +186,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + /// Converts an [`ErrorKind`] into an [`Error`]. + /// +@@ -245,14 +230,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -261,24 +245,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -304,7 +270,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -335,7 +300,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -369,12 +333,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(dyn error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -440,12 +403,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -474,8 +436,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -501,10 +462,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -516,22 +476,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -539,33 +495,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- #[allow(deprecated)] +- fn cause(&self) -> Option<&dyn error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +- +- fn source(&self) -> Option<&(dyn error::Error + 'static)> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.source(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index b286e40..7472d9c 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -1,19 +1,22 @@ +-use crate::cmp; +-use crate::io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind, IoVecMut, +- IoVec}; +-use crate::fmt; +-use crate::mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use crate::io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use crate::io::{BufRead, IoVecMut, IoVec}; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for &mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { + (**self).read(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + (**self).read_vectored(bufs) +@@ -24,11 +27,13 @@ impl Read for &mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -39,11 +44,11 @@ impl Read for &mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for &mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + (**self).write_vectored(bufs) +@@ -62,12 +67,11 @@ impl Write for &mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for &mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for &mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -86,13 +90,14 @@ impl BufRead for &mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { + (**self).read(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + (**self).read_vectored(bufs) +@@ -103,11 +108,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -118,11 +125,12 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + (**self).write_vectored(bufs) +@@ -141,12 +149,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -186,7 +194,6 @@ impl Write for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for &[u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -206,6 +213,7 @@ impl Read for &[u8] { + Ok(amt) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let mut nread = 0; +@@ -245,6 +253,7 @@ impl Read for &[u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -254,7 +263,7 @@ impl Read for &[u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for &[u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -268,7 +277,6 @@ impl BufRead for &[u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for &mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -279,6 +287,7 @@ impl Write for &mut [u8] { + Ok(amt) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + let mut nwritten = 0; +@@ -307,7 +316,7 @@ impl Write for &mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -315,6 +324,7 @@ impl Write for Vec { + Ok(buf.len()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + let len = bufs.iter().map(|b| b.len()).sum(); +diff --git a/mod.rs b/mod.rs +index e3e2754..400eca6 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -257,50 +257,38 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use crate::cmp; +-use crate::fmt; +-use crate::slice; +-use crate::str; +-use crate::memchr; +-use crate::ops::{Deref, DerefMut}; +-use crate::ptr; +-use crate::sys; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::cmp; ++use core::fmt; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++#[cfg(feature="collections")] use core::ops::{Deref, DerefMut}; ++use core::ptr; ++use core::slice; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = crate::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl Drop for Guard<'_> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -325,6 +313,7 @@ impl Drop for Guard<'_> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -352,10 +341,12 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + read_to_end_with_reservation(r, buf, 32) + } + ++#[cfg(feature="collections")] + fn read_to_end_with_reservation(r: &mut R, + buf: &mut Vec, + reservation_size: usize) -> Result +@@ -462,7 +453,6 @@ fn read_to_end_with_reservation(r: &mut R, + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -519,7 +509,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Like `read`, except that it reads into a slice of buffers. +@@ -530,7 +519,7 @@ pub trait Read { + /// + /// The default implementation simply passes the first nonempty buffer to + /// `read`. +- #[unstable(feature = "iovec", issue = "58452")] ++ #[cfg(feature="collections")] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> Result { + match bufs.iter_mut().find(|b| !b.is_empty()) { + Some(buf) => self.read(buf), +@@ -560,7 +549,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -613,7 +601,7 @@ pub trait Read { + /// file.) + /// + /// [`std::fs::read`]: ../fs/fn.read.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -656,7 +644,7 @@ pub trait Read { + /// reading from a file.) + /// + /// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -719,7 +707,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -771,7 +758,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -808,7 +794,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } +@@ -843,7 +828,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -879,42 +863,77 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + ++#[cfg(feature="collections")] ++pub struct IoVecBuffer<'a>(&'a [u8]); ++ ++#[cfg(feature="collections")] ++impl<'a> IoVecBuffer<'a> { ++ #[inline] ++ pub fn new(buf: &'a [u8]) -> IoVecBuffer<'a> { ++ IoVecBuffer(buf) ++ } ++ ++ #[inline] ++ pub fn as_slice(&self) -> &[u8] { ++ self.0 ++ } ++} ++#[cfg(feature="collections")] ++pub struct IoVecMutBuffer<'a>(&'a mut [u8]); ++ ++#[cfg(feature="collections")] ++impl<'a> IoVecMutBuffer<'a> { ++ #[inline] ++ pub fn new(buf: &'a mut [u8]) -> IoVecMutBuffer<'a> { ++ IoVecMutBuffer(buf) ++ } ++ ++ #[inline] ++ pub fn as_slice(&self) -> &[u8] { ++ self.0 ++ } ++ ++ #[inline] ++ pub fn as_mut_slice(&mut self) -> &mut [u8] { ++ self.0 ++ } ++} ++ + /// A buffer type used with `Read::read_vectored`. + /// + /// It is semantically a wrapper around an `&mut [u8]`, but is guaranteed to be + /// ABI compatible with the `iovec` type on Unix platforms and `WSABUF` on + /// Windows. +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + #[repr(transparent)] +-pub struct IoVecMut<'a>(sys::io::IoVecMut<'a>); ++pub struct IoVecMut<'a>(IoVecMutBuffer<'a>); + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> fmt::Debug for IoVecMut<'a> { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(self.0.as_slice(), fmt) + } + } + ++#[cfg(feature="collections")] + impl<'a> IoVecMut<'a> { + /// Creates a new `IoVecMut` wrapping a byte slice. + /// + /// # Panics + /// + /// Panics on Windows if the slice is larger than 4GB. +- #[unstable(feature = "iovec", issue = "58452")] + #[inline] + pub fn new(buf: &'a mut [u8]) -> IoVecMut<'a> { +- IoVecMut(sys::io::IoVecMut::new(buf)) ++ IoVecMut(IoVecMutBuffer::new(buf)) + } + } + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> Deref for IoVecMut<'a> { + type Target = [u8]; + +@@ -924,7 +943,7 @@ impl<'a> Deref for IoVecMut<'a> { + } + } + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> DerefMut for IoVecMut<'a> { + #[inline] + fn deref_mut(&mut self) -> &mut [u8] { +@@ -937,31 +956,31 @@ impl<'a> DerefMut for IoVecMut<'a> { + /// It is semantically a wrapper around an `&[u8]`, but is guaranteed to be + /// ABI compatible with the `iovec` type on Unix platforms and `WSABUF` on + /// Windows. +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + #[repr(transparent)] +-pub struct IoVec<'a>(sys::io::IoVec<'a>); ++pub struct IoVec<'a>(IoVecBuffer<'a>); + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> fmt::Debug for IoVec<'a> { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(self.0.as_slice(), fmt) + } + } + ++#[cfg(feature="collections")] + impl<'a> IoVec<'a> { + /// Creates a new `IoVec` wrapping a byte slice. + /// + /// # Panics + /// + /// Panics on Windows if the slice is larger than 4GB. +- #[unstable(feature = "iovec", issue = "58452")] + #[inline] + pub fn new(buf: &'a [u8]) -> IoVec<'a> { +- IoVec(sys::io::IoVec::new(buf)) ++ IoVec(IoVecBuffer::new(buf)) + } + } + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> Deref for IoVec<'a> { + type Target = [u8]; + +@@ -972,13 +991,11 @@ impl<'a> Deref for IoVec<'a> { + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -992,21 +1009,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -1049,7 +1063,6 @@ impl Initializer { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this writer, returning how many bytes were written. +@@ -1098,7 +1111,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Like `write`, except that it writes from a slice of buffers. +@@ -1109,7 +1121,7 @@ pub trait Write { + /// + /// The default implementation simply passes the first nonempty buffer to + /// `write`. +- #[unstable(feature = "iovec", issue = "58452")] ++ #[cfg(feature="collections")] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> Result { + match bufs.iter().find(|b| !b.is_empty()) { + Some(buf) => self.write(buf), +@@ -1140,7 +1152,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this writer. +@@ -1173,7 +1184,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1225,7 +1235,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1281,7 +1290,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1311,7 +1319,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1327,7 +1334,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + } + +@@ -1337,29 +1343,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Sets the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Sets the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Sets the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1439,7 +1442,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Returns the contents of the internal buffer, filling it with more data + /// from the inner reader if it is empty. +@@ -1485,7 +1488,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1507,7 +1509,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1563,7 +1564,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1622,7 +1622,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1663,7 +1662,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1702,7 +1700,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1714,7 +1711,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1740,7 +1736,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1763,7 +1758,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1790,13 +1784,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1806,7 +1798,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1818,6 +1809,7 @@ impl Read for Chain { + self.second.read(buf) + } + ++ #[cfg(feature="collections")] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> Result { + if !self.done_first { + match self.first.read_vectored(bufs)? { +@@ -1838,7 +1830,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1865,7 +1857,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -1900,7 +1891,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -1926,7 +1916,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "take_set_limit", since = "1.27.0")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -1951,7 +1940,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -1976,7 +1964,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -2005,13 +1992,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -2028,15 +2013,9 @@ impl Read for Take { + unsafe fn initializer(&self) -> Initializer { + self.inner.initializer() + } +- +- fn read_to_end(&mut self, buf: &mut Vec) -> Result { +- let reservation_size = cmp::min(self.limit, 32) as usize; +- +- read_to_end_with_reservation(self, buf, reservation_size) +- } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -2063,13 +2042,11 @@ impl BufRead for Take { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -2093,14 +2070,14 @@ impl Iterator for Bytes { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -2125,13 +2102,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 2e19edf..66294a3 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -8,7 +8,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 6aaf8f1..447ce47 100644 +--- a/util.rs ++++ b/util.rs +@@ -1,8 +1,9 @@ + #![allow(missing_copy_implementations)] + +-use crate::fmt; +-use crate::io::{self, Read, Initializer, Write, ErrorKind, BufRead, IoVec, IoVecMut}; +-use crate::mem; ++use core::fmt; ++use crate::io::{self, Read, Initializer, Write, ErrorKind}; ++#[cfg(feature="collections")] use crate::io::{BufRead, IoVec, IoVecMut}; ++use core::mem; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -39,7 +40,6 @@ use crate::mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -68,7 +68,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -88,10 +87,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -101,7 +98,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -109,7 +107,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -122,7 +119,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -139,10 +135,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -152,6 +146,7 @@ impl Read for Repeat { + Ok(buf.len()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let mut nwritten = 0; +@@ -167,7 +162,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -180,7 +174,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -197,14 +190,13 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + let total_len = bufs.iter().map(|b| b.len()).sum(); +@@ -215,7 +207,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/e3a8f7db479ce6562bfc312f412b65dc4f3c77d5.patch b/patches/e3a8f7db479ce6562bfc312f412b65dc4f3c77d5.patch new file mode 100644 index 0000000..68be42d --- /dev/null +++ b/patches/e3a8f7db479ce6562bfc312f412b65dc4f3c77d5.patch @@ -0,0 +1,1602 @@ +diff --git a/buffered.rs b/buffered.rs +index 0c1d155..0523e4d 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -1,12 +1,12 @@ + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use io::prelude::*; + +-use cmp; +-use error; +-use fmt; ++use core::cmp; ++use core::fmt; + use io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom}; +-use memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -42,7 +42,6 @@ use memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -66,7 +65,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -87,7 +85,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -120,7 +117,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -141,7 +137,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + + /// Returns a reference to the internally buffered data. +@@ -166,7 +161,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -189,7 +183,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + } + +@@ -198,7 +191,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -218,7 +210,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -241,7 +232,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -261,7 +251,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -271,7 +260,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -380,7 +368,6 @@ impl Seek for BufReader { + /// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -415,7 +402,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -430,7 +416,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -448,7 +433,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -497,7 +481,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -515,7 +498,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Returns a reference to the internally buffered data. +@@ -532,7 +514,6 @@ impl BufWriter { + /// // See how many bytes are currently buffered + /// let bytes_buffered = buf_writer.buffer().len(); + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf + } +@@ -556,7 +537,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -565,7 +545,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -585,7 +564,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -595,7 +573,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -605,7 +582,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -644,7 +620,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -677,23 +652,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -764,7 +729,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -785,7 +749,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -806,7 +769,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -830,7 +792,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -853,7 +814,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -879,7 +839,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -890,7 +849,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -935,7 +893,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index 758d856..42c61cc 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -1,7 +1,7 @@ + use io::prelude::*; + +-use core::convert::TryInto; +-use cmp; ++#[cfg(feature="collections")] use core::convert::TryInto; ++use core::cmp; + use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + + /// A `Cursor` wraps an in-memory buffer and provides it with a +@@ -70,7 +70,6 @@ use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -93,7 +92,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -111,7 +109,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -127,7 +124,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -146,7 +142,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -168,7 +163,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -188,11 +182,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -213,17 +205,16 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -234,12 +225,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -252,6 +247,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result, buf: &[u8]) -> io::Result { + let pos: usize = (*pos_mut).try_into().map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -278,7 +274,6 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -287,7 +282,7 @@ impl Write for Cursor<&mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl Write for Cursor<&mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) +@@ -295,7 +290,7 @@ impl Write for Cursor<&mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) +@@ -303,8 +298,8 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) +diff --git a/error.rs b/error.rs +index e9b4f60..31c0ff1 100644 +--- a/error.rs ++++ b/error.rs +@@ -1,8 +1,13 @@ +-use error; +-use fmt; +-use result; +-use sys; +-use convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -38,7 +43,6 @@ use convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -52,12 +56,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -67,13 +69,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -85,48 +90,35 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + #[non_exhaustive] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -138,10 +130,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -152,15 +142,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -169,7 +156,6 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + } + +@@ -200,7 +186,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + /// Converts an [`ErrorKind`] into an [`Error`]. + /// +@@ -245,14 +230,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -261,24 +245,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -304,7 +270,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -335,7 +300,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -369,12 +333,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(dyn error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -440,12 +403,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -474,8 +436,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -501,10 +462,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -516,22 +476,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -539,25 +495,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- #[allow(deprecated)] +- fn cause(&self) -> Option<&dyn error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index 2577b28..691dc32 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -1,12 +1,15 @@ +-use cmp; +-use io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind}; +-use fmt; +-use mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use io::BufRead; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for &mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -18,11 +21,13 @@ impl Read for &mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -33,7 +38,6 @@ impl Read for &mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for &mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -51,12 +55,11 @@ impl Write for &mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for &mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for &mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -75,7 +78,7 @@ impl BufRead for &mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -87,11 +90,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -102,7 +107,7 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -120,12 +125,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -151,7 +156,6 @@ impl BufRead for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for &[u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -197,6 +201,7 @@ impl Read for &[u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -206,7 +211,7 @@ impl Read for &[u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for &[u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -220,7 +225,6 @@ impl BufRead for &[u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for &mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -246,7 +250,7 @@ impl Write for &mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +diff --git a/mod.rs b/mod.rs +index b634ea4..1646c3e 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -257,48 +257,37 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use cmp; +-use fmt; +-use slice; +-use str; +-use memchr; +-use ptr; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::cmp; ++use core::fmt; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++use core::ptr; ++use core::slice; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl Drop for Guard<'_> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -323,6 +312,7 @@ impl Drop for Guard<'_> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -350,10 +340,12 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + read_to_end_with_reservation(r, buf, 32) + } + ++#[cfg(feature="collections")] + fn read_to_end_with_reservation(r: &mut R, + buf: &mut Vec, + reservation_size: usize) -> Result +@@ -460,7 +452,6 @@ fn read_to_end_with_reservation(r: &mut R, + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -517,7 +508,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Determines if this `Read`er can work with buffers of uninitialized +@@ -542,7 +532,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -595,7 +584,7 @@ pub trait Read { + /// file.) + /// + /// [`std::fs::read`]: ../fs/fn.read.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -638,7 +627,7 @@ pub trait Read { + /// reading from a file.) + /// + /// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -701,7 +690,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -753,7 +741,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -790,7 +777,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } +@@ -825,7 +811,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -861,20 +846,17 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -888,21 +870,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -945,7 +924,6 @@ impl Initializer { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this writer, returning how many bytes were written. +@@ -994,7 +972,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Flush this output stream, ensuring that all intermediately buffered +@@ -1020,7 +997,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this writer. +@@ -1053,7 +1029,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1105,7 +1080,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1161,7 +1135,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1191,7 +1164,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1207,7 +1179,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + } + +@@ -1217,29 +1188,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Sets the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Sets the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Sets the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1319,7 +1287,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Returns the contents of the internal buffer, filling it with more data + /// from the inner reader if it is empty. +@@ -1365,7 +1333,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1387,7 +1354,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1443,7 +1409,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1502,7 +1467,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1543,7 +1507,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1582,7 +1545,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1594,7 +1556,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1620,7 +1581,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1643,7 +1603,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1670,13 +1629,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1686,7 +1643,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1708,7 +1664,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1735,7 +1691,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -1770,7 +1725,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -1796,7 +1750,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "take_set_limit", since = "1.27.0")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -1821,7 +1774,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -1846,7 +1798,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -1875,13 +1826,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -1898,15 +1847,9 @@ impl Read for Take { + unsafe fn initializer(&self) -> Initializer { + self.inner.initializer() + } +- +- fn read_to_end(&mut self, buf: &mut Vec) -> Result { +- let reservation_size = cmp::min(self.limit, 32) as usize; +- +- read_to_end_with_reservation(self, buf, reservation_size) +- } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -1933,13 +1876,11 @@ impl BufRead for Take { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -1963,14 +1904,14 @@ impl Iterator for Bytes { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -1995,13 +1936,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 2e19edf..66294a3 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -8,7 +8,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 8df961a..2b08122 100644 +--- a/util.rs ++++ b/util.rs +@@ -1,8 +1,9 @@ + #![allow(missing_copy_implementations)] + +-use fmt; +-use io::{self, Read, Initializer, Write, ErrorKind, BufRead}; +-use mem; ++use core::fmt; ++use io::{self, Read, Initializer, Write, ErrorKind}; ++use core::mem; ++#[cfg(feature="collections")] use io::BufRead; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -39,7 +40,6 @@ use mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -68,7 +68,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -88,10 +87,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -101,7 +98,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -109,7 +107,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -122,7 +119,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -139,10 +135,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -158,7 +152,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -171,7 +164,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -188,10 +180,8 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } +@@ -199,7 +189,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/e5277c1457d397f22ba18a1d40c1318729becbb4.patch b/patches/e5277c1457d397f22ba18a1d40c1318729becbb4.patch new file mode 100644 index 0000000..7967c12 --- /dev/null +++ b/patches/e5277c1457d397f22ba18a1d40c1318729becbb4.patch @@ -0,0 +1,1704 @@ +diff --git a/buffered.rs b/buffered.rs +index cefff2f..0393156 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -10,13 +10,13 @@ + + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use io::prelude::*; + +-use cmp; +-use error; +-use fmt; ++use core::cmp; ++use core::fmt; + use io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom}; +-use memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -46,7 +46,6 @@ use memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -69,7 +68,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -90,7 +88,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -123,7 +120,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -144,36 +140,8 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + +- /// Returns `true` if there are no bytes in the internal buffer. +- /// +- /// # Examples +- // +- /// ```no_run +- /// # #![feature(bufreader_is_empty)] +- /// use std::io::BufReader; +- /// use std::io::BufRead; +- /// use std::fs::File; +- /// +- /// fn main() -> std::io::Result<()> { +- /// let f1 = File::open("log.txt")?; +- /// let mut reader = BufReader::new(f1); +- /// assert!(reader.is_empty()); +- /// +- /// if reader.fill_buf()?.len() > 0 { +- /// assert!(!reader.is_empty()); +- /// } +- /// Ok(()) +- /// } +- /// ``` +- #[unstable(feature = "bufreader_is_empty", issue = "45323", reason = "recently added")] +- #[rustc_deprecated(since = "1.26.0", reason = "use .buffer().is_empty() instead")] +- pub fn is_empty(&self) -> bool { +- self.buffer().is_empty() +- } +- + /// Returns a reference to the internally buffered data. + /// + /// Unlike `fill_buf`, this will not attempt to fill the buffer if it is empty. +@@ -196,7 +164,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -219,7 +186,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + } + +@@ -228,7 +194,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -248,7 +213,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -271,7 +235,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -291,7 +254,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -301,7 +263,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -403,7 +364,6 @@ impl Seek for BufReader { + /// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -438,7 +398,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -452,7 +411,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -470,7 +428,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -519,7 +476,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -537,7 +493,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Unwraps this `BufWriter`, returning the underlying writer. +@@ -559,7 +514,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -568,7 +522,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -588,7 +541,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -598,7 +550,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -608,7 +559,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -647,7 +597,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -680,23 +629,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -754,7 +693,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -775,7 +713,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -796,7 +733,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -820,7 +756,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -843,7 +778,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -869,7 +803,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -880,7 +813,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -925,7 +857,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index 2673f3c..5b2e073 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -10,7 +10,7 @@ + + use io::prelude::*; + +-use cmp; ++use core::cmp; + use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + + /// A `Cursor` wraps another type and provides it with a +@@ -78,7 +78,6 @@ use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -101,7 +100,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -119,7 +117,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -135,7 +132,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -154,7 +150,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -176,7 +171,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -196,11 +190,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -221,17 +213,16 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -242,12 +233,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -261,6 +256,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result Result { +@@ -271,12 +267,14 @@ fn try_into(n: u64) -> Result { + } + } + ++#[cfg(feature="collections")] + #[cfg(any(target_pointer_width = "64"))] + fn try_into(n: u64) -> Result { + Ok(n as usize) + } + + // Resizing write implementation ++#[cfg(feature="collections")] + fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result { + let pos: usize = try_into(*pos_mut).map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -303,7 +301,6 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result Write for Cursor<&'a mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -312,7 +309,7 @@ impl<'a> Write for Cursor<&'a mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl<'a> Write for Cursor<&'a mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) +@@ -320,7 +317,7 @@ impl<'a> Write for Cursor<&'a mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) +@@ -328,8 +325,8 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) +diff --git a/error.rs b/error.rs +index bdd675e..3acdadf 100644 +--- a/error.rs ++++ b/error.rs +@@ -8,11 +8,16 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use error; +-use fmt; +-use result; +-use sys; +-use convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -48,7 +53,6 @@ use convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -62,12 +66,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -77,13 +79,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -95,47 +100,34 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -147,10 +139,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -161,15 +151,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -178,15 +165,10 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + + /// A marker variant that tells the compiler that users of this enum cannot + /// match it exhaustively. +- #[unstable(feature = "io_error_internals", +- reason = "better expressed through extensible enums that this \ +- enum cannot be exhaustively matched against", +- issue = "0")] + #[doc(hidden)] + __Nonexhaustive, + } +@@ -219,7 +201,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + #[inline] + fn from(kind: ErrorKind) -> Error { +@@ -248,14 +229,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -264,24 +244,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -307,7 +269,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -338,7 +299,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -372,12 +332,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -443,12 +402,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -477,8 +435,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -504,10 +461,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -519,22 +475,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -542,24 +494,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- fn cause(&self) -> Option<&error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index fe1179a..452b8b7 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -8,15 +8,18 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use cmp; +-use io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind}; +-use fmt; +-use mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use io::BufRead; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, R: Read + ?Sized> Read for &'a mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -28,11 +31,13 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -43,7 +48,6 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, W: Write + ?Sized> Write for &'a mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -61,12 +65,11 @@ impl<'a, W: Write + ?Sized> Write for &'a mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, S: Seek + ?Sized> Seek for &'a mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -85,7 +88,7 @@ impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -97,11 +100,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -112,7 +117,7 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -130,12 +135,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -161,7 +166,6 @@ impl BufRead for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Read for &'a [u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -207,6 +211,7 @@ impl<'a> Read for &'a [u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -216,7 +221,7 @@ impl<'a> Read for &'a [u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a> BufRead for &'a [u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -230,7 +235,6 @@ impl<'a> BufRead for &'a [u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Write for &'a mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -256,7 +260,7 @@ impl<'a> Write for &'a mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +diff --git a/mod.rs b/mod.rs +index 63b631a..16922f8 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -267,50 +267,38 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use cmp; ++use core::cmp; + use core::str as core_str; +-use error as std_error; +-use fmt; +-use result; +-use str; +-use memchr; +-use ptr; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::fmt; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++use core::ptr; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl<'a> Drop for Guard<'a> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -335,6 +323,7 @@ impl<'a> Drop for Guard<'a> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -362,6 +351,7 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + let start_len = buf.len(); + let mut g = Guard { len: buf.len(), buf: buf }; +@@ -465,7 +455,6 @@ fn read_to_end(r: &mut R, buf: &mut Vec) -> Result + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -522,7 +511,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Determines if this `Read`er can work with buffers of uninitialized +@@ -547,7 +535,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -595,7 +582,7 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -633,7 +620,7 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -696,7 +683,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -748,7 +734,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -785,7 +770,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } +@@ -826,10 +810,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "io", reason = "the semantics of a partial read/write \ +- of where errors happen is currently \ +- unclear and may change", +- issue = "27802")] + fn chars(self) -> Chars where Self: Sized { + Chars { inner: self } + } +@@ -864,7 +844,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -900,20 +879,17 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -927,21 +903,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -984,7 +957,6 @@ impl Initializer { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this object, returning how many bytes were written. +@@ -1033,7 +1005,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Flush this output stream, ensuring that all intermediately buffered +@@ -1059,7 +1030,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this write. +@@ -1092,7 +1062,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1144,7 +1113,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1200,7 +1168,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1230,7 +1197,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1246,7 +1212,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + } + +@@ -1256,29 +1221,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Set the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Set the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Set the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1358,7 +1320,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Fills the internal buffer of this object, returning the buffer contents. + /// +@@ -1403,7 +1365,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1425,7 +1386,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1481,7 +1441,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1540,7 +1499,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1581,7 +1539,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1620,7 +1577,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1632,7 +1588,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1658,7 +1613,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1681,7 +1635,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1708,13 +1661,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1724,7 +1675,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1746,7 +1696,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1773,7 +1723,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -1808,7 +1757,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -1835,7 +1783,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "take_set_limit", issue = "42781")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -1860,7 +1807,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -1885,7 +1831,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -1914,13 +1859,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -1939,7 +1882,7 @@ impl Read for Take { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -1978,13 +1921,11 @@ fn read_one_byte(reader: &mut Read) -> Option> { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -1999,8 +1940,6 @@ impl Iterator for Bytes { + /// Please see the documentation of `chars()` for more details. + /// + /// [chars]: trait.Read.html#method.chars +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] + #[derive(Debug)] + pub struct Chars { + inner: R, +@@ -2009,8 +1948,6 @@ pub struct Chars { + /// An enumeration of possible errors that can be generated from the `Chars` + /// adapter. + #[derive(Debug)] +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] + pub enum CharsError { + /// Variant representing that the underlying stream was read successfully + /// but it did not contain valid utf8 data. +@@ -2020,8 +1957,6 @@ pub enum CharsError { + Other(Error), + } + +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] + impl Iterator for Chars { + type Item = result::Result; + +@@ -2052,25 +1987,6 @@ impl Iterator for Chars { + } + } + +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] +-impl std_error::Error for CharsError { +- fn description(&self) -> &str { +- match *self { +- CharsError::NotUtf8 => "invalid utf8 encoding", +- CharsError::Other(ref e) => std_error::Error::description(e), +- } +- } +- fn cause(&self) -> Option<&std_error::Error> { +- match *self { +- CharsError::NotUtf8 => None, +- CharsError::Other(ref e) => e.cause(), +- } +- } +-} +- +-#[unstable(feature = "io", reason = "awaiting stability of Read::chars", +- issue = "27802")] + impl fmt::Display for CharsError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match *self { +@@ -2089,14 +2005,14 @@ impl fmt::Display for CharsError { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -2121,13 +2037,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 8772d0f..49d66c9 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -18,7 +18,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 195310a..20755b7 100644 +--- a/util.rs ++++ b/util.rs +@@ -10,9 +10,10 @@ + + #![allow(missing_copy_implementations)] + +-use fmt; +-use io::{self, Read, Initializer, Write, ErrorKind, BufRead}; +-use mem; ++use core::fmt; ++use io::{self, Read, Initializer, Write, ErrorKind}; ++use core::mem; ++#[cfg(feature="collections")] use io::BufRead; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -44,7 +45,6 @@ use mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -73,7 +73,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -93,10 +92,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -106,7 +103,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -114,7 +112,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -127,7 +124,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -144,10 +140,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte: byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -163,7 +157,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -176,7 +169,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -193,10 +185,8 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } +@@ -204,7 +194,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/ea505fd60b09bbfb127c874a27abac52d44bfe00.patch b/patches/ea505fd60b09bbfb127c874a27abac52d44bfe00.patch new file mode 100644 index 0000000..2384df8 --- /dev/null +++ b/patches/ea505fd60b09bbfb127c874a27abac52d44bfe00.patch @@ -0,0 +1,1600 @@ +diff --git a/buffered.rs b/buffered.rs +index 03c97de..9618137 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -10,13 +10,13 @@ + + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use io::prelude::*; + +-use cmp; +-use error; +-use fmt; ++use core::cmp; ++use core::fmt; + use io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom}; +-use memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -52,7 +52,6 @@ use memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -76,7 +75,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -97,7 +95,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -130,7 +127,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -151,7 +147,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + + /// Returns a reference to the internally buffered data. +@@ -176,7 +171,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -199,7 +193,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + } + +@@ -208,7 +201,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -228,7 +220,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -251,7 +242,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -271,7 +261,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -281,7 +270,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -389,7 +377,6 @@ impl Seek for BufReader { + /// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -424,7 +411,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -439,7 +425,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -457,7 +442,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -506,7 +490,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -524,7 +507,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Unwraps this `BufWriter`, returning the underlying writer. +@@ -546,7 +528,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -555,7 +536,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -575,7 +555,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -585,7 +564,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -595,7 +573,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -634,7 +611,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -667,23 +643,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -754,7 +720,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -775,7 +740,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -796,7 +760,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -820,7 +783,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -843,7 +805,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -869,7 +830,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -880,7 +840,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -925,7 +884,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index 14f2015..1d60dac 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -10,8 +10,8 @@ + + use io::prelude::*; + +-use core::convert::TryInto; +-use cmp; ++#[cfg(feature="collections")] use core::convert::TryInto; ++use core::cmp; + use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + + /// A `Cursor` wraps an in-memory buffer and provides it with a +@@ -80,7 +80,6 @@ use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -103,7 +102,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -121,7 +119,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -137,7 +134,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -156,7 +152,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -178,7 +173,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -198,11 +192,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -223,17 +215,16 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -244,12 +235,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -262,6 +257,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result, buf: &[u8]) -> io::Result { + let pos: usize = (*pos_mut).try_into().map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -288,7 +284,6 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result Write for Cursor<&'a mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -297,7 +292,7 @@ impl<'a> Write for Cursor<&'a mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl<'a> Write for Cursor<&'a mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) +@@ -305,7 +300,7 @@ impl<'a> Write for Cursor<&'a mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) +@@ -313,8 +308,8 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) +diff --git a/error.rs b/error.rs +index 3e50988..71667ce 100644 +--- a/error.rs ++++ b/error.rs +@@ -8,11 +8,16 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use error; +-use fmt; +-use result; +-use sys; +-use convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -48,7 +53,6 @@ use convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -62,12 +66,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -77,13 +79,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -95,48 +100,35 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + #[non_exhaustive] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -148,10 +140,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -162,15 +152,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -179,7 +166,6 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + } + +@@ -210,7 +196,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + #[inline] + fn from(kind: ErrorKind) -> Error { +@@ -239,14 +224,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -255,24 +239,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -298,7 +264,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -329,7 +294,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -363,12 +327,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(dyn error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -434,12 +397,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -468,8 +430,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -495,10 +456,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -510,22 +470,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -533,24 +489,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- fn cause(&self) -> Option<&dyn error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index fe1179a..452b8b7 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -8,15 +8,18 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use cmp; +-use io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind}; +-use fmt; +-use mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use io::BufRead; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, R: Read + ?Sized> Read for &'a mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -28,11 +31,13 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -43,7 +48,6 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, W: Write + ?Sized> Write for &'a mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -61,12 +65,11 @@ impl<'a, W: Write + ?Sized> Write for &'a mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, S: Seek + ?Sized> Seek for &'a mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -85,7 +88,7 @@ impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -97,11 +100,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -112,7 +117,7 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -130,12 +135,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -161,7 +166,6 @@ impl BufRead for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Read for &'a [u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -207,6 +211,7 @@ impl<'a> Read for &'a [u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -216,7 +221,7 @@ impl<'a> Read for &'a [u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a> BufRead for &'a [u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -230,7 +235,6 @@ impl<'a> BufRead for &'a [u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Write for &'a mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -256,7 +260,7 @@ impl<'a> Write for &'a mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +diff --git a/mod.rs b/mod.rs +index b83f3fb..883fa30 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -267,47 +267,36 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use cmp; +-use fmt; +-use str; +-use memchr; +-use ptr; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::cmp; ++use core::fmt; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++use core::ptr; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl<'a> Drop for Guard<'a> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -332,6 +321,7 @@ impl<'a> Drop for Guard<'a> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -359,10 +349,12 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + read_to_end_with_reservation(r, buf, 32) + } + ++#[cfg(feature="collections")] + fn read_to_end_with_reservation(r: &mut R, + buf: &mut Vec, + reservation_size: usize) -> Result +@@ -469,7 +461,6 @@ fn read_to_end_with_reservation(r: &mut R, + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -526,7 +517,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Determines if this `Read`er can work with buffers of uninitialized +@@ -551,7 +541,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -604,7 +593,7 @@ pub trait Read { + /// file.) + /// + /// [`std::fs::read`]: ../fs/fn.read.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -647,7 +636,7 @@ pub trait Read { + /// reading from a file.) + /// + /// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -710,7 +699,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -762,7 +750,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -799,7 +786,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } +@@ -834,7 +820,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -870,20 +855,17 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -897,21 +879,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -954,7 +933,6 @@ impl Initializer { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this object, returning how many bytes were written. +@@ -1003,7 +981,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Flush this output stream, ensuring that all intermediately buffered +@@ -1029,7 +1006,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this write. +@@ -1062,7 +1038,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1114,7 +1089,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1170,7 +1144,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1200,7 +1173,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1216,7 +1188,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + } + +@@ -1226,29 +1197,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Set the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Set the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Set the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1328,7 +1296,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Fills the internal buffer of this object, returning the buffer contents. + /// +@@ -1373,7 +1341,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1395,7 +1362,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1451,7 +1417,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1510,7 +1475,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1551,7 +1515,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1590,7 +1553,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1602,7 +1564,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1628,7 +1589,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1651,7 +1611,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1678,13 +1637,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1694,7 +1651,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1716,7 +1672,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1743,7 +1699,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -1778,7 +1733,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -1804,7 +1758,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "take_set_limit", since = "1.27.0")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -1829,7 +1782,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -1854,7 +1806,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -1883,13 +1834,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -1906,15 +1855,9 @@ impl Read for Take { + unsafe fn initializer(&self) -> Initializer { + self.inner.initializer() + } +- +- fn read_to_end(&mut self, buf: &mut Vec) -> Result { +- let reservation_size = cmp::min(self.limit, 32) as usize; +- +- read_to_end_with_reservation(self, buf, reservation_size) +- } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -1953,13 +1896,11 @@ fn read_one_byte(reader: &mut dyn Read) -> Option> { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -1975,14 +1916,14 @@ impl Iterator for Bytes { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -2007,13 +1948,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 8772d0f..49d66c9 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -18,7 +18,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 33f741d..878fb82 100644 +--- a/util.rs ++++ b/util.rs +@@ -10,9 +10,10 @@ + + #![allow(missing_copy_implementations)] + +-use fmt; +-use io::{self, Read, Initializer, Write, ErrorKind, BufRead}; +-use mem; ++use core::fmt; ++use io::{self, Read, Initializer, Write, ErrorKind}; ++use core::mem; ++#[cfg(feature="collections")] use io::BufRead; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -44,7 +45,6 @@ use mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -73,7 +73,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -93,10 +92,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -106,7 +103,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -114,7 +112,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -127,7 +124,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -144,10 +140,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte: byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -163,7 +157,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -176,7 +169,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -193,10 +185,8 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } +@@ -204,7 +194,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/ebbecac538137fca1c36ceca91337b5ff4d196b5.patch b/patches/ebbecac538137fca1c36ceca91337b5ff4d196b5.patch new file mode 100644 index 0000000..5c51a01 --- /dev/null +++ b/patches/ebbecac538137fca1c36ceca91337b5ff4d196b5.patch @@ -0,0 +1,1602 @@ +diff --git a/buffered.rs b/buffered.rs +index 056aa7c..9e294e3 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -1,12 +1,12 @@ + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use io::prelude::*; + +-use cmp; +-use error; +-use fmt; ++use core::cmp; ++use core::fmt; + use io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom}; +-use memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -42,7 +42,6 @@ use memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -66,7 +65,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -87,7 +85,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -120,7 +117,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -141,7 +137,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + + /// Returns a reference to the internally buffered data. +@@ -166,7 +161,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -189,7 +183,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + } + +@@ -198,7 +191,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -218,7 +210,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -241,7 +232,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -261,7 +251,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -271,7 +260,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -380,7 +368,6 @@ impl Seek for BufReader { + /// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -415,7 +402,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -430,7 +416,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -448,7 +433,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -497,7 +481,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -515,7 +498,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Returns a reference to the internally buffered data. +@@ -532,7 +514,6 @@ impl BufWriter { + /// // See how many bytes are currently buffered + /// let bytes_buffered = buf_writer.buffer().len(); + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf + } +@@ -556,7 +537,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -565,7 +545,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -585,7 +564,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -595,7 +573,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -605,7 +582,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -644,7 +620,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -677,23 +652,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -764,7 +729,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -785,7 +749,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -806,7 +769,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -830,7 +792,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -853,7 +814,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -879,7 +839,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -890,7 +849,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -935,7 +893,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index b205f78..3d7e33f 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -1,7 +1,7 @@ + use io::prelude::*; + +-use core::convert::TryInto; +-use cmp; ++#[cfg(feature="collections")] use core::convert::TryInto; ++use core::cmp; + use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + + /// A `Cursor` wraps an in-memory buffer and provides it with a +@@ -70,7 +70,6 @@ use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -93,7 +92,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -111,7 +109,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -127,7 +124,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -146,7 +142,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -168,7 +163,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -188,11 +182,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -213,17 +205,16 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -234,12 +225,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -252,6 +247,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result, buf: &[u8]) -> io::Result { + let pos: usize = (*pos_mut).try_into().map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -278,7 +274,6 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result Write for Cursor<&'a mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -287,7 +282,7 @@ impl<'a> Write for Cursor<&'a mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl<'a> Write for Cursor<&'a mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) +@@ -295,7 +290,7 @@ impl<'a> Write for Cursor<&'a mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) +@@ -303,8 +298,8 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) +diff --git a/error.rs b/error.rs +index e9b4f60..31c0ff1 100644 +--- a/error.rs ++++ b/error.rs +@@ -1,8 +1,13 @@ +-use error; +-use fmt; +-use result; +-use sys; +-use convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -38,7 +43,6 @@ use convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -52,12 +56,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -67,13 +69,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -85,48 +90,35 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + #[non_exhaustive] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -138,10 +130,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -152,15 +142,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -169,7 +156,6 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + } + +@@ -200,7 +186,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + /// Converts an [`ErrorKind`] into an [`Error`]. + /// +@@ -245,14 +230,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -261,24 +245,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -304,7 +270,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -335,7 +300,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -369,12 +333,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(dyn error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -440,12 +403,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -474,8 +436,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -501,10 +462,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -516,22 +476,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -539,25 +495,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- #[allow(deprecated)] +- fn cause(&self) -> Option<&dyn error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index ec75a87..e9d6bf2 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -1,12 +1,15 @@ +-use cmp; +-use io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind}; +-use fmt; +-use mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use io::BufRead; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, R: Read + ?Sized> Read for &'a mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -18,11 +21,13 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -33,7 +38,6 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, W: Write + ?Sized> Write for &'a mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -51,12 +55,11 @@ impl<'a, W: Write + ?Sized> Write for &'a mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, S: Seek + ?Sized> Seek for &'a mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -75,7 +78,7 @@ impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -87,11 +90,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -102,7 +107,7 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -120,12 +125,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -151,7 +156,6 @@ impl BufRead for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Read for &'a [u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -197,6 +201,7 @@ impl<'a> Read for &'a [u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -206,7 +211,7 @@ impl<'a> Read for &'a [u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a> BufRead for &'a [u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -220,7 +225,6 @@ impl<'a> BufRead for &'a [u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Write for &'a mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -246,7 +250,7 @@ impl<'a> Write for &'a mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +diff --git a/mod.rs b/mod.rs +index 28a6fbd..2f5ae43 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -257,48 +257,37 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use cmp; +-use fmt; +-use slice; +-use str; +-use memchr; +-use ptr; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::cmp; ++use core::fmt; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++use core::ptr; ++use core::slice; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl<'a> Drop for Guard<'a> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -323,6 +312,7 @@ impl<'a> Drop for Guard<'a> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -350,10 +340,12 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + read_to_end_with_reservation(r, buf, 32) + } + ++#[cfg(feature="collections")] + fn read_to_end_with_reservation(r: &mut R, + buf: &mut Vec, + reservation_size: usize) -> Result +@@ -460,7 +452,6 @@ fn read_to_end_with_reservation(r: &mut R, + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -517,7 +508,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Determines if this `Read`er can work with buffers of uninitialized +@@ -542,7 +532,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -595,7 +584,7 @@ pub trait Read { + /// file.) + /// + /// [`std::fs::read`]: ../fs/fn.read.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -638,7 +627,7 @@ pub trait Read { + /// reading from a file.) + /// + /// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -701,7 +690,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -753,7 +741,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -790,7 +777,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } +@@ -825,7 +811,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -861,20 +846,17 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -888,21 +870,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -945,7 +924,6 @@ impl Initializer { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this writer, returning how many bytes were written. +@@ -994,7 +972,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Flush this output stream, ensuring that all intermediately buffered +@@ -1020,7 +997,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this writer. +@@ -1053,7 +1029,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1105,7 +1080,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1161,7 +1135,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1191,7 +1164,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1207,7 +1179,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + } + +@@ -1217,29 +1188,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Set the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Set the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Set the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1319,7 +1287,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Returns the contents of the internal buffer, filling it with more data + /// from the inner reader if it is empty. +@@ -1365,7 +1333,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1387,7 +1354,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1443,7 +1409,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1502,7 +1467,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1543,7 +1507,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1582,7 +1545,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1594,7 +1556,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1620,7 +1581,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1643,7 +1603,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1670,13 +1629,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1686,7 +1643,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1708,7 +1664,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1735,7 +1691,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -1770,7 +1725,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -1796,7 +1750,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "take_set_limit", since = "1.27.0")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -1821,7 +1774,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -1846,7 +1798,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -1875,13 +1826,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -1898,15 +1847,9 @@ impl Read for Take { + unsafe fn initializer(&self) -> Initializer { + self.inner.initializer() + } +- +- fn read_to_end(&mut self, buf: &mut Vec) -> Result { +- let reservation_size = cmp::min(self.limit, 32) as usize; +- +- read_to_end_with_reservation(self, buf, reservation_size) +- } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -1933,13 +1876,11 @@ impl BufRead for Take { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -1963,14 +1904,14 @@ impl Iterator for Bytes { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -1995,13 +1936,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 2e19edf..66294a3 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -8,7 +8,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 8df961a..2b08122 100644 +--- a/util.rs ++++ b/util.rs +@@ -1,8 +1,9 @@ + #![allow(missing_copy_implementations)] + +-use fmt; +-use io::{self, Read, Initializer, Write, ErrorKind, BufRead}; +-use mem; ++use core::fmt; ++use io::{self, Read, Initializer, Write, ErrorKind}; ++use core::mem; ++#[cfg(feature="collections")] use io::BufRead; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -39,7 +40,6 @@ use mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -68,7 +68,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -88,10 +87,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -101,7 +98,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -109,7 +107,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -122,7 +119,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -139,10 +135,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -158,7 +152,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -171,7 +164,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -188,10 +180,8 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } +@@ -199,7 +189,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/eca11b99a7d25e4e6573472a16537c1aacb5d5e1.patch b/patches/eca11b99a7d25e4e6573472a16537c1aacb5d5e1.patch new file mode 100644 index 0000000..51bba96 --- /dev/null +++ b/patches/eca11b99a7d25e4e6573472a16537c1aacb5d5e1.patch @@ -0,0 +1,1600 @@ +diff --git a/buffered.rs b/buffered.rs +index e26e6d3..c754cf1 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -10,13 +10,13 @@ + + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use io::prelude::*; + +-use cmp; +-use error; +-use fmt; ++use core::cmp; ++use core::fmt; + use io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom}; +-use memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -52,7 +52,6 @@ use memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -76,7 +75,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -97,7 +95,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -130,7 +127,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -151,7 +147,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + + /// Returns a reference to the internally buffered data. +@@ -176,7 +171,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -199,7 +193,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + } + +@@ -208,7 +201,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -228,7 +220,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -251,7 +242,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -271,7 +261,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -281,7 +270,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -387,7 +375,6 @@ impl Seek for BufReader { + /// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -422,7 +409,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -437,7 +423,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -455,7 +440,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -504,7 +488,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -522,7 +505,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Unwraps this `BufWriter`, returning the underlying writer. +@@ -544,7 +526,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -553,7 +534,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -573,7 +553,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -583,7 +562,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -593,7 +571,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -632,7 +609,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -665,23 +641,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -752,7 +718,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -773,7 +738,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -794,7 +758,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -818,7 +781,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -841,7 +803,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -867,7 +828,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -878,7 +838,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -923,7 +882,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index 14f2015..1d60dac 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -10,8 +10,8 @@ + + use io::prelude::*; + +-use core::convert::TryInto; +-use cmp; ++#[cfg(feature="collections")] use core::convert::TryInto; ++use core::cmp; + use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + + /// A `Cursor` wraps an in-memory buffer and provides it with a +@@ -80,7 +80,6 @@ use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -103,7 +102,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -121,7 +119,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -137,7 +134,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -156,7 +152,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -178,7 +173,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -198,11 +192,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -223,17 +215,16 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -244,12 +235,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -262,6 +257,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result, buf: &[u8]) -> io::Result { + let pos: usize = (*pos_mut).try_into().map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -288,7 +284,6 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result Write for Cursor<&'a mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -297,7 +292,7 @@ impl<'a> Write for Cursor<&'a mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl<'a> Write for Cursor<&'a mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) +@@ -305,7 +300,7 @@ impl<'a> Write for Cursor<&'a mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) +@@ -313,8 +308,8 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) +diff --git a/error.rs b/error.rs +index 386de08..4a9559a 100644 +--- a/error.rs ++++ b/error.rs +@@ -8,11 +8,16 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use error; +-use fmt; +-use result; +-use sys; +-use convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -48,7 +53,6 @@ use convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -62,12 +66,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -77,13 +79,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -95,48 +100,35 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + #[non_exhaustive] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -148,10 +140,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -162,15 +152,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -179,7 +166,6 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + } + +@@ -210,7 +196,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + /// Converts an [`ErrorKind`] into an [`Error`]. + /// +@@ -252,14 +237,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -268,24 +252,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -311,7 +277,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -342,7 +307,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -376,12 +340,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(dyn error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -447,12 +410,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -481,8 +443,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -508,10 +469,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -523,22 +483,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -546,24 +502,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- fn cause(&self) -> Option<&dyn error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index fe1179a..452b8b7 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -8,15 +8,18 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use cmp; +-use io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind}; +-use fmt; +-use mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use io::BufRead; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, R: Read + ?Sized> Read for &'a mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -28,11 +31,13 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -43,7 +48,6 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, W: Write + ?Sized> Write for &'a mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -61,12 +65,11 @@ impl<'a, W: Write + ?Sized> Write for &'a mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, S: Seek + ?Sized> Seek for &'a mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -85,7 +88,7 @@ impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -97,11 +100,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -112,7 +117,7 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -130,12 +135,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -161,7 +166,6 @@ impl BufRead for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Read for &'a [u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -207,6 +211,7 @@ impl<'a> Read for &'a [u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -216,7 +221,7 @@ impl<'a> Read for &'a [u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a> BufRead for &'a [u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -230,7 +235,6 @@ impl<'a> BufRead for &'a [u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Write for &'a mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -256,7 +260,7 @@ impl<'a> Write for &'a mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +diff --git a/mod.rs b/mod.rs +index e263db2..2176464 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -267,47 +267,36 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use cmp; +-use fmt; +-use str; +-use memchr; +-use ptr; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::cmp; ++use core::fmt; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++use core::ptr; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl<'a> Drop for Guard<'a> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -332,6 +321,7 @@ impl<'a> Drop for Guard<'a> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -359,10 +349,12 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + read_to_end_with_reservation(r, buf, 32) + } + ++#[cfg(feature="collections")] + fn read_to_end_with_reservation(r: &mut R, + buf: &mut Vec, + reservation_size: usize) -> Result +@@ -469,7 +461,6 @@ fn read_to_end_with_reservation(r: &mut R, + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -526,7 +517,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Determines if this `Read`er can work with buffers of uninitialized +@@ -551,7 +541,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -604,7 +593,7 @@ pub trait Read { + /// file.) + /// + /// [`std::fs::read`]: ../fs/fn.read.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -647,7 +636,7 @@ pub trait Read { + /// reading from a file.) + /// + /// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -710,7 +699,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -762,7 +750,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -799,7 +786,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } +@@ -834,7 +820,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -870,20 +855,17 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -897,21 +879,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -954,7 +933,6 @@ impl Initializer { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this object, returning how many bytes were written. +@@ -1003,7 +981,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Flush this output stream, ensuring that all intermediately buffered +@@ -1029,7 +1006,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this write. +@@ -1062,7 +1038,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1114,7 +1089,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1170,7 +1144,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1200,7 +1173,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1216,7 +1188,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + } + +@@ -1226,29 +1197,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Set the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Set the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Set the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1328,7 +1296,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Returns the contents of the internal buffer, filling it with more data + /// from the inner reader if it is empty. +@@ -1374,7 +1342,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1396,7 +1363,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1452,7 +1418,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1511,7 +1476,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1552,7 +1516,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1591,7 +1554,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1603,7 +1565,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1629,7 +1590,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1652,7 +1612,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1679,13 +1638,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1695,7 +1652,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1717,7 +1673,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1744,7 +1700,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -1779,7 +1734,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -1805,7 +1759,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "take_set_limit", since = "1.27.0")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -1830,7 +1783,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -1855,7 +1807,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -1884,13 +1835,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -1907,15 +1856,9 @@ impl Read for Take { + unsafe fn initializer(&self) -> Initializer { + self.inner.initializer() + } +- +- fn read_to_end(&mut self, buf: &mut Vec) -> Result { +- let reservation_size = cmp::min(self.limit, 32) as usize; +- +- read_to_end_with_reservation(self, buf, reservation_size) +- } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -1954,13 +1897,11 @@ fn read_one_byte(reader: &mut dyn Read) -> Option> { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -1976,14 +1917,14 @@ impl Iterator for Bytes { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -2008,13 +1949,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 8772d0f..49d66c9 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -18,7 +18,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 12995d0..397eef4 100644 +--- a/util.rs ++++ b/util.rs +@@ -10,9 +10,10 @@ + + #![allow(missing_copy_implementations)] + +-use fmt; +-use io::{self, Read, Initializer, Write, ErrorKind, BufRead}; +-use mem; ++use core::fmt; ++use io::{self, Read, Initializer, Write, ErrorKind}; ++use core::mem; ++#[cfg(feature="collections")] use io::BufRead; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -49,7 +50,6 @@ use mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -78,7 +78,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -98,10 +97,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -111,7 +108,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -119,7 +117,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -132,7 +129,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -149,10 +145,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -168,7 +162,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -181,7 +174,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -198,10 +190,8 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } +@@ -209,7 +199,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/ee89c088b057affb5bdb96195e107a218b64b1c5.patch b/patches/ee89c088b057affb5bdb96195e107a218b64b1c5.patch new file mode 100644 index 0000000..a2a0160 --- /dev/null +++ b/patches/ee89c088b057affb5bdb96195e107a218b64b1c5.patch @@ -0,0 +1,1608 @@ +diff --git a/buffered.rs b/buffered.rs +index 7ede050..2359343 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -10,13 +10,13 @@ + + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use io::prelude::*; + +-use cmp; +-use error; +-use fmt; ++use core::cmp; ++use core::fmt; + use io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom}; +-use memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -52,7 +52,6 @@ use memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -76,7 +75,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -97,7 +95,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -130,7 +127,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -151,7 +147,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + + /// Returns a reference to the internally buffered data. +@@ -176,7 +171,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -199,7 +193,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + } + +@@ -208,7 +201,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -228,7 +220,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -251,7 +242,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -271,7 +261,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -281,7 +270,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -387,7 +375,6 @@ impl Seek for BufReader { + /// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -422,7 +409,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -437,7 +423,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -455,7 +440,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -504,7 +488,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -522,7 +505,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Returns a reference to the internally buffered data. +@@ -539,7 +521,6 @@ impl BufWriter { + /// // See how many bytes are currently buffered + /// let bytes_buffered = buf_writer.buffer().len(); + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf + } +@@ -563,7 +544,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -572,7 +552,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -592,7 +571,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -602,7 +580,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -612,7 +589,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -651,7 +627,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -684,23 +659,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -771,7 +736,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -792,7 +756,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -813,7 +776,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -837,7 +799,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -860,7 +821,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -886,7 +846,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -897,7 +856,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -942,7 +900,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index f7a9033..d97489f 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -10,8 +10,8 @@ + + use io::prelude::*; + +-use core::convert::TryInto; +-use cmp; ++#[cfg(feature="collections")] use core::convert::TryInto; ++use core::cmp; + use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + + /// A `Cursor` wraps an in-memory buffer and provides it with a +@@ -80,7 +80,6 @@ use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -103,7 +102,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -121,7 +119,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -137,7 +134,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -156,7 +152,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -178,7 +173,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -198,11 +192,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -223,17 +215,16 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -244,12 +235,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -262,6 +257,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result, buf: &[u8]) -> io::Result { + let pos: usize = (*pos_mut).try_into().map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -288,7 +284,6 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result Write for Cursor<&'a mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -297,7 +292,7 @@ impl<'a> Write for Cursor<&'a mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl<'a> Write for Cursor<&'a mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) +@@ -305,7 +300,7 @@ impl<'a> Write for Cursor<&'a mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) +@@ -313,8 +308,8 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) +diff --git a/error.rs b/error.rs +index 32e2996..b4455e3 100644 +--- a/error.rs ++++ b/error.rs +@@ -8,11 +8,16 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use error; +-use fmt; +-use result; +-use sys; +-use convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -48,7 +53,6 @@ use convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -62,12 +66,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -77,13 +79,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -95,48 +100,35 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + #[non_exhaustive] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -148,10 +140,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -162,15 +152,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -179,7 +166,6 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + } + +@@ -210,7 +196,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + /// Converts an [`ErrorKind`] into an [`Error`]. + /// +@@ -252,14 +237,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -268,24 +252,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -311,7 +277,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -342,7 +307,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -376,12 +340,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(dyn error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -447,12 +410,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -481,8 +443,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -508,10 +469,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -523,22 +483,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -546,24 +502,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- fn cause(&self) -> Option<&dyn error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index fe1179a..452b8b7 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -8,15 +8,18 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use cmp; +-use io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind}; +-use fmt; +-use mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use io::BufRead; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, R: Read + ?Sized> Read for &'a mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -28,11 +31,13 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -43,7 +48,6 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, W: Write + ?Sized> Write for &'a mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -61,12 +65,11 @@ impl<'a, W: Write + ?Sized> Write for &'a mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, S: Seek + ?Sized> Seek for &'a mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -85,7 +88,7 @@ impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -97,11 +100,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -112,7 +117,7 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -130,12 +135,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -161,7 +166,6 @@ impl BufRead for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Read for &'a [u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -207,6 +211,7 @@ impl<'a> Read for &'a [u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -216,7 +221,7 @@ impl<'a> Read for &'a [u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a> BufRead for &'a [u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -230,7 +235,6 @@ impl<'a> BufRead for &'a [u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Write for &'a mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -256,7 +260,7 @@ impl<'a> Write for &'a mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +diff --git a/mod.rs b/mod.rs +index dc97701..6ea0b47 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -267,47 +267,36 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use cmp; +-use fmt; +-use str; +-use memchr; +-use ptr; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::cmp; ++use core::fmt; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++use core::ptr; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl<'a> Drop for Guard<'a> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -332,6 +321,7 @@ impl<'a> Drop for Guard<'a> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -359,10 +349,12 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + read_to_end_with_reservation(r, buf, 32) + } + ++#[cfg(feature="collections")] + fn read_to_end_with_reservation(r: &mut R, + buf: &mut Vec, + reservation_size: usize) -> Result +@@ -469,7 +461,6 @@ fn read_to_end_with_reservation(r: &mut R, + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -526,7 +517,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Determines if this `Read`er can work with buffers of uninitialized +@@ -551,7 +541,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -604,7 +593,7 @@ pub trait Read { + /// file.) + /// + /// [`std::fs::read`]: ../fs/fn.read.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -647,7 +636,7 @@ pub trait Read { + /// reading from a file.) + /// + /// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -710,7 +699,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -762,7 +750,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -799,7 +786,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } +@@ -834,7 +820,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -870,20 +855,17 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -897,21 +879,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -954,7 +933,6 @@ impl Initializer { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this object, returning how many bytes were written. +@@ -1003,7 +981,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Flush this output stream, ensuring that all intermediately buffered +@@ -1029,7 +1006,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this write. +@@ -1062,7 +1038,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1114,7 +1089,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1170,7 +1144,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1200,7 +1173,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1216,7 +1188,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + } + +@@ -1226,29 +1197,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Set the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Set the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Set the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1328,7 +1296,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Returns the contents of the internal buffer, filling it with more data + /// from the inner reader if it is empty. +@@ -1374,7 +1342,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1396,7 +1363,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1452,7 +1418,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1511,7 +1476,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1552,7 +1516,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1591,7 +1554,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1603,7 +1565,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1629,7 +1590,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1652,7 +1612,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1679,13 +1638,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1695,7 +1652,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1717,7 +1673,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1744,7 +1700,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -1779,7 +1734,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -1805,7 +1759,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "take_set_limit", since = "1.27.0")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -1830,7 +1783,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -1855,7 +1807,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -1884,13 +1835,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -1907,15 +1856,9 @@ impl Read for Take { + unsafe fn initializer(&self) -> Initializer { + self.inner.initializer() + } +- +- fn read_to_end(&mut self, buf: &mut Vec) -> Result { +- let reservation_size = cmp::min(self.limit, 32) as usize; +- +- read_to_end_with_reservation(self, buf, reservation_size) +- } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -1954,13 +1897,11 @@ fn read_one_byte(reader: &mut dyn Read) -> Option> { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -1976,14 +1917,14 @@ impl Iterator for Bytes { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -2008,13 +1949,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 8772d0f..49d66c9 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -18,7 +18,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 12995d0..397eef4 100644 +--- a/util.rs ++++ b/util.rs +@@ -10,9 +10,10 @@ + + #![allow(missing_copy_implementations)] + +-use fmt; +-use io::{self, Read, Initializer, Write, ErrorKind, BufRead}; +-use mem; ++use core::fmt; ++use io::{self, Read, Initializer, Write, ErrorKind}; ++use core::mem; ++#[cfg(feature="collections")] use io::BufRead; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -49,7 +50,6 @@ use mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -78,7 +78,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -98,10 +97,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -111,7 +108,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -119,7 +117,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -132,7 +129,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -149,10 +145,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -168,7 +162,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -181,7 +174,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -198,10 +190,8 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } +@@ -209,7 +199,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/f22dca0a1bef4141e75326caacc3cd59f3d5be8e.patch b/patches/f22dca0a1bef4141e75326caacc3cd59f3d5be8e.patch new file mode 100644 index 0000000..0390641 --- /dev/null +++ b/patches/f22dca0a1bef4141e75326caacc3cd59f3d5be8e.patch @@ -0,0 +1,1869 @@ +diff --git a/buffered.rs b/buffered.rs +index a14c10d..3e78c01 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -1,12 +1,12 @@ + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use crate::io::prelude::*; + +-use crate::cmp; +-use crate::error; +-use crate::fmt; ++use core::cmp; ++use core::fmt; + use crate::io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom, IoVec, IoVecMut}; +-use crate::memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -42,7 +42,6 @@ use crate::memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -66,7 +65,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -87,7 +85,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -122,7 +119,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -143,7 +139,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + + /// Returns a reference to the internally buffered data. +@@ -168,7 +163,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -191,7 +185,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + } + +@@ -200,7 +193,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -220,7 +212,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -256,7 +247,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -276,7 +266,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -286,7 +275,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -395,7 +383,6 @@ impl Seek for BufReader { + /// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -430,7 +417,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -445,7 +431,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -463,7 +448,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -512,7 +496,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -530,7 +513,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Returns a reference to the internally buffered data. +@@ -547,7 +529,6 @@ impl BufWriter { + /// // See how many bytes are currently buffered + /// let bytes_buffered = buf_writer.buffer().len(); + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf + } +@@ -571,7 +552,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -580,7 +560,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -616,7 +595,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -626,7 +604,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -636,7 +613,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -675,7 +651,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -708,23 +683,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -795,7 +760,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -816,7 +780,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -837,7 +800,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -861,7 +823,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -884,7 +845,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -910,7 +870,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -921,7 +880,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -966,7 +924,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index 873da08..3d39e57 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -1,9 +1,10 @@ + use crate::io::prelude::*; + +-use crate::cmp; +-use crate::io::{self, Initializer, SeekFrom, Error, ErrorKind, IoVec, IoVecMut}; ++use core::cmp; ++use crate::io::{self, Initializer, SeekFrom, Error, ErrorKind}; ++#[cfg(feature="collections")] use crate::io::{IoVec, IoVecMut}; + +-use core::convert::TryInto; ++#[cfg(feature="collections")] use core::convert::TryInto; + + /// A `Cursor` wraps an in-memory buffer and provides it with a + /// [`Seek`] implementation. +@@ -71,7 +72,6 @@ use core::convert::TryInto; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -94,7 +94,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -112,7 +111,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -128,7 +126,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -147,7 +144,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -169,7 +165,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -189,11 +184,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -214,14 +207,14 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + ++ #[cfg(feature="collections")] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let mut nread = 0; + for buf in bufs { +@@ -236,7 +229,7 @@ impl Read for Cursor where T: AsRef<[u8]> { + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -247,12 +240,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -264,6 +261,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result, buf: &[u8]) -> io::Result { + let pos: usize = (*pos_mut).try_into().map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -308,6 +307,7 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result, +@@ -321,13 +321,13 @@ fn vec_write_vectored( + Ok(nwritten) + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Cursor<&mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, self.inner, buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + slice_write_vectored(&mut self.pos, self.inner, bufs) +@@ -336,12 +336,13 @@ impl Write for Cursor<&mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl Write for Cursor<&mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) + } + ++ #[cfg(feature="collections")] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + vec_write_vectored(&mut self.pos, self.inner, bufs) + } +@@ -349,12 +350,13 @@ impl Write for Cursor<&mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) + } + ++ #[cfg(feature="collections")] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + vec_write_vectored(&mut self.pos, &mut self.inner, bufs) + } +@@ -362,13 +364,14 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + slice_write_vectored(&mut self.pos, &mut self.inner, bufs) +diff --git a/error.rs b/error.rs +index fdc5625..e4ce8b5 100644 +--- a/error.rs ++++ b/error.rs +@@ -1,8 +1,13 @@ +-use crate::error; +-use crate::fmt; +-use crate::result; +-use crate::sys; +-use crate::convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -38,7 +43,6 @@ use crate::convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -52,12 +56,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -67,13 +69,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -85,48 +90,35 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + #[non_exhaustive] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -138,10 +130,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -152,15 +142,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -169,7 +156,6 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + } + +@@ -200,7 +186,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + /// Converts an [`ErrorKind`] into an [`Error`]. + /// +@@ -245,14 +230,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -261,24 +245,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -304,7 +270,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -335,7 +300,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -369,12 +333,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(dyn error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -440,12 +403,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -474,8 +436,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -501,10 +462,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -516,22 +476,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -539,25 +495,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- #[allow(deprecated)] +- fn cause(&self) -> Option<&dyn error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index b286e40..7472d9c 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -1,19 +1,22 @@ +-use crate::cmp; +-use crate::io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind, IoVecMut, +- IoVec}; +-use crate::fmt; +-use crate::mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use crate::io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use crate::io::{BufRead, IoVecMut, IoVec}; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for &mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { + (**self).read(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + (**self).read_vectored(bufs) +@@ -24,11 +27,13 @@ impl Read for &mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -39,11 +44,11 @@ impl Read for &mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for &mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + (**self).write_vectored(bufs) +@@ -62,12 +67,11 @@ impl Write for &mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for &mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for &mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -86,13 +90,14 @@ impl BufRead for &mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { + (**self).read(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + (**self).read_vectored(bufs) +@@ -103,11 +108,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -118,11 +125,12 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + (**self).write_vectored(bufs) +@@ -141,12 +149,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -186,7 +194,6 @@ impl Write for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for &[u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -206,6 +213,7 @@ impl Read for &[u8] { + Ok(amt) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let mut nread = 0; +@@ -245,6 +253,7 @@ impl Read for &[u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -254,7 +263,7 @@ impl Read for &[u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for &[u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -268,7 +277,6 @@ impl BufRead for &[u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for &mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -279,6 +287,7 @@ impl Write for &mut [u8] { + Ok(amt) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + let mut nwritten = 0; +@@ -307,7 +316,7 @@ impl Write for &mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -315,6 +324,7 @@ impl Write for Vec { + Ok(buf.len()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + let len = bufs.iter().map(|b| b.len()).sum(); +diff --git a/mod.rs b/mod.rs +index e3e2754..400eca6 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -257,50 +257,38 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use crate::cmp; +-use crate::fmt; +-use crate::slice; +-use crate::str; +-use crate::memchr; +-use crate::ops::{Deref, DerefMut}; +-use crate::ptr; +-use crate::sys; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::cmp; ++use core::fmt; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++#[cfg(feature="collections")] use core::ops::{Deref, DerefMut}; ++use core::ptr; ++use core::slice; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = crate::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl Drop for Guard<'_> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -325,6 +313,7 @@ impl Drop for Guard<'_> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -352,10 +341,12 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + read_to_end_with_reservation(r, buf, 32) + } + ++#[cfg(feature="collections")] + fn read_to_end_with_reservation(r: &mut R, + buf: &mut Vec, + reservation_size: usize) -> Result +@@ -462,7 +453,6 @@ fn read_to_end_with_reservation(r: &mut R, + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -519,7 +509,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Like `read`, except that it reads into a slice of buffers. +@@ -530,7 +519,7 @@ pub trait Read { + /// + /// The default implementation simply passes the first nonempty buffer to + /// `read`. +- #[unstable(feature = "iovec", issue = "58452")] ++ #[cfg(feature="collections")] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> Result { + match bufs.iter_mut().find(|b| !b.is_empty()) { + Some(buf) => self.read(buf), +@@ -560,7 +549,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -613,7 +601,7 @@ pub trait Read { + /// file.) + /// + /// [`std::fs::read`]: ../fs/fn.read.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -656,7 +644,7 @@ pub trait Read { + /// reading from a file.) + /// + /// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -719,7 +707,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -771,7 +758,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -808,7 +794,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } +@@ -843,7 +828,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -879,42 +863,77 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + ++#[cfg(feature="collections")] ++pub struct IoVecBuffer<'a>(&'a [u8]); ++ ++#[cfg(feature="collections")] ++impl<'a> IoVecBuffer<'a> { ++ #[inline] ++ pub fn new(buf: &'a [u8]) -> IoVecBuffer<'a> { ++ IoVecBuffer(buf) ++ } ++ ++ #[inline] ++ pub fn as_slice(&self) -> &[u8] { ++ self.0 ++ } ++} ++#[cfg(feature="collections")] ++pub struct IoVecMutBuffer<'a>(&'a mut [u8]); ++ ++#[cfg(feature="collections")] ++impl<'a> IoVecMutBuffer<'a> { ++ #[inline] ++ pub fn new(buf: &'a mut [u8]) -> IoVecMutBuffer<'a> { ++ IoVecMutBuffer(buf) ++ } ++ ++ #[inline] ++ pub fn as_slice(&self) -> &[u8] { ++ self.0 ++ } ++ ++ #[inline] ++ pub fn as_mut_slice(&mut self) -> &mut [u8] { ++ self.0 ++ } ++} ++ + /// A buffer type used with `Read::read_vectored`. + /// + /// It is semantically a wrapper around an `&mut [u8]`, but is guaranteed to be + /// ABI compatible with the `iovec` type on Unix platforms and `WSABUF` on + /// Windows. +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + #[repr(transparent)] +-pub struct IoVecMut<'a>(sys::io::IoVecMut<'a>); ++pub struct IoVecMut<'a>(IoVecMutBuffer<'a>); + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> fmt::Debug for IoVecMut<'a> { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(self.0.as_slice(), fmt) + } + } + ++#[cfg(feature="collections")] + impl<'a> IoVecMut<'a> { + /// Creates a new `IoVecMut` wrapping a byte slice. + /// + /// # Panics + /// + /// Panics on Windows if the slice is larger than 4GB. +- #[unstable(feature = "iovec", issue = "58452")] + #[inline] + pub fn new(buf: &'a mut [u8]) -> IoVecMut<'a> { +- IoVecMut(sys::io::IoVecMut::new(buf)) ++ IoVecMut(IoVecMutBuffer::new(buf)) + } + } + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> Deref for IoVecMut<'a> { + type Target = [u8]; + +@@ -924,7 +943,7 @@ impl<'a> Deref for IoVecMut<'a> { + } + } + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> DerefMut for IoVecMut<'a> { + #[inline] + fn deref_mut(&mut self) -> &mut [u8] { +@@ -937,31 +956,31 @@ impl<'a> DerefMut for IoVecMut<'a> { + /// It is semantically a wrapper around an `&[u8]`, but is guaranteed to be + /// ABI compatible with the `iovec` type on Unix platforms and `WSABUF` on + /// Windows. +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + #[repr(transparent)] +-pub struct IoVec<'a>(sys::io::IoVec<'a>); ++pub struct IoVec<'a>(IoVecBuffer<'a>); + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> fmt::Debug for IoVec<'a> { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(self.0.as_slice(), fmt) + } + } + ++#[cfg(feature="collections")] + impl<'a> IoVec<'a> { + /// Creates a new `IoVec` wrapping a byte slice. + /// + /// # Panics + /// + /// Panics on Windows if the slice is larger than 4GB. +- #[unstable(feature = "iovec", issue = "58452")] + #[inline] + pub fn new(buf: &'a [u8]) -> IoVec<'a> { +- IoVec(sys::io::IoVec::new(buf)) ++ IoVec(IoVecBuffer::new(buf)) + } + } + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> Deref for IoVec<'a> { + type Target = [u8]; + +@@ -972,13 +991,11 @@ impl<'a> Deref for IoVec<'a> { + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -992,21 +1009,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -1049,7 +1063,6 @@ impl Initializer { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this writer, returning how many bytes were written. +@@ -1098,7 +1111,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Like `write`, except that it writes from a slice of buffers. +@@ -1109,7 +1121,7 @@ pub trait Write { + /// + /// The default implementation simply passes the first nonempty buffer to + /// `write`. +- #[unstable(feature = "iovec", issue = "58452")] ++ #[cfg(feature="collections")] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> Result { + match bufs.iter().find(|b| !b.is_empty()) { + Some(buf) => self.write(buf), +@@ -1140,7 +1152,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this writer. +@@ -1173,7 +1184,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1225,7 +1235,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1281,7 +1290,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1311,7 +1319,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1327,7 +1334,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + } + +@@ -1337,29 +1343,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Sets the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Sets the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Sets the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1439,7 +1442,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Returns the contents of the internal buffer, filling it with more data + /// from the inner reader if it is empty. +@@ -1485,7 +1488,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1507,7 +1509,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1563,7 +1564,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1622,7 +1622,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1663,7 +1662,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1702,7 +1700,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1714,7 +1711,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1740,7 +1736,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1763,7 +1758,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1790,13 +1784,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1806,7 +1798,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1818,6 +1809,7 @@ impl Read for Chain { + self.second.read(buf) + } + ++ #[cfg(feature="collections")] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> Result { + if !self.done_first { + match self.first.read_vectored(bufs)? { +@@ -1838,7 +1830,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1865,7 +1857,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -1900,7 +1891,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -1926,7 +1916,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "take_set_limit", since = "1.27.0")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -1951,7 +1940,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -1976,7 +1964,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -2005,13 +1992,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -2028,15 +2013,9 @@ impl Read for Take { + unsafe fn initializer(&self) -> Initializer { + self.inner.initializer() + } +- +- fn read_to_end(&mut self, buf: &mut Vec) -> Result { +- let reservation_size = cmp::min(self.limit, 32) as usize; +- +- read_to_end_with_reservation(self, buf, reservation_size) +- } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -2063,13 +2042,11 @@ impl BufRead for Take { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -2093,14 +2070,14 @@ impl Iterator for Bytes { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -2125,13 +2102,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 2e19edf..66294a3 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -8,7 +8,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 6aaf8f1..447ce47 100644 +--- a/util.rs ++++ b/util.rs +@@ -1,8 +1,9 @@ + #![allow(missing_copy_implementations)] + +-use crate::fmt; +-use crate::io::{self, Read, Initializer, Write, ErrorKind, BufRead, IoVec, IoVecMut}; +-use crate::mem; ++use core::fmt; ++use crate::io::{self, Read, Initializer, Write, ErrorKind}; ++#[cfg(feature="collections")] use crate::io::{BufRead, IoVec, IoVecMut}; ++use core::mem; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -39,7 +40,6 @@ use crate::mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -68,7 +68,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -88,10 +87,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -101,7 +98,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -109,7 +107,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -122,7 +119,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -139,10 +135,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -152,6 +146,7 @@ impl Read for Repeat { + Ok(buf.len()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let mut nwritten = 0; +@@ -167,7 +162,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -180,7 +174,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -197,14 +190,13 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + let total_len = bufs.iter().map(|b| b.len()).sum(); +@@ -215,7 +207,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/fb162e69449b423c5aed0d9c39f6c046fa300c30.patch b/patches/fb162e69449b423c5aed0d9c39f6c046fa300c30.patch new file mode 100644 index 0000000..be181ac --- /dev/null +++ b/patches/fb162e69449b423c5aed0d9c39f6c046fa300c30.patch @@ -0,0 +1,1868 @@ +diff --git a/buffered.rs b/buffered.rs +index 6383a14..d612c95 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -1,12 +1,12 @@ + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use io::prelude::*; + +-use cmp; +-use error; +-use fmt; ++use core::cmp; ++use core::fmt; + use io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom, IoVec, IoVecMut}; +-use memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -42,7 +42,6 @@ use memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -66,7 +65,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -87,7 +85,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -120,7 +117,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -141,7 +137,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + + /// Returns a reference to the internally buffered data. +@@ -166,7 +161,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -189,7 +183,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + } + +@@ -198,7 +191,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -218,7 +210,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -254,7 +245,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -274,7 +264,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -284,7 +273,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -393,7 +381,6 @@ impl Seek for BufReader { + /// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -428,7 +415,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -443,7 +429,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -461,7 +446,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -510,7 +494,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -528,7 +511,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Returns a reference to the internally buffered data. +@@ -545,7 +527,6 @@ impl BufWriter { + /// // See how many bytes are currently buffered + /// let bytes_buffered = buf_writer.buffer().len(); + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf + } +@@ -569,7 +550,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -578,7 +558,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -614,7 +593,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -624,7 +602,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -634,7 +611,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -673,7 +649,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -706,23 +681,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -793,7 +758,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -814,7 +778,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -835,7 +798,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -859,7 +821,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -882,7 +843,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -908,7 +868,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -919,7 +878,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -964,7 +922,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index 577a115..8813aba 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -1,8 +1,9 @@ + use io::prelude::*; + +-use core::convert::TryInto; +-use cmp; +-use io::{self, Initializer, SeekFrom, Error, ErrorKind, IoVec, IoVecMut}; ++#[cfg(feature="collections")] use core::convert::TryInto; ++use core::cmp; ++use io::{self, Initializer, SeekFrom, Error, ErrorKind}; ++#[cfg(feature="collections")] use io::{IoVec, IoVecMut}; + + /// A `Cursor` wraps an in-memory buffer and provides it with a + /// [`Seek`] implementation. +@@ -70,7 +71,6 @@ use io::{self, Initializer, SeekFrom, Error, ErrorKind, IoVec, IoVecMut}; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -93,7 +93,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -111,7 +110,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -127,7 +125,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -146,7 +143,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -168,7 +164,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -188,11 +183,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -213,14 +206,14 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + ++ #[cfg(feature="collections")] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let mut nread = 0; + for buf in bufs { +@@ -235,7 +228,7 @@ impl Read for Cursor where T: AsRef<[u8]> { + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -246,12 +239,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -263,6 +260,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result, buf: &[u8]) -> io::Result { + let pos: usize = (*pos_mut).try_into().map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -307,6 +306,7 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result, +@@ -320,13 +320,13 @@ fn vec_write_vectored( + Ok(nwritten) + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Cursor<&mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, self.inner, buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + slice_write_vectored(&mut self.pos, self.inner, bufs) +@@ -335,12 +335,13 @@ impl Write for Cursor<&mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl Write for Cursor<&mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) + } + ++ #[cfg(feature="collections")] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + vec_write_vectored(&mut self.pos, self.inner, bufs) + } +@@ -348,12 +349,13 @@ impl Write for Cursor<&mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) + } + ++ #[cfg(feature="collections")] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + vec_write_vectored(&mut self.pos, &mut self.inner, bufs) + } +@@ -361,13 +363,14 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + slice_write_vectored(&mut self.pos, &mut self.inner, bufs) +diff --git a/error.rs b/error.rs +index e9b4f60..31c0ff1 100644 +--- a/error.rs ++++ b/error.rs +@@ -1,8 +1,13 @@ +-use error; +-use fmt; +-use result; +-use sys; +-use convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -38,7 +43,6 @@ use convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -52,12 +56,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -67,13 +69,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -85,48 +90,35 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + #[non_exhaustive] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -138,10 +130,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -152,15 +142,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -169,7 +156,6 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + } + +@@ -200,7 +186,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + /// Converts an [`ErrorKind`] into an [`Error`]. + /// +@@ -245,14 +230,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -261,24 +245,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -304,7 +270,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -335,7 +300,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -369,12 +333,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(dyn error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -440,12 +403,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -474,8 +436,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -501,10 +462,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -516,22 +476,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -539,25 +495,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- #[allow(deprecated)] +- fn cause(&self) -> Option<&dyn error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index aa8db17..aaf1b00 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -1,19 +1,22 @@ +-use cmp; +-use io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind, IoVecMut, +- IoVec}; +-use fmt; +-use mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use io::{BufRead, IoVecMut, IoVec}; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for &mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { + (**self).read(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + (**self).read_vectored(bufs) +@@ -24,11 +27,13 @@ impl Read for &mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -39,11 +44,11 @@ impl Read for &mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for &mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + (**self).write_vectored(bufs) +@@ -62,12 +67,11 @@ impl Write for &mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for &mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for &mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -86,13 +90,14 @@ impl BufRead for &mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { + (**self).read(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + (**self).read_vectored(bufs) +@@ -103,11 +108,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -118,11 +125,12 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + (**self).write_vectored(bufs) +@@ -141,12 +149,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -172,7 +180,6 @@ impl BufRead for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for &[u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -192,6 +199,7 @@ impl Read for &[u8] { + Ok(amt) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let mut nread = 0; +@@ -231,6 +239,7 @@ impl Read for &[u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -240,7 +249,7 @@ impl Read for &[u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for &[u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -254,7 +263,6 @@ impl BufRead for &[u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for &mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -265,6 +273,7 @@ impl Write for &mut [u8] { + Ok(amt) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + let mut nwritten = 0; +@@ -293,7 +302,7 @@ impl Write for &mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -301,6 +310,7 @@ impl Write for Vec { + Ok(buf.len()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + let len = bufs.iter().map(|b| b.len()).sum(); +diff --git a/mod.rs b/mod.rs +index 12b158e..90064c4 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -257,50 +257,38 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use cmp; +-use fmt; +-use slice; +-use str; +-use memchr; +-use ops::{Deref, DerefMut}; +-use ptr; +-use sys; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::cmp; ++use core::fmt; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++#[cfg(feature="collections")] use core::ops::{Deref, DerefMut}; ++use core::ptr; ++use core::slice; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl Drop for Guard<'_> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -325,6 +313,7 @@ impl Drop for Guard<'_> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -352,10 +341,12 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + read_to_end_with_reservation(r, buf, 32) + } + ++#[cfg(feature="collections")] + fn read_to_end_with_reservation(r: &mut R, + buf: &mut Vec, + reservation_size: usize) -> Result +@@ -462,7 +453,6 @@ fn read_to_end_with_reservation(r: &mut R, + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -519,7 +509,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Like `read`, except that it reads into a slice of buffers. +@@ -530,7 +519,7 @@ pub trait Read { + /// + /// The default implementation simply passes the first nonempty buffer to + /// `read`. +- #[unstable(feature = "iovec", issue = "58452")] ++ #[cfg(feature="collections")] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> Result { + match bufs.iter_mut().find(|b| !b.is_empty()) { + Some(buf) => self.read(buf), +@@ -560,7 +549,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -613,7 +601,7 @@ pub trait Read { + /// file.) + /// + /// [`std::fs::read`]: ../fs/fn.read.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -656,7 +644,7 @@ pub trait Read { + /// reading from a file.) + /// + /// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -719,7 +707,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -771,7 +758,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -808,7 +794,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } +@@ -843,7 +828,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -879,42 +863,77 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + ++#[cfg(feature="collections")] ++pub struct IoVecBuffer<'a>(&'a [u8]); ++ ++#[cfg(feature="collections")] ++impl<'a> IoVecBuffer<'a> { ++ #[inline] ++ pub fn new(buf: &'a [u8]) -> IoVecBuffer<'a> { ++ IoVecBuffer(buf) ++ } ++ ++ #[inline] ++ pub fn as_slice(&self) -> &[u8] { ++ self.0 ++ } ++} ++#[cfg(feature="collections")] ++pub struct IoVecMutBuffer<'a>(&'a mut [u8]); ++ ++#[cfg(feature="collections")] ++impl<'a> IoVecMutBuffer<'a> { ++ #[inline] ++ pub fn new(buf: &'a mut [u8]) -> IoVecMutBuffer<'a> { ++ IoVecMutBuffer(buf) ++ } ++ ++ #[inline] ++ pub fn as_slice(&self) -> &[u8] { ++ self.0 ++ } ++ ++ #[inline] ++ pub fn as_mut_slice(&mut self) -> &mut [u8] { ++ self.0 ++ } ++} ++ + /// A buffer type used with `Read::read_vectored`. + /// + /// It is semantically a wrapper around an `&mut [u8]`, but is guaranteed to be + /// ABI compatible with the `iovec` type on Unix platforms and `WSABUF` on + /// Windows. +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + #[repr(transparent)] +-pub struct IoVecMut<'a>(sys::io::IoVecMut<'a>); ++pub struct IoVecMut<'a>(IoVecMutBuffer<'a>); + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> fmt::Debug for IoVecMut<'a> { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(self.0.as_slice(), fmt) + } + } + ++#[cfg(feature="collections")] + impl<'a> IoVecMut<'a> { + /// Creates a new `IoVecMut` wrapping a byte slice. + /// + /// # Panics + /// + /// Panics on Windows if the slice is larger than 4GB. +- #[unstable(feature = "iovec", issue = "58452")] + #[inline] + pub fn new(buf: &'a mut [u8]) -> IoVecMut<'a> { +- IoVecMut(sys::io::IoVecMut::new(buf)) ++ IoVecMut(IoVecMutBuffer::new(buf)) + } + } + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> Deref for IoVecMut<'a> { + type Target = [u8]; + +@@ -924,7 +943,7 @@ impl<'a> Deref for IoVecMut<'a> { + } + } + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> DerefMut for IoVecMut<'a> { + #[inline] + fn deref_mut(&mut self) -> &mut [u8] { +@@ -937,31 +956,31 @@ impl<'a> DerefMut for IoVecMut<'a> { + /// It is semantically a wrapper around an `&[u8]`, but is guaranteed to be + /// ABI compatible with the `iovec` type on Unix platforms and `WSABUF` on + /// Windows. +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + #[repr(transparent)] +-pub struct IoVec<'a>(sys::io::IoVec<'a>); ++pub struct IoVec<'a>(IoVecBuffer<'a>); + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> fmt::Debug for IoVec<'a> { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(self.0.as_slice(), fmt) + } + } + ++#[cfg(feature="collections")] + impl<'a> IoVec<'a> { + /// Creates a new `IoVec` wrapping a byte slice. + /// + /// # Panics + /// + /// Panics on Windows if the slice is larger than 4GB. +- #[unstable(feature = "iovec", issue = "58452")] + #[inline] + pub fn new(buf: &'a [u8]) -> IoVec<'a> { +- IoVec(sys::io::IoVec::new(buf)) ++ IoVec(IoVecBuffer::new(buf)) + } + } + +-#[unstable(feature = "iovec", issue = "58452")] ++#[cfg(feature="collections")] + impl<'a> Deref for IoVec<'a> { + type Target = [u8]; + +@@ -972,13 +991,11 @@ impl<'a> Deref for IoVec<'a> { + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -992,21 +1009,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -1049,7 +1063,6 @@ impl Initializer { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this writer, returning how many bytes were written. +@@ -1098,7 +1111,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Like `write`, except that it writes from a slice of buffers. +@@ -1109,7 +1121,7 @@ pub trait Write { + /// + /// The default implementation simply passes the first nonempty buffer to + /// `write`. +- #[unstable(feature = "iovec", issue = "58452")] ++ #[cfg(feature="collections")] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> Result { + match bufs.iter().find(|b| !b.is_empty()) { + Some(buf) => self.write(buf), +@@ -1140,7 +1152,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this writer. +@@ -1173,7 +1184,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1225,7 +1235,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1281,7 +1290,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1311,7 +1319,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1327,7 +1334,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + } + +@@ -1337,29 +1343,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Sets the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Sets the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Sets the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1439,7 +1442,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Returns the contents of the internal buffer, filling it with more data + /// from the inner reader if it is empty. +@@ -1485,7 +1488,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1507,7 +1509,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1563,7 +1564,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1622,7 +1622,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1663,7 +1662,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1702,7 +1700,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1714,7 +1711,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1740,7 +1736,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1763,7 +1758,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1790,13 +1784,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1806,7 +1798,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1818,6 +1809,7 @@ impl Read for Chain { + self.second.read(buf) + } + ++ #[cfg(feature="collections")] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> Result { + if !self.done_first { + match self.first.read_vectored(bufs)? { +@@ -1838,7 +1830,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1865,7 +1857,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -1900,7 +1891,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -1926,7 +1916,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "take_set_limit", since = "1.27.0")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -1951,7 +1940,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -1976,7 +1964,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -2005,13 +1992,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -2028,15 +2013,9 @@ impl Read for Take { + unsafe fn initializer(&self) -> Initializer { + self.inner.initializer() + } +- +- fn read_to_end(&mut self, buf: &mut Vec) -> Result { +- let reservation_size = cmp::min(self.limit, 32) as usize; +- +- read_to_end_with_reservation(self, buf, reservation_size) +- } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -2063,13 +2042,11 @@ impl BufRead for Take { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -2093,14 +2070,14 @@ impl Iterator for Bytes { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -2125,13 +2102,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 2e19edf..66294a3 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -8,7 +8,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 5ce955e..c7d8697 100644 +--- a/util.rs ++++ b/util.rs +@@ -1,8 +1,9 @@ + #![allow(missing_copy_implementations)] + +-use fmt; +-use io::{self, Read, Initializer, Write, ErrorKind, BufRead, IoVec, IoVecMut}; +-use mem; ++use core::fmt; ++use io::{self, Read, Initializer, Write, ErrorKind}; ++use core::mem; ++#[cfg(feature="collections")] use io::{BufRead, IoVec, IoVecMut}; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -39,7 +40,6 @@ use mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -68,7 +68,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -88,10 +87,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -101,7 +98,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -109,7 +107,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -122,7 +119,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -139,10 +135,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -152,6 +146,7 @@ impl Read for Repeat { + Ok(buf.len()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let mut nwritten = 0; +@@ -167,7 +162,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -180,7 +174,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -197,14 +190,13 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } + ++ #[cfg(feature="collections")] + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + let total_len = bufs.iter().map(|b| b.len()).sum(); +@@ -215,7 +207,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/patches/fc84f5f837a3e1b9b9bc992dd603d3d968502288.patch b/patches/fc84f5f837a3e1b9b9bc992dd603d3d968502288.patch new file mode 100644 index 0000000..c5e6686 --- /dev/null +++ b/patches/fc84f5f837a3e1b9b9bc992dd603d3d968502288.patch @@ -0,0 +1,1608 @@ +diff --git a/buffered.rs b/buffered.rs +index 7ede050..2359343 100644 +--- a/buffered.rs ++++ b/buffered.rs +@@ -10,13 +10,13 @@ + + //! Buffering wrappers for I/O traits + ++use core::prelude::v1::*; + use io::prelude::*; + +-use cmp; +-use error; +-use fmt; ++use core::cmp; ++use core::fmt; + use io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom}; +-use memchr; ++use io::memchr; + + /// The `BufReader` struct adds buffering to any reader. + /// +@@ -52,7 +52,6 @@ use memchr; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufReader { + inner: R, + buf: Box<[u8]>, +@@ -76,7 +75,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: R) -> BufReader { + BufReader::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -97,7 +95,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: R) -> BufReader { + unsafe { + let mut buffer = Vec::with_capacity(cap); +@@ -130,7 +127,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &R { &self.inner } + + /// Gets a mutable reference to the underlying reader. +@@ -151,7 +147,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut R { &mut self.inner } + + /// Returns a reference to the internally buffered data. +@@ -176,7 +171,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf[self.pos..self.cap] + } +@@ -199,7 +193,6 @@ impl BufReader { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> R { self.inner } + } + +@@ -208,7 +201,6 @@ impl BufReader { + /// the buffer will not be flushed, allowing for more efficient seeks. + /// This method does not return the location of the underlying reader, so the caller + /// must track this information themselves if it is required. +- #[unstable(feature = "bufreader_seek_relative", issue = "31100")] + pub fn seek_relative(&mut self, offset: i64) -> io::Result<()> { + let pos = self.pos as u64; + if offset < 0 { +@@ -228,7 +220,6 @@ impl BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for BufReader { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + // If we don't have any buffered data and we're doing a massive read +@@ -251,7 +242,6 @@ impl Read for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl BufRead for BufReader { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + // If we've reached the end of our internal buffer then we need to fetch +@@ -271,7 +261,6 @@ impl BufRead for BufReader { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufReader where R: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufReader") +@@ -281,7 +270,6 @@ impl fmt::Debug for BufReader where R: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufReader { + /// Seek to an offset, in bytes, in the underlying reader. + /// +@@ -387,7 +375,6 @@ impl Seek for BufReader { + /// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write + /// [`TcpStream`]: ../../std/net/struct.TcpStream.html + /// [`flush`]: #method.flush +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct BufWriter { + inner: Option, + buf: Vec, +@@ -422,7 +409,6 @@ pub struct BufWriter { + /// }; + /// ``` + #[derive(Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct IntoInnerError(W, Error); + + impl BufWriter { +@@ -437,7 +423,6 @@ impl BufWriter { + /// + /// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap()); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> BufWriter { + BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner) + } +@@ -455,7 +440,6 @@ impl BufWriter { + /// let stream = TcpStream::connect("127.0.0.1:34254").unwrap(); + /// let mut buffer = BufWriter::with_capacity(100, stream); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> BufWriter { + BufWriter { + inner: Some(inner), +@@ -504,7 +488,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() } + + /// Gets a mutable reference to the underlying writer. +@@ -522,7 +505,6 @@ impl BufWriter { + /// // we can use reference just like buffer + /// let reference = buffer.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() } + + /// Returns a reference to the internally buffered data. +@@ -539,7 +521,6 @@ impl BufWriter { + /// // See how many bytes are currently buffered + /// let bytes_buffered = buf_writer.buffer().len(); + /// ``` +- #[unstable(feature = "bufreader_buffer", issue = "45323")] + pub fn buffer(&self) -> &[u8] { + &self.buf + } +@@ -563,7 +544,6 @@ impl BufWriter { + /// // unwrap the TcpStream and flush the buffer + /// let stream = buffer.into_inner().unwrap(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(mut self) -> Result>> { + match self.flush_buf() { + Err(e) => Err(IntoInnerError(self, e)), +@@ -572,7 +552,6 @@ impl BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for BufWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buf.len() + buf.len() > self.buf.capacity() { +@@ -592,7 +571,6 @@ impl Write for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for BufWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("BufWriter") +@@ -602,7 +580,6 @@ impl fmt::Debug for BufWriter where W: fmt::Debug { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Seek for BufWriter { + /// Seek to the offset, in bytes, in the underlying writer. + /// +@@ -612,7 +589,6 @@ impl Seek for BufWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Drop for BufWriter { + fn drop(&mut self) { + if self.inner.is_some() && !self.panicked { +@@ -651,7 +627,6 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn error(&self) -> &Error { &self.1 } + + /// Returns the buffered writer instance which generated the error. +@@ -684,23 +659,13 @@ impl IntoInnerError { + /// } + /// }; + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> W { self.0 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl From> for Error { + fn from(iie: IntoInnerError) -> Error { iie.1 } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for IntoInnerError { +- fn description(&self) -> &str { +- error::Error::description(self.error()) +- } +-} +- +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for IntoInnerError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.error().fmt(f) +@@ -771,7 +736,6 @@ impl fmt::Display for IntoInnerError { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct LineWriter { + inner: BufWriter, + need_flush: bool, +@@ -792,7 +756,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: W) -> LineWriter { + // Lines typically aren't that long, don't use a giant buffer + LineWriter::with_capacity(1024, inner) +@@ -813,7 +776,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn with_capacity(cap: usize, inner: W) -> LineWriter { + LineWriter { + inner: BufWriter::with_capacity(cap, inner), +@@ -837,7 +799,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &W { self.inner.get_ref() } + + /// Gets a mutable reference to the underlying writer. +@@ -860,7 +821,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() } + + /// Unwraps this `LineWriter`, returning the underlying writer. +@@ -886,7 +846,6 @@ impl LineWriter { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> Result>> { + self.inner.into_inner().map_err(|IntoInnerError(buf, e)| { + IntoInnerError(LineWriter { +@@ -897,7 +856,6 @@ impl LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for LineWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + if self.need_flush { +@@ -942,7 +900,6 @@ impl Write for LineWriter { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for LineWriter where W: fmt::Debug { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("LineWriter") +diff --git a/cursor.rs b/cursor.rs +index 14f2015..1d60dac 100644 +--- a/cursor.rs ++++ b/cursor.rs +@@ -10,8 +10,8 @@ + + use io::prelude::*; + +-use core::convert::TryInto; +-use cmp; ++#[cfg(feature="collections")] use core::convert::TryInto; ++use core::cmp; + use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + + /// A `Cursor` wraps an in-memory buffer and provides it with a +@@ -80,7 +80,6 @@ use io::{self, Initializer, SeekFrom, Error, ErrorKind}; + /// assert_eq!(&buff.get_ref()[5..15], &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Clone, Debug)] + pub struct Cursor { + inner: T, +@@ -103,7 +102,6 @@ impl Cursor { + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(inner: T) -> Cursor { + Cursor { pos: 0, inner: inner } + } +@@ -121,7 +119,6 @@ impl Cursor { + /// + /// let vec = buff.into_inner(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn into_inner(self) -> T { self.inner } + + /// Gets a reference to the underlying value in this cursor. +@@ -137,7 +134,6 @@ impl Cursor { + /// + /// let reference = buff.get_ref(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_ref(&self) -> &T { &self.inner } + + /// Gets a mutable reference to the underlying value in this cursor. +@@ -156,7 +152,6 @@ impl Cursor { + /// + /// let reference = buff.get_mut(); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn get_mut(&mut self) -> &mut T { &mut self.inner } + + /// Returns the current position of this cursor. +@@ -178,7 +173,6 @@ impl Cursor { + /// buff.seek(SeekFrom::Current(-1)).unwrap(); + /// assert_eq!(buff.position(), 1); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn position(&self) -> u64 { self.pos } + + /// Sets the position of this cursor. +@@ -198,11 +192,9 @@ impl Cursor { + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn set_position(&mut self, pos: u64) { self.pos = pos; } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl io::Seek for Cursor where T: AsRef<[u8]> { + fn seek(&mut self, style: SeekFrom) -> io::Result { + let (base_pos, offset) = match style { +@@ -223,17 +215,16 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Cursor where T: AsRef<[u8]> { + fn read(&mut self, buf: &mut [u8]) -> io::Result { +- let n = Read::read(&mut self.fill_buf()?, buf)?; ++ let n = Read::read(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(n) + } + + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { + let n = buf.len(); +- Read::read_exact(&mut self.fill_buf()?, buf)?; ++ Read::read_exact(&mut self.get_buf()?, buf)?; + self.pos += n as u64; + Ok(()) + } +@@ -244,12 +235,16 @@ impl Read for Cursor where T: AsRef<[u8]> { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl BufRead for Cursor where T: AsRef<[u8]> { +- fn fill_buf(&mut self) -> io::Result<&[u8]> { ++impl Cursor where T: AsRef<[u8]> { ++ fn get_buf(&mut self) -> io::Result<&[u8]> { + let amt = cmp::min(self.pos, self.inner.as_ref().len() as u64); + Ok(&self.inner.as_ref()[(amt as usize)..]) + } ++} ++ ++#[cfg(feature="collections")] ++impl BufRead for Cursor where T: AsRef<[u8]> { ++ fn fill_buf(&mut self) -> io::Result<&[u8]> { self.get_buf() } + fn consume(&mut self, amt: usize) { self.pos += amt as u64; } + } + +@@ -262,6 +257,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result, buf: &[u8]) -> io::Result { + let pos: usize = (*pos_mut).try_into().map_err(|_| { + Error::new(ErrorKind::InvalidInput, +@@ -288,7 +284,6 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result Write for Cursor<&'a mut [u8]> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +@@ -297,7 +292,7 @@ impl<'a> Write for Cursor<&'a mut [u8]> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_mut_vec", since = "1.25.0")] ++#[cfg(feature="collections")] + impl<'a> Write for Cursor<&'a mut Vec> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, self.inner, buf) +@@ -305,7 +300,7 @@ impl<'a> Write for Cursor<&'a mut Vec> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature = "collections")] + impl Write for Cursor> { + fn write(&mut self, buf: &[u8]) -> io::Result { + vec_write(&mut self.pos, &mut self.inner, buf) +@@ -313,8 +308,8 @@ impl Write for Cursor> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "cursor_box_slice", since = "1.5.0")] +-impl Write for Cursor> { ++#[cfg(feature = "alloc")] ++impl Write for Cursor<::alloc::boxed::Box<[u8]>> { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + slice_write(&mut self.pos, &mut self.inner, buf) +diff --git a/error.rs b/error.rs +index 32e2996..b4455e3 100644 +--- a/error.rs ++++ b/error.rs +@@ -8,11 +8,16 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use error; +-use fmt; +-use result; +-use sys; +-use convert::From; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++#[cfg(not(feature="alloc"))] use ::FakeBox as Box; ++use core::convert::Into; ++use core::fmt; ++use core::marker::{Send, Sync}; ++use core::option::Option::{self, Some, None}; ++use core::result; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(not(feature="collections"))] use ::ErrorString as String; ++use core::convert::From; + + /// A specialized [`Result`](../result/enum.Result.html) type for I/O + /// operations. +@@ -48,7 +53,6 @@ use convert::From; + /// Ok(buffer) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub type Result = result::Result; + + /// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and +@@ -62,12 +66,10 @@ pub type Result = result::Result; + /// [`Write`]: ../io/trait.Write.html + /// [`Seek`]: ../io/trait.Seek.html + /// [`ErrorKind`]: enum.ErrorKind.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Error { + repr: Repr, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.repr, f) +@@ -77,13 +79,16 @@ impl fmt::Debug for Error { + enum Repr { + Os(i32), + Simple(ErrorKind), ++ #[cfg(feature="alloc")] + Custom(Box), ++ #[cfg(not(feature="alloc"))] ++ Custom(Custom), + } + + #[derive(Debug)] + struct Custom { + kind: ErrorKind, +- error: Box, ++ error: String, + } + + /// A list specifying general categories of I/O error. +@@ -95,48 +100,35 @@ struct Custom { + /// + /// [`io::Error`]: struct.Error.html + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +-#[stable(feature = "rust1", since = "1.0.0")] + #[allow(deprecated)] + #[non_exhaustive] + pub enum ErrorKind { + /// An entity was not found, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + NotFound, + /// The operation lacked the necessary privileges to complete. +- #[stable(feature = "rust1", since = "1.0.0")] + PermissionDenied, + /// The connection was refused by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionRefused, + /// The connection was reset by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionReset, + /// The connection was aborted (terminated) by the remote server. +- #[stable(feature = "rust1", since = "1.0.0")] + ConnectionAborted, + /// The network operation failed because it was not connected yet. +- #[stable(feature = "rust1", since = "1.0.0")] + NotConnected, + /// A socket address could not be bound because the address is already in + /// use elsewhere. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrInUse, + /// A nonexistent interface was requested or the requested address was not + /// local. +- #[stable(feature = "rust1", since = "1.0.0")] + AddrNotAvailable, + /// The operation failed because a pipe was closed. +- #[stable(feature = "rust1", since = "1.0.0")] + BrokenPipe, + /// An entity already exists, often a file. +- #[stable(feature = "rust1", since = "1.0.0")] + AlreadyExists, + /// The operation needs to block to complete, but the blocking operation was + /// requested to not occur. +- #[stable(feature = "rust1", since = "1.0.0")] + WouldBlock, + /// A parameter was incorrect. +- #[stable(feature = "rust1", since = "1.0.0")] + InvalidInput, + /// Data not valid for the operation were encountered. + /// +@@ -148,10 +140,8 @@ pub enum ErrorKind { + /// `InvalidData` if the file's contents are not valid UTF-8. + /// + /// [`InvalidInput`]: #variant.InvalidInput +- #[stable(feature = "io_invalid_data", since = "1.2.0")] + InvalidData, + /// The I/O operation's timeout expired, causing it to be canceled. +- #[stable(feature = "rust1", since = "1.0.0")] + TimedOut, + /// An error returned when an operation could not be completed because a + /// call to [`write`] returned [`Ok(0)`]. +@@ -162,15 +152,12 @@ pub enum ErrorKind { + /// + /// [`write`]: ../../std/io/trait.Write.html#tymethod.write + /// [`Ok(0)`]: ../../std/io/type.Result.html +- #[stable(feature = "rust1", since = "1.0.0")] + WriteZero, + /// This operation was interrupted. + /// + /// Interrupted operations can typically be retried. +- #[stable(feature = "rust1", since = "1.0.0")] + Interrupted, + /// Any I/O error not part of this list. +- #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// An error returned when an operation could not be completed because an +@@ -179,7 +166,6 @@ pub enum ErrorKind { + /// This typically means that an operation could only succeed if it read a + /// particular number of bytes but only a smaller number of bytes could be + /// read. +- #[stable(feature = "read_exact", since = "1.6.0")] + UnexpectedEof, + } + +@@ -210,7 +196,6 @@ impl ErrorKind { + + /// Intended for use for errors not exposed to the user, where allocating onto + /// the heap (for normal construction via Error::new) is too costly. +-#[stable(feature = "io_error_from_errorkind", since = "1.14.0")] + impl From for Error { + /// Converts an [`ErrorKind`] into an [`Error`]. + /// +@@ -252,14 +237,13 @@ impl Error { + /// // errors can also be created from other errors + /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn new(kind: ErrorKind, error: E) -> Error +- where E: Into> ++ where E: Into + { + Self::_new(kind, error.into()) + } + +- fn _new(kind: ErrorKind, error: Box) -> Error { ++ fn _new(kind: ErrorKind, error: String) -> Error { + Error { + repr: Repr::Custom(Box::new(Custom { + kind, +@@ -268,24 +252,6 @@ impl Error { + } + } + +- /// Returns an error representing the last OS error which occurred. +- /// +- /// This function reads the value of `errno` for the target platform (e.g. +- /// `GetLastError` on Windows) and will return a corresponding instance of +- /// `Error` for the error code. +- /// +- /// # Examples +- /// +- /// ``` +- /// use std::io::Error; +- /// +- /// println!("last OS error: {:?}", Error::last_os_error()); +- /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] +- pub fn last_os_error() -> Error { +- Error::from_raw_os_error(sys::os::errno() as i32) +- } +- + /// Creates a new instance of an `Error` from a particular OS error code. + /// + /// # Examples +@@ -311,7 +277,6 @@ impl Error { + /// assert_eq!(error.kind(), io::ErrorKind::InvalidInput); + /// # } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn from_raw_os_error(code: i32) -> Error { + Error { repr: Repr::Os(code) } + } +@@ -342,7 +307,6 @@ impl Error { + /// print_os_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn raw_os_error(&self) -> Option { + match self.repr { + Repr::Os(i) => Some(i), +@@ -376,12 +340,11 @@ impl Error { + /// print_error(&Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_ref(&self) -> Option<&(dyn error::Error+Send+Sync+'static)> { ++ pub fn get_ref(&self) -> Option<&String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref c) => Some(&*c.error), ++ Repr::Custom(ref c) => Some(&c.error), + } + } + +@@ -447,12 +410,11 @@ impl Error { + /// print_error(&change_error(Error::new(ErrorKind::Other, MyError::new()))); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error+Send+Sync+'static)> { ++ pub fn get_mut(&mut self) -> Option<&mut String> { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +- Repr::Custom(ref mut c) => Some(&mut *c.error), ++ Repr::Custom(ref mut c) => Some(&mut c.error), + } + } + +@@ -481,8 +443,7 @@ impl Error { + /// print_error(Error::new(ErrorKind::Other, "oh no!")); + /// } + /// ``` +- #[stable(feature = "io_error_inner", since = "1.3.0")] +- pub fn into_inner(self) -> Option> { ++ pub fn into_inner(self) -> Option { + match self.repr { + Repr::Os(..) => None, + Repr::Simple(..) => None, +@@ -508,10 +469,9 @@ impl Error { + /// print_error(Error::new(ErrorKind::AddrInUse, "oh no!")); + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn kind(&self) -> ErrorKind { + match self.repr { +- Repr::Os(code) => sys::decode_error_kind(code), ++ Repr::Os(_code) => ErrorKind::Other, + Repr::Custom(ref c) => c.kind, + Repr::Simple(kind) => kind, + } +@@ -523,22 +483,18 @@ impl fmt::Debug for Repr { + match *self { + Repr::Os(code) => + fmt.debug_struct("Os") +- .field("code", &code) +- .field("kind", &sys::decode_error_kind(code)) +- .field("message", &sys::os::error_string(code)).finish(), ++ .field("code", &code).finish(), + Repr::Custom(ref c) => fmt::Debug::fmt(&c, fmt), + Repr::Simple(kind) => fmt.debug_tuple("Kind").field(&kind).finish(), + } + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + match self.repr { + Repr::Os(code) => { +- let detail = sys::os::error_string(code); +- write!(fmt, "{} (os error {})", detail, code) ++ write!(fmt, "os error {}", code) + } + Repr::Custom(ref c) => c.error.fmt(fmt), + Repr::Simple(kind) => write!(fmt, "{}", kind.as_str()), +@@ -546,24 +502,6 @@ impl fmt::Display for Error { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] +-impl error::Error for Error { +- fn description(&self) -> &str { +- match self.repr { +- Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), +- Repr::Custom(ref c) => c.error.description(), +- } +- } +- +- fn cause(&self) -> Option<&dyn error::Error> { +- match self.repr { +- Repr::Os(..) => None, +- Repr::Simple(..) => None, +- Repr::Custom(ref c) => c.error.cause(), +- } +- } +-} +- + fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +diff --git a/impls.rs b/impls.rs +index fe1179a..452b8b7 100644 +--- a/impls.rs ++++ b/impls.rs +@@ -8,15 +8,18 @@ + // option. This file may not be copied, modified, or distributed + // except according to those terms. + +-use cmp; +-use io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind}; +-use fmt; +-use mem; ++#[cfg(feature="alloc")] use alloc::boxed::Box; ++use core::cmp; ++use io::{self, SeekFrom, Read, Initializer, Write, Seek, Error, ErrorKind}; ++#[cfg(feature="collections")] use io::BufRead; ++use core::fmt; ++use core::mem; ++#[cfg(feature="collections")] use collections::string::String; ++#[cfg(feature="collections")] use collections::vec::Vec; + + // ============================================================================= + // Forwarding implementations + +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, R: Read + ?Sized> Read for &'a mut R { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -28,11 +31,13 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -43,7 +48,6 @@ impl<'a, R: Read + ?Sized> Read for &'a mut R { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, W: Write + ?Sized> Write for &'a mut W { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -61,12 +65,11 @@ impl<'a, W: Write + ?Sized> Write for &'a mut W { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a, S: Seek + ?Sized> Seek for &'a mut S { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -85,7 +88,7 @@ impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Read for Box { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -97,11 +100,13 @@ impl Read for Box { + (**self).initializer() + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + (**self).read_to_end(buf) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_string(&mut self, buf: &mut String) -> io::Result { + (**self).read_to_string(buf) +@@ -112,7 +117,7 @@ impl Read for Box { + (**self).read_exact(buf) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Write for Box { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } +@@ -130,12 +135,12 @@ impl Write for Box { + (**self).write_fmt(fmt) + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="alloc")] + impl Seek for Box { + #[inline] + fn seek(&mut self, pos: SeekFrom) -> io::Result { (**self).seek(pos) } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Box { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() } +@@ -161,7 +166,6 @@ impl BufRead for Box { + /// + /// Note that reading updates the slice to point to the yet unread part. + /// The slice will be empty when EOF is reached. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Read for &'a [u8] { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -207,6 +211,7 @@ impl<'a> Read for &'a [u8] { + Ok(()) + } + ++ #[cfg(feature="collections")] + #[inline] + fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { + buf.extend_from_slice(*self); +@@ -216,7 +221,7 @@ impl<'a> Read for &'a [u8] { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl<'a> BufRead for &'a [u8] { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) } +@@ -230,7 +235,6 @@ impl<'a> BufRead for &'a [u8] { + /// + /// Note that writing updates the slice to point to the yet unwritten part. + /// The slice will be empty when it has been completely overwritten. +-#[stable(feature = "rust1", since = "1.0.0")] + impl<'a> Write for &'a mut [u8] { + #[inline] + fn write(&mut self, data: &[u8]) -> io::Result { +@@ -256,7 +260,7 @@ impl<'a> Write for &'a mut [u8] { + + /// Write is implemented for `Vec` by appending to the vector. + /// The vector will grow as needed. +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Write for Vec { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { +diff --git a/mod.rs b/mod.rs +index dc97701..6ea0b47 100644 +--- a/mod.rs ++++ b/mod.rs +@@ -267,47 +267,36 @@ + //! [`Result`]: ../result/enum.Result.html + //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap + +-#![stable(feature = "rust1", since = "1.0.0")] +- +-use cmp; +-use fmt; +-use str; +-use memchr; +-use ptr; +- +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::{BufReader, BufWriter, LineWriter}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::buffered::IntoInnerError; +-#[stable(feature = "rust1", since = "1.0.0")] ++use core::cmp; ++use core::fmt; ++#[cfg(feature="collections")] use collections::string::String; ++use core::str; ++#[cfg(feature="collections")] use collections::vec::Vec; ++#[cfg(not(core_memchr))] ++mod memchr; ++#[cfg(all(feature="collections",core_memchr))] ++use core::slice::memchr; ++use core::ptr; ++ ++#[cfg(feature="collections")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; ++#[cfg(feature="collections")] pub use self::buffered::IntoInnerError; + pub use self::cursor::Cursor; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::error::{Result, Error, ErrorKind}; +-#[stable(feature = "rust1", since = "1.0.0")] + pub use self::util::{copy, sink, Sink, empty, Empty, repeat, Repeat}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{stdin, stdout, stderr, Stdin, Stdout, Stderr}; +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use self::stdio::{StdoutLock, StderrLock, StdinLock}; +-#[unstable(feature = "print_internals", issue = "0")] +-pub use self::stdio::{_print, _eprint}; +-#[unstable(feature = "libstd_io_internals", issue = "42788")] +-#[doc(no_inline, hidden)] +-pub use self::stdio::{set_panic, set_print}; + + pub mod prelude; +-mod buffered; ++#[cfg(feature="collections")] mod buffered; + mod cursor; + mod error; + mod impls; +-mod lazy; + mod util; +-mod stdio; + +-const DEFAULT_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE; ++const DEFAULT_BUF_SIZE: usize = 8 * 1024; + ++#[cfg(feature="collections")] + struct Guard<'a> { buf: &'a mut Vec, len: usize } + ++#[cfg(feature="collections")] + impl<'a> Drop for Guard<'a> { + fn drop(&mut self) { + unsafe { self.buf.set_len(self.len); } +@@ -332,6 +321,7 @@ impl<'a> Drop for Guard<'a> { + // 2. We're passing a raw buffer to the function `f`, and it is expected that + // the function only *appends* bytes to the buffer. We'll get undefined + // behavior if existing bytes are overwritten to have non-UTF-8 data. ++#[cfg(feature="collections")] + fn append_to_string(buf: &mut String, f: F) -> Result + where F: FnOnce(&mut Vec) -> Result + { +@@ -359,10 +349,12 @@ fn append_to_string(buf: &mut String, f: F) -> Result + // + // Because we're extending the buffer with uninitialized data for trusted + // readers, we need to make sure to truncate that if any of this panics. ++#[cfg(feature="collections")] + fn read_to_end(r: &mut R, buf: &mut Vec) -> Result { + read_to_end_with_reservation(r, buf, 32) + } + ++#[cfg(feature="collections")] + fn read_to_end_with_reservation(r: &mut R, + buf: &mut Vec, + reservation_size: usize) -> Result +@@ -469,7 +461,6 @@ fn read_to_end_with_reservation(r: &mut R, + /// [`BufReader`]: struct.BufReader.html + /// [`&str`]: ../../std/primitive.str.html + /// [slice]: ../../std/primitive.slice.html +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Read { + /// Pull some bytes from this source into the specified buffer, returning +@@ -526,7 +517,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read(&mut self, buf: &mut [u8]) -> Result; + + /// Determines if this `Read`er can work with buffers of uninitialized +@@ -551,7 +541,6 @@ pub trait Read { + /// + /// [`Initializer::nop()`]: ../../std/io/struct.Initializer.html#method.nop + /// [`Initializer`]: ../../std/io/struct.Initializer.html +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + Initializer::zeroing() +@@ -604,7 +593,7 @@ pub trait Read { + /// file.) + /// + /// [`std::fs::read`]: ../fs/fn.read.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_end(&mut self, buf: &mut Vec) -> Result { + read_to_end(self, buf) + } +@@ -647,7 +636,7 @@ pub trait Read { + /// reading from a file.) + /// + /// [`std::fs::read_to_string`]: ../fs/fn.read_to_string.html +- #[stable(feature = "rust1", since = "1.0.0")] ++ #[cfg(feature="collections")] + fn read_to_string(&mut self, buf: &mut String) -> Result { + // Note that we do *not* call `.read_to_end()` here. We are passing + // `&mut Vec` (the raw contents of `buf`) into the `read_to_end` +@@ -710,7 +699,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "read_exact", since = "1.6.0")] + fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> { + while !buf.is_empty() { + match self.read(buf) { +@@ -762,7 +750,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + + /// Transforms this `Read` instance to an [`Iterator`] over its bytes. +@@ -799,7 +786,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn bytes(self) -> Bytes where Self: Sized { + Bytes { inner: self } + } +@@ -834,7 +820,6 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn chain(self, next: R) -> Chain where Self: Sized { + Chain { first: self, second: next, done_first: false } + } +@@ -870,20 +855,17 @@ pub trait Read { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn take(self, limit: u64) -> Take where Self: Sized { + Take { inner: self, limit: limit } + } + } + + /// A type used to conditionally initialize buffers passed to `Read` methods. +-#[unstable(feature = "read_initializer", issue = "42788")] + #[derive(Debug)] + pub struct Initializer(bool); + + impl Initializer { + /// Returns a new `Initializer` which will zero out buffers. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn zeroing() -> Initializer { + Initializer(true) +@@ -897,21 +879,18 @@ impl Initializer { + /// read from buffers passed to `Read` methods, and that the return value of + /// the method accurately reflects the number of bytes that have been + /// written to the head of the buffer. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub unsafe fn nop() -> Initializer { + Initializer(false) + } + + /// Indicates if a buffer should be initialized. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn should_initialize(&self) -> bool { + self.0 + } + + /// Initializes a buffer if necessary. +- #[unstable(feature = "read_initializer", issue = "42788")] + #[inline] + pub fn initialize(&self, buf: &mut [u8]) { + if self.should_initialize() { +@@ -954,7 +933,6 @@ impl Initializer { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + #[doc(spotlight)] + pub trait Write { + /// Write a buffer into this object, returning how many bytes were written. +@@ -1003,7 +981,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write(&mut self, buf: &[u8]) -> Result; + + /// Flush this output stream, ensuring that all intermediately buffered +@@ -1029,7 +1006,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn flush(&mut self) -> Result<()>; + + /// Attempts to write an entire buffer into this write. +@@ -1062,7 +1038,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { + while !buf.is_empty() { + match self.write(buf) { +@@ -1114,7 +1089,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> { + // Create a shim which translates a Write to a fmt::Write and saves + // off I/O errors. instead of discarding them +@@ -1170,7 +1144,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn by_ref(&mut self) -> &mut Self where Self: Sized { self } + } + +@@ -1200,7 +1173,6 @@ pub trait Write { + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub trait Seek { + /// Seek to an offset, in bytes, in a stream. + /// +@@ -1216,7 +1188,6 @@ pub trait Seek { + /// Seeking to a negative offset is considered an error. + /// + /// [`SeekFrom::Start`]: enum.SeekFrom.html#variant.Start +- #[stable(feature = "rust1", since = "1.0.0")] + fn seek(&mut self, pos: SeekFrom) -> Result; + } + +@@ -1226,29 +1197,26 @@ pub trait Seek { + /// + /// [`Seek`]: trait.Seek.html + #[derive(Copy, PartialEq, Eq, Clone, Debug)] +-#[stable(feature = "rust1", since = "1.0.0")] + pub enum SeekFrom { + /// Set the offset to the provided number of bytes. +- #[stable(feature = "rust1", since = "1.0.0")] +- Start(#[stable(feature = "rust1", since = "1.0.0")] u64), ++ Start(u64), + + /// Set the offset to the size of this object plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- End(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ End(i64), + + /// Set the offset to the current position plus the specified number of + /// bytes. + /// + /// It is possible to seek beyond the end of an object, but it's an error to + /// seek before byte 0. +- #[stable(feature = "rust1", since = "1.0.0")] +- Current(#[stable(feature = "rust1", since = "1.0.0")] i64), ++ Current(i64), + } + ++#[cfg(feature="collections")] + fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + -> Result { + let mut read = 0; +@@ -1328,7 +1296,7 @@ fn read_until(r: &mut R, delim: u8, buf: &mut Vec) + /// } + /// ``` + /// +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + pub trait BufRead: Read { + /// Returns the contents of the internal buffer, filling it with more data + /// from the inner reader if it is empty. +@@ -1374,7 +1342,6 @@ pub trait BufRead: Read { + /// // ensure the bytes we worked with aren't returned again later + /// stdin.consume(length); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn fill_buf(&mut self) -> Result<&[u8]>; + + /// Tells this buffer that `amt` bytes have been consumed from the buffer, +@@ -1396,7 +1363,6 @@ pub trait BufRead: Read { + /// that method's example includes an example of `consume()`. + /// + /// [`fill_buf`]: #tymethod.fill_buf +- #[stable(feature = "rust1", since = "1.0.0")] + fn consume(&mut self, amt: usize); + + /// Read all bytes into `buf` until the delimiter `byte` or EOF is reached. +@@ -1452,7 +1418,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, b""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_until(&mut self, byte: u8, buf: &mut Vec) -> Result { + read_until(self, byte, buf) + } +@@ -1511,7 +1476,6 @@ pub trait BufRead: Read { + /// assert_eq!(num_bytes, 0); + /// assert_eq!(buf, ""); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn read_line(&mut self, buf: &mut String) -> Result { + // Note that we are not calling the `.read_until` method here, but + // rather our hardcoded implementation. For more details as to why, see +@@ -1552,7 +1516,6 @@ pub trait BufRead: Read { + /// assert_eq!(split_iter.next(), Some(b"dolor".to_vec())); + /// assert_eq!(split_iter.next(), None); + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + fn split(self, byte: u8) -> Split where Self: Sized { + Split { buf: self, delim: byte } + } +@@ -1591,7 +1554,6 @@ pub trait BufRead: Read { + /// Each line of the iterator has the same error semantics as [`BufRead::read_line`]. + /// + /// [`BufRead::read_line`]: trait.BufRead.html#method.read_line +- #[stable(feature = "rust1", since = "1.0.0")] + fn lines(self) -> Lines where Self: Sized { + Lines { buf: self } + } +@@ -1603,7 +1565,6 @@ pub trait BufRead: Read { + /// Please see the documentation of [`chain`] for more details. + /// + /// [`chain`]: trait.Read.html#method.chain +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Chain { + first: T, + second: U, +@@ -1629,7 +1590,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn into_inner(self) -> (T, U) { + (self.first, self.second) + } +@@ -1652,7 +1612,6 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> (&T, &U) { + (&self.first, &self.second) + } +@@ -1679,13 +1638,11 @@ impl Chain { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> (&mut T, &mut U) { + (&mut self.first, &mut self.second) + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Chain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Chain") +@@ -1695,7 +1652,6 @@ impl fmt::Debug for Chain { + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Chain { + fn read(&mut self, buf: &mut [u8]) -> Result { + if !self.done_first { +@@ -1717,7 +1673,7 @@ impl Read for Chain { + } + } + +-#[stable(feature = "chain_bufread", since = "1.9.0")] ++#[cfg(feature="collections")] + impl BufRead for Chain { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { +@@ -1744,7 +1700,6 @@ impl BufRead for Chain { + /// Please see the documentation of [`take`] for more details. + /// + /// [`take`]: trait.Read.html#method.take +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Take { + inner: T, +@@ -1779,7 +1734,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "rust1", since = "1.0.0")] + pub fn limit(&self) -> u64 { self.limit } + + /// Sets the number of bytes that can be read before this instance will +@@ -1805,7 +1759,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "take_set_limit", since = "1.27.0")] + pub fn set_limit(&mut self, limit: u64) { + self.limit = limit; + } +@@ -1830,7 +1783,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "io_take_into_inner", since = "1.15.0")] + pub fn into_inner(self) -> T { + self.inner + } +@@ -1855,7 +1807,6 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_ref(&self) -> &T { + &self.inner + } +@@ -1884,13 +1835,11 @@ impl Take { + /// Ok(()) + /// } + /// ``` +- #[stable(feature = "more_io_inner_methods", since = "1.20.0")] + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Take { + fn read(&mut self, buf: &mut [u8]) -> Result { + // Don't call into inner reader at all at EOF because it may still block +@@ -1907,15 +1856,9 @@ impl Read for Take { + unsafe fn initializer(&self) -> Initializer { + self.inner.initializer() + } +- +- fn read_to_end(&mut self, buf: &mut Vec) -> Result { +- let reservation_size = cmp::min(self.limit, 32) as usize; +- +- read_to_end_with_reservation(self, buf, reservation_size) +- } + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl BufRead for Take { + fn fill_buf(&mut self) -> Result<&[u8]> { + // Don't call into inner reader at all at EOF because it may still block +@@ -1954,13 +1897,11 @@ fn read_one_byte(reader: &mut dyn Read) -> Option> { + /// Please see the documentation of [`bytes`] for more details. + /// + /// [`bytes`]: trait.Read.html#method.bytes +-#[stable(feature = "rust1", since = "1.0.0")] + #[derive(Debug)] + pub struct Bytes { + inner: R, + } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Iterator for Bytes { + type Item = Result; + +@@ -1976,14 +1917,14 @@ impl Iterator for Bytes { + /// `BufRead`. Please see the documentation of `split()` for more details. + /// + /// [split]: trait.BufRead.html#method.split +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Split { + buf: B, + delim: u8, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Split { + type Item = Result>; + +@@ -2008,13 +1949,13 @@ impl Iterator for Split { + /// `BufRead`. Please see the documentation of `lines()` for more details. + /// + /// [lines]: trait.BufRead.html#method.lines +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + #[derive(Debug)] + pub struct Lines { + buf: B, + } + +-#[stable(feature = "rust1", since = "1.0.0")] ++#[cfg(feature="collections")] + impl Iterator for Lines { + type Item = Result; + +diff --git a/prelude.rs b/prelude.rs +index 8772d0f..49d66c9 100644 +--- a/prelude.rs ++++ b/prelude.rs +@@ -18,7 +18,8 @@ + //! use std::io::prelude::*; + //! ``` + +-#![stable(feature = "rust1", since = "1.0.0")] ++pub use super::{Read, Write, Seek}; ++#[cfg(feature="collections")] pub use super::BufRead; + +-#[stable(feature = "rust1", since = "1.0.0")] +-pub use super::{Read, Write, BufRead, Seek}; ++#[cfg(feature="collections")] pub use alloc::boxed::Box; ++#[cfg(feature="collections")] pub use collections::vec::Vec; +diff --git a/util.rs b/util.rs +index 12995d0..397eef4 100644 +--- a/util.rs ++++ b/util.rs +@@ -10,9 +10,10 @@ + + #![allow(missing_copy_implementations)] + +-use fmt; +-use io::{self, Read, Initializer, Write, ErrorKind, BufRead}; +-use mem; ++use core::fmt; ++use io::{self, Read, Initializer, Write, ErrorKind}; ++use core::mem; ++#[cfg(feature="collections")] use io::BufRead; + + /// Copies the entire contents of a reader into a writer. + /// +@@ -49,7 +50,6 @@ use mem; + /// Ok(()) + /// } + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn copy(reader: &mut R, writer: &mut W) -> io::Result + where R: Read, W: Write + { +@@ -78,7 +78,6 @@ pub fn copy(reader: &mut R, writer: &mut W) -> io::Result< + /// the documentation of [`empty()`][`empty`] for more details. + /// + /// [`empty`]: fn.empty.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Empty { _priv: () } + + /// Constructs a new handle to an empty reader. +@@ -98,10 +97,8 @@ pub struct Empty { _priv: () } + /// io::empty().read_to_string(&mut buffer).unwrap(); + /// assert!(buffer.is_empty()); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn empty() -> Empty { Empty { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Empty { + #[inline] + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Ok(0) } +@@ -111,7 +108,8 @@ impl Read for Empty { + Initializer::nop() + } + } +-#[stable(feature = "rust1", since = "1.0.0")] ++ ++#[cfg(feature="collections")] + impl BufRead for Empty { + #[inline] + fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) } +@@ -119,7 +117,6 @@ impl BufRead for Empty { + fn consume(&mut self, _n: usize) {} + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Empty { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Empty { .. }") +@@ -132,7 +129,6 @@ impl fmt::Debug for Empty { + /// see the documentation of `repeat()` for more details. + /// + /// [repeat]: fn.repeat.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Repeat { byte: u8 } + + /// Creates an instance of a reader that infinitely repeats one byte. +@@ -149,10 +145,8 @@ pub struct Repeat { byte: u8 } + /// io::repeat(0b101).read_exact(&mut buffer).unwrap(); + /// assert_eq!(buffer, [0b101, 0b101, 0b101]); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn repeat(byte: u8) -> Repeat { Repeat { byte } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Read for Repeat { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { +@@ -168,7 +162,6 @@ impl Read for Repeat { + } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Repeat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Repeat { .. }") +@@ -181,7 +174,6 @@ impl fmt::Debug for Repeat { + /// see the documentation of `sink()` for more details. + /// + /// [sink]: fn.sink.html +-#[stable(feature = "rust1", since = "1.0.0")] + pub struct Sink { _priv: () } + + /// Creates an instance of a writer which will successfully consume all data. +@@ -198,10 +190,8 @@ pub struct Sink { _priv: () } + /// let num_bytes = io::sink().write(&buffer).unwrap(); + /// assert_eq!(num_bytes, 5); + /// ``` +-#[stable(feature = "rust1", since = "1.0.0")] + pub fn sink() -> Sink { Sink { _priv: () } } + +-#[stable(feature = "rust1", since = "1.0.0")] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } +@@ -209,7 +199,6 @@ impl Write for Sink { + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + +-#[stable(feature = "std_debug", since = "1.16.0")] + impl fmt::Debug for Sink { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Sink { .. }") diff --git a/src/lib.rs b/src/lib.rs index 990600b..83ebe15 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,8 +3,9 @@ //! the [std documentation](https://doc.rust-lang.org/nightly/std/io/index.html) //! for a full description of the functionality. #![allow(stable_features,unused_features)] -#![feature(question_mark,const_fn,collections,alloc,unicode,copy_from_slice, - str_char,try_from,str_internals,align_offset,doc_spotlight,slice_internals)] +#![feature(question_mark,const_fn,copy_from_slice,non_exhaustive, + bind_by_move_pattern_guards,try_from,str_internals,align_offset,doc_spotlight, + slice_internals)] #![no_std] #[cfg_attr(feature="collections",macro_use)]