Skip to content

Commit 5fc1c79

Browse files
committed
bump up regex-syntax dependency version to 0.7.0
1 parent c976ad0 commit 5fc1c79

File tree

4 files changed

+28
-39
lines changed

4 files changed

+28
-39
lines changed

clippy_lints/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ if_chain = "1.0"
1717
itertools = "0.10.1"
1818
pulldown-cmark = { version = "0.9", default-features = false }
1919
quine-mc_cluskey = "0.2"
20-
regex-syntax = "0.6"
20+
regex-syntax = "0.7"
2121
serde = { version = "1.0", features = ["derive"] }
2222
serde_json = { version = "1.0", optional = true }
2323
tempfile = { version = "3.3.0", optional = true }

clippy_lints/src/regex.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -129,30 +129,32 @@ fn const_str<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> Option<String>
129129
}
130130

131131
fn is_trivial_regex(s: &regex_syntax::hir::Hir) -> Option<&'static str> {
132-
use regex_syntax::hir::Anchor::{EndText, StartText};
133-
use regex_syntax::hir::HirKind::{Alternation, Anchor, Concat, Empty, Literal};
132+
use regex_syntax::hir::HirKind::{Alternation, Concat, Empty, Literal, Look};
133+
use regex_syntax::hir::Look as HirLook;
134134

135135
let is_literal = |e: &[regex_syntax::hir::Hir]| e.iter().all(|e| matches!(*e.kind(), Literal(_)));
136136

137137
match *s.kind() {
138-
Empty | Anchor(_) => Some("the regex is unlikely to be useful as it is"),
138+
Empty | Look(_) => Some("the regex is unlikely to be useful as it is"),
139139
Literal(_) => Some("consider using `str::contains`"),
140140
Alternation(ref exprs) => {
141-
if exprs.iter().all(|e| e.kind().is_empty()) {
141+
if exprs.iter().all(|e| matches!(e.kind(), Empty)) {
142142
Some("the regex is unlikely to be useful as it is")
143143
} else {
144144
None
145145
}
146146
},
147147
Concat(ref exprs) => match (exprs[0].kind(), exprs[exprs.len() - 1].kind()) {
148-
(&Anchor(StartText), &Anchor(EndText)) if exprs[1..(exprs.len() - 1)].is_empty() => {
148+
(&Look(HirLook::Start), &Look(HirLook::End)) if exprs[1..(exprs.len() - 1)].is_empty() => {
149149
Some("consider using `str::is_empty`")
150150
},
151-
(&Anchor(StartText), &Anchor(EndText)) if is_literal(&exprs[1..(exprs.len() - 1)]) => {
151+
(&Look(HirLook::Start), &Look(HirLook::End)) if is_literal(&exprs[1..(exprs.len() - 1)]) => {
152152
Some("consider using `==` on `str`s")
153153
},
154-
(&Anchor(StartText), &Literal(_)) if is_literal(&exprs[1..]) => Some("consider using `str::starts_with`"),
155-
(&Literal(_), &Anchor(EndText)) if is_literal(&exprs[1..(exprs.len() - 1)]) => {
154+
(&Look(HirLook::Start), &Literal(_)) if is_literal(&exprs[1..]) => {
155+
Some("consider using `str::starts_with`")
156+
},
157+
(&Literal(_), &Look(HirLook::End)) if is_literal(&exprs[1..(exprs.len() - 1)]) => {
156158
Some("consider using `str::ends_with`")
157159
},
158160
_ if is_literal(exprs) => Some("consider using `str::contains`"),
@@ -175,10 +177,7 @@ fn check_set<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, utf8: bool) {
175177
}
176178

177179
fn check_regex<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, utf8: bool) {
178-
let mut parser = regex_syntax::ParserBuilder::new()
179-
.unicode(true)
180-
.allow_invalid_utf8(!utf8)
181-
.build();
180+
let mut parser = regex_syntax::ParserBuilder::new().unicode(true).utf8(!utf8).build();
182181

183182
if let ExprKind::Lit(ref lit) = expr.kind {
184183
if let LitKind::Str(ref r, style) = lit.node {

tests/ui/regex.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ fn syntax_error() {
3434
let set_error = RegexSet::new(&[OPENING_PAREN, r"[a-z]+\.(com|org|net)"]);
3535
let bset_error = BRegexSet::new(&[OPENING_PAREN, r"[a-z]+\.(com|org|net)"]);
3636

37+
// These following three cases are considering valid since regex-1.8.0
3738
let raw_string_error = Regex::new(r"[...\/...]");
3839
let raw_string_error = Regex::new(r#"[...\/...]"#);
40+
let _ = Regex::new(r"(?<hi>hi)").unwrap();
3941

4042
let escaped_string_span = Regex::new("\\b\\c");
4143

tests/ui/regex.stderr

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -82,122 +82,110 @@ error: regex parse error:
8282
LL | let bset_error = BRegexSet::new(&[OPENING_PAREN, r"[a-z]+/.(com|org|net)"]);
8383
| ^^^^^^^^^^^^^
8484

85-
error: regex syntax error: unrecognized escape sequence
86-
--> $DIR/regex.rs:37:45
87-
|
88-
LL | let raw_string_error = Regex::new(r"[...//...]");
89-
| ^^
90-
91-
error: regex syntax error: unrecognized escape sequence
92-
--> $DIR/regex.rs:38:46
93-
|
94-
LL | let raw_string_error = Regex::new(r#"[...//...]"#);
95-
| ^^
96-
9785
error: regex parse error:
9886
/b/c
9987
^^
10088
error: unrecognized escape sequence
101-
--> $DIR/regex.rs:40:42
89+
--> $DIR/regex.rs:42:42
10290
|
10391
LL | let escaped_string_span = Regex::new("/b/c");
10492
| ^^^^^^^^
10593
|
10694
= help: consider using a raw string literal: `r".."`
10795

10896
error: regex syntax error: duplicate flag
109-
--> $DIR/regex.rs:42:34
97+
--> $DIR/regex.rs:44:34
11098
|
11199
LL | let aux_span = Regex::new("(?ixi)");
112100
| ^ ^
113101

114102
error: trivial regex
115-
--> $DIR/regex.rs:46:33
103+
--> $DIR/regex.rs:48:33
116104
|
117105
LL | let trivial_eq = Regex::new("^foobar$");
118106
| ^^^^^^^^^^
119107
|
120108
= help: consider using `==` on `str`s
121109

122110
error: trivial regex
123-
--> $DIR/regex.rs:48:48
111+
--> $DIR/regex.rs:50:48
124112
|
125113
LL | let trivial_eq_builder = RegexBuilder::new("^foobar$");
126114
| ^^^^^^^^^^
127115
|
128116
= help: consider using `==` on `str`s
129117

130118
error: trivial regex
131-
--> $DIR/regex.rs:50:42
119+
--> $DIR/regex.rs:52:42
132120
|
133121
LL | let trivial_starts_with = Regex::new("^foobar");
134122
| ^^^^^^^^^
135123
|
136124
= help: consider using `str::starts_with`
137125

138126
error: trivial regex
139-
--> $DIR/regex.rs:52:40
127+
--> $DIR/regex.rs:54:40
140128
|
141129
LL | let trivial_ends_with = Regex::new("foobar$");
142130
| ^^^^^^^^^
143131
|
144132
= help: consider using `str::ends_with`
145133

146134
error: trivial regex
147-
--> $DIR/regex.rs:54:39
135+
--> $DIR/regex.rs:56:39
148136
|
149137
LL | let trivial_contains = Regex::new("foobar");
150138
| ^^^^^^^^
151139
|
152140
= help: consider using `str::contains`
153141

154142
error: trivial regex
155-
--> $DIR/regex.rs:56:39
143+
--> $DIR/regex.rs:58:39
156144
|
157145
LL | let trivial_contains = Regex::new(NOT_A_REAL_REGEX);
158146
| ^^^^^^^^^^^^^^^^
159147
|
160148
= help: consider using `str::contains`
161149

162150
error: trivial regex
163-
--> $DIR/regex.rs:58:40
151+
--> $DIR/regex.rs:60:40
164152
|
165153
LL | let trivial_backslash = Regex::new("a/.b");
166154
| ^^^^^^^
167155
|
168156
= help: consider using `str::contains`
169157

170158
error: trivial regex
171-
--> $DIR/regex.rs:61:36
159+
--> $DIR/regex.rs:63:36
172160
|
173161
LL | let trivial_empty = Regex::new("");
174162
| ^^
175163
|
176164
= help: the regex is unlikely to be useful as it is
177165

178166
error: trivial regex
179-
--> $DIR/regex.rs:63:36
167+
--> $DIR/regex.rs:65:36
180168
|
181169
LL | let trivial_empty = Regex::new("^");
182170
| ^^^
183171
|
184172
= help: the regex is unlikely to be useful as it is
185173

186174
error: trivial regex
187-
--> $DIR/regex.rs:65:36
175+
--> $DIR/regex.rs:67:36
188176
|
189177
LL | let trivial_empty = Regex::new("^$");
190178
| ^^^^
191179
|
192180
= help: consider using `str::is_empty`
193181

194182
error: trivial regex
195-
--> $DIR/regex.rs:67:44
183+
--> $DIR/regex.rs:69:44
196184
|
197185
LL | let binary_trivial_empty = BRegex::new("^$");
198186
| ^^^^
199187
|
200188
= help: consider using `str::is_empty`
201189

202-
error: aborting due to 25 previous errors
190+
error: aborting due to 23 previous errors
203191

0 commit comments

Comments
 (0)