@@ -1205,27 +1205,6 @@ impl HeaderName {
12051205 ///
12061206 /// This function panics when the static string is a invalid header.
12071207 ///
1208- /// Until [Allow panicking in constants](https://github.com/rust-lang/rfcs/pull/2345)
1209- /// makes its way into stable, the panic message at compile-time is
1210- /// going to look cryptic, but should at least point at your header value:
1211- ///
1212- /// ```text
1213- /// error: any use of this value will cause an error
1214- /// --> http/src/header/name.rs:1241:13
1215- /// |
1216- /// 1241 | ([] as [u8; 0])[0]; // Invalid header name
1217- /// | ^^^^^^^^^^^^^^^^^^
1218- /// | |
1219- /// | index out of bounds: the length is 0 but the index is 0
1220- /// | inside `http::HeaderName::from_static` at http/src/header/name.rs:1241:13
1221- /// | inside `INVALID_NAME` at src/main.rs:3:34
1222- /// |
1223- /// ::: src/main.rs:3:1
1224- /// |
1225- /// 3 | const INVALID_NAME: HeaderName = HeaderName::from_static("Capitalized");
1226- /// | ------------------------------------------------------------------------
1227- /// ```
1228- ///
12291208 /// # Examples
12301209 ///
12311210 /// ```
@@ -1252,7 +1231,6 @@ impl HeaderName {
12521231 /// let a = HeaderName::from_static("foobar");
12531232 /// let b = HeaderName::from_static("FOOBAR"); // This line panics!
12541233 /// ```
1255- #[ allow( unconditional_panic) ] // required for the panic circumvention
12561234 pub const fn from_static ( src : & ' static str ) -> HeaderName {
12571235 let name_bytes = src. as_bytes ( ) ;
12581236 if let Some ( standard) = StandardHeader :: from_bytes ( name_bytes) {
@@ -1272,13 +1250,8 @@ impl HeaderName {
12721250 i += 1 ;
12731251 }
12741252 } {
1275- // TODO: When msrv is bumped to larger than 1.57, this should be
1276- // replaced with `panic!` macro.
1277- // https://blog.rust-lang.org/2021/12/02/Rust-1.57.0.html#panic-in-const-contexts
1278- //
1279- // See the panics section of this method's document for details.
1280- #[ allow( clippy:: no_effect, clippy:: out_of_bounds_indexing) ]
1281- ( [ ] as [ u8 ; 0 ] ) [ 0 ] ; // Invalid header name
1253+ // Invalid header name
1254+ panic ! ( "HeaderName::from_static with invalid bytes" )
12821255 }
12831256
12841257 HeaderName {
0 commit comments