Error: Type or Const Parameters on Foreign Items
Open
Nobody has claimed this yet.
bug
good-first-pr
- Dominant language
- C++
- Stars
- 2.9k
- Forks
- 231
- Avg merge
- 19h 55m
- Merged PRs (30d)
- 67
Description
Type or Const Parameters Not Allowed on Foreign Items
I tried this code from E0044:
- You can view the same on compiler-explorer
#![allow(unused)]
fn main() {
extern "C" { fn some_func<T>(x: T); }
}
I expected to see this happen:
- Give error, like rustc-1.49:
➜ mahad-testsuite rustc E0044.rs
error[E0044]: foreign items may not have type parameters
--> E0044.rs:3:14
|
3 | extern "C" { fn some_func<T>(x: T); }
| ^^^^^^^^^^^^^^^^^^^^^^ can't have type parameters
|
= help: replace the type parameters with concrete types like `u32`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0044`.
Instead, this happened:
- Compiled Successfuly.
➜ gccrs-build gcc/crab1 -frust-incomplete-and-experimental-compiler-do-not-use ../mahad-testsuite/E0044.rs
Analyzing compilation unit
Performing interprocedural optimizations
<*free_lang_data> {heap 828k} <visibility> {heap 828k} <build_ssa_passes> {heap 828k} <opt_local_passes> {heap 1104k} <remove_symbols> {heap 1104k} <targetclone> {heap 1104k} <free-fnsummary> {heap 1104k}Streaming LTO
<whole-program> {heap 1104k} <fnsummary> {heap 1104k} <inline> {heap 1104k} <modref> {heap 1104k} <free-fnsummary> {heap 1104k} <single-use> {heap 1104k} <comdats> {heap 1104k}Assembling functions:
<simdclone> {heap 1104k} E0044::main
Time variable usr sys wall GGC
phase parsing : 0.00 ( 0%) 0.00 ( 0%) 0.01 ( 33%) 25k ( 12%)
phase opt and generate : 0.00 ( 0%) 0.01 (100%) 0.02 ( 67%) 58k ( 26%)
parser (global) : 0.00 ( 0%) 0.00 ( 0%) 0.01 ( 33%) 25k ( 12%)
integrated RA : 0.00 ( 0%) 0.01 (100%) 0.01 ( 33%) 24k ( 11%)
initialize rtl : 0.00 ( 0%) 0.00 ( 0%) 0.01 ( 33%) 12k ( 6%)
TOTAL : 0.00 0.01 0.03 221k
Extra diagnostic checks enabled; compiler may run slowly.
Configure with --enable-checking=release to disable checks.
Meta
- What version of Rust GCC were you using, git sha 5406b633a1f5e6e3ae8da02589adf4ea003dec12.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the Rust reproducer from the issue with gccrs at commit 5406b633a1f5e6e3ae8da02589adf4ea003dec12 and compare it with rustc's E0044 diagnostic. Trace gccrs handling of foreign items and generic parameters; done means the example is rejected with an appropriate error instead of compiling successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100