about summary refs log tree commit diff
diff options
context:
space:
mode:
authormikerite <33983332+mikerite@users.noreply.github.com>2018-09-24 09:11:32 +0200
committerGitHub <noreply@github.com>2018-09-24 09:11:32 +0200
commit417cf206cace45cc656f9a605221017e4fe4ef94 (patch)
treefd99346c9d1c2992d784ad47e13e82aff344fd18
parentbc6d85ceafdec687f3d5c25777a661724cae77de (diff)
parentab71f0866323bac7255da8687a2850e1daddf816 (diff)
downloadrust-417cf206cace45cc656f9a605221017e4fe4ef94.tar.gz
rust-417cf206cace45cc656f9a605221017e4fe4ef94.zip
Merge pull request #3213 from mikerite/fix-3204
Fix single_char_pattern crash (#3204)
-rw-r--r--clippy_lints/src/methods.rs8
-rw-r--r--tests/ui/single_char_pattern.rs4
2 files changed, 9 insertions, 3 deletions
diff --git a/clippy_lints/src/methods.rs b/clippy_lints/src/methods.rs
index 03e3d2628e8..54df9809a3e 100644
--- a/clippy_lints/src/methods.rs
+++ b/clippy_lints/src/methods.rs
@@ -16,7 +16,6 @@ use crate::utils::{get_arg_name, get_trait_def_id, implements_trait, in_macro, i
             span_lint, span_lint_and_sugg, span_lint_and_then, span_note_and_lint, walk_ptrs_ty, walk_ptrs_ty_depth, SpanlessEq};
 use crate::utils::paths;
 use crate::utils::sugg;
-use crate::consts::{constant, Constant};
 use crate::rustc_errors::Applicability;
 
 #[derive(Clone)]
@@ -1914,8 +1913,11 @@ fn lint_chars_last_cmp_with_unwrap<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, info: &
 
 /// lint for length-1 `str`s for methods in `PATTERN_METHODS`
 fn lint_single_char_pattern<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, _expr: &'tcx hir::Expr, arg: &'tcx hir::Expr) {
-    if let Some((Constant::Str(r), _)) = constant(cx, cx.tables, arg) {
-        if r.len() == 1 {
+    if_chain! {
+        if let hir::ExprKind::Lit(lit) = &arg.node;
+        if let ast::LitKind::Str(r, _) = lit.node;
+        if r.as_str().len() == 1;
+        then {
             let snip = snippet(cx, arg.span, "..");
             let hint = format!("'{}'", &snip[1..snip.len() - 1]);
             span_lint_and_sugg(
diff --git a/tests/ui/single_char_pattern.rs b/tests/ui/single_char_pattern.rs
index 147f974b999..c4e88e9ee2b 100644
--- a/tests/ui/single_char_pattern.rs
+++ b/tests/ui/single_char_pattern.rs
@@ -45,4 +45,8 @@ fn main() {
 
     x.replace(";", ",").split(","); // issue #2978
     x.starts_with("\x03"); // issue #2996
+
+    // Issue #3204
+    const S: &str = "#";
+    x.find(S);
 }