diff options
| author | bors <bors@rust-lang.org> | 2022-01-02 06:28:34 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-01-02 06:28:34 +0000 |
| commit | f7934f693bceb4820751394be72b781e264da6d6 (patch) | |
| tree | e17ab8c0a8381250e6b9c9a92fb7f33fd9e82cd2 | |
| parent | 7b13c628a214a03f4f45b80e26313df55654d254 (diff) | |
| parent | 54cd8248190506054057d6bf12f1e957f09b13d6 (diff) | |
| download | rust-f7934f693bceb4820751394be72b781e264da6d6.tar.gz rust-f7934f693bceb4820751394be72b781e264da6d6.zip | |
Auto merge of #92034 - petrochenkov:nolinknores, r=joshtriplett
Remove effect of `#[no_link]` attribute on name resolution Previously it hid all non-macro names from other crates. This has no relation to linking and can change name resolution behavior in some cases (e.g. glob conflicts), in addition to just producing the "unresolved name" errors. I can kind of understand the possible reasoning behind the current behavior - if you can use names from a `no_link` crates then you can use, for example, functions too, but whether it will actually work or produce link-time errors will depend on random factors like inliner behavior. (^^^ This is not the actual reason why the current behavior exist, I've looked through git history and it's mostly accidental.) I think this risk is ok for such an obscure attribute, and we don't need to specifically prevent use of non-macro items from such crates. (I'm not actually sure why would anyone use `#[no_link]` on a crate, even if it's macro only, if you aware of any use cases, please share. IIRC, at some point it was used for crates implementing custom derives - the now removed legacy ones, not the current proc macros.) Extracted from https://github.com/rust-lang/rust/pull/91795.
| -rw-r--r-- | compiler/rustc_metadata/src/rmeta/decoder.rs | 10 | ||||
| -rw-r--r-- | src/test/ui/no-link.rs | 3 | ||||
| -rw-r--r-- | src/test/ui/no-link.stderr | 9 |
3 files changed, 3 insertions, 19 deletions
diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index 1069c244058..8ff3b1e72d8 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -1100,10 +1100,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { }; // Iterate over all children. - let macros_only = self.dep_kind.lock().macros_only(); - if !macros_only { - let children = self.root.tables.children.get(self, id).unwrap_or_else(Lazy::empty); - + if let Some(children) = self.root.tables.children.get(self, id) { for child_index in children.decode((self, sess)) { // FIXME: Merge with the logic below. if let None | Some(EntryKind::ForeignMod | EntryKind::Impl(_)) = @@ -1172,11 +1169,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { if let EntryKind::Mod(exports) = kind { for exp in exports.decode((self, sess)) { - match exp.res { - Res::Def(DefKind::Macro(..), _) => {} - _ if macros_only => continue, - _ => {} - } callback(exp); } } diff --git a/src/test/ui/no-link.rs b/src/test/ui/no-link.rs index 939271832e3..c80e61b4511 100644 --- a/src/test/ui/no-link.rs +++ b/src/test/ui/no-link.rs @@ -1,8 +1,9 @@ +// check-pass // aux-build:empty-struct.rs #[no_link] extern crate empty_struct; fn main() { - empty_struct::XEmpty1; //~ ERROR cannot find value `XEmpty1` in crate `empty_struct` + empty_struct::XEmpty1 {}; } diff --git a/src/test/ui/no-link.stderr b/src/test/ui/no-link.stderr deleted file mode 100644 index 66a74ff6560..00000000000 --- a/src/test/ui/no-link.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0425]: cannot find value `XEmpty1` in crate `empty_struct` - --> $DIR/no-link.rs:7:19 - | -LL | empty_struct::XEmpty1; - | ^^^^^^^ not found in `empty_struct` - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0425`. |
