Closed
Description
I tried this code (reduced testcase from code in cap-std):
use std::path::Path;
use std::ffi::OsStr;
use std::ops::Deref;
fn frob(path: &str) -> impl Deref<Target = Path> + '_ {
OsStr::new(path).as_ref()
}
fn open_parent<'path>(_path: &'path Path) {
todo!()
}
fn main() {
let old_path = frob("hello");
open_parent(&old_path);
}
When compiled with stable Rust, it compiles with no errors.
When compiled with nightly Rust, it gets the following error:
error[E0308]: mismatched types
--> src/main.rs:16:17
|
5 | fn frob(path: &str) -> impl Deref<Target = Path> + '_ {
| ------------------------------ the found opaque type
...
16 | open_parent(&old_path);
| ^^^^^^^^^ expected struct `Path`, found opaque type
|
= note: expected struct `Path`
found opaque type `impl Deref<Target = Path>`
For more information about this error, try `rustc --explain E0308`.
error: could not compile `abc` due to previous error
The error can be avoided by changing &old_path
to &*old_path
, which works on both stable and nightly. I've already fixed the upstream code do to this; I'm filing this bug as it may affect other users as well.
Meta
Stable rustc --version --verbose
:
rustc 1.58.1 (db9d1b20b 2022-01-20)
binary: rustc
commit-hash: db9d1b20bba1968c1ec1fc49616d4742c1725b4b
commit-date: 2022-01-20
host: x86_64-unknown-linux-gnu
release: 1.58.1
LLVM version: 13.0.0
Nightly rustc --version --verbose
:
rustc 1.60.0-nightly (0c292c966 2022-02-08)
binary: rustc
commit-hash: 0c292c9667f1b202a9150d58bdd2e89e3e803996
commit-date: 2022-02-08
host: x86_64-unknown-linux-gnu
release: 1.60.0-nightly
LLVM version: 13.0.0
Activity
oli-obk commentedon Feb 10, 2022
Ah interesting. Treating any equality check between opaque types and other types as "will succeed modulo the opaque type obligation" will skip other code paths like trying autoderef
Emilgardis commentedon Feb 10, 2022
This also fails rustdoc disambiguator with a boxed dyn Error
bisected
searched nightlies: from nightly-2022-02-08 to nightly-2022-02-10
regressed nightly: nightly-2022-02-09
searched commit range: 734368a...0c292c9
regressed commit: e7cc3bd
Auto merge of #93893 - oli-obk:sad_revert, r=oli-obk