forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#128792 - compiler-errors:foreign-sig, r=<try>
Use `FnSig` instead of raw `FnDecl` for `ForeignItemKind::Fn`, fix ICE for `Fn` trait error on safe foreign fn Let's use `hir::FnSig` instead of `hir::FnDecl + hir::Safety` for `ForeignItemKind::Fn`. This consolidates some handling code between normal fns and foreign fns. Separetly, fix an ICE where we weren't handling `Fn` trait errors for safe foreign fns. If perf is bad for the first commit, I can rework the ICE fix to not rely on it. But if perf is good, I prefer we fix and clean up things all at once 👍 r? spastorino Fixes rust-lang#128764
- Loading branch information
Showing
27 changed files
with
170 additions
and
106 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Make sure we don't ICE when a foreign fn doesn't implement `Fn` due to arg mismatch. | ||
|
||
unsafe extern "Rust" { | ||
pub safe fn foo(); | ||
pub safe fn bar(x: u32); | ||
} | ||
|
||
fn test(_: impl Fn(i32)) {} | ||
|
||
fn main() { | ||
test(foo); //~ ERROR function is expected to take 1 argument, but it takes 0 arguments | ||
test(bar); //~ ERROR type mismatch in function arguments | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
error[E0593]: function is expected to take 1 argument, but it takes 0 arguments | ||
--> $DIR/foreign-safe-fn-arg-mismatch.rs:11:10 | ||
| | ||
LL | pub safe fn foo(); | ||
| ------------------ takes 0 arguments | ||
... | ||
LL | test(foo); | ||
| ---- ^^^ expected function that takes 1 argument | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
note: required by a bound in `test` | ||
--> $DIR/foreign-safe-fn-arg-mismatch.rs:8:17 | ||
| | ||
LL | fn test(_: impl Fn(i32)) {} | ||
| ^^^^^^^ required by this bound in `test` | ||
|
||
error[E0631]: type mismatch in function arguments | ||
--> $DIR/foreign-safe-fn-arg-mismatch.rs:12:10 | ||
| | ||
LL | pub safe fn bar(x: u32); | ||
| ------------------------ found signature defined here | ||
... | ||
LL | test(bar); | ||
| ---- ^^^ expected due to this | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
= note: expected function signature `fn(i32) -> _` | ||
found function signature `fn(u32) -> _` | ||
note: required by a bound in `test` | ||
--> $DIR/foreign-safe-fn-arg-mismatch.rs:8:17 | ||
| | ||
LL | fn test(_: impl Fn(i32)) {} | ||
| ^^^^^^^ required by this bound in `test` | ||
help: consider wrapping the function in a closure | ||
| | ||
LL | test(|arg0: i32| bar(/* u32 */)); | ||
| +++++++++++ +++++++++++ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
Some errors have detailed explanations: E0593, E0631. | ||
For more information about an error, try `rustc --explain E0593`. |
This file contains 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
Oops, something went wrong.