rust-lang/rust

New "type annotations needed" error in Rust nightly-2025-06-24

Closed this issue ยท 10 comments

Starting in Rust nightly-2025-06-24, I'm seeing a new "type annotations needed" error, in tests/path/arg.rs in rustix. The code below is a reduced standalone testcase.

I tried this code:

use std::ffi::CStr;
use std::borrow::{Borrow, Cow};

fn red() -> &'static CStr {
    todo!()
}
fn green() -> Cow<'static, CStr> {
    todo!()
}

fn main() {
    assert!(red() == Borrow::borrow(&green()))
}

I expected to see this happen: The code compiles.

Instead, this happened: Starting with Rust nightly-2025-06-24, and still with nightly-2025-06-27, I get this error:

error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type
  --> t.rs:12:22
   |
12 |     assert!(red() == Borrow::borrow(&green()))
   |                      ^^^^^^^^^^^^^^^^^^^^^^^^ cannot call associated function of trait
   |
help: use a fully-qualified path to one of the available implementations
   |
12 |     assert!(red() == <OsString as Borrow>::borrow(&green()))
   |                      ++++++++++++       +
12 |     assert!(red() == <PathBuf as Borrow>::borrow(&green()))
   |                      +++++++++++       +
12 |     assert!(red() == <&T as Borrow>::borrow(&green()))
   |                      ++++++       +
12 |     assert!(red() == <&mut T as Borrow>::borrow(&green()))
   |                      ++++++++++       +
     and 13 other candidates

error[E0283]: type annotations needed
  --> t.rs:12:22
   |
12 |     assert!(red() == Borrow::borrow(&green()))
   |                   -- ^^^^^^^^^^^^^^ cannot infer type of the type parameter `Borrowed` declared on the trait `Borrow`
   |                   |
   |                   type must be known at this point
   |
   = note: multiple `impl`s satisfying `CStr: PartialEq<_>` found in the following crates: `alloc`, `core`:
           - impl PartialEq for CStr;
           - impl PartialEq<&CStr> for CStr;
           - impl PartialEq<CString> for CStr;
           - impl PartialEq<Cow<'_, CStr>> for CStr;
   = note: required for `&CStr` to implement `PartialEq<&_>`
help: consider specifying the generic argument
   |
12 |     assert!(red() == Borrow::<Borrowed>::borrow(&green()))
   |                            ++++++++++++

Some errors have detailed explanations: E0283, E0790.
For more information about an error, try `rustc --explain E0283`.
error: could not compile `rustix` (example "t") due to 2 previous errors

Meta

The first nightly version with the error is:

rustc 1.90.0-nightly (28f1c8079 2025-06-24)
binary: rustc
commit-hash: 28f1c807911c63f08d98e7b468cfcf15a441e34b
commit-date: 2025-06-24
host: x86_64-unknown-linux-gnu
release: 1.90.0-nightly
LLVM version: 20.1.7

The last nightly version without the error is:

rustc 1.90.0-nightly (706f244db 2025-06-23)
binary: rustc
commit-hash: 706f244db581212cabf2e619e0113d70999b2bbe
commit-date: 2025-06-23
host: x86_64-unknown-linux-gnu
release: 1.90.0-nightly
LLVM version: 20.1.7

Regression arises from #137268

I notice in that crater run there were an unusually high number of error -> error cases for a crater...

lqd commented

Crater has regularly (or always) been showing 160K errors / failures to prepare for at least 6 months, unfortunately.

Crater has regularly (or always) been showing 160K errors / failures to prepare for at least 6 months, unfortunately.

we've had 15k within the last 6 months, I swear.

We discussed this during a libs meeting. We want to rerun crater since some noise filtering has been added since that PR, hopefully we better assess the impact then.

start/end commits from the rollup

@craterbot run start=master#36b21637e93b038453924d3c66821089e71d8baa end=master#3129d37ef7075ee3cbaa3d6cbe1b5794f67192b0 mode=check-only

๐Ÿšจ Error: failed to parse the command

๐Ÿ†˜ If you have any trouble with Crater please ask in t-infra on Zulip
โ„น๏ธ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot run start=master#36b21637e93b038453924d3c66821089e71d8baa end=master#3129d37ef7075ee3cbaa3d6cbe1b5794f67192b0 mode=check-only

๐Ÿ‘Œ Experiment pr-143164 created and queued.
๐Ÿ” You can check out the queue and this experiment's details.

โ„น๏ธ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

๐Ÿšง Experiment pr-143164 is now running

โ„น๏ธ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

๐ŸŽ‰ Experiment pr-143164 is completed!
๐Ÿ“Š 26 regressed and 7 fixed (674135 total)
๐Ÿ“ฐ Open the summary report.

โš ๏ธ If you notice any spurious failure please add them to the denylist!
โ„น๏ธ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

The crater results show only 1 regression in the tests of yash-builtin. Considering that this and rustix's tests are the only regressions that have been discovered, @rust-lang/libs considers this acceptable breakage due to type/trait inference as per our stability policy. As such, we don't plan on reverting this.