Skip to content

Commit 76da7ae

Browse files
Match ergonomics 2024: test type inference
1 parent 5a35fc4 commit 76da7ae

5 files changed

+87
-9
lines changed

tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024.rs

+23
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,27 @@ pub fn main() {
6363
if let Some(&mut x) = &Some(&mut 0) {
6464
let _: &u32 = x;
6565
}
66+
67+
fn generic<R: Ref>() -> (R, bool) {
68+
R::meow()
69+
}
70+
71+
trait Ref: Sized {
72+
fn meow() -> (Self, bool);
73+
}
74+
75+
impl Ref for &'static [(); 0] {
76+
fn meow() -> (Self, bool) {
77+
(&[], false)
78+
}
79+
}
80+
81+
impl Ref for &'static mut [(); 0] {
82+
fn meow() -> (Self, bool) {
83+
(&mut [], true)
84+
}
85+
}
86+
87+
let (&_, b) = generic();
88+
assert!(!b);
6689
}

tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_fail.both.stderr

+16-3
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,20 @@ LL | let Foo(mut a) = &mut Foo(0);
150150
= help: add `#![feature(mut_ref)]` to the crate attributes to enable
151151
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
152152

153-
error: aborting due to 14 previous errors
153+
error[E0277]: the trait bound `&_: main::Ref` is not satisfied
154+
--> $DIR/ref_pat_eat_one_layer_2024_fail.rs:83:14
155+
|
156+
LL | let &_ = generic();
157+
| ^^^^^^^^^ the trait `main::Ref` is not implemented for `&_`
158+
|
159+
= help: the trait `main::Ref` is implemented for `&'static mut [(); 0]`
160+
note: required by a bound in `generic`
161+
--> $DIR/ref_pat_eat_one_layer_2024_fail.rs:69:19
162+
|
163+
LL | fn generic<R: Ref>() -> R {
164+
| ^^^ required by this bound in `generic`
165+
166+
error: aborting due to 15 previous errors
154167

155-
Some errors have detailed explanations: E0308, E0658.
156-
For more information about an error, try `rustc --explain E0308`.
168+
Some errors have detailed explanations: E0277, E0308, E0658.
169+
For more information about an error, try `rustc --explain E0277`.

tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_fail.classic.stderr

+16-3
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,20 @@ LL | let Foo(mut a) = &mut Foo(0);
180180
= help: add `#![feature(mut_ref)]` to the crate attributes to enable
181181
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
182182

183-
error: aborting due to 16 previous errors
183+
error[E0277]: the trait bound `&_: main::Ref` is not satisfied
184+
--> $DIR/ref_pat_eat_one_layer_2024_fail.rs:83:14
185+
|
186+
LL | let &_ = generic();
187+
| ^^^^^^^^^ the trait `main::Ref` is not implemented for `&_`
188+
|
189+
= help: the trait `main::Ref` is implemented for `&'static mut [(); 0]`
190+
note: required by a bound in `generic`
191+
--> $DIR/ref_pat_eat_one_layer_2024_fail.rs:69:19
192+
|
193+
LL | fn generic<R: Ref>() -> R {
194+
| ^^^ required by this bound in `generic`
195+
196+
error: aborting due to 17 previous errors
184197

185-
Some errors have detailed explanations: E0308, E0658.
186-
For more information about an error, try `rustc --explain E0308`.
198+
Some errors have detailed explanations: E0277, E0308, E0658.
199+
For more information about an error, try `rustc --explain E0277`.

tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_fail.rs

+16
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,20 @@ pub fn main() {
6565
let Foo(mut a) = &mut Foo(0);
6666
//~^ ERROR: binding cannot be both mutable and by-reference
6767
a = &mut 42;
68+
69+
fn generic<R: Ref>() -> R {
70+
R::meow()
71+
}
72+
73+
trait Ref: Sized {
74+
fn meow() -> Self;
75+
}
76+
77+
impl Ref for &'static mut [(); 0] {
78+
fn meow() -> Self {
79+
&mut []
80+
}
81+
}
82+
83+
let &_ = generic(); //~ERROR: the trait bound `&_: main::Ref` is not satisfied [E0277]
6884
}

tests/ui/match/ref_pat_eat_one_layer_2024/ref_pat_eat_one_layer_2024_fail.structural.stderr

+16-3
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,20 @@ LL | let Foo(mut a) = &mut Foo(0);
161161
= help: add `#![feature(mut_ref)]` to the crate attributes to enable
162162
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
163163

164-
error: aborting due to 15 previous errors
164+
error[E0277]: the trait bound `&_: main::Ref` is not satisfied
165+
--> $DIR/ref_pat_eat_one_layer_2024_fail.rs:83:14
166+
|
167+
LL | let &_ = generic();
168+
| ^^^^^^^^^ the trait `main::Ref` is not implemented for `&_`
169+
|
170+
= help: the trait `main::Ref` is implemented for `&'static mut [(); 0]`
171+
note: required by a bound in `generic`
172+
--> $DIR/ref_pat_eat_one_layer_2024_fail.rs:69:19
173+
|
174+
LL | fn generic<R: Ref>() -> R {
175+
| ^^^ required by this bound in `generic`
176+
177+
error: aborting due to 16 previous errors
165178

166-
Some errors have detailed explanations: E0308, E0658.
167-
For more information about an error, try `rustc --explain E0308`.
179+
Some errors have detailed explanations: E0277, E0308, E0658.
180+
For more information about an error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)