Misleading error info where it should require explicit type annotations in nightly
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
use std::io::Read;
struct Wrapper<In> {
i: In,
}
impl<In: Read> Read for Wrapper<In> {
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
self.i.read(buf)
}
}
impl<In> Read for &Wrapper<In>
where
for<'a> &'a In: Read,
{
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
(&self.i).read(buf)
}
}
trait FromReadable<S: Read>: Default {
fn get(s: S) -> Self {
Self::default()
}
}
#[derive(Default)]
struct Got;
impl<S: Read> FromReadable<S> for Got {}
fn from_readable<S: Read, G: FromReadable<S>>(g: G) {}
impl<In> Wrapper<In>
where
for<'a> &'a In: Read,
{
fn foo(&self) {
let got = Got::get(self);
//from_readable::<&In, _>(got)
from_readable(got)
}
}
Current output
error[E0275]: overflow evaluating the requirement `for<'a> &'a Wrapper<_>: std::io::Read`
|
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`playground`)
note: required for `&'a Wrapper<Wrapper<_>>` to implement `for<'a> std::io::Read`
--> src/lib.rs:15:10
|
15 | impl<In> Read for &Wrapper<In>
| ^^^^ ^^^^^^^^^^^^
16 | where for <'a> &'a In :Read
| ---- unsatisfied trait bound introduced here
= note: 126 redundant requirements hidden
= note: required for `&Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<...>>>>>>>>>>>` to implement `for<'a> std::io::Read`
= note: the full type name has been written to '/playground/target/debug/deps/playground-a9202c2be828afe8.long-type-989942384064675355.txt'
For more information about this error, try `rustc --explain E0275`.
Desired output
error[E0282]: type annotations needed
--> src/lib.rs:38:9
|
38 | from_readable(got)
| ^^^^^^^^^^^^^ cannot infer type of the type parameter `S` declared on the function `from_readable`
|
help: consider specifying the generic arguments
|
38 | from_readable::<S, Got>(got)
| ++++++++++
For more information about this error, try `rustc --explain E0282`.
error: could not compile `playground` (lib) due to previous error
Rationale and extra context
Current stable channel version 1.74 gives the desired output, but nightly channel version 1.76 gives the misleading infos.
Other cases
No response
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 code example from the issue with Rust 1.76 nightly and compare its diagnostics with stable 1.74. Start by tracing the compiler's type inference and diagnostic handling for the reported E0275 overflow, then add coverage for this example so the result reports E0282 and the missing type parameter as shown.
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
- Clearly specified
- Newbie friendliness
- 35/100