Repository navigation
The link attribute is not scoped to the extern block it is written on - #2390
Open
isHeSatoshi wants to merge 1 commit into
Open
isHeSatoshi wants to merge 1 commit into
isHeSatoshi wants to merge 1 commit into
Conversation
The rule said the `link` attribute names a library "to link with for the items within an extern block", which suggests the library is bound to those items. It is not: the library is added to the link, so it can resolve symbols declared in any extern block, and that is why the rule further down already says a `link` attribute on an empty extern block can "satisfy the linking requirements of extern blocks elsewhere in your code". Say what the attribute actually does, and point at that rule so it follows from the introduction instead of contradicting it.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1986.
The rule said the
linkattribute specifies a library "to link with for the items within anexternblock", which suggests the library is bound to the items of that block.It is not. I checked by asking rustc for the link line it would use, using a
bincrate so that linking actually happens:fooon the link line?#[link(name = "foo")] unsafe extern "C" {}+fn main() {}"foo.lib")fn main() {}#[link(name = "foo")] unsafe extern "C" { fn bar(); }+fn main() {}The first row is the interesting one: the
externblock is empty, so there are no items for the library to be bound to, and the library is passed to the linker anyway.The page already implies this.
r[items.extern.attributes.link.empty-block], a few rules further down, says an empty block can be used "to satisfy the linking requirements of extern blocks elsewhere in your code (including upstream crates)", which does not fit "for the items within anexternblock".So the change states what the attribute does and points at that rule, so that the rule follows from the introduction rather than contradicting it.
cargo run --package=style-check -- srcpasses. No new links beyond a rule reference that mdbook-spec resolves automatically.