Skip to content

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

Open
@sunfishcode

Description

@sunfishcode

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-inferenceArea: Type inferenceC-bugCategory: This is a bug.I-libs-nominatedNominated for discussion during a libs team meeting.P-highHigh priorityT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions