-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a crate keyword and allow it to link external crates #12017
Conversation
@huonw r? This is a first iteration for this change! It seems pretty complete, although I would appreciate a detailed review on both methods since the re-factor could have introduced some regressions. |
Was it decided to go with A C library is certainly not considered a crate, and the plan for supporting libclang-based symbol resolution for native libraries was to add an attribute to an |
@thestinger, you may be interested in these minutes: https://github.com/mozilla/rust/wiki/Meeting-weekly-2013-12-17#wiki-extern-mod---extern-crate |
Ah, I wasn't aware it had been discussed - nevermind then. |
@@ -4608,12 +4587,33 @@ impl Parser { | |||
visibility, | |||
maybe_append(attrs, extra_attrs)); | |||
return IoviItem(item); | |||
} else { | |||
} else if self.eat_keyword(keywords::Crate) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this might be better to put this before .parse_opt_abis
. i.e.
if self.is_keyword(keywords::Extern) {
let next_is_mod = self.eat_keyword(keywords::Mod);
if self.eat_keyword(keywords::Crate) || next_is_mod {
if next_is_mod { self.span_note(...) }
self.parse_item_extern_crate(lo, visibility, attrs);
}
let opt_abis = self.parse_opt_abis();
if self.eat_keyword(keywords::Fn) { ... }
...
}
This means that extern "ABI" crate blah;
is an "unexpected token crate
" error, which seems reasonable. Although the keeping it the way it is now seems ok-ish.
Also, as I hinted in then code above above, wouldn't this be better as (something equivalent to) self.eat_keyword(keywords::Crate) || self.eat_keyword(keywords::Mod)
rather than duplicating the logic below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As it is now, it still raises the "ABI" error but I think we should get rid of that. I'll refactor the code based on your suggestions.
This requiers to change all usages of |
return self.parse_item_foreign_mod(lo, opt_abis, visibility, attrs); | ||
} | ||
|
||
if opt_abis.is_some() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we need the "expected
fnor
{"
error here? (i.e. replace this if
with just self.span_fatal(self.span, format!("expected ... but found {}", self.this_token_to_str())
.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The else if self.token
should handle extern {
I'll add an else clause with the error you suggested or re-write this if entirely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I'm talking about the case when it's not a {
or fn
(i.e. neither case is triggered above): test it with extern blah;
. It should emit an error, but it won't.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And yet I again, I should stop doing so many things at the same time. I was talking about the else if self.token
not this specific if statement. I agree it should go away, in fact, I already removed it.
I would like this to be held off until a meeting, where making |
@cmr I went ahead and worked on this based on @brson comment. The idea is to make it a full keyword for now and then contextualized it later if there's an agreement to do that. #9880 (comment) |
In the meeting today we decided to continue with Let's please rename uses of
|
I asked @cmr to remove his r+ because I realized that this still emits a NOTE for |
@alexcrichton Commented the |
Looks like this failed due to a legitimate reason |
@alexcrichton damn, I forgot to update the error message. Done: r? p=? |
This patch replaces all `crate` usage with `krate` before introducing the new keyword. This ensures that after introducing the keyword, there won't be any compilation errors. krate might not be the most expressive substitution for crate but it's a very close abbreviation for it. `module` was already used in several places already.
This patch adds a new keyword `crate` which is intended to replace mod in the context of `extern mod` as part of the issue rust-lang#9880. The patch doesn't replace all `extern mod` cases since it is necessary to first push a new snapshot 0. The implementation could've been less invasive than this. However I preferred to take this chance to split the `parse_item_foreign_mod` method and pull the `extern crate` part out of there, hence the new method `parse_item_foreign_crate`.
This patch gets rid of ObsoleteExternModAttributesInParens and ObsoleteNamedExternModule since the replacement of `extern mod` with `extern crate` avoids those cases and raises different errors. Both have been around for at least a version which makes this a good moment to get rid of them.
The first setp for #9880 is to add a new `crate` keyword. This PR does exactly that. I took a chance to refactor `parse_item_foreign_mod` and I broke it down into 2 separate methods to isolate each feature. The next step will be to push a new stage0 snapshot and then get rid of all `extern mod` around the code.
minor: Bump deps
The first setp for #9880 is to add a new
crate
keyword. This PR does exactly that. I took a chance to refactorparse_item_foreign_mod
and I broke it down into 2 separate methods to isolate each feature.The next step will be to push a new stage0 snapshot and then get rid of all
extern mod
around the code.