-
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
Add some more regression tests #77956
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7db8904
Add test for issue-70877
JohnTitor 11a188a
Add test for issue-70944
JohnTitor c266c07
Add test for issue-71659
JohnTitor fc3a5dc
Add test for issue-74816
JohnTitor 23092c7
Add test for issue-75707
JohnTitor 59cc9de
Add test for issue-75983
JohnTitor d80f93d
Use smaller example for issue-71659
JohnTitor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#![feature(associated_type_defaults)] | ||
#![feature(generic_associated_types)] | ||
#![allow(incomplete_features)] | ||
|
||
trait Trait1 { | ||
fn foo(); | ||
} | ||
|
||
trait Trait2 { | ||
type Associated: Trait1 = Self; | ||
//~^ ERROR: the trait bound `Self: Trait1` is not satisfied | ||
//~| the size for values of type `Self` cannot be known | ||
} | ||
|
||
impl Trait2 for () {} | ||
|
||
fn call_foo<T: Trait2>() { | ||
T::Associated::foo() | ||
} | ||
|
||
fn main() { | ||
call_foo::<()>() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
error[E0277]: the trait bound `Self: Trait1` is not satisfied | ||
--> $DIR/issue-74816.rs:10:5 | ||
| | ||
LL | type Associated: Trait1 = Self; | ||
| ^^^^^^^^^^^^^^^^^------^^^^^^^^ | ||
| | | | ||
| | required by this bound in `Trait2::Associated` | ||
| the trait `Trait1` is not implemented for `Self` | ||
| | ||
help: consider further restricting `Self` | ||
| | ||
LL | trait Trait2: Trait1 { | ||
| ^^^^^^^^ | ||
|
||
error[E0277]: the size for values of type `Self` cannot be known at compilation time | ||
--> $DIR/issue-74816.rs:10:5 | ||
| | ||
LL | type Associated: Trait1 = Self; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| doesn't have a size known at compile-time | ||
| required by this bound in `Trait2::Associated` | ||
| | ||
help: consider further restricting `Self` | ||
| | ||
LL | trait Trait2: Sized { | ||
| ^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#![feature(type_alias_impl_trait)] | ||
#![feature(impl_trait_in_bindings)] | ||
#![allow(incomplete_features)] | ||
|
||
type FooArg<'a> = &'a dyn ToString; | ||
type FooRet = impl std::fmt::Debug; | ||
|
||
type FooItem = Box<dyn Fn(FooArg) -> FooRet>; | ||
type Foo = impl Iterator<Item = FooItem>; //~ ERROR: type mismatch | ||
|
||
#[repr(C)] | ||
struct Bar(u8); | ||
|
||
impl Iterator for Bar { | ||
type Item = FooItem; | ||
|
||
fn next(&mut self) -> Option<Self::Item> { | ||
Some(Box::new(quux)) | ||
} | ||
} | ||
|
||
fn quux(st: FooArg) -> FooRet { | ||
Some(st.to_string()) | ||
} | ||
|
||
fn ham() -> Foo { | ||
Bar(1) | ||
} | ||
|
||
fn oof() -> impl std::fmt::Debug { | ||
let mut bar = ham(); | ||
let func = bar.next().unwrap(); | ||
return func(&"oof"); | ||
} | ||
|
||
fn main() { | ||
let _ = oof(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
error[E0271]: type mismatch resolving `<Bar as Iterator>::Item == Box<(dyn for<'r> Fn(&'r (dyn ToString + 'r)) -> Option<String> + 'static)>` | ||
--> $DIR/issue-70877.rs:9:12 | ||
| | ||
LL | type FooRet = impl std::fmt::Debug; | ||
| -------------------- the expected opaque type | ||
... | ||
LL | type Foo = impl Iterator<Item = FooItem>; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected opaque type, found enum `Option` | ||
| | ||
= note: expected struct `Box<(dyn for<'r> Fn(&'r (dyn ToString + 'r)) -> impl Debug + 'static)>` | ||
found struct `Box<(dyn for<'r> Fn(&'r (dyn ToString + 'r)) -> Option<String> + 'static)>` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0271`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// check-pass | ||
// Regression test of #70944, should compile fine. | ||
|
||
use std::ops::Index; | ||
|
||
pub struct KeyA; | ||
pub struct KeyB; | ||
pub struct KeyC; | ||
|
||
pub trait Foo: Index<KeyA> + Index<KeyB> + Index<KeyC> {} | ||
pub trait FooBuilder { | ||
type Inner: Foo; | ||
fn inner(&self) -> &Self::Inner; | ||
} | ||
|
||
pub fn do_stuff(foo: &impl FooBuilder) { | ||
let inner = foo.inner(); | ||
&inner[KeyA]; | ||
&inner[KeyB]; | ||
&inner[KeyC]; | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// check-pass | ||
|
||
#![feature(trait_alias)] | ||
|
||
struct Bar; | ||
trait Foo {} | ||
impl Foo for Bar {} | ||
|
||
trait Baz = Foo where Bar: Foo; | ||
|
||
fn new() -> impl Baz { | ||
Bar | ||
} | ||
|
||
fn main() { | ||
let _ = new(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#![feature(unsize)] | ||
|
||
use std::marker::Unsize; | ||
|
||
pub trait CastTo<T: ?Sized>: Unsize<T> { | ||
fn cast_to(&self) -> &T; | ||
} | ||
|
||
impl<T: ?Sized, U: ?Sized + Unsize<T>> CastTo<T> for U { | ||
fn cast_to(&self) -> &T { | ||
self | ||
} | ||
} | ||
|
||
impl<T: ?Sized> Cast for T {} | ||
pub trait Cast { | ||
fn cast<T: ?Sized>(&self) -> &T | ||
where | ||
Self: CastTo<T>, | ||
{ | ||
self | ||
} | ||
} | ||
|
||
pub trait Foo: CastTo<[i32]> {} | ||
impl Foo for [i32; 0] {} | ||
|
||
fn main() { | ||
let x: &dyn Foo = &[]; | ||
let x = x.cast::<[i32]>(); | ||
//~^ ERROR: the trait bound `dyn Foo: CastTo<[i32]>` is not satisfied | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
error[E0277]: the trait bound `dyn Foo: CastTo<[i32]>` is not satisfied | ||
--> $DIR/issue-71659.rs:30:15 | ||
| | ||
LL | let x = x.cast::<[i32]>(); | ||
| ^^^^ the trait `CastTo<[i32]>` is not implemented for `dyn Foo` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
pub trait Callback { | ||
fn cb(); | ||
} | ||
|
||
pub trait Processing { | ||
type Call: Callback; | ||
} | ||
|
||
fn f<P: Processing + ?Sized>() { | ||
P::Call::cb(); | ||
} | ||
|
||
fn main() { | ||
struct MyCall; | ||
f::<dyn Processing<Call = MyCall>>(); | ||
//~^ ERROR: the trait bound `MyCall: Callback` is not satisfied | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
error[E0277]: the trait bound `MyCall: Callback` is not satisfied | ||
--> $DIR/issue-75707.rs:15:5 | ||
| | ||
LL | fn f<P: Processing + ?Sized>() { | ||
| ---------- required by this bound in `f` | ||
... | ||
LL | f::<dyn Processing<Call = MyCall>>(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Callback` is not implemented for `MyCall` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Any reason this is not using the minimal version that's in the issue description (as opposed to what's in the playground?)
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.
Ah, good point! I assumed that both examples were the same.