E0428: Duplicate Definition Message in Circular include! Cases
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
cargo new repro && cd repro && \
printf 'include!("functions.rs");\ninclude!("process.rs");\nfn main() {}\n' > src/main.rs && \
printf 'fn function() {}\n' > src/functions.rs && \
printf 'include!("functions.rs");\n' > src/process.rs && \
cargo check
Current output
Creating binary (application) `repro` package
note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Checking repro v0.1.0 (/users/maenas/downloads/repro)
error[E0428]: the name `function` is defined multiple times
--> src/functions.rs:1:1
|
1 | fn function() {}
| ^^^^^^^^^^^^^
| |
| `function` redefined here
| previous definition of the value `function` here
|
= note: `function` must be defined only once in the value namespace of this module
For more information about this error, try `rustc --explain E0428`.
error: could not compile `repro` (bin "repro") due to 1 previous error
Desired output
Creating binary (application) `repro` package
note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Checking repro v0.1.0 (/users/maenas/downloads/repro)
error[E0428]: the name `function` is defined multiple times
--> src/functions.rs:1:1
|
1 | fn function() {}
| ^^^^^^^^^^^^^ duplicate inclusion of `function` here via circular `include!`
= note: the first definition is included via `src/main.rs` with:
include!("functions.rs");
= note: the duplicate definition is brought in via `src/process.rs`, which itself does:
include!("functions.rs");
= help: this circular inclusion causes `functions.rs` to be processed twice.
For more information about this error, try `rustc --explain E0428`.
error: could not compile `repro` (bin "repro") due to 1 previous error
Or something like:
error[E0428]: duplicate definition caused by circular include! expansion
. . .
= note: the file `functions.rs` was included multiple times:
- once directly in `src/main.rs` via `include!("functions.rs");`
- once indirectly in `src/process.rs` (which also does `include!("functions.rs");`)
Rationale and extra context
It says "function redefined here" and also "previous definition of the value function here." It appears to be referring to only one place, but it reads as though there is supposed to be a second "here" that is being left out, especially since that (showing two locations) is how this error message normally works.
The sentence "the name function is defined multiple times" also is confusing. In the source code, there's only one definition of function.
The error explanation doesn't mention this as a cause either. Not knowing the cause of the error, a user might:
- look in the source code for multiple definitions
- grep /src for multiple definitions
- run rustc --explain E0428
without being able to determine the cause of the error. Of course, many or most would realize the true problem quickly, but the error message appears more confusing than other similar circular errors.
The cause of this error is circular use of the !include macro.
Other cases
cargo new repro && cd repro && \
printf 'include!("a.rs");\nfn main() {}\n' > src/main.rs && \
printf 'include!("a.rs");\n' > src/a.rs && \
cargo check
Rust Version
rustc 1.83.0 (90b35a623 2024-11-26)
binary: rustc
commit-hash: 90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf
commit-date: 2024-11-26
host: aarch64-apple-darwin
release: 1.83.0
LLVM version: 19.1.1
Anything else?
No response
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 with the circular include reproductions involving src/main.rs, src/process.rs, src/functions.rs, and src/a.rs, then run cargo check to observe E0428. Trace the compiler's include! expansion and duplicate-definition diagnostic handling. Done means circular inclusion reports the relevant inclusion paths or otherwise explains the cause, with regression coverage for the shown cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100