-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Extern Function Declarations Type Check #10877 #11804
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
Extern Function Declarations Type Check #10877 #11804
Conversation
Functions declared in an 'extern' were not properly typed checked and will report syntax errors on failure instead of an ICE. Fixes rust-lang#10877
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// error-pattern: expected |
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.
It would be better to write tests with //~ ERROR ...
on every line that should fail. (full docs, section about errors)
Ahh bugger. I had errors on each line on the my first one but saw another compile-fail that used the single error-pattern. Will sort that, and the |
Yeah, |
Sorry, some more questions on this one before I push the next round of changes up (unless I should do that so others can test?). I've syntax errors popping up for the expected cases, including the ones @huonw mentioned, is it similar to what you might expect? extern_patterns.rs:7:9: 7:10 error: expected identifier, found path
extern_patterns.rs:7 fn foo(_: int);
^ I'm also seeing failures on this type of definition within pub fn printf(_: *u8, ...); This seems to match with the changes I'm making though, since we're effectively cracking down on the allowed definitions of All tests pass so far on a |
Awesome! (Those failure look they are because |
Nevermind, I'm just slow on the uptake. Those one's are meant to fail, the message has been changed because it seems to be failing before it hits the
Now it's as I commented just before. So I would just need to adjust the failure message in the test, I'll try a few more test cases. |
Be careful: most failing tests are meant to fail for some specific reason, and unless that reason is because it's actually testing patterns in For the case above, change it to |
That was my first test case, I get the heebies when a new error/warning appears in a file I haven't touched. Long story short, it's still not quite right. Continue the research! |
Changed how I was checking for the ident as the previous method did not account for the right patterns. This update ensures the extern fn fail on the patterns expected, based on the test cases I have in: src/test/compile-fail/extern-bad-fn-decls.rs The changes to intrinsics.rs and variadic-ffi.rs are because in extern definitions the use of '_' is not allowed, based on my understanding of the issue. I'm in need of help past this point as my tests are failing by the errors that are being reported are what I expect. Something else is going on but I'm at a loss as to where to even start looking. Hopefully this change is a little more up to scratch! :)
Previous method of testing these failures reworked to break them out into separate files to ensure proper coverage, and that the tests actually perform as desired. Removed old test file.
The commits themselves look good to me, but I'm curious what others think about doing this in the parser rather than in typeck somewhere. I would expect this to not modify the grammar of the language itself but rather reject certain valid-syntax programs. |
My understanding of the problem was the functions needed to conform to a No destructuring or pattern matching, or normal awesome tasty rust like :) On Wednesday, January 29, 2014, Alex Crichton notifications@github.com
|
This is not just patching up some typechecking code though, this is changing the grammar of the rust language itself. We'd need to go an add special rules for the grammar of an extern function as opposed to a regular function. That's just my opinion though, I may be liking the grammar symmetry with regular functions too much. |
Ah I see your point. You could be but symmetry across language components Will happily adjust as required, rather do it right the first time! On Wednesday, January 29, 2014, Alex Crichton notifications@github.com
|
I'm going to have a try at completing this in the type checker as an alternative, but I was wondering if there was any further thoughts on this from anyone ? @huonw , or @alexcrichton ? Apologies, I don't mean to pester and I know there is a lot going! :) |
I've put this on the meeting agenda for today. (I'm still in favor of the typechecker route over the parser route). |
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// Concerning issue #10877 |
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'd prefer not only the issue number but also a paragraph explaining in English what the test is driving at. e.g., Test that patterns are disallowed in extern fns.
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.
(This naturally applies to all the other tests too)
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.
Okey dokey, I'll sort that out.
Closing due to inactivity, but I'd love to see this bug get fixed! |
[`impl_trait_in_params`]: avoid ICE when function with `impl Trait` type has no parameters Fixes rust-lang#11803 If I'm reading the old code correctly, it was taking the span of the first parameter (without checking that it exists, which caused the ICE) and uses that to figure out where the generic parameter to insert should go (cc `@blyxyas` you wrote the lint, is that correct?). This seemed equivalent to just `generics.span`, which doesn't require calculating the spans like that and simplifies it a fair bit changelog: don't ICE when function has no parameters but generics have an `impl Trait` type
Functions declared in an 'extern' were not properly typed checked and
will report syntax errors on failure instead of an ICE.
Based on some guidance from @huonw and @pnkfelix, I've added an additional
argument to force a ident only function declaration check. I believe I've done it so
that unless it's an
ForeignItemFn
it will use the normal type checking.A test has been added to compile-fail from the examples in the issue.
Fixes #10877