Skip to content

Commit 7c84ba1

Browse files
committed
use char instead of &str for single char patterns
1 parent a8437cf commit 7c84ba1

File tree

30 files changed

+44
-44
lines changed

30 files changed

+44
-44
lines changed

src/librustc_builtin_macros/asm.rs

Lines changed: 4 additions & 4 deletions
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,

src/librustc_builtin_macros/format.rs

Lines changed: 1 addition & 1 deletion
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

src/librustc_codegen_llvm/back/lto.rs

Lines changed: 1 addition & 1 deletion
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());

src/librustc_codegen_utils/link.rs

Lines changed: 1 addition & 1 deletion
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",

src/librustc_driver/args.rs

Lines changed: 1 addition & 1 deletion
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,

src/librustc_driver/lib.rs

Lines changed: 1 addition & 1 deletion
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;

src/librustc_expand/proc_macro_server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ impl ToInternal<TokenStream> for TokenTree<Group, Punct, Ident, Literal> {
209209
TokenTree::Literal(self::Literal {
210210
lit: token::Lit { kind: token::Integer, symbol, suffix },
211211
span,
212-
}) if symbol.as_str().starts_with("-") => {
212+
}) if symbol.as_str().starts_with('-') => {
213213
let minus = BinOp(BinOpToken::Minus);
214214
let symbol = Symbol::intern(&symbol.as_str()[1..]);
215215
let integer = TokenKind::lit(token::Integer, symbol, suffix);
@@ -220,7 +220,7 @@ impl ToInternal<TokenStream> for TokenTree<Group, Punct, Ident, Literal> {
220220
TokenTree::Literal(self::Literal {
221221
lit: token::Lit { kind: token::Float, symbol, suffix },
222222
span,
223-
}) if symbol.as_str().starts_with("-") => {
223+
}) if symbol.as_str().starts_with('-') => {
224224
let minus = BinOp(BinOpToken::Minus);
225225
let symbol = Symbol::intern(&symbol.as_str()[1..]);
226226
let float = TokenKind::lit(token::Float, symbol, suffix);

src/librustc_hir/hir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1496,7 +1496,7 @@ pub fn is_range_literal(sm: &SourceMap, expr: &Expr<'_>) -> bool {
14961496
let end_point = sm.end_point(*span);
14971497

14981498
if let Ok(end_string) = sm.span_to_snippet(end_point) {
1499-
!(end_string.ends_with("}") || end_string.ends_with(")"))
1499+
!(end_string.ends_with('}') || end_string.ends_with(')'))
15001500
} else {
15011501
false
15021502
}

src/librustc_incremental/assert_module_sources.rs

Lines changed: 1 addition & 1 deletion
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)

src/librustc_incremental/persist/fs.rs

Lines changed: 3 additions & 3 deletions
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
}

0 commit comments

Comments
 (0)