Fix match ergonomics in closure parameters

Fixes #4476.
This commit is contained in:
Florian Diebold
2020-05-29 17:35:57 +02:00
parent 30658b25d2
commit 6f67a46a6a
2 changed files with 61 additions and 5 deletions

View File

@@ -520,3 +520,53 @@ fn main() {
105..107 '()': ()
")
}
#[test]
fn match_ergonomics_in_closure_params() {
assert_snapshot!(
infer(r#"
#[lang = "fn_once"]
trait FnOnce<Args> {
type Output;
}
fn foo<T, U, F: FnOnce(T) -> U>(t: T, f: F) -> U { loop {} }
fn test() {
foo(&(1, "a"), |&(x, y)| x); // normal, no match ergonomics
foo(&(1, "a"), |(x, y)| x);
}
"#),
@r###"
94..95 't': T
100..101 'f': F
111..122 '{ loop {} }': U
113..120 'loop {}': !
118..120 '{}': ()
134..233 '{ ... x); }': ()
140..143 'foo': fn foo<&(i32, &str), i32, |&(i32, &str)| -> i32>(&(i32, &str), |&(i32, &str)| -> i32) -> i32
140..167 'foo(&(...y)| x)': i32
144..153 '&(1, "a")': &(i32, &str)
145..153 '(1, "a")': (i32, &str)
146..147 '1': i32
149..152 '"a"': &str
155..166 '|&(x, y)| x': |&(i32, &str)| -> i32
156..163 '&(x, y)': &(i32, &str)
157..163 '(x, y)': (i32, &str)
158..159 'x': i32
161..162 'y': &str
165..166 'x': i32
204..207 'foo': fn foo<&(i32, &str), &i32, |&(i32, &str)| -> &i32>(&(i32, &str), |&(i32, &str)| -> &i32) -> &i32
204..230 'foo(&(...y)| x)': &i32
208..217 '&(1, "a")': &(i32, &str)
209..217 '(1, "a")': (i32, &str)
210..211 '1': i32
213..216 '"a"': &str
219..229 '|(x, y)| x': |&(i32, &str)| -> &i32
220..226 '(x, y)': (i32, &str)
221..222 'x': &i32
224..225 'y': &&str
228..229 'x': &i32
"###
);
}