Skip to content

Commit

Permalink
refactor(header): add comment and lint allowing to panic in const con…
Browse files Browse the repository at this point in the history
…text workaround
  • Loading branch information
tottoto authored and seanmonstar committed Feb 19, 2024
1 parent fe1932d commit b8ddea7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/header/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1269,6 +1269,12 @@ impl HeaderName {
i += 1;
}
} {
// TODO: When msrv is bumped to larger than 1.57, this should be
// replaced with `panic!` macro.
// https://blog.rust-lang.org/2021/12/02/Rust-1.57.0.html#panic-in-const-contexts
//
// See the panics section of this method's document for details.
#[allow(clippy::no_effect)]
([] as [u8; 0])[0]; // Invalid header name
}

Expand Down
6 changes: 6 additions & 0 deletions src/header/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ impl HeaderValue {
let mut i = 0;
while i < bytes.len() {
if !is_visible_ascii(bytes[i]) {
// TODO: When msrv is bumped to larger than 1.57, this should be
// replaced with `panic!` macro.
// https://blog.rust-lang.org/2021/12/02/Rust-1.57.0.html#panic-in-const-contexts
//
// See the panics section of this method's document for details.
#[allow(clippy::no_effect)]
([] as [u8; 0])[0]; // Invalid header value
}
i += 1;
Expand Down

0 comments on commit b8ddea7

Please sign in to comment.