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

Two conflicting concrete types for the same opaque type #114597

Closed
Nashenas88 opened this issue Aug 7, 2023 · 8 comments · Fixed by #114602
Closed

Two conflicting concrete types for the same opaque type #114597

Nashenas88 opened this issue Aug 7, 2023 · 8 comments · Fixed by #114602
Assignees
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug. P-critical Critical priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Nashenas88
Copy link
Contributor

I tried this code:

https://cs.opensource.google/fuchsia/fuchsia/+/main:src/connectivity/network/netcfg/src/lib.rs;l=1762;drc=4a7d2eb6793e61c0021f8dd7dab35804590d36b6
The function beginning with the signature:

async fn create_device_stream(
        &self,
    ) -> Result<
        impl futures::Stream<Item = Result<devices::NetworkDeviceInstance, anyhow::Error>>,
        anyhow::Error,
    > { ... }

I expected to see this happen: Compiles successfully, as it did on previous releases.

Instead, this happened:

error: concrete type differs from previous defining opaque type use
    --> ../../src/connectivity/network/netcfg/src/lib.rs:1765:9
     |
1765 |         impl futures::Stream<Item = Result<devices::NetworkDeviceInstance, anyhow::Error>>,
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |         |
     |         expected `TryFlattenUnordered<futures::stream::Fuse<TryFilterMap<futures::stream::ErrInto<Watcher, anyhow::Error>, [async block@../../src/connectivity/network/netcfg/src/lib.rs:1782:17: 1843:18], [closure@../../src/connectivity/network/netcfg/src/lib.rs:1780:29: 1780:82]>>>`, got `TryFlattenUnordered<futures::stream::Fuse<TryFilterMap<futures::stream::ErrInto<Watcher, anyhow::Error>, [async block@../../src/connectivity/network/netcfg/src/lib.rs:1782:17: 1843:18], [closure@../../src/connectivity/network/netcfg/src/lib.rs:1780:29: 1780:82]>>>`
     |         this expression supplies two conflicting concrete types for the same opaque type
error: aborting due to previous error

Recompiling with -Zverbose outputs:

error: concrete type differs from previous defining opaque type use
    --> ../../src/connectivity/network/netcfg/src/lib.rs:1765:9
     |
1765 |         impl futures::Stream<Item = Result<devices::NetworkDeviceInstance, anyhow::Error>>,
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |         |
     |         expected `TryFlattenUnordered<futures::stream::Fuse<TryFilterMap<futures::stream::ErrInto<Watcher, anyhow::Error>, [static NetCfg<ReEarlyBound(DefId(0:3068 ~ netcfg[7715]::{impl#13}::create_device_stream::{opaque#0}::'a), 2, 'a)>::create_device_stream::{closure#0}::{closure#2}::{closure#0} upvar_tys=(fuchsia_fs::directory::WatchEvent, PathBuf, InstallerProxy) for<Region(BrAnon(None)), Region(BrAnon(None)), Region(BrAnon(None)), Region(BrAnon(None))> {ResumeTy, fuchsia_fs::directory::WatchEvent, PathBuf, InstallerProxy, &ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrAnon(None) }) InstallerProxy, &ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrAnon(None) }) PathBuf, Opaque(DefId(0:2630 ~ netcfg[7715]::devices::{impl#4}::get_instance_stream::{opaque#0}), [ReLateBound(DebruijnIndex(0), BoundRegion { var: 2, kind: BrAnon(None) }), ReLateBound(DebruijnIndex(0), BoundRegion { var: 3, kind: BrAnon(None) })]), ()}], [NetCfg<ReEarlyBound(DefId(0:3068 ~ netcfg[7715]::{impl#13}::create_device_stream::{opaque#0}::'a), 2, 'a)>::create_device_stream::{closure#0}::{closure#2} closure_kind_ty=i16 closure_sig_as_fn_ptr_ty=extern "rust-call" fn((WatchMessage,)) -> [static NetCfg<ReEarlyBound(DefId(0:3068 ~ netcfg[7715]::{impl#13}::create_device_stream::{opaque#0}::'a), 2, 'a)>::create_device_stream::{closure#0}::{closure#2}::{closure#0} upvar_tys=(fuchsia_fs::directory::WatchEvent, PathBuf, InstallerProxy) for<Region(BrAnon(None)), Region(BrAnon(None)), Region(BrAnon(None)), Region(BrAnon(None))> {ResumeTy, fuchsia_fs::directory::WatchEvent, PathBuf, InstallerProxy, &ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrAnon(None) }) InstallerProxy, &ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrAnon(None) }) PathBuf, Opaque(DefId(0:2630 ~ netcfg[7715]::devices::{impl#4}::get_instance_stream::{opaque#0}), [ReLateBound(DebruijnIndex(0), BoundRegion { var: 2, kind: BrAnon(None) }), ReLateBound(DebruijnIndex(0), BoundRegion { var: 3, kind: BrAnon(None) })]), ()}] upvar_tys=(InstallerProxy)]>>>`, got `TryFlattenUnordered<futures::stream::Fuse<TryFilterMap<futures::stream::ErrInto<Watcher, anyhow::Error>, [static NetCfg<ReEarlyBound(DefId(0:626 ~ netcfg[7715]::{impl#13}::'a), 0, 'a)>::create_device_stream::{closure#0}::{closure#2}::{closure#0} upvar_tys=(fuchsia_fs::directory::WatchEvent, PathBuf, InstallerProxy) for<Region(BrAnon(None)), Region(BrAnon(None)), Region(BrAnon(None)), Region(BrAnon(None))> {ResumeTy, fuchsia_fs::directory::WatchEvent, PathBuf, InstallerProxy, &ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrAnon(None) }) InstallerProxy, &ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrAnon(None) }) PathBuf, Opaque(DefId(0:2630 ~ netcfg[7715]::devices::{impl#4}::get_instance_stream::{opaque#0}), [ReLateBound(DebruijnIndex(0), BoundRegion { var: 2, kind: BrAnon(None) }), ReLateBound(DebruijnIndex(0), BoundRegion { var: 3, kind: BrAnon(None) })]), ()}], [NetCfg<ReEarlyBound(DefId(0:626 ~ netcfg[7715]::{impl#13}::'a), 0, 'a)>::create_device_stream::{closure#0}::{closure#2} closure_kind_ty=i16 closure_sig_as_fn_ptr_ty=extern "rust-call" fn((WatchMessage,)) -> [static NetCfg<ReEarlyBound(DefId(0:626 ~ netcfg[7715]::{impl#13}::'a), 0, 'a)>::create_device_stream::{closure#0}::{closure#2}::{closure#0} upvar_tys=(fuchsia_fs::directory::WatchEvent, PathBuf, InstallerProxy) for<Region(BrAnon(None)), Region(BrAnon(None)), Region(BrAnon(None)), Region(BrAnon(None))> {ResumeTy, fuchsia_fs::directory::WatchEvent, PathBuf, InstallerProxy, &ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrAnon(None) }) InstallerProxy, &ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrAnon(None) }) PathBuf, Opaque(DefId(0:2630 ~ netcfg[7715]::devices::{impl#4}::get_instance_stream::{opaque#0}), [ReLateBound(DebruijnIndex(0), BoundRegion { var: 2, kind: BrAnon(None) }), ReLateBound(DebruijnIndex(0), BoundRegion { var: 3, kind: BrAnon(None) })]), ()}] upvar_tys=(InstallerProxy)]>>>`
     |         this expression supplies two conflicting concrete types for the same opaque type

error: aborting due to previous error

Which when diffed, shows a change only from instances of
NetCfg<ReEarlyBound(DefId(0:3068 ~ netcfg[7715]::{impl#13}::create_device_stream::{opaque#0}::'a), 2, 'a)> to
NetCfg<ReEarlyBound(DefId(0:626 ~ netcfg[7715]::{impl#13}::'a), 0, 'a)>.

Meta

Error output is from rustc commit 139b49b
Likely related to #113661, CC @oli-obk @lcnr

@Nashenas88 Nashenas88 added the C-bug Category: This is a bug. label Aug 7, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Aug 7, 2023
@Nashenas88
Copy link
Contributor Author

I'm working to find a minimized test-case.

@compiler-errors
Copy link
Member

Probably fixed by #114574.

@Nashenas88 Nashenas88 changed the title New compilation error on nightly with RPITIT. New compilation error on nightly with RPIT. Aug 7, 2023
@Nashenas88
Copy link
Contributor Author

I was able to minimize (see on Playground):

use futures; // 0.3.28
use futures::{Stream, StreamExt as _, TryStreamExt as _};
use std::pin::Pin;
use std::task::{Context, Poll};

struct A<'a> {
    dat: &'a (),
}

struct Streamer;

impl Streamer {
    async fn new() -> Self {
        Self
    }
}

impl Stream for Streamer {
    type Item = Result<(), ()>;

    fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
        todo!()
    }
}

struct B;

impl B {
    async fn get_stream() -> impl Stream<Item = Result<Self, ()>> {
        futures::stream::try_unfold((), |()| async move { Ok(Some((B, ()))) })
    }
}

impl<'a> A<'a> {
    async fn a(&self) -> Result<impl Stream<Item=Result<B, ()>>, ()> {
        let stream_of_streams = Streamer::new().await.err_into::<()>().try_filter_map(move |()| {
            async move {
                let stream = B::get_stream().await;
                Ok(Some(stream.filter_map(move |r| {
                    futures::future::ready(match r {
                        Ok(b) => Some(Ok(b)),
                        _ => None,
                    })
                }).boxed()
                ))
            }
        }).fuse().try_flatten_unordered(1);
        Ok(stream_of_streams)
    }
}

Gives:

error: concrete type differs from previous defining opaque type use
  --> src/lib.rs:35:33
   |
35 |     async fn a(&self) -> Result<impl Stream<Item=Result<B, ()>>, ()> {
   |                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |                                 |
   |                                 expected `TryFlattenUnordered<futures::stream::Fuse<TryFilterMap<futures::stream::ErrInto<Streamer, ()>, [async block@src/lib.rs:37:13: 46:14], [closure@src/lib.rs:36:87: 36:96]>>>`, got `TryFlattenUnordered<futures::stream::Fuse<TryFilterMap<futures::stream::ErrInto<Streamer, ()>, [async block@src/lib.rs:37:13: 46:14], [closure@src/lib.rs:36:87: 36:96]>>>`
   |                                 this expression supplies two conflicting concrete types for the same opaque type

error: could not compile `playground` (lib) due to previous error

With -Zverbose:

error: concrete type differs from previous defining opaque type use
  --> ../../src/connectivity/network/netcfg/src/lib2.rs:35:33
   |
35 |     async fn a(&self) -> Result<impl Stream<Item = Result<B, ()>>, ()> {
   |                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |                                 |
   |                                 expected `TryFlattenUnordered<futures::stream::Fuse<TryFilterMap<futures::stream::ErrInto<Streamer, ()>, [static A<ReEarlyBound(DefId(0:47 ~ lib2[3a14]::{impl#3}::a::{opaque#0}::'a), 2, 'a)>::a::{closure#0}::{closure#0}::{closure#0} upvar_tys=() {ResumeTy, Opaque(DefId(0:42 ~ lib2[3a14]::{impl#2}::get_stream::{opaque#0}), []), ()}], [A<ReEarlyBound(DefId(0:47 ~ lib2[3a14]::{impl#3}::a::{opaque#0}::'a), 2, 'a)>::a::{closure#0}::{closure#0} closure_kind_ty=i16 closure_sig_as_fn_ptr_ty=extern "rust-call" fn(((),)) -> [static A<ReEarlyBound(DefId(0:47 ~ lib2[3a14]::{impl#3}::a::{opaque#0}::'a), 2, 'a)>::a::{closure#0}::{closure#0}::{closure#0} upvar_tys=() {ResumeTy, Opaque(DefId(0:42 ~ lib2[3a14]::{impl#2}::get_stream::{opaque#0}), []), ()}] upvar_tys=()]>>>`, got `TryFlattenUnordered<futures::stream::Fuse<TryFilterMap<futures::stream::ErrInto<Streamer, ()>, [static A<ReEarlyBound(DefId(0:32 ~ lib2[3a14]::{impl#3}::'a), 0, 'a)>::a::{closure#0}::{closure#0}::{closure#0} upvar_tys=() {ResumeTy, Opaque(DefId(0:42 ~ lib2[3a14]::{impl#2}::get_stream::{opaque#0}), []), ()}], [A<ReEarlyBound(DefId(0:32 ~ lib2[3a14]::{impl#3}::'a), 0, 'a)>::a::{closure#0}::{closure#0} closure_kind_ty=i16 closure_sig_as_fn_ptr_ty=extern "rust-call" fn(((),)) -> [static A<ReEarlyBound(DefId(0:32 ~ lib2[3a14]::{impl#3}::'a), 0, 'a)>::a::{closure#0}::{closure#0}::{closure#0} upvar_tys=() {ResumeTy, Opaque(DefId(0:42 ~ lib2[3a14]::{impl#2}::get_stream::{opaque#0}), []), ()}] upvar_tys=()]>>>`
   |                                 this expression supplies two conflicting concrete types for the same opaque type

error: aborting due to previous error; 1 warning emitted

Main diff of:
A<ReEarlyBound(DefId(0:47 ~ lib2[3a14]::{impl#3}::a::{opaque#0}::'a), 2, 'a)> vs
A<ReEarlyBound(DefId(0:32 ~ lib2[3a14]::{impl#3}::'a), 0, 'a)>

@compiler-errors compiler-errors self-assigned this Aug 7, 2023
@compiler-errors
Copy link
Member

Ideally this would be minimized to not rely on any external crates, but I can at least test that locally.

@compiler-errors compiler-errors added A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Aug 7, 2023
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Aug 7, 2023
@Nashenas88
Copy link
Contributor Author

I was able to minimize this further (See on Playground):

use futures::{Stream, StreamExt as _};

struct A<'a> {
    dat: &'a (),
}

impl<'a> A<'a> {
    async fn a(&self) -> impl Stream<Item = ()> {
        futures::stream::repeat(())
            .map(|()| futures::stream::repeat(()))
            .flatten_unordered(None)
    }
}

Verbose:

error: concrete type differs from previous defining opaque type use
 --> src/lib.rs:9:26
  |
9 |     async fn a(&self) -> impl Stream<Item = ()> {
  |                          ^^^^^^^^^^^^^^^^^^^^^^
  |                          |
  |                          expected `stream::stream::flatten_unordered::FlattenUnorderedWithFlowController<futures::stream::Map<futures::stream::Repeat<()>, [A<ReEarlyBound(DefId(0:18 ~ minim[be95]::{impl#0}::a::{opaque#0}::'a), 2, 'a)>::a::{closure#0}::{closure#0} closure_kind_ty=i16 closure_sig_as_fn_ptr_ty=extern "rust-call" fn(((),)) -> futures::stream::Repeat<()> upvar_tys=()]>, ()>`, got `stream::stream::flatten_unordered::FlattenUnorderedWithFlowController<futures::stream::Map<futures::stream::Repeat<()>, [A<ReEarlyBound(DefId(0:11 ~ minim[be95]::{impl#0}::'a), 0, 'a)>::a::{closure#0}::{closure#0} closure_kind_ty=i16 closure_sig_as_fn_ptr_ty=extern "rust-call" fn(((),)) -> futures::stream::Repeat<()> upvar_tys=()]>, ()>`
  |                          this expression supplies two conflicting concrete types for the same opaque type

@Nashenas88
Copy link
Contributor Author

And one with no deps:

struct A<'a> {
    dat: &'a (),
}

impl<'a> A<'a> {
    async fn a(&self) -> impl Iterator<Item = std::iter::Repeat<()>> {
        std::iter::repeat(()).map(|()| std::iter::repeat(()))
    }
}

Verbose:

error: concrete type differs from previous defining opaque type use
 --> src/lib.rs:6:26
  |
6 |     async fn a(&self) -> impl Iterator<Item = std::iter::Repeat<()>> {
  |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |                          |
  |                          expected `Map<std::iter::Repeat<()>, [A<ReEarlyBound(DefId(0:14 ~ minim[1a84]::{impl#0}::a::{opaque#0}::'a), 2, 'a)>::a::{closure#0}::{closure#0} closure_kind_ty=i16 closure_sig_as_fn_ptr_ty=extern "rust-call" fn(((),)) -> std::iter::Repeat<()> upvar_tys=()]>`, got `Map<std::iter::Repeat<()>, [A<ReEarlyBound(DefId(0:7 ~ minim[1a84]::{impl#0}::'a), 0, 'a)>::a::{closure#0}::{closure#0} closure_kind_ty=i16 closure_sig_as_fn_ptr_ty=extern "rust-call" fn(((),)) -> std::iter::Repeat<()> upvar_tys=()]>`
  |                          this expression supplies two conflicting concrete types for the same opaque type

@compiler-errors
Copy link
Member

Thanks!

@apiraino
Copy link
Contributor

apiraino commented Aug 8, 2023

WG-prioritization assigning priority (Zulip discussion).

@rustbot label -I-prioritize +P-critical +T-compiler

@rustbot rustbot added P-critical Critical priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Aug 8, 2023
@bors bors closed this as completed in bf62436 Aug 8, 2023
@Nashenas88 Nashenas88 changed the title New compilation error on nightly with RPIT. Two conflicting concrete types for the same opaque type Aug 9, 2023
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. P-critical Critical priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants