public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] Add location info when opening a file fails in include_str and include_bytes. Resolves issue #1872
@ 2023-03-05 11:41 Thomas Schwinge
0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2023-03-05 11:41 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:6d25dac7370289ef8e44f1f8370572aebac6e8e4
commit 6d25dac7370289ef8e44f1f8370572aebac6e8e4
Author: Nikos Alexandris <nikos-alexandris@protonmail.com>
Date: Thu Mar 2 03:14:46 2023 +0200
Add location info when opening a file fails in include_str and include_bytes. Resolves issue #1872
gcc/rust/ChangeLog:
* expand/rust-macro-builtins.cc (load_file_bytes): Add location parameter.
(MacroBuiltin::include_bytes_handler): Pass location to load_file_bytes.
(MacroBuiltin::include_str_handler): Pass location to load_file_bytes.
gcc/testsuite/ChangeLog:
* rust/compile/builtin_macro_include_bytes_location_info.rs: New test.
* rust/compile/builtin_macro_include_str_location_info.rs: New test.
Signed-off-by: Nikos Alexandris <nikos-alexandris@protonmail.com>
Diff:
---
gcc/rust/expand/rust-macro-builtins.cc | 12 +++++++-----
.../compile/builtin_macro_include_bytes_location_info.rs | 10 ++++++++++
.../rust/compile/builtin_macro_include_str_location_info.rs | 10 ++++++++++
3 files changed, 27 insertions(+), 5 deletions(-)
diff --git a/gcc/rust/expand/rust-macro-builtins.cc b/gcc/rust/expand/rust-macro-builtins.cc
index d7f15784ceb..5f317a0a1df 100644
--- a/gcc/rust/expand/rust-macro-builtins.cc
+++ b/gcc/rust/expand/rust-macro-builtins.cc
@@ -308,12 +308,12 @@ source_relative_path (std::string path, Location locus)
FIXME: platform specific. */
std::vector<uint8_t>
-load_file_bytes (const char *filename)
+load_file_bytes (Location invoc_locus, const char *filename)
{
RAIIFile file_wrap (filename);
if (file_wrap.get_raw () == nullptr)
{
- rust_error_at (Location (), "cannot open filename %s: %m", filename);
+ rust_error_at (invoc_locus, "cannot open filename %s: %m", filename);
return std::vector<uint8_t> ();
}
@@ -326,7 +326,7 @@ load_file_bytes (const char *filename)
if (fread (&buf[0], fsize, 1, f) != 1)
{
- rust_error_at (Location (), "error reading file %s: %m", filename);
+ rust_error_at (invoc_locus, "error reading file %s: %m", filename);
return std::vector<uint8_t> ();
}
@@ -391,7 +391,8 @@ MacroBuiltin::include_bytes_handler (Location invoc_locus,
std::string target_filename
= source_relative_path (lit_expr->as_string (), invoc_locus);
- std::vector<uint8_t> bytes = load_file_bytes (target_filename.c_str ());
+ std::vector<uint8_t> bytes
+ = load_file_bytes (invoc_locus, target_filename.c_str ());
/* Is there a more efficient way to do this? */
std::vector<std::unique_ptr<AST::Expr>> elts;
@@ -455,7 +456,8 @@ MacroBuiltin::include_str_handler (Location invoc_locus,
std::string target_filename
= source_relative_path (lit_expr->as_string (), invoc_locus);
- std::vector<uint8_t> bytes = load_file_bytes (target_filename.c_str ());
+ std::vector<uint8_t> bytes
+ = load_file_bytes (invoc_locus, target_filename.c_str ());
/* FIXME: reuse lexer */
int expect_single = 0;
diff --git a/gcc/testsuite/rust/compile/builtin_macro_include_bytes_location_info.rs b/gcc/testsuite/rust/compile/builtin_macro_include_bytes_location_info.rs
new file mode 100644
index 00000000000..98bf53b777f
--- /dev/null
+++ b/gcc/testsuite/rust/compile/builtin_macro_include_bytes_location_info.rs
@@ -0,0 +1,10 @@
+#![feature(rustc_attrs)]
+
+#[rustc_builtin_macro]
+macro_rules! include_bytes {
+ () => {{}};
+}
+
+fn main() {
+ include_bytes!("nonexistent.txt"); // { dg-error "cannot open filename (.*?)nonexistent.txt: No such file or directory" }
+}
diff --git a/gcc/testsuite/rust/compile/builtin_macro_include_str_location_info.rs b/gcc/testsuite/rust/compile/builtin_macro_include_str_location_info.rs
new file mode 100644
index 00000000000..a94603353f7
--- /dev/null
+++ b/gcc/testsuite/rust/compile/builtin_macro_include_str_location_info.rs
@@ -0,0 +1,10 @@
+#![feature(rustc_attrs)]
+
+#[rustc_builtin_macro]
+macro_rules! include_str {
+ () => {{}};
+}
+
+fn main() {
+ include_str!("nonexistent.txt"); // { dg-error "cannot open filename (.*?)nonexistent.txt: No such file or directory" }
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-03-05 11:41 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-05 11:41 [gcc/devel/rust/master] Add location info when opening a file fails in include_str and include_bytes. Resolves issue #1872 Thomas Schwinge
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).