Skip to content
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

Compilation error regression on nightly #93841

Closed
sunfishcode opened this issue Feb 10, 2022 · 2 comments · Fixed by #93893
Closed

Compilation error regression on nightly #93841

sunfishcode opened this issue Feb 10, 2022 · 2 comments · Fixed by #93893
Assignees
Labels
A-impl-trait Area: impl Trait. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly.

Comments

@sunfishcode
Copy link
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
@sunfishcode sunfishcode added regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. C-bug Category: This is a bug. labels Feb 10, 2022
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Feb 10, 2022
@oli-obk oli-obk self-assigned this Feb 10, 2022
@oli-obk oli-obk added the A-impl-trait Area: impl Trait. Universally / existentially quantified anonymous types with static dispatch. label Feb 10, 2022
@oli-obk
Copy link
Contributor

oli-obk commented 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
Copy link
Contributor

Emilgardis commented Feb 10, 2022

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

@bors bors closed this as completed in 6499c5e Feb 11, 2022
@apiraino apiraino removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Feb 15, 2022
flip1995 pushed a commit to flip1995/rust-clippy that referenced this issue Feb 24, 2022
Revert lazy TAIT PR

Revert rust-lang/rust#92306 (sorry `@Aaron1011,` will include your changes in the fix PR)
Revert rust-lang/rust#93783
Revert rust-lang/rust#92007

fixes rust-lang/rust#93788
fixes rust-lang/rust#93794
fixes rust-lang/rust#93821
fixes rust-lang/rust#93831
fixes rust-lang/rust#93841
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-impl-trait Area: impl Trait. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants