Skip to content

Commit

Permalink
Extract semantic constant
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagoarrais committed Jul 8, 2019
1 parent 6d1aaac commit 7d1a944
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion clippy_lints/src/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ fn is_add(cx: &LateContext<'_, '_>, src: &Expr, target: &Expr) -> bool {
}
}

// Max length a b"foo" string can take
const MAX_LENGTH_BYTE_STRING_LIT: usize = 32;

declare_lint_pass!(StringLitAsBytes => [STRING_LIT_AS_BYTES]);

impl<'a, 'tcx> LateLintPass<'a, 'tcx> for StringLitAsBytes {
Expand Down Expand Up @@ -173,7 +176,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for StringLitAsBytes {
);
} else if callsite == expanded
&& lit_content.as_str().chars().all(|c| c.is_ascii())
&& lit_content.as_str().len() <= 32
&& lit_content.as_str().len() <= MAX_LENGTH_BYTE_STRING_LIT
&& !in_macro_or_desugar(args[0].span)
{
span_lint_and_sugg(
Expand Down

0 comments on commit 7d1a944

Please sign in to comment.