-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Type inference fails in light of generic type aliases with default parameter. #50822
Comments
Huh, scrap that, it's not even type inference, because the following compiles: pub struct Foo<A: Default, B: Default>(A, B);
impl<A: Default, B: Default> Foo<A, B> {
fn new(a: A) -> Self { Foo(a, B::default()) }
}
pub type Bar<A, B=usize> = Foo<A, B>;
fn main() {
let bar = Bar::<_>::new(42usize);
} I don't know what the hell the problem is. |
As mentioned by talchas on irc, this doesn't even need type aliases: pub struct Foo<A: Default, B = usize>(A, B);
impl<A: Default, B> Foo<A, B> {
fn new(a: A) -> Self { Foo(a, panic!()) }
}
fn main() {
let bar = Foo::new(42usize);
} Fails with:
In this example, |
And because of rust-lang/rust#50822 (comment) bind Box::new and RawVec::new to Global.
@glandium What happens if you repeat the default on the |
|
CC @eddyb is this one of the situations there's no good solution for? |
|
I just ran into this with this (minified) example (playground): enum Foo<A = (), B = ()> {
A(A),
B(B),
}
fn main() {
let a = Foo::A(());
} This fails to compile with The same happens if I don't let This feels very weird and unergonomic to me. Allowing it (apart from implementation complexity) should be a non-breaking change, because it allows strictly more code to compile. |
Come to think of it, inference shouldn't even be involved. For a type This is not made up, this is how rustc itself presents those types in errors. It even goes as far as presenting |
@glandium |
Well, this bug is exactly that people have to do the equivalent of |
@glandium My example was about inferring |
This turns `Box<T>` into `Box<T, A: Alloc = Global>`. This is a minimalist change to achieve this, not touching anything that could have backwards incompatible consequences like requiring type annotations in places where they currently aren't required, per rust-lang#50822 (comment)
This turns `Box<T>` into `Box<T, A: Alloc = Global>`. This is a minimalist change to achieve this, not touching anything that could have backwards incompatible consequences like requiring type annotations in places where they currently aren't required, per rust-lang#50822 (comment)
This turns `Box<T>` into `Box<T, A: Alloc = Global>`. This is a minimalist change to achieve this, not touching anything that could have backwards incompatible consequences like requiring type annotations in places where they currently aren't required, per rust-lang#50822 (comment)
Triage: this still fails to compile |
I'm closing this as "not a bug", as per #50822 (comment). |
Consider the following source:
This fails to build with:
IOW, it does want
Bar::<usize>::new
instead ofBar::new
.pub type Bar<A> = Foo<A, usize>
also doesBar::new
work.The text was updated successfully, but these errors were encountered: