Match ergonomics 2024: test type inference

This commit is contained in:
Jules Bertholet 2024-07-05 11:17:49 -04:00
parent 5a35fc446e
commit 76da7aebe4
No known key found for this signature in database
GPG Key ID: 32034DAFC38C1BFC
5 changed files with 87 additions and 9 deletions

View File

@ -63,4 +63,27 @@ pub fn main() {
if let Some(&mut x) = &Some(&mut 0) {
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);
}

View File

@ -150,7 +150,20 @@ LL | let Foo(mut a) = &mut Foo(0);
= 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
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.
For more information about an error, try `rustc --explain E0308`.
error: aborting due to 15 previous errors
Some errors have detailed explanations: E0277, E0308, E0658.
For more information about an error, try `rustc --explain E0277`.

View File

@ -180,7 +180,20 @@ LL | let Foo(mut a) = &mut Foo(0);
= 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
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.
For more information about an error, try `rustc --explain E0308`.
error: aborting due to 17 previous errors
Some errors have detailed explanations: E0277, E0308, E0658.
For more information about an error, try `rustc --explain E0277`.

View File

@ -65,4 +65,20 @@ pub fn main() {
let Foo(mut a) = &mut Foo(0);
//~^ ERROR: binding cannot be both mutable and by-reference
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]
}

View File

@ -161,7 +161,20 @@ LL | let Foo(mut a) = &mut Foo(0);
= 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
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.
For more information about an error, try `rustc --explain E0308`.
error: aborting due to 16 previous errors
Some errors have detailed explanations: E0277, E0308, E0658.
For more information about an error, try `rustc --explain E0277`.