diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2023-08-02 16:57:09 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-01-16 19:04:33 +0100 |
commit | c8911dde92a98f1c9230a04c62a5287b562bc720 (patch) | |
tree | 047dcd5a581084b8fc30514dc286b060f258115e /gcc/rust/rust-session-manager.cc | |
parent | ccef457297594c5eadf57ec402122f260c1edc8f (diff) | |
download | gcc-c8911dde92a98f1c9230a04c62a5287b562bc720.zip gcc-c8911dde92a98f1c9230a04c62a5287b562bc720.tar.gz gcc-c8911dde92a98f1c9230a04c62a5287b562bc720.tar.bz2 |
gccrs: Move extern crate resolving
Move extern crate resolving under the extern crate declaration instead
of doing it under the crate's root as extern crates are not resolved by
the top level resolver.
gcc/rust/ChangeLog:
* metadata/rust-extern-crate.cc (ExternCrate::ExternCrate):
Update definition to allow Extern crate with no content (pure
proc macros).
(ExternCrate::ok): Panic on no content.
(ExternCrate::load): Likewise.
* metadata/rust-extern-crate.h: Update prototypes.
* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::go):
Remove macro resolution.
(TopLevel::visit): Likewise.
* resolve/rust-toplevel-name-resolver-2.0.h: Add visit prototype
for extern crate.
* rust-session-manager.cc (Session::load_extern_crate): Adapt
content depending on the loaded crate's content.
* util/rust-hir-map.cc (Mappings::lookup_derive_proc_macros):
Change return type to optional because it is way more
convenient.
(Mappings::lookup_bang_proc_macros): Likewise.
(Mappings::lookup_attribute_proc_macros): Likewise.
* util/rust-hir-map.h: Update function prototypes.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'gcc/rust/rust-session-manager.cc')
-rw-r--r-- | gcc/rust/rust-session-manager.cc | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc index d0d92a8..2a8ef97 100644 --- a/gcc/rust/rust-session-manager.cc +++ b/gcc/rust/rust-session-manager.cc @@ -1018,19 +1018,24 @@ Session::load_extern_crate (const std::string &crate_name, location_t locus) { s = Import::open_package (import_name, locus, relative_import_path); } - if (s.first == NULL) + if (s.first == NULL && s.second.empty ()) { rust_error_at (locus, "failed to locate crate %<%s%>", import_name.c_str ()); return UNKNOWN_NODEID; } - Imports::ExternCrate extern_crate (*s.first, s.second); - bool ok = extern_crate.load (locus); - if (!ok) + auto extern_crate = s.first == nullptr + ? Imports::ExternCrate (crate_name, s.second) + : Imports::ExternCrate (*s.first); + if (s.first != nullptr) { - rust_error_at (locus, "failed to load crate metadata"); - return UNKNOWN_NODEID; + bool ok = extern_crate.load (locus); + if (!ok) + { + rust_error_at (locus, "failed to load crate metadata"); + return UNKNOWN_NODEID; + } } // ensure the current vs this crate name don't collide |