Skip to content

Compilation error regression on nightly #93841

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-bugCategory: This is a bug.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