diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2025-01-22 20:37:24 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-22 20:37:24 +0100 |
| commit | b4266b0bcdbfcf40c3b76f37a9b31dbc3f1992bb (patch) | |
| tree | 1f5bef3c1213b1334639f19f54d046b6d6153e0d /src | |
| parent | f8759830353d9d0391712552f7359489cac97f73 (diff) | |
| parent | 57dd42d6134539f5a98f59039bcba6d93daf9d6a (diff) | |
| download | rust-b4266b0bcdbfcf40c3b76f37a9b31dbc3f1992bb.tar.gz rust-b4266b0bcdbfcf40c3b76f37a9b31dbc3f1992bb.zip | |
Rollup merge of #135557 - estebank:wtf8, r=fee1-dead
Point at invalid utf-8 span on user's source code
```
error: couldn't read `$DIR/not-utf8-bin-file.rs`: stream did not contain valid UTF-8
--> $DIR/not-utf8-2.rs:6:5
|
LL | include!("not-utf8-bin-file.rs");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: byte `193` is not valid utf-8
--> $DIR/not-utf8-bin-file.rs:2:14
|
LL | let _ = "�|�␂!5�cc␕␂��";
| ^
= note: this error originates in the macro `include` (in Nightly builds, run with -Z macro-backtrace for more info)
```
When we attempt to load a Rust source code file, if there is a OS file failure we try reading the file as bytes. If that succeeds we try to turn it into UTF-8. If *that* fails, we provide additional context about *where* the file has the first invalid UTF-8 character.
Fix #76869.
Diffstat (limited to 'src')
| -rw-r--r-- | src/tools/compiletest/src/errors.rs | 2 | ||||
| -rw-r--r-- | src/tools/tidy/src/tests_revision_unpaired_stdout_stderr.rs | 2 |
2 files changed, 3 insertions, 1 deletions
diff --git a/src/tools/compiletest/src/errors.rs b/src/tools/compiletest/src/errors.rs index efe758e65cf..37ef63ae42e 100644 --- a/src/tools/compiletest/src/errors.rs +++ b/src/tools/compiletest/src/errors.rs @@ -101,6 +101,8 @@ pub fn load_errors(testfile: &Path, revision: Option<&str>) -> Vec<Error> { rdr.lines() .enumerate() + // We want to ignore utf-8 failures in tests during collection of annotations. + .filter(|(_, line)| line.is_ok()) .filter_map(|(line_num, line)| { parse_expected(last_nonfollow_error, line_num + 1, &line.unwrap(), revision).map( |(which, error)| { diff --git a/src/tools/tidy/src/tests_revision_unpaired_stdout_stderr.rs b/src/tools/tidy/src/tests_revision_unpaired_stdout_stderr.rs index 00edf99a30d..ee92d302db3 100644 --- a/src/tools/tidy/src/tests_revision_unpaired_stdout_stderr.rs +++ b/src/tools/tidy/src/tests_revision_unpaired_stdout_stderr.rs @@ -58,7 +58,7 @@ pub fn check(tests_path: impl AsRef<Path>, bad: &mut bool) { let mut expected_revisions = BTreeSet::new(); - let contents = std::fs::read_to_string(test).unwrap(); + let Ok(contents) = std::fs::read_to_string(test) else { continue }; // Collect directives. iter_header(&contents, &mut |HeaderLine { revision, directive, .. }| { |
