Skip to content

Commit 07d9ed2

Browse files
authored
Rollup merge of #69481 - matthiaskrgr:single_char, r=ecstatic-morse
use char instead of &str for single char patterns
2 parents a245221 + 7c84ba1 commit 07d9ed2

File tree

30 files changed

+44
-44
lines changed

30 files changed

+44
-44
lines changed

Diff for: src/librustc_builtin_macros/asm.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ fn parse_inline_asm<'a>(
182182
};
183183

184184
let is_rw = output.is_some();
185-
let is_indirect = constraint_str.contains("*");
185+
let is_indirect = constraint_str.contains('*');
186186
outputs.push(ast::InlineAsmOutput {
187187
constraint: output.unwrap_or(constraint),
188188
expr,
@@ -199,15 +199,15 @@ fn parse_inline_asm<'a>(
199199

200200
let constraint = parse_asm_str(&mut p)?;
201201

202-
if constraint.as_str().starts_with("=") {
202+
if constraint.as_str().starts_with('=') {
203203
struct_span_err!(
204204
cx.parse_sess.span_diagnostic,
205205
p.prev_span,
206206
E0662,
207207
"input operand constraint contains '='"
208208
)
209209
.emit();
210-
} else if constraint.as_str().starts_with("+") {
210+
} else if constraint.as_str().starts_with('+') {
211211
struct_span_err!(
212212
cx.parse_sess.span_diagnostic,
213213
p.prev_span,
@@ -234,7 +234,7 @@ fn parse_inline_asm<'a>(
234234

235235
if OPTIONS.iter().any(|&opt| s == opt) {
236236
cx.span_warn(p.prev_span, "expected a clobber, found an option");
237-
} else if s.as_str().starts_with("{") || s.as_str().ends_with("}") {
237+
} else if s.as_str().starts_with('{') || s.as_str().ends_with('}') {
238238
struct_span_err!(
239239
cx.parse_sess.span_diagnostic,
240240
p.prev_span,

Diff for: src/librustc_builtin_macros/format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ pub fn expand_preparsed_format_args(
894894
};
895895

896896
let (is_literal, fmt_snippet) = match ecx.source_map().span_to_snippet(fmt_sp) {
897-
Ok(s) => (s.starts_with("\"") || s.starts_with("r#"), Some(s)),
897+
Ok(s) => (s.starts_with('"') || s.starts_with("r#"), Some(s)),
898898
_ => (false, None),
899899
};
900900

Diff for: src/librustc_codegen_llvm/back/lto.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ impl ThinLTOImports {
917917
if line.is_empty() {
918918
let importing_module = current_module.take().expect("Importing module not set");
919919
imports.insert(importing_module, mem::replace(&mut current_imports, vec![]));
920-
} else if line.starts_with(" ") {
920+
} else if line.starts_with(' ') {
921921
// Space marks an imported module
922922
assert_ne!(current_module, None);
923923
current_imports.push(line.trim().to_string());

Diff for: src/librustc_codegen_utils/link.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub fn find_crate_name(sess: Option<&Session>, attrs: &[ast::Attribute], input:
7878
}
7979
if let Input::File(ref path) = *input {
8080
if let Some(s) = path.file_stem().and_then(|s| s.to_str()) {
81-
if s.starts_with("-") {
81+
if s.starts_with('-') {
8282
let msg = format!(
8383
"crate names cannot start with a `-`, but \
8484
`{}` has a leading hyphen",

Diff for: src/librustc_driver/args.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::fs;
44
use std::io;
55

66
pub fn arg_expand(arg: String) -> Result<Vec<String>, Error> {
7-
if arg.starts_with("@") {
7+
if arg.starts_with('@') {
88
let path = &arg[1..];
99
let file = match fs::read_to_string(path) {
1010
Ok(file) => file,

Diff for: src/librustc_driver/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ fn stdout_isatty() -> bool {
521521

522522
fn handle_explain(registry: Registry, code: &str, output: ErrorOutputType) {
523523
let normalised =
524-
if code.starts_with("E") { code.to_string() } else { format!("E{0:0>4}", code) };
524+
if code.starts_with('E') { code.to_string() } else { format!("E{0:0>4}", code) };
525525
match registry.find_description(&normalised) {
526526
Some(ref description) => {
527527
let mut is_in_code_block = false;

Diff for: src/librustc_expand/proc_macro_server.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ impl ToInternal<TokenStream> for TokenTree<Group, Punct, Ident, Literal> {
205205
TokenTree::Literal(self::Literal {
206206
lit: token::Lit { kind: token::Integer, symbol, suffix },
207207
span,
208-
}) if symbol.as_str().starts_with("-") => {
208+
}) if symbol.as_str().starts_with('-') => {
209209
let minus = BinOp(BinOpToken::Minus);
210210
let symbol = Symbol::intern(&symbol.as_str()[1..]);
211211
let integer = TokenKind::lit(token::Integer, symbol, suffix);
@@ -216,7 +216,7 @@ impl ToInternal<TokenStream> for TokenTree<Group, Punct, Ident, Literal> {
216216
TokenTree::Literal(self::Literal {
217217
lit: token::Lit { kind: token::Float, symbol, suffix },
218218
span,
219-
}) if symbol.as_str().starts_with("-") => {
219+
}) if symbol.as_str().starts_with('-') => {
220220
let minus = BinOp(BinOpToken::Minus);
221221
let symbol = Symbol::intern(&symbol.as_str()[1..]);
222222
let float = TokenKind::lit(token::Float, symbol, suffix);

Diff for: src/librustc_hir/hir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1504,7 +1504,7 @@ pub fn is_range_literal(sm: &SourceMap, expr: &Expr<'_>) -> bool {
15041504
let end_point = sm.end_point(*span);
15051505

15061506
if let Ok(end_string) = sm.span_to_snippet(end_point) {
1507-
!(end_string.ends_with("}") || end_string.ends_with(")"))
1507+
!(end_string.ends_with('}') || end_string.ends_with(')'))
15081508
} else {
15091509
false
15101510
}

Diff for: src/librustc_incremental/assert_module_sources.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl AssertModuleSource<'tcx> {
107107
}
108108

109109
// Split of the "special suffix" if there is one.
110-
let (user_path, cgu_special_suffix) = if let Some(index) = user_path.rfind(".") {
110+
let (user_path, cgu_special_suffix) = if let Some(index) = user_path.rfind('.') {
111111
(&user_path[..index], Some(&user_path[index + 1..]))
112112
} else {
113113
(&user_path[..], None)

Diff for: src/librustc_incremental/persist/fs.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ pub fn lock_file_path(session_dir: &Path) -> PathBuf {
152152
let directory_name = session_dir.file_name().unwrap().to_string_lossy();
153153
assert_no_characters_lost(&directory_name);
154154

155-
let dash_indices: Vec<_> = directory_name.match_indices("-").map(|(idx, _)| idx).collect();
155+
let dash_indices: Vec<_> = directory_name.match_indices('-').map(|(idx, _)| idx).collect();
156156
if dash_indices.len() != 3 {
157157
bug!(
158158
"Encountered incremental compilation session directory with \
@@ -342,7 +342,7 @@ pub fn finalize_session_directory(sess: &Session, svh: Svh) {
342342

343343
// Keep the 's-{timestamp}-{random-number}' prefix, but replace the
344344
// '-working' part with the SVH of the crate
345-
let dash_indices: Vec<_> = old_sub_dir_name.match_indices("-").map(|(idx, _)| idx).collect();
345+
let dash_indices: Vec<_> = old_sub_dir_name.match_indices('-').map(|(idx, _)| idx).collect();
346346
if dash_indices.len() != 3 {
347347
bug!(
348348
"Encountered incremental compilation session directory with \
@@ -594,7 +594,7 @@ fn extract_timestamp_from_session_dir(directory_name: &str) -> Result<SystemTime
594594
return Err(());
595595
}
596596

597-
let dash_indices: Vec<_> = directory_name.match_indices("-").map(|(idx, _)| idx).collect();
597+
let dash_indices: Vec<_> = directory_name.match_indices('-').map(|(idx, _)| idx).collect();
598598
if dash_indices.len() != 3 {
599599
return Err(());
600600
}

Diff for: src/librustc_interface/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ pub fn get_codegen_backend(sess: &Session) -> Box<dyn CodegenBackend> {
244244
.as_ref()
245245
.unwrap_or(&sess.target.target.options.codegen_backend);
246246
let backend = match &codegen_name[..] {
247-
filename if filename.contains(".") => load_backend_from_dylib(filename.as_ref()),
247+
filename if filename.contains('.') => load_backend_from_dylib(filename.as_ref()),
248248
codegen_name => get_builtin_codegen_backend(codegen_name),
249249
};
250250

Diff for: src/librustc_llvm/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ fn main() {
178178
for lib in output(&mut cmd).split_whitespace() {
179179
let name = if lib.starts_with("-l") {
180180
&lib[2..]
181-
} else if lib.starts_with("-") {
181+
} else if lib.starts_with('-') {
182182
&lib[1..]
183183
} else if Path::new(lib).exists() {
184184
// On MSVC llvm-config will print the full name to libraries, but

Diff for: src/librustc_mir/borrow_check/diagnostics/region_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
612612
} else {
613613
"'_".to_string()
614614
};
615-
let suggestion = if snippet.ends_with(";") {
615+
let suggestion = if snippet.ends_with(';') {
616616
// `type X = impl Trait;`
617617
format!("{} + {};", &snippet[..snippet.len() - 1], suggestable_fr_name)
618618
} else {

Diff for: src/librustc_mir/borrow_check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ fn do_mir_borrowck<'a, 'tcx>(
365365
// Skip over locals that begin with an underscore or have no name
366366
match mbcx.local_names[local] {
367367
Some(name) => {
368-
if name.as_str().starts_with("_") {
368+
if name.as_str().starts_with('_') {
369369
continue;
370370
}
371371
}

Diff for: src/librustc_mir/transform/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ impl<'tcx> MirSource<'tcx> {
122122
/// type `T`.
123123
pub fn default_name<T: ?Sized>() -> Cow<'static, str> {
124124
let name = ::std::any::type_name::<T>();
125-
if let Some(tail) = name.rfind(":") { Cow::from(&name[tail + 1..]) } else { Cow::from(name) }
125+
if let Some(tail) = name.rfind(':') { Cow::from(&name[tail + 1..]) } else { Cow::from(name) }
126126
}
127127

128128
/// A streamlined trait that you can implement to create a pass; the

Diff for: src/librustc_parse/parser/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ impl<'a> Parser<'a> {
753753
s.print_usize(float.trunc() as usize);
754754
s.pclose();
755755
s.s.word(".");
756-
s.s.word(fstr.splitn(2, ".").last().unwrap().to_string())
756+
s.s.word(fstr.splitn(2, '.').last().unwrap().to_string())
757757
});
758758
err.span_suggestion(
759759
lo.to(self.prev_span),

Diff for: src/librustc_passes/dead.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ impl DeadVisitor<'tcx> {
553553
node_type: &str,
554554
participle: &str,
555555
) {
556-
if !name.as_str().starts_with("_") {
556+
if !name.as_str().starts_with('_') {
557557
self.tcx.struct_span_lint_hir(lint::builtin::DEAD_CODE, id, span, |lint| {
558558
lint.build(&format!("{} is never {}: `{}`", node_type, participle, name)).emit()
559559
});

Diff for: src/librustc_resolve/build_reduced_graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
11031103
// Macro uses will remove items from this set, and the remaining
11041104
// items will be reported as `unused_macros`.
11051105
fn insert_unused_macro(&mut self, ident: Ident, node_id: NodeId, span: Span) {
1106-
if !ident.as_str().starts_with("_") {
1106+
if !ident.as_str().starts_with('_') {
11071107
self.r.unused_macros.insert(node_id, span);
11081108
}
11091109
}

Diff for: src/librustc_resolve/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2663,7 +2663,7 @@ impl<'a> Resolver<'a> {
26632663
"{} as {}{}",
26642664
&snippet[..pos],
26652665
suggested_name,
2666-
if snippet.ends_with(";") { ";" } else { "" }
2666+
if snippet.ends_with(';') { ";" } else { "" }
26672667
))
26682668
}
26692669
}

Diff for: src/librustc_target/abi/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl TargetDataLayout {
101101
match &*spec_parts {
102102
["e"] => dl.endian = Endian::Little,
103103
["E"] => dl.endian = Endian::Big,
104-
[p] if p.starts_with("P") => {
104+
[p] if p.starts_with('P') => {
105105
dl.instruction_address_space = parse_address_space(&p[1..], "P")?
106106
}
107107
["a", ref a @ ..] => dl.aggregate_align = align(a, "a")?,
@@ -111,7 +111,7 @@ impl TargetDataLayout {
111111
dl.pointer_size = size(s, p)?;
112112
dl.pointer_align = align(a, p)?;
113113
}
114-
[s, ref a @ ..] if s.starts_with("i") => {
114+
[s, ref a @ ..] if s.starts_with('i') => {
115115
let bits = match s[1..].parse::<u64>() {
116116
Ok(bits) => bits,
117117
Err(_) => {
@@ -135,7 +135,7 @@ impl TargetDataLayout {
135135
dl.i128_align = a;
136136
}
137137
}
138-
[s, ref a @ ..] if s.starts_with("v") => {
138+
[s, ref a @ ..] if s.starts_with('v') => {
139139
let v_size = size(&s[1..], "v")?;
140140
let a = align(a, s)?;
141141
if let Some(v) = dl.vector_align.iter_mut().find(|v| v.0 == v_size) {

Diff for: src/librustc_typeck/astconv.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1858,7 +1858,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
18581858
{
18591859
let types: Vec<_> =
18601860
assoc_items.iter().map(|item| format!("{} = Type", item.ident)).collect();
1861-
let code = if snippet.ends_with(">") {
1861+
let code = if snippet.ends_with('>') {
18621862
// The user wrote `Trait<'a>` or similar and we don't have a type we can
18631863
// suggest, but at least we can clue them to the correct syntax
18641864
// `Trait<'a, Item = Type>` while accounting for the `<'a>` in the

Diff for: src/librustc_typeck/check/demand.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
412412
{
413413
if let hir::ExprKind::Lit(_) = expr.kind {
414414
if let Ok(src) = sm.span_to_snippet(sp) {
415-
if src.starts_with("\"") {
415+
if src.starts_with('"') {
416416
return Some((
417417
sp,
418418
"consider adding a leading `b`",
@@ -709,7 +709,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
709709
{
710710
// Remove fractional part from literal, for example `42.0f32` into `42`
711711
let src = src.trim_end_matches(&checked_ty.to_string());
712-
src.split(".").next().unwrap()
712+
src.split('.').next().unwrap()
713713
} else {
714714
src.trim_end_matches(&checked_ty.to_string())
715715
},

Diff for: src/librustc_typeck/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4996,7 +4996,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
49964996
let sugg = if receiver.ends_with(".clone()")
49974997
&& method_call_list.contains(&method_call.as_str())
49984998
{
4999-
let max_len = receiver.rfind(".").unwrap();
4999+
let max_len = receiver.rfind('.').unwrap();
50005000
format!("{}{}", &receiver[..max_len], method_call)
50015001
} else {
50025002
if expr.precedence().order() < ExprPrecedence::MethodCall.order() {

Diff for: src/librustc_typeck/check/op.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -597,12 +597,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
597597
Ok(lstring) => {
598598
err.span_suggestion(
599599
lhs_expr.span,
600-
if lstring.starts_with("&") {
600+
if lstring.starts_with('&') {
601601
remove_borrow_msg
602602
} else {
603603
msg
604604
},
605-
if lstring.starts_with("&") {
605+
if lstring.starts_with('&') {
606606
// let a = String::new();
607607
// let _ = &a + "bar";
608608
format!("{}", &lstring[1..])
@@ -630,7 +630,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
630630
is_assign,
631631
) {
632632
(Ok(l), Ok(r), false) => {
633-
let to_string = if l.starts_with("&") {
633+
let to_string = if l.starts_with('&') {
634634
// let a = String::new(); let b = String::new();
635635
// let _ = &a + b;
636636
format!("{}", &l[1..])

Diff for: src/librustc_typeck/collect.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2206,7 +2206,7 @@ fn from_target_feature(
22062206
item.span(),
22072207
format!("`{}` is not valid for this target", feature),
22082208
);
2209-
if feature.starts_with("+") {
2209+
if feature.starts_with('+') {
22102210
let valid = whitelist.contains_key(&feature[1..]);
22112211
if valid {
22122212
err.help("consider removing the leading `+` in the feature name");
@@ -2337,7 +2337,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
23372337
codegen_fn_attrs.flags |= CodegenFnAttrFlags::TRACK_CALLER;
23382338
} else if attr.check_name(sym::export_name) {
23392339
if let Some(s) = attr.value_str() {
2340-
if s.as_str().contains("\0") {
2340+
if s.as_str().contains('\0') {
23412341
// `#[export_name = ...]` will be converted to a null-terminated string,
23422342
// so it may not contain any null characters.
23432343
struct_span_err!(

Diff for: src/librustdoc/html/markdown.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ impl LangString {
707707
x if x.starts_with("edition") => {
708708
data.edition = x[7..].parse::<Edition>().ok();
709709
}
710-
x if allow_error_code_check && x.starts_with("E") && x.len() == 5 => {
710+
x if allow_error_code_check && x.starts_with('E') && x.len() == 5 => {
711711
if x[1..].parse::<u32>().is_ok() {
712712
data.error_codes.push(x.to_owned());
713713
seen_rust_tags = !seen_other_tags || seen_rust_tags;

Diff for: src/librustdoc/html/render.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pub type NameDoc = (String, Option<String>);
8686

8787
crate fn ensure_trailing_slash(v: &str) -> impl fmt::Display + '_ {
8888
crate::html::format::display_fn(move |f| {
89-
if !v.ends_with("/") && !v.is_empty() { write!(f, "{}/", v) } else { write!(f, "{}", v) }
89+
if !v.ends_with('/') && !v.is_empty() { write!(f, "{}/", v) } else { write!(f, "{}", v) }
9090
})
9191
}
9292

Diff for: src/librustdoc/html/render/cache.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ fn extern_location(
534534

535535
if let Some(url) = extern_url {
536536
let mut url = url.to_string();
537-
if !url.ends_with("/") {
537+
if !url.ends_with('/') {
538538
url.push('/');
539539
}
540540
return Remote(url);
@@ -548,7 +548,7 @@ fn extern_location(
548548
.filter_map(|a| a.value_str())
549549
.map(|url| {
550550
let mut url = url.to_string();
551-
if !url.ends_with("/") {
551+
if !url.ends_with('/') {
552552
url.push('/')
553553
}
554554
Remote(url)

Diff for: src/librustdoc/markdown.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn extract_leading_metadata(s: &str) -> (Vec<&str>, &str) {
1919
let mut count = 0;
2020

2121
for line in s.lines() {
22-
if line.starts_with("# ") || line.starts_with("%") {
22+
if line.starts_with("# ") || line.starts_with('%') {
2323
// trim the whitespace after the symbol
2424
metadata.push(line[1..].trim_start());
2525
count += line.len() + 1;

Diff for: src/libstd/io/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2396,9 +2396,9 @@ impl<B: BufRead> Iterator for Lines<B> {
23962396
match self.buf.read_line(&mut buf) {
23972397
Ok(0) => None,
23982398
Ok(_n) => {
2399-
if buf.ends_with("\n") {
2399+
if buf.ends_with('\n') {
24002400
buf.pop();
2401-
if buf.ends_with("\r") {
2401+
if buf.ends_with('\r') {
24022402
buf.pop();
24032403
}
24042404
}

0 commit comments

Comments
 (0)