Skip to content

Commit 65a02f1

Browse files
authored
Rollup merge of #72668 - awoimbee:give-fn-parenthetical-notation-parentheses, r=estebank
Fix missing parentheses Fn notation error Fixes #72611 Well, fixes the error output, I think E0658 is the right error to throw in this case so I didn't change that
2 parents ffe3292 + c54d4fe commit 65a02f1

File tree

4 files changed

+77
-2
lines changed

4 files changed

+77
-2
lines changed

src/librustc_typeck/astconv.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -1151,9 +1151,16 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
11511151
.as_ref()
11521152
.and_then(|args| args.args.get(0))
11531153
.and_then(|arg| match arg {
1154-
hir::GenericArg::Type(ty) => {
1155-
sess.source_map().span_to_snippet(ty.span).ok()
1154+
hir::GenericArg::Type(ty) => match ty.kind {
1155+
hir::TyKind::Tup(t) => t
1156+
.iter()
1157+
.map(|e| sess.source_map().span_to_snippet(e.span))
1158+
.collect::<Result<Vec<_>, _>>()
1159+
.map(|a| a.join(", ")),
1160+
_ => sess.source_map().span_to_snippet(ty.span),
11561161
}
1162+
.map(|s| format!("({})", s))
1163+
.ok(),
11571164
_ => None,
11581165
})
11591166
.unwrap_or_else(|| "()".to_string()),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// run-rustfix
2+
fn e0658<F, G, H>(f: F, g: G, h: H) -> i32
3+
where
4+
F: Fn(i32) -> i32, //~ ERROR E0658
5+
G: Fn(i32, i32) -> (i32, i32), //~ ERROR E0658
6+
H: Fn(i32) -> i32, //~ ERROR E0658
7+
{
8+
f(3);
9+
g(3, 4);
10+
h(3)
11+
}
12+
13+
fn main() {
14+
e0658(
15+
|a| a,
16+
|a, b| (b, a),
17+
|a| a,
18+
);
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// run-rustfix
2+
fn e0658<F, G, H>(f: F, g: G, h: H) -> i32
3+
where
4+
F: Fn<i32, Output = i32>, //~ ERROR E0658
5+
G: Fn<(i32, i32, ), Output = (i32, i32)>, //~ ERROR E0658
6+
H: Fn<(i32,), Output = i32>, //~ ERROR E0658
7+
{
8+
f(3);
9+
g(3, 4);
10+
h(3)
11+
}
12+
13+
fn main() {
14+
e0658(
15+
|a| a,
16+
|a, b| (b, a),
17+
|a| a,
18+
);
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
error[E0658]: the precise format of `Fn`-family traits' type parameters is subject to change
2+
--> $DIR/fn-trait-notation.rs:4:8
3+
|
4+
LL | F: Fn<i32, Output = i32>,
5+
| ^^^^^^^^^^^^^^^^^^^^^ help: use parenthetical notation instead: `Fn(i32) -> i32`
6+
|
7+
= note: see issue #29625 <https://github.com/rust-lang/rust/issues/29625> for more information
8+
= help: add `#![feature(unboxed_closures)]` to the crate attributes to enable
9+
10+
error[E0658]: the precise format of `Fn`-family traits' type parameters is subject to change
11+
--> $DIR/fn-trait-notation.rs:5:8
12+
|
13+
LL | G: Fn<(i32, i32, ), Output = (i32, i32)>,
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use parenthetical notation instead: `Fn(i32, i32) -> (i32, i32)`
15+
|
16+
= note: see issue #29625 <https://github.com/rust-lang/rust/issues/29625> for more information
17+
= help: add `#![feature(unboxed_closures)]` to the crate attributes to enable
18+
19+
error[E0658]: the precise format of `Fn`-family traits' type parameters is subject to change
20+
--> $DIR/fn-trait-notation.rs:6:8
21+
|
22+
LL | H: Fn<(i32,), Output = i32>,
23+
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: use parenthetical notation instead: `Fn(i32) -> i32`
24+
|
25+
= note: see issue #29625 <https://github.com/rust-lang/rust/issues/29625> for more information
26+
= help: add `#![feature(unboxed_closures)]` to the crate attributes to enable
27+
28+
error: aborting due to 3 previous errors
29+
30+
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)