Skip to content

Compilation error regression on nightly #93841

Closed
@sunfishcode

Description

@sunfishcode
Member

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

added
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
on Feb 10, 2022
self-assigned this
on Feb 10, 2022
added
A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.
on Feb 10, 2022
oli-obk

oli-obk commented on Feb 10, 2022

@oli-obk
Contributor

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

Emilgardis commented on Feb 10, 2022

@Emilgardis
Contributor

This also fails rustdoc disambiguator with a boxed dyn Error

//! ```rust
//! use std::fmt::Write;
//! let mut s = String::new();
//! write!(s, "Hello")?;
//! # Ok::<(), std::boxed::Box<dyn std::error::Error + 'static>>(())
//! ```
cargo test --doc
   Compiling rust-doc v0.1.0 (G:\workspace\rust-doc)
    Finished test [unoptimized + debuginfo] target(s) in 7.25s
   Doc-tests rust-doc

running 1 test
test src\lib.rs - (line 1) ... FAILED

failures:

---- src\lib.rs - (line 1) stdout ----
error[E0308]: mismatched types
 --> src\lib.rs:5:1
  |
2 | fn main() { #[allow(non_snake_case)] fn _doctest_main_src_lib_rs_1_0() -> Result<(), impl core::fmt::Debug> {
  |                                                                                      --------------------- the expected opaque type
...
6 | Ok::<(), std::boxed::Box<dyn std::error::Error + 'static>>(())
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `std::fmt::Error`, found struct `Box`
  |
  = note: expected opaque type `impl Debug`
                  found struct `Box<dyn std::error::Error>`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
Couldn't compile the test.

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

removed
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
on Feb 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

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

    Participants

    @oli-obk@Emilgardis@sunfishcode@apiraino@rustbot

    Issue actions

      Compilation error regression on nightly · Issue #93841 · rust-lang/rust