Showing wrong compiler error in this case.
Open
Nobody has claimed this yet.
A-diagnostics
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
// If we remove this enum, the compiler error seems reasonable.
enum Terminal<E> {
Error(E),
}
struct From<I>(I);
fn repeat<T>(value: T, n: usize) -> From<_>
where
T: Clone,
{
From(std::iter::repeat_n(value, n))
}
Current output
[{
"resource": "/Users/yawang/Documents/rust-test/src/lib.rs",
"owner": "rustc",
"code": {
"value": "Click for full compiler diagnostic",
"target": {
"$mid": 1,
"path": "/diagnostic message [0]",
"scheme": "rust-analyzer-diagnostics-view",
"query": "0",
"fragment": "file:///Users/yawang/Documents/rust-test/src/lib.rs"
}
},
"severity": 8,
"message": "cycle detected when computing the variances for items in this crate\n...which again requires computing the variances for items in this crate, completing the cycle\nsee https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information",
"source": "rustc",
"startLineNumber": 1,
"startColumn": 1,
"endLineNumber": 1,
"endColumn": 1,
"relatedInformation": [
{
"startLineNumber": 7,
"startColumn": 1,
"endLineNumber": 9,
"endColumn": 14,
"message": "...which requires computing function signature of `repeat`...",
"resource": "/Users/yawang/Documents/rust-test/src/lib.rs"
},
{
"startLineNumber": 7,
"startColumn": 1,
"endLineNumber": 9,
"endColumn": 14,
"message": "...which requires type-checking `repeat`...",
"resource": "/Users/yawang/Documents/rust-test/src/lib.rs"
},
{
"startLineNumber": 5,
"startColumn": 1,
"endLineNumber": 5,
"endColumn": 15,
"message": "...which requires computing the variances of `From`...",
"resource": "/Users/yawang/Documents/rust-test/src/lib.rs"
},
{
"startLineNumber": 1,
"startColumn": 1,
"endLineNumber": 1,
"endColumn": 17,
"message": "cycle used when computing the variances of `Terminal`",
"resource": "/Users/yawang/Documents/rust-test/src/lib.rs"
}
]
}]
Desired output
[{
"resource": "/Users/yawang/Documents/rust-test/src/lib.rs",
"owner": "rustc",
"code": {
"value": "Click for full compiler diagnostic",
"target": {
"$mid": 1,
"path": "/diagnostic message [1]",
"scheme": "rust-analyzer-diagnostics-view",
"query": "1",
"fragment": "file:///Users/yawang/Documents/rust-test/src/lib.rs"
}
},
"severity": 8,
"message": "the placeholder `_` is not allowed within types on item signatures for return types\nnot allowed in type signatures",
"source": "rustc",
"startLineNumber": 7,
"startColumn": 42,
"endLineNumber": 7,
"endColumn": 43
},{
"resource": "/Users/yawang/Documents/rust-test/src/lib.rs",
"owner": "rustc",
"code": {
"value": "Click for full compiler diagnostic",
"target": {
"$mid": 1,
"path": "/diagnostic message [0]",
"scheme": "rust-analyzer-diagnostics-view",
"query": "0",
"fragment": "file:///Users/yawang/Documents/rust-test/src/lib.rs"
}
},
"severity": 8,
"message": "type annotations needed\ncannot infer type for struct `From<_>`",
"source": "rustc",
"startLineNumber": 10,
"startColumn": 1,
"endLineNumber": 12,
"endColumn": 2
}]
Rationale and extra context
No response
Other cases
Rust Version
rustc 1.86.0 (05f9846f8 2025-03-31)
binary: rustc
commit-hash: 05f9846f893b09a1be1fc8560e33fc3c815cfecb
commit-date: 2025-03-31
host: aarch64-apple-darwin
release: 1.86.0
LLVM version: 19.1.7
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
Reproduce the case in src/lib.rs using rustc 1.86.0 and compare the current diagnostic with the desired output. Start by investigating the compiler query cycle reported in the diagnostic and the handling of the _ return type in repeat. Done means the invalid placeholder diagnostic appears at the return type and the separate inference error is reported for From<_>.
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
- 35/100