New "type annotations needed" error in Rust nightly-2025-06-24 · Issue #143164 · rust-lang/rust · GitHub
Skip to content

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

Closed

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

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Jun 28, 2025
  2. workingjubilee commented on Jun 28, 2025

    @workingjubilee
    Member

    Regression arises from #137268

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

  3. changed the title [-]New "type annotations needed" erorr in Rust nightly-2025-06-24[/-] [+]New "type annotations needed" error in Rust nightly-2025-06-24[/+] on Jun 29, 2025
  4. lqd commented on Jun 29, 2025

    @lqd
    Member

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

  5. added
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Jun 29, 2025
  6. added and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    regression-untriagedUntriaged performance or correctness regression.
    on Jun 29, 2025
  7. workingjubilee commented on Jun 29, 2025

    @workingjubilee
    Member

    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.

  8. 6 remaining items

  9. craterbot commented on Jul 30, 2025

    @craterbot
  10. the8472 commented on Jul 30, 2025

    @the8472
    Member

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

  11. craterbot commented on Jul 30, 2025

    @craterbot
    Collaborator

    👌 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

  12. craterbot commented on Jul 31, 2025

    @craterbot
    Collaborator

    🚧 Experiment pr-143164 is now running

    ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

  13. craterbot commented on Aug 1, 2025

    @craterbot
    Collaborator

    🎉 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

  14. added
    S-waiting-on-reviewStatus: Awaiting review from the assignee but also interested parties.
    and removed
    S-waiting-on-craterStatus: Waiting on a crater run to be completed.
    on Aug 1, 2025
  15. added and removed on Aug 8, 2025
  16. Amanieu commented on Aug 13, 2025

    @Amanieu
    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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 priorityS-waiting-on-reviewStatus: Awaiting review from the assignee but also interested parties.T-libs-api[DEPRECATED; DO NOT USE]regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions