-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
#37653 support default impl for specialization
#45404
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
Changes from 4 commits
f5c55ff
13e80af
b20bfb1
2f22a92
220bb22
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // Copyright 2015 The Rust Project Developers. See the COPYRIGHT | ||
| // file at the top-level directory of this distribution and at | ||
| // http://rust-lang.org/COPYRIGHT. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
| // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
| // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
| // option. This file may not be copied, modified, or distributed | ||
| // except according to those terms. | ||
|
|
||
|
||
| #![feature(specialization)] | ||
|
|
||
| trait Foo { | ||
| fn foo_one(&self) -> &'static str; | ||
| fn foo_two(&self) -> &'static str; | ||
| } | ||
|
|
||
| struct MyStruct; | ||
|
|
||
| default impl<T> Foo for T { | ||
| fn foo_one(&self) -> &'static str { | ||
| "generic" | ||
| } | ||
| } | ||
|
|
||
| impl Foo for MyStruct {} | ||
| //~^ ERROR not all trait items implemented, missing: `foo_two` [E0046] | ||
|
||
|
|
||
| fn main() { | ||
| println!("{}", MyStruct.foo_one()); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // Copyright 2015 The Rust Project Developers. See the COPYRIGHT | ||
| // file at the top-level directory of this distribution and at | ||
| // http://rust-lang.org/COPYRIGHT. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
| // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
| // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
| // option. This file may not be copied, modified, or distributed | ||
| // except according to those terms. | ||
|
|
||
| #![feature(specialization)] | ||
|
|
||
|
||
| trait Foo { | ||
| fn foo_one(&self) -> &'static str; | ||
| fn foo_two(&self) -> &'static str; | ||
| } | ||
|
|
||
| struct MyStruct; | ||
|
|
||
| default impl<T> Foo for T { | ||
| fn foo_one(&self) -> &'static str { | ||
|
||
| "generic" | ||
| } | ||
| } | ||
|
|
||
|
|
||
| fn main() { | ||
| println!("{}", MyStruct.foo_one()); | ||
| //~^ ERROR no method named `foo_one` found for type `MyStruct` in the current scope | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| // Copyright 2016 The Rust Project Developers. See the COPYRIGHT | ||
| // Copyright 2015 The Rust Project Developers. See the COPYRIGHT | ||
| // file at the top-level directory of this distribution and at | ||
| // http://rust-lang.org/COPYRIGHT. | ||
| // | ||
|
|
@@ -10,23 +10,9 @@ | |
|
|
||
| #![feature(specialization)] | ||
|
|
||
| // Regression test for ICE when combining specialized associated types and type | ||
| // aliases | ||
| trait Foo<'a, T: Eq + 'a> { } | ||
|
||
|
|
||
| trait Id_ { | ||
| type Out; | ||
| } | ||
| default impl<U> Foo<'static, U> for () {} | ||
| //~^ ERROR the trait bound `U: std::cmp::Eq` is not satisfied | ||
|
|
||
| type Id<T> = <T as Id_>::Out; | ||
|
|
||
| default impl<T> Id_ for T { | ||
| type Out = T; | ||
| } | ||
|
|
||
| fn test_proection() { | ||
| let x: Id<bool> = panic!(); | ||
| } | ||
|
|
||
| fn main() { | ||
|
|
||
| } | ||
| fn main(){} | ||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I don't think we should have to modify select.rs at all. Instead, what I would expect is for us to modify the set of predicates associated with default impls, analogously to what we do with traits. This would be part of the
predicates_ofquery -- for example, in traits, we insertSelf: Trait<...>right here:rust/src/librustc_typeck/collect.rs
Lines 1444 to 1446 in 4d2d3fc
I would think that we would want to do the same code in the case of a
default impl. In that case, I don't think we should have to modifyselect.rsat all. The required assumptions will be found in the environment.