aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/ast/rust-ast-full-test.cc28
-rw-r--r--gcc/testsuite/rust/compile/torture/extern_mod2.rs19
2 files changed, 34 insertions, 13 deletions
diff --git a/gcc/rust/ast/rust-ast-full-test.cc b/gcc/rust/ast/rust-ast-full-test.cc
index 9b11498..b1572e1 100644
--- a/gcc/rust/ast/rust-ast-full-test.cc
+++ b/gcc/rust/ast/rust-ast-full-test.cc
@@ -4010,7 +4010,15 @@ filename_from_path_attribute (std::vector<Attribute> &outer_attrs)
return "";
}
- auto path = path_attr.get_attr_input ().as_string ();
+ auto path_value = path_attr.get_attr_input ().as_string ();
+
+ // At this point, the 'path' is of the following format: '= "<file.rs>"'
+ // We need to remove the equal sign and only keep the actual filename.
+ // In order to do this, we can simply go through the string until we find
+ // a character that is not an equal sign or whitespace
+ auto filename_begin = path_value.find_first_not_of ("=\t ");
+
+ auto path = path_value.substr (filename_begin);
// On windows, the path might mix '/' and '\' separators. Replace the
// UNIX-like separators by MSDOS separators to make sure the path will resolve
@@ -4022,7 +4030,7 @@ filename_from_path_attribute (std::vector<Attribute> &outer_attrs)
path.replace ('/', '\\');
#endif /* HAVE_DOS_BASED_FILE_SYSTEM */
- return path_attr.get_attr_input ().as_string ();
+ return path;
}
void
@@ -4031,10 +4039,6 @@ Module::process_file_path ()
rust_assert (kind == Module::ModuleKind::UNLOADED);
rust_assert (module_file.empty ());
- auto path_string = filename_from_path_attribute (get_outer_attrs ());
- if (!path_string.empty ())
- return;
-
// This corresponds to the path of the file 'including' the module. So the
// file that contains the 'mod <file>;' directive
std::string including_fname (outer_filename);
@@ -4053,6 +4057,13 @@ Module::process_file_path ()
current_directory_name
= including_fname.substr (0, dir_slash_pos) + file_separator;
+ auto path_string = filename_from_path_attribute (get_outer_attrs ());
+ if (!path_string.empty ())
+ {
+ module_file = current_directory_name + path_string;
+ return;
+ }
+
// FIXME: We also have to search for
// <directory>/<including_fname>/<module_name>.rs In rustc, this is done via
// the concept of `DirOwnernship`, which is based on whether or not the
@@ -4079,6 +4090,9 @@ Module::process_file_path ()
rust_error_at (locus, "no candidate found for module %s",
module_name.c_str ());
+ if (no_candidates_found || multiple_candidates_found)
+ return;
+
module_file = file_mod_found ? expected_file_path
: current_directory_name + expected_dir_path;
}
@@ -4098,7 +4112,7 @@ Module::load_items ()
if (file_wrap.get_raw () == nullptr)
{
- rust_error_at (Location (), "cannot open module file %s: %m",
+ rust_error_at (get_locus (), "cannot open module file %s: %m",
module_file.c_str ());
return;
}
diff --git a/gcc/testsuite/rust/compile/torture/extern_mod2.rs b/gcc/testsuite/rust/compile/torture/extern_mod2.rs
index f3379e3..4984d5d 100644
--- a/gcc/testsuite/rust/compile/torture/extern_mod2.rs
+++ b/gcc/testsuite/rust/compile/torture/extern_mod2.rs
@@ -3,14 +3,21 @@
#[path = "modules/valid_path.rs"]
mod not_a_valid_path;
-// #[path]
-// FIXME: This is wrong
-// mod error;
+#[path ="modules/valid_path.rs"]
+mod path_without_extra_equal;
+
+#[path= "modules/valid_path.rs"]
+mod no_leading_equal;
+
+#[path = "modules/valid_path.rs"]
+mod extra_spaces;
+
+#[path] // { dg-error "path attributes must contain a filename" }
+mod error; // { dg-error "no candidate found" }
// This is "valid", and should only error out when parsing
// the file
-// FIXME: Fix path attribute expanding
-// #[path = "not_a_valid_file.rs"]
-// mod another_error;
+#[path = "not_a_valid_file.rs"]
+mod another_error; // { dg-error "No such file or directory" }
fn main() {}