-
Notifications
You must be signed in to change notification settings - Fork 14.1k
tests/ui: A New Order [19/N]
#143210
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
Merged
Merged
tests/ui: A New Order [19/N]
#143210
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Prev
Previous commit
cleaned up some tests
- Loading branch information
commit bf5910d9bb0c5cc3e4fb1a1a9ed3d73e26793c71
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,14 +1,35 @@ | ||
| //@ run-pass | ||
| // Tests for the new |args| expr lambda syntax | ||
| //! Test basic closure syntax and usage with generic functions. | ||
| //! | ||
| //! This test checks that closure syntax works correctly for: | ||
| //! - Closures with parameters and return values | ||
| //! - Closures without parameters (both expression and block forms) | ||
| //! - Integration with generic functions and FnOnce trait bounds | ||
|
|
||
| //@ run-pass | ||
|
|
||
| fn f<F>(i: isize, f: F) -> isize where F: FnOnce(isize) -> isize { f(i) } | ||
| fn f<F>(i: isize, f: F) -> isize | ||
| where | ||
| F: FnOnce(isize) -> isize, | ||
| { | ||
| f(i) | ||
| } | ||
|
|
||
| fn g<G>(_g: G) where G: FnOnce() { } | ||
| fn g<G>(_g: G) | ||
| where | ||
| G: FnOnce(), | ||
| { | ||
| } | ||
|
|
||
| pub fn main() { | ||
| // Closure with parameter that returns the same value | ||
| assert_eq!(f(10, |a| a), 10); | ||
| g(||()); | ||
|
|
||
| // Closure without parameters - expression form | ||
| g(|| ()); | ||
|
|
||
| // Test closure reuse in generic context | ||
| assert_eq!(f(10, |a| a), 10); | ||
| g(||{}); | ||
|
|
||
| // Closure without parameters - block form | ||
| g(|| {}); | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,27 +1,32 @@ | ||
| //@ run-pass | ||
|
|
||
| #![allow(non_camel_case_types)] | ||
| //! Test newtype pattern with generic parameters. | ||
| //@ run-pass | ||
|
|
||
| #[derive(Clone)] | ||
| struct myvec<X>(Vec<X> ); | ||
| struct MyVec<T>(Vec<T>); | ||
|
|
||
| fn myvec_deref<X:Clone>(mv: myvec<X>) -> Vec<X> { | ||
| let myvec(v) = mv; | ||
| return v.clone(); | ||
| fn extract_inner_vec<T: Clone>(wrapper: MyVec<T>) -> Vec<T> { | ||
| let MyVec(inner_vec) = wrapper; | ||
| inner_vec.clone() | ||
| } | ||
|
|
||
| fn myvec_elt<X>(mv: myvec<X>) -> X { | ||
| let myvec(v) = mv; | ||
| return v.into_iter().next().unwrap(); | ||
| fn get_first_element<T>(wrapper: MyVec<T>) -> T { | ||
| let MyVec(inner_vec) = wrapper; | ||
| inner_vec.into_iter().next().unwrap() | ||
| } | ||
|
|
||
| pub fn main() { | ||
| let mv = myvec(vec![1, 2, 3]); | ||
| let mv_clone = mv.clone(); | ||
| let mv_clone = myvec_deref(mv_clone); | ||
| assert_eq!(mv_clone[1], 2); | ||
| assert_eq!(myvec_elt(mv.clone()), 1); | ||
| let myvec(v) = mv; | ||
| assert_eq!(v[2], 3); | ||
| let my_vec = MyVec(vec![1, 2, 3]); | ||
| let cloned_vec = my_vec.clone(); | ||
|
|
||
| // Test extracting inner vector | ||
| let extracted = extract_inner_vec(cloned_vec); | ||
| assert_eq!(extracted[1], 2); | ||
|
|
||
| // Test getting first element | ||
| assert_eq!(get_first_element(my_vec.clone()), 1); | ||
|
|
||
| // Test direct destructuring | ||
| let MyVec(inner) = my_vec; | ||
| assert_eq!(inner[2], 3); | ||
| } | ||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -1,23 +1,25 @@ | ||
| //! Test basic newtype pattern functionality. | ||
|
|
||
| //@ run-pass | ||
|
|
||
| #![allow(non_camel_case_types)] | ||
| #[derive(Copy, Clone)] | ||
| struct mytype(Mytype); | ||
| struct Counter(CounterData); | ||
|
|
||
| #[derive(Copy, Clone)] | ||
| struct Mytype { | ||
| compute: fn(mytype) -> isize, | ||
| struct CounterData { | ||
| compute: fn(Counter) -> isize, | ||
| val: isize, | ||
| } | ||
|
|
||
| fn compute(i: mytype) -> isize { | ||
| let mytype(m) = i; | ||
| return m.val + 20; | ||
| fn compute_value(counter: Counter) -> isize { | ||
| let Counter(data) = counter; | ||
| data.val + 20 | ||
| } | ||
|
|
||
| pub fn main() { | ||
| let myval = mytype(Mytype{compute: compute, val: 30}); | ||
| println!("{}", compute(myval)); | ||
| let mytype(m) = myval; | ||
| assert_eq!((m.compute)(myval), 50); | ||
| let my_counter = Counter(CounterData { compute: compute_value, val: 30 }); | ||
|
|
||
| // Test destructuring and function pointer call | ||
| let Counter(data) = my_counter; | ||
| assert_eq!((data.compute)(my_counter), 50); | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,18 +1,22 @@ | ||
| //! Test that enums inherit Send/!Send properties from their variants. | ||
| //! | ||
| //! Uses the unstable `negative_impls` feature to explicitly opt-out of Send. | ||
|
|
||
| #![feature(negative_impls)] | ||
|
|
||
| use std::marker::Send; | ||
|
|
||
| struct NoSend; | ||
| impl !Send for NoSend {} | ||
|
|
||
| enum Foo { | ||
| A(NoSend) | ||
| enum Container { | ||
| WithNoSend(NoSend), | ||
| } | ||
|
|
||
| fn bar<T: Send>(_: T) {} | ||
| fn requires_send<T: Send>(_: T) {} | ||
|
|
||
| fn main() { | ||
| let x = Foo::A(NoSend); | ||
| bar(x); | ||
| let container = Container::WithNoSend(NoSend); | ||
| requires_send(container); | ||
| //~^ ERROR `NoSend` cannot be sent between threads safely | ||
| } |
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -1,16 +1,22 @@ | ||
| //! Test that enums inherit Sync/!Sync properties from their variants. | ||
| //! | ||
| //! Uses the unstable `negative_impls` feature to explicitly opt-out of Sync. | ||
|
|
||
| #![feature(negative_impls)] | ||
|
|
||
| use std::marker::Sync; | ||
|
|
||
| struct NoSync; | ||
| impl !Sync for NoSync {} | ||
|
|
||
| enum Foo { A(NoSync) } | ||
| enum Container { | ||
| WithNoSync(NoSync), | ||
| } | ||
|
|
||
| fn bar<T: Sync>(_: T) {} | ||
| fn requires_sync<T: Sync>(_: T) {} | ||
|
|
||
| fn main() { | ||
| let x = Foo::A(NoSync); | ||
| bar(x); | ||
| let container = Container::WithNoSync(NoSync); | ||
| requires_sync(container); | ||
| //~^ ERROR `NoSync` cannot be shared between threads safely [E0277] | ||
| } |
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -1,9 +1,11 @@ | ||
| //! Test that `Rc<T>` does not implement `Send`. | ||
|
|
||
| use std::rc::Rc; | ||
|
|
||
| fn bar<T: Send>(_: T) {} | ||
| fn requires_send<T: Send>(_: T) {} | ||
|
|
||
| fn main() { | ||
| let x = Rc::new(5); | ||
| bar(x); | ||
| let rc_value = Rc::new(5); | ||
| requires_send(rc_value); | ||
| //~^ ERROR `Rc<{integer}>` cannot be sent between threads safely | ||
| } |
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -1,14 +1,21 @@ | ||
| //! Test negative Sync implementation on structs. | ||
| //! | ||
| //! Uses the unstable `negative_impls` feature to explicitly opt-out of Sync. | ||
|
|
||
| #![feature(negative_impls)] | ||
|
|
||
| use std::marker::Sync; | ||
|
|
||
| struct Foo { a: isize } | ||
| impl !Sync for Foo {} | ||
| struct NotSync { | ||
| value: isize, | ||
| } | ||
|
|
||
| impl !Sync for NotSync {} | ||
|
|
||
| fn bar<T: Sync>(_: T) {} | ||
| fn requires_sync<T: Sync>(_: T) {} | ||
|
|
||
| fn main() { | ||
| let x = Foo { a: 5 }; | ||
| bar(x); | ||
| //~^ ERROR `Foo` cannot be shared between threads safely [E0277] | ||
| let not_sync = NotSync { value: 5 }; | ||
| requires_sync(not_sync); | ||
| //~^ ERROR `NotSync` cannot be shared between threads safely [E0277] | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
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.
Mind keeping the original var names here? They're understandable enough so IMO not worth any churn.
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.
honestly, they might be undestandable, but we can do better, right?
myvec_eltfor me is not understanable and fused spelling is not good here likemyvec, just adding_make it way bettermy_vecThere 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.
The function names indeed aren't a very clear and those changes seemed fine. I was talking specifically about variable names;
mv->my_vecandmv_clone->cloned_vecdoesn't really make anything more clear, so in these cases I'd lean toward preferring the existing code to keep churn down.All the same, 🤷♂️