Skip to content

Conversation

@beanow-at-crabnebula
Copy link

We're using Rust 1.86 and one compile error showed up for ssstar.

    Checking ssstar v0.7.3 (/media/workspace/src/cn/ssstar/ssstar)
error[E0283]: type annotations needed
   --> ssstar/src/extract.rs:294:60
    |
294 |             Self::Object { key } => path.to_string_lossy() == key.as_ref(),
    |                                                            ^^ cannot infer type for reference `&_`
    |
    = note: multiple `impl`s satisfying `Cow<'_, str>: PartialEq<&_>` found in the `alloc` crate:
            - impl<'a, 'b> PartialEq<&'b str> for Cow<'a, str>;
            - impl<'a> PartialEq<&'a ByteStr> for Cow<'a, str>;

error[E0283]: type annotations needed
   --> ssstar/src/extract.rs:294:67
    |
294 |             Self::Object { key } => path.to_string_lossy() == key.as_ref(),
    |                                                                   ^^^^^^
    |
    = note: multiple `impl`s satisfying `std::string::String: AsRef<_>` found in the following crates: `alloc`, `std`:
            - impl AsRef<Path> for std::string::String;
            - impl AsRef<[u8]> for std::string::String;
            - impl AsRef<std::ffi::OsStr> for std::string::String;
            - impl AsRef<str> for std::string::String;
help: try using a fully qualified path to specify the expected types
    |
294 -             Self::Object { key } => path.to_string_lossy() == key.as_ref(),
294 +             Self::Object { key } => path.to_string_lossy() == <std::string::String as AsRef<T>>::as_ref(key),
    |

For more information about this error, try `rustc --explain E0283`.
error: could not compile `ssstar` (lib) due to 2 previous errors

I think this is a regression in the compiler, so I submitted a report rust-lang/rust#139542
But eventually when ByteStr stabilizes this problem may come back. So using as_str() should help with this.

@beanow-at-crabnebula
Copy link
Author

As a quick summary from the upstream bug report.

Implementing unstable feature flags for new trait impls is complicated, so it's a known issue that they appear in stable Rust. In this case it did as well, and causes type inference regressions.

No patch expected from the Rust side right now, so the more explicit .as_str() should resolve this.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant