Skip to content

Commit

Permalink
Match ergonomics 2024: test type inference
Browse files Browse the repository at this point in the history
  • Loading branch information
Jules-Bertholet committed Jul 5, 2024
1 parent 5a35fc4 commit 76da7ae
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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`

error: aborting due to 15 previous errors

Some errors have detailed explanations: E0308, E0658.
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`.
Original file line number Diff line number Diff line change
Expand Up @@ -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`

error: aborting due to 17 previous errors

Some errors have detailed explanations: E0308, E0658.
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`.
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
Original file line number Diff line number Diff line change
Expand Up @@ -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`

error: aborting due to 16 previous errors

Some errors have detailed explanations: E0308, E0658.
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`.

0 comments on commit 76da7ae

Please sign in to comment.