Skip to content

impl PartialEq<{str,String}> for {Path,PathBuf} #140956

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Kixunil
Copy link
Contributor

@Kixunil Kixunil commented May 13, 2025

This is a revival of #105877

Comparison of paths and strings is expected to be possible and needed e.g. in tests. This change adds the impls os PartialEq between strings and paths, both owned and unsized, in both directions.

ACP: rust-lang/libs-team#151

@rustbot
Copy link
Collaborator

rustbot commented May 13, 2025

r? @joboet

rustbot has assigned @joboet.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels May 13, 2025
@rust-log-analyzer

This comment has been minimized.

@Kixunil Kixunil force-pushed the impl-partialeq-str-for-path branch from 44bb04c to 90838cd Compare May 13, 2025 01:37
@rust-log-analyzer

This comment has been minimized.

@Kixunil Kixunil force-pushed the impl-partialeq-str-for-path branch from 90838cd to c7d5b49 Compare May 13, 2025 01:48
@rust-log-analyzer

This comment has been minimized.

Comparison of paths and strings is expected to be possible and needed
e.g. in tests. This change adds the impls os `PartialEq` between strings
and paths, both owned and unsized, in both directions.

ACP: rust-lang/libs-team#151
@Kixunil Kixunil force-pushed the impl-partialeq-str-for-path branch from c7d5b49 to f908d17 Compare May 13, 2025 02:32
@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-llvm-19 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
#18 exporting to docker image format
#18 sending tarball 21.1s done
#18 DONE 29.1s
##[endgroup]
Setting extra environment values for docker:  --env ENABLE_GCC_CODEGEN=1 --env GCC_EXEC_PREFIX=/usr/lib/gcc/
[CI_JOB_NAME=x86_64-gnu-llvm-19]
[CI_JOB_NAME=x86_64-gnu-llvm-19]
debug: `DISABLE_CI_RUSTC_IF_INCOMPATIBLE` configured.
---
sccache: Listening on address 127.0.0.1:4226
##[group]Configure the build
configure: processing command line
configure: 
configure: build.configure-args := ['--build=x86_64-unknown-linux-gnu', '--llvm-root=/usr/lib/llvm-19', '--enable-llvm-link-shared', '--set', 'rust.randomize-layout=true', '--set', 'rust.thin-lto-import-instr-limit=10', '--set', 'build.print-step-timings', '--enable-verbose-tests', '--set', 'build.metrics', '--enable-verbose-configure', '--enable-sccache', '--disable-manage-submodules', '--enable-locked-deps', '--enable-cargo-native-static', '--set', 'rust.codegen-units-std=1', '--set', 'dist.compression-profile=balanced', '--dist-compression-formats=xz', '--set', 'rust.lld=false', '--disable-dist-src', '--release-channel=nightly', '--enable-debug-assertions', '--enable-overflow-checks', '--enable-llvm-assertions', '--set', 'rust.verify-llvm-ir', '--set', 'rust.codegen-backends=llvm,cranelift,gcc', '--set', 'llvm.static-libstdcpp', '--set', 'gcc.download-ci-gcc=true', '--enable-new-symbol-mangling']
configure: build.build          := x86_64-unknown-linux-gnu
configure: target.x86_64-unknown-linux-gnu.llvm-config := /usr/lib/llvm-19/bin/llvm-config
configure: llvm.link-shared     := True
configure: rust.randomize-layout := True
configure: rust.thin-lto-import-instr-limit := 10
---

6    |                              |
7    |                              type must be known at this point
8    |
-    = note: cannot satisfy `String: PartialEq<_>`
-    = help: the following types implement trait `PartialEq<Rhs>`:
-              `String` implements `PartialEq<&str>`
-              `String` implements `PartialEq<ByteStr>`
-              `String` implements `PartialEq<ByteString>`
-              `String` implements `PartialEq<Cow<'_, str>>`
-       `String` implements `PartialEq<Path>`
-              `String` implements `PartialEq<PathBuf>`
-              `String` implements `PartialEq<str>`
-              `String` implements `PartialEq`
+    = note: multiple `impl`s satisfying `String: PartialEq<_>` found in the following crates: `alloc`, `std`:
+            - impl PartialEq for String;
+            - impl PartialEq<Path> for String;
+            - impl PartialEq<PathBuf> for String;
19 help: try using a fully qualified path to specify the expected types
20    |
21 LL -         if String::from("a") == "a".try_into().unwrap() {}


The actual stderr differed from the expected stderr.
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args inference/issue-72616.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/inference/issue-72616.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "--target=x86_64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/inference/issue-72616" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
error[E0283]: type annotations needed
##[error]  --> /checkout/tests/ui/inference/issue-72616.rs:22:37
   |
LL |         if String::from("a") == "a".try_into().unwrap() {}
   |                              --     ^^^^^^^^
   |                              |
   |                              type must be known at this point
   |
   = note: multiple `impl`s satisfying `String: PartialEq<_>` found in the following crates: `alloc`, `std`:
           - impl PartialEq for String;
           - impl PartialEq<Path> for String;
           - impl PartialEq<PathBuf> for String;
help: try using a fully qualified path to specify the expected types
   |
LL -         if String::from("a") == "a".try_into().unwrap() {}
LL +         if String::from("a") == <&str as TryInto<T>>::try_into("a").unwrap() {}
   |

error[E0283]: type annotations needed
##[error]  --> /checkout/tests/ui/inference/issue-72616.rs:22:37
   |
LL |         if String::from("a") == "a".try_into().unwrap() {}
   |                                     ^^^^^^^^
   |
   = note: multiple `impl`s satisfying `_: TryFrom<&str>` found in the following crates: `core`, `std`:
           - impl TryFrom<&str> for std::sys::net::connection::socket::LookupHost;
           - impl<T, U> TryFrom<U> for T
             where U: Into<T>;
   = note: required for `&str` to implement `TryInto<_>`
help: try using a fully qualified path to specify the expected types
   |
LL -         if String::from("a") == "a".try_into().unwrap() {}
LL +         if String::from("a") == <&str as TryInto<T>>::try_into("a").unwrap() {}
   |

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0283`.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants