Skip to content

Commit 307e884

Browse files
Rollup merge of #153200 - AbstractiveNord:lexer-less-clone, r=Kivooeo
Remove redundant clone Don't clone file content just for utf8 checks.
2 parents f3035e7 + c97f2c3 commit 307e884

File tree

1 file changed

+2
-9
lines changed
  • compiler/rustc_parse/src

1 file changed

+2
-9
lines changed

compiler/rustc_parse/src/lib.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,16 +118,9 @@ pub fn new_parser_from_file<'a>(
118118
let msg = format!("couldn't read `{}`: {}", path.display(), e);
119119
let mut err = psess.dcx().struct_fatal(msg);
120120
if let Ok(contents) = std::fs::read(path)
121-
&& let Err(utf8err) = String::from_utf8(contents.clone())
121+
&& let Err(utf8err) = std::str::from_utf8(&contents)
122122
{
123-
utf8_error(
124-
sm,
125-
&path.display().to_string(),
126-
sp,
127-
&mut err,
128-
utf8err.utf8_error(),
129-
&contents,
130-
);
123+
utf8_error(sm, &path.display().to_string(), sp, &mut err, utf8err, &contents);
131124
}
132125
if let Some(sp) = sp {
133126
err.span(sp);

0 commit comments

Comments
 (0)