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

impl_trait_in_bindings is a breaking change #83021

Closed
oli-obk opened this issue Mar 11, 2021 · 1 comment
Closed

impl_trait_in_bindings is a breaking change #83021

oli-obk opened this issue Mar 11, 2021 · 1 comment
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug. F-impl_trait_in_bindings `#![feature(impl_trait_in_bindings)]`

Comments

@oli-obk
Copy link
Contributor

oli-obk commented Mar 11, 2021

The following program compiles without the impl_trait_in_bindings feature, but not with that feature. I believe this is because the way impl_trait_in_bindings is set up. If you look at

let revealed_ty = if self.fcx.tcx.features().impl_trait_in_bindings {
self.fcx.instantiate_opaque_types_from_value(self.parent_id, o_ty, ty.span)
} else {
o_ty
};

you can see that enabling the feature gate runs a completely different algorithm instead of emitting a feature error when the feature gate is not active. Before stabilizing type_alias_impl_trait we need to make sure that we change all such occurrences of feature-gate based type processing.

#![allow(incomplete_features)]
#![feature(type_alias_impl_trait)]
#![feature(impl_trait_in_bindings)]
use std::marker::PhantomData;

trait MyIndex<T> {
    type O;
    fn my_index(self) -> Self::O;
}
trait MyFrom<T>: Sized {
    type Error;
    fn my_from(value: T) -> Result<Self, Self::Error>;
}

trait F {}
impl F for () {}
type DummyT<T> = impl F;
fn _dummy_t<T>() -> DummyT<T> {}

struct Phantom1<T>(PhantomData<T>);
struct Phantom2<T>(PhantomData<T>);
struct Scope<T>(Phantom2<DummyT<T>>);

impl<T> Scope<T> {
    fn new() -> Self {
        unimplemented!()
    }
}

impl<T> MyFrom<Phantom2<T>> for Phantom1<T> {
    type Error = ();
    fn my_from(_: Phantom2<T>) -> Result<Self, Self::Error> {
        unimplemented!()
    }
}

impl<T: MyFrom<Phantom2<DummyT<U>>>, U> MyIndex<Phantom1<T>> for Scope<U> {
    type O = T;
    fn my_index(self) -> Self::O {
        MyFrom::my_from(self.0).ok().unwrap()
    }
}

fn main() {
    let _pos: Phantom1<DummyT<()>> = Scope::new().my_index();
}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
error[E0282]: type annotations needed
  --> src/main.rs:45:38
   |
7  |     type O;
   |     ------- `<Self as MyIndex<T>>::O` defined here
...
45 |     let _pos: Phantom1<DummyT<()>> = Scope::new().my_index();
   |                                      ^^^^^^^^^^-------------
   |                                      |
   |                                      this method call resolves to `<Self as MyIndex<T>>::O`
   |                                      cannot infer type for type parameter `T`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0282`.
error: could not compile `playground`

To learn more, run the command again with --verbose.

@oli-obk oli-obk added A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` F-impl_trait_in_bindings `#![feature(impl_trait_in_bindings)]` labels Mar 11, 2021
@oli-obk oli-obk removed the F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` label May 3, 2022
@kpreid
Copy link
Contributor

kpreid commented Jul 10, 2024

This could probably be closed, because the feature in question was removed by #86729.

@oli-obk oli-obk closed this as completed Jul 10, 2024
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. F-impl_trait_in_bindings `#![feature(impl_trait_in_bindings)]`
Projects
None yet
Development

No branches or pull requests

3 participants