about summary refs log tree commit diff
path: root/compiler/rustc_builtin_macros/src/lib.rs
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2025-01-15 21:24:31 +0000
committerEsteban Küber <esteban@kuber.com.ar>2025-01-22 00:52:27 +0000
commit57dd42d6134539f5a98f59039bcba6d93daf9d6a (patch)
tree09e6374ea06094fc073a535434b1109a9eb34915 /compiler/rustc_builtin_macros/src/lib.rs
parent6a64e3b89724395d87a394ed9ebd954c474b080a (diff)
downloadrust-57dd42d6134539f5a98f59039bcba6d93daf9d6a.tar.gz
rust-57dd42d6134539f5a98f59039bcba6d93daf9d6a.zip
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: `[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 'compiler/rustc_builtin_macros/src/lib.rs')
-rw-r--r--compiler/rustc_builtin_macros/src/lib.rs1
1 files changed, 1 insertions, 0 deletions
diff --git a/compiler/rustc_builtin_macros/src/lib.rs b/compiler/rustc_builtin_macros/src/lib.rs
index 6071d36f8eb..0918403b855 100644
--- a/compiler/rustc_builtin_macros/src/lib.rs
+++ b/compiler/rustc_builtin_macros/src/lib.rs
@@ -16,6 +16,7 @@
 #![feature(proc_macro_internals)]
 #![feature(proc_macro_quote)]
 #![feature(rustdoc_internals)]
+#![feature(string_from_utf8_lossy_owned)]
 #![feature(try_blocks)]
 #![warn(unreachable_pub)]
 // tidy-alphabetical-end