Match ergonomics 2024: test type inference
This commit is contained in:
parent
5a35fc446e
commit
76da7aebe4
5 changed files with 87 additions and 9 deletions
|
@ -63,4 +63,27 @@ pub fn main() {
|
||||||
if let Some(&mut x) = &Some(&mut 0) {
|
if let Some(&mut x) = &Some(&mut 0) {
|
||||||
let _: &u32 = x;
|
let _: &u32 = x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn generic<R: Ref>() -> (R, bool) {
|
||||||
|
R::meow()
|
||||||
|
}
|
||||||
|
|
||||||
|
trait Ref: Sized {
|
||||||
|
fn meow() -> (Self, bool);
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Ref for &'static [(); 0] {
|
||||||
|
fn meow() -> (Self, bool) {
|
||||||
|
(&[], false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Ref for &'static mut [(); 0] {
|
||||||
|
fn meow() -> (Self, bool) {
|
||||||
|
(&mut [], true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let (&_, b) = generic();
|
||||||
|
assert!(!b);
|
||||||
}
|
}
|
||||||
|
|
|
@ -150,7 +150,20 @@ LL | let Foo(mut a) = &mut Foo(0);
|
||||||
= help: add `#![feature(mut_ref)]` to the crate attributes to enable
|
= help: add `#![feature(mut_ref)]` to the crate attributes to enable
|
||||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||||
|
|
||||||
error: aborting due to 14 previous errors
|
error[E0277]: the trait bound `&_: main::Ref` is not satisfied
|
||||||
|
--> $DIR/ref_pat_eat_one_layer_2024_fail.rs:83:14
|
||||||
|
|
|
||||||
|
LL | let &_ = generic();
|
||||||
|
| ^^^^^^^^^ the trait `main::Ref` is not implemented for `&_`
|
||||||
|
|
|
||||||
|
= help: the trait `main::Ref` is implemented for `&'static mut [(); 0]`
|
||||||
|
note: required by a bound in `generic`
|
||||||
|
--> $DIR/ref_pat_eat_one_layer_2024_fail.rs:69:19
|
||||||
|
|
|
||||||
|
LL | fn generic<R: Ref>() -> R {
|
||||||
|
| ^^^ required by this bound in `generic`
|
||||||
|
|
||||||
Some errors have detailed explanations: E0308, E0658.
|
error: aborting due to 15 previous errors
|
||||||
For more information about an error, try `rustc --explain E0308`.
|
|
||||||
|
Some errors have detailed explanations: E0277, E0308, E0658.
|
||||||
|
For more information about an error, try `rustc --explain E0277`.
|
||||||
|
|
|
@ -180,7 +180,20 @@ LL | let Foo(mut a) = &mut Foo(0);
|
||||||
= help: add `#![feature(mut_ref)]` to the crate attributes to enable
|
= help: add `#![feature(mut_ref)]` to the crate attributes to enable
|
||||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||||
|
|
||||||
error: aborting due to 16 previous errors
|
error[E0277]: the trait bound `&_: main::Ref` is not satisfied
|
||||||
|
--> $DIR/ref_pat_eat_one_layer_2024_fail.rs:83:14
|
||||||
|
|
|
||||||
|
LL | let &_ = generic();
|
||||||
|
| ^^^^^^^^^ the trait `main::Ref` is not implemented for `&_`
|
||||||
|
|
|
||||||
|
= help: the trait `main::Ref` is implemented for `&'static mut [(); 0]`
|
||||||
|
note: required by a bound in `generic`
|
||||||
|
--> $DIR/ref_pat_eat_one_layer_2024_fail.rs:69:19
|
||||||
|
|
|
||||||
|
LL | fn generic<R: Ref>() -> R {
|
||||||
|
| ^^^ required by this bound in `generic`
|
||||||
|
|
||||||
Some errors have detailed explanations: E0308, E0658.
|
error: aborting due to 17 previous errors
|
||||||
For more information about an error, try `rustc --explain E0308`.
|
|
||||||
|
Some errors have detailed explanations: E0277, E0308, E0658.
|
||||||
|
For more information about an error, try `rustc --explain E0277`.
|
||||||
|
|
|
@ -65,4 +65,20 @@ pub fn main() {
|
||||||
let Foo(mut a) = &mut Foo(0);
|
let Foo(mut a) = &mut Foo(0);
|
||||||
//~^ ERROR: binding cannot be both mutable and by-reference
|
//~^ ERROR: binding cannot be both mutable and by-reference
|
||||||
a = &mut 42;
|
a = &mut 42;
|
||||||
|
|
||||||
|
fn generic<R: Ref>() -> R {
|
||||||
|
R::meow()
|
||||||
|
}
|
||||||
|
|
||||||
|
trait Ref: Sized {
|
||||||
|
fn meow() -> Self;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Ref for &'static mut [(); 0] {
|
||||||
|
fn meow() -> Self {
|
||||||
|
&mut []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let &_ = generic(); //~ERROR: the trait bound `&_: main::Ref` is not satisfied [E0277]
|
||||||
}
|
}
|
||||||
|
|
|
@ -161,7 +161,20 @@ LL | let Foo(mut a) = &mut Foo(0);
|
||||||
= help: add `#![feature(mut_ref)]` to the crate attributes to enable
|
= help: add `#![feature(mut_ref)]` to the crate attributes to enable
|
||||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||||
|
|
||||||
error: aborting due to 15 previous errors
|
error[E0277]: the trait bound `&_: main::Ref` is not satisfied
|
||||||
|
--> $DIR/ref_pat_eat_one_layer_2024_fail.rs:83:14
|
||||||
|
|
|
||||||
|
LL | let &_ = generic();
|
||||||
|
| ^^^^^^^^^ the trait `main::Ref` is not implemented for `&_`
|
||||||
|
|
|
||||||
|
= help: the trait `main::Ref` is implemented for `&'static mut [(); 0]`
|
||||||
|
note: required by a bound in `generic`
|
||||||
|
--> $DIR/ref_pat_eat_one_layer_2024_fail.rs:69:19
|
||||||
|
|
|
||||||
|
LL | fn generic<R: Ref>() -> R {
|
||||||
|
| ^^^ required by this bound in `generic`
|
||||||
|
|
||||||
Some errors have detailed explanations: E0308, E0658.
|
error: aborting due to 16 previous errors
|
||||||
For more information about an error, try `rustc --explain E0308`.
|
|
||||||
|
Some errors have detailed explanations: E0277, E0308, E0658.
|
||||||
|
For more information about an error, try `rustc --explain E0277`.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue