Skip to content

Commit f7934f6

Browse files
committed
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 #91795.
2 parents 7b13c62 + 54cd824 commit f7934f6

File tree

3 files changed

+3
-19
lines changed

3 files changed

+3
-19
lines changed

Diff for: compiler/rustc_metadata/src/rmeta/decoder.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -1100,10 +1100,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
11001100
};
11011101

11021102
// Iterate over all children.
1103-
let macros_only = self.dep_kind.lock().macros_only();
1104-
if !macros_only {
1105-
let children = self.root.tables.children.get(self, id).unwrap_or_else(Lazy::empty);
1106-
1103+
if let Some(children) = self.root.tables.children.get(self, id) {
11071104
for child_index in children.decode((self, sess)) {
11081105
// FIXME: Merge with the logic below.
11091106
if let None | Some(EntryKind::ForeignMod | EntryKind::Impl(_)) =
@@ -1172,11 +1169,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
11721169

11731170
if let EntryKind::Mod(exports) = kind {
11741171
for exp in exports.decode((self, sess)) {
1175-
match exp.res {
1176-
Res::Def(DefKind::Macro(..), _) => {}
1177-
_ if macros_only => continue,
1178-
_ => {}
1179-
}
11801172
callback(exp);
11811173
}
11821174
}

Diff for: src/test/ui/no-link.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
// check-pass
12
// aux-build:empty-struct.rs
23

34
#[no_link]
45
extern crate empty_struct;
56

67
fn main() {
7-
empty_struct::XEmpty1; //~ ERROR cannot find value `XEmpty1` in crate `empty_struct`
8+
empty_struct::XEmpty1 {};
89
}

Diff for: src/test/ui/no-link.stderr

-9
This file was deleted.

0 commit comments

Comments
 (0)