Skip to content

Commit c9d05aa

Browse files
committed
Point at correct span for parenthesized types
1 parent b370c11 commit c9d05aa

23 files changed

+95
-91
lines changed

src/librustc/hir/lowering.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1893,10 +1893,13 @@ impl<'a> LoweringContext<'a> {
18931893
if let Ok(snippet) = self.sess.source_map().span_to_snippet(data.span) {
18941894
// Do not suggest going from `Trait()` to `Trait<>`
18951895
if data.inputs.len() > 0 {
1896+
let split = snippet.find('(').unwrap();
1897+
let trait_name = &snippet[0..split];
1898+
let args = &snippet[split + 1 .. snippet.len() - 1];
18961899
err.span_suggestion(
18971900
data.span,
18981901
"use angle brackets instead",
1899-
format!("<{}>", &snippet[1..snippet.len() - 1]),
1902+
format!("{}<{}>", trait_name, args),
19001903
Applicability::MaybeIncorrect,
19011904
);
19021905
}

src/libsyntax/parse/parser/path.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,11 @@ impl<'a> Parser<'a> {
129129
self.parse_path(style)
130130
}
131131

132-
crate fn parse_path_segments(&mut self,
133-
segments: &mut Vec<PathSegment>,
134-
style: PathStyle)
135-
-> PResult<'a, ()> {
132+
crate fn parse_path_segments(
133+
&mut self,
134+
segments: &mut Vec<PathSegment>,
135+
style: PathStyle,
136+
) -> PResult<'a, ()> {
136137
loop {
137138
let segment = self.parse_path_segment(style)?;
138139
if style == PathStyle::Expr {
@@ -196,12 +197,12 @@ impl<'a> Parser<'a> {
196197
let (args, constraints) =
197198
self.parse_generic_args_with_leaning_angle_bracket_recovery(style, lo)?;
198199
self.expect_gt()?;
199-
let span = lo.to(self.prev_span);
200+
let span = ident.span.to(self.prev_span);
200201
AngleBracketedArgs { args, constraints, span }.into()
201202
} else {
202203
// `(T, U) -> R`
203204
let (inputs, _) = self.parse_paren_comma_seq(|p| p.parse_ty())?;
204-
let span = lo.to(self.prev_span);
205+
let span = ident.span.to(self.prev_span);
205206
let output = if self.eat(&token::RArrow) {
206207
Some(self.parse_ty_common(false, false, false)?)
207208
} else {

src/test/ui/anonymous-higher-ranked-lifetime.stderr

+11-11
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ LL | f1(|_: (), _: ()| {});
1818
| expected signature of `fn(&(), &()) -> _`
1919
...
2020
LL | fn f1<F>(_: F) where F: Fn(&(), &()) {}
21-
| -- ---------- required by this bound in `f1`
21+
| -- ------------ required by this bound in `f1`
2222

2323
error[E0631]: type mismatch in closure arguments
2424
--> $DIR/anonymous-higher-ranked-lifetime.rs:4:5
@@ -40,7 +40,7 @@ LL | f2(|_: (), _: ()| {});
4040
| expected signature of `fn(&'a (), &()) -> _`
4141
...
4242
LL | fn f2<F>(_: F) where F: for<'a> Fn(&'a (), &()) {}
43-
| -- ------------- required by this bound in `f2`
43+
| -- --------------- required by this bound in `f2`
4444

4545
error[E0631]: type mismatch in closure arguments
4646
--> $DIR/anonymous-higher-ranked-lifetime.rs:6:5
@@ -62,7 +62,7 @@ LL | f3(|_: (), _: ()| {});
6262
| expected signature of `fn(&(), &()) -> _`
6363
...
6464
LL | fn f3<'a, F>(_: F) where F: Fn(&'a (), &()) {}
65-
| -- ------------- required by this bound in `f3`
65+
| -- --------------- required by this bound in `f3`
6666

6767
error[E0631]: type mismatch in closure arguments
6868
--> $DIR/anonymous-higher-ranked-lifetime.rs:8:5
@@ -84,7 +84,7 @@ LL | f4(|_: (), _: ()| {});
8484
| expected signature of `fn(&(), &'r ()) -> _`
8585
...
8686
LL | fn f4<F>(_: F) where F: for<'r> Fn(&(), &'r ()) {}
87-
| -- ------------- required by this bound in `f4`
87+
| -- --------------- required by this bound in `f4`
8888

8989
error[E0631]: type mismatch in closure arguments
9090
--> $DIR/anonymous-higher-ranked-lifetime.rs:10:5
@@ -106,7 +106,7 @@ LL | f5(|_: (), _: ()| {});
106106
| expected signature of `fn(&'r (), &'r ()) -> _`
107107
...
108108
LL | fn f5<F>(_: F) where F: for<'r> Fn(&'r (), &'r ()) {}
109-
| -- ---------------- required by this bound in `f5`
109+
| -- ------------------ required by this bound in `f5`
110110

111111
error[E0631]: type mismatch in closure arguments
112112
--> $DIR/anonymous-higher-ranked-lifetime.rs:12:5
@@ -128,7 +128,7 @@ LL | g1(|_: (), _: ()| {});
128128
| expected signature of `fn(&(), std::boxed::Box<(dyn for<'r> std::ops::Fn(&'r ()) + 'static)>) -> _`
129129
...
130130
LL | fn g1<F>(_: F) where F: Fn(&(), Box<dyn Fn(&())>) {}
131-
| -- ----------------------- required by this bound in `g1`
131+
| -- ------------------------- required by this bound in `g1`
132132

133133
error[E0631]: type mismatch in closure arguments
134134
--> $DIR/anonymous-higher-ranked-lifetime.rs:14:5
@@ -150,7 +150,7 @@ LL | g2(|_: (), _: ()| {});
150150
| expected signature of `fn(&(), for<'r> fn(&'r ())) -> _`
151151
...
152152
LL | fn g2<F>(_: F) where F: Fn(&(), fn(&())) {}
153-
| -- -------------- required by this bound in `g2`
153+
| -- ---------------- required by this bound in `g2`
154154

155155
error[E0631]: type mismatch in closure arguments
156156
--> $DIR/anonymous-higher-ranked-lifetime.rs:16:5
@@ -172,7 +172,7 @@ LL | g3(|_: (), _: ()| {});
172172
| expected signature of `fn(&'s (), std::boxed::Box<(dyn for<'r> std::ops::Fn(&'r ()) + 'static)>) -> _`
173173
...
174174
LL | fn g3<F>(_: F) where F: for<'s> Fn(&'s (), Box<dyn Fn(&())>) {}
175-
| -- -------------------------- required by this bound in `g3`
175+
| -- ---------------------------- required by this bound in `g3`
176176

177177
error[E0631]: type mismatch in closure arguments
178178
--> $DIR/anonymous-higher-ranked-lifetime.rs:18:5
@@ -194,7 +194,7 @@ LL | g4(|_: (), _: ()| {});
194194
| expected signature of `fn(&(), for<'r> fn(&'r ())) -> _`
195195
...
196196
LL | fn g4<F>(_: F) where F: Fn(&(), for<'r> fn(&'r ())) {}
197-
| -- ------------------------- required by this bound in `g4`
197+
| -- --------------------------- required by this bound in `g4`
198198

199199
error[E0631]: type mismatch in closure arguments
200200
--> $DIR/anonymous-higher-ranked-lifetime.rs:20:5
@@ -216,7 +216,7 @@ LL | h1(|_: (), _: (), _: (), _: ()| {});
216216
| expected signature of `fn(&(), std::boxed::Box<(dyn for<'r> std::ops::Fn(&'r ()) + 'static)>, &(), for<'r, 's> fn(&'r (), &'s ())) -> _`
217217
...
218218
LL | fn h1<F>(_: F) where F: Fn(&(), Box<dyn Fn(&())>, &(), fn(&(), &())) {}
219-
| -- ------------------------------------------ required by this bound in `h1`
219+
| -- -------------------------------------------- required by this bound in `h1`
220220

221221
error[E0631]: type mismatch in closure arguments
222222
--> $DIR/anonymous-higher-ranked-lifetime.rs:22:5
@@ -238,7 +238,7 @@ LL | h2(|_: (), _: (), _: (), _: ()| {});
238238
| expected signature of `fn(&(), std::boxed::Box<(dyn for<'r> std::ops::Fn(&'r ()) + 'static)>, &'t0 (), for<'r, 's> fn(&'r (), &'s ())) -> _`
239239
...
240240
LL | fn h2<F>(_: F) where F: for<'t0> Fn(&(), Box<dyn Fn(&())>, &'t0 (), fn(&(), &())) {}
241-
| -- ---------------------------------------------- required by this bound in `h2`
241+
| -- ------------------------------------------------ required by this bound in `h2`
242242

243243
error: aborting due to 22 previous errors
244244

src/test/ui/closure-expected-type/expect-fn-supply-fn.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ error[E0631]: type mismatch in closure arguments
4242
LL | fn with_closure_expecting_fn_with_free_region<F>(_: F)
4343
| ------------------------------------------
4444
LL | where F: for<'a> FnOnce(fn(&'a u32), &i32)
45-
| ------------------- required by this bound in `with_closure_expecting_fn_with_free_region`
45+
| ------------------------- required by this bound in `with_closure_expecting_fn_with_free_region`
4646
...
4747
LL | with_closure_expecting_fn_with_free_region(|x: fn(&u32), y| {});
4848
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ---------------- found signature of `fn(for<'r> fn(&'r u32), _) -> _`
@@ -55,7 +55,7 @@ error[E0631]: type mismatch in closure arguments
5555
LL | fn with_closure_expecting_fn_with_bound_region<F>(_: F)
5656
| -------------------------------------------
5757
LL | where F: FnOnce(fn(&u32), &i32)
58-
| ---------------- required by this bound in `with_closure_expecting_fn_with_bound_region`
58+
| ---------------------- required by this bound in `with_closure_expecting_fn_with_bound_region`
5959
...
6060
LL | with_closure_expecting_fn_with_bound_region(|x: fn(&'x u32), y| {});
6161
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ------------------- found signature of `fn(fn(&'x u32), _) -> _`
@@ -68,7 +68,7 @@ error[E0631]: type mismatch in closure arguments
6868
LL | fn with_closure_expecting_fn_with_bound_region<F>(_: F)
6969
| -------------------------------------------
7070
LL | where F: FnOnce(fn(&u32), &i32)
71-
| ---------------- required by this bound in `with_closure_expecting_fn_with_bound_region`
71+
| ---------------------- required by this bound in `with_closure_expecting_fn_with_bound_region`
7272
...
7373
LL | with_closure_expecting_fn_with_bound_region(|x: Foo<'_>, y| {
7474
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ --------------- found signature of `for<'r> fn(fn(&'r u32), _) -> _`

src/test/ui/error-codes/E0214.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
2-
--> $DIR/E0214.rs:2:15
2+
--> $DIR/E0214.rs:2:12
33
|
44
LL | let v: Vec(&str) = vec!["foo"];
5-
| ^^^^^^
6-
| |
7-
| only `Fn` traits may use parentheses
8-
| help: use angle brackets instead: `<&str>`
5+
| ^^^^^^^^^
6+
| |
7+
| only `Fn` traits may use parentheses
8+
| help: use angle brackets instead: `Vec<&str>`
99

1010
error: aborting due to previous error
1111

src/test/ui/feature-gates/feature-gate-unboxed-closures-manual-impls.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ LL | impl Fn<()> for Foo {
4444
= help: add `#![feature(unboxed_closures)]` to the crate attributes to enable
4545

4646
error[E0229]: associated type bindings are not allowed here
47-
--> $DIR/feature-gate-unboxed-closures-manual-impls.rs:15:12
47+
--> $DIR/feature-gate-unboxed-closures-manual-impls.rs:15:6
4848
|
4949
LL | impl FnOnce() for Foo1 {
50-
| ^^ associated type not allowed here
50+
| ^^^^^^^^ associated type not allowed here
5151

5252
error[E0658]: the precise format of `Fn`-family traits' type parameters is subject to change. Use parenthetical notation (Fn(Foo, Bar) -> Baz) instead
5353
--> $DIR/feature-gate-unboxed-closures-manual-impls.rs:21:6

src/test/ui/issues/issue-23589.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
2-
--> $DIR/issue-23589.rs:2:15
2+
--> $DIR/issue-23589.rs:2:12
33
|
44
LL | let v: Vec(&str) = vec!['1', '2'];
5-
| ^^^^^^
6-
| |
7-
| only `Fn` traits may use parentheses
8-
| help: use angle brackets instead: `<&str>`
5+
| ^^^^^^^^^
6+
| |
7+
| only `Fn` traits may use parentheses
8+
| help: use angle brackets instead: `Vec<&str>`
99

1010
error[E0308]: mismatched types
1111
--> $DIR/issue-23589.rs:2:29

src/test/ui/issues/issue-32995-2.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
error: parenthesized type parameters may only be used with a `Fn` trait
2-
--> $DIR/issue-32995-2.rs:4:28
2+
--> $DIR/issue-32995-2.rs:4:22
33
|
44
LL | { fn f<X: ::std::marker()::Send>() {} }
5-
| ^^
5+
| ^^^^^^^^
66
|
77
= note: `#[deny(parenthesized_params_in_types_and_modules)]` on by default
88
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
99
= note: for more information, see issue #42238 <https://github.com/rust-lang/rust/issues/42238>
1010

1111
error: parenthesized type parameters may only be used with a `Fn` trait
12-
--> $DIR/issue-32995-2.rs:8:35
12+
--> $DIR/issue-32995-2.rs:8:29
1313
|
1414
LL | { fn f() -> impl ::std::marker()::Send { } }
15-
| ^^
15+
| ^^^^^^^^
1616
|
1717
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
1818
= note: for more information, see issue #42238 <https://github.com/rust-lang/rust/issues/42238>
1919

2020
error: parenthesized type parameters may only be used with a `Fn` trait
21-
--> $DIR/issue-32995-2.rs:16:19
21+
--> $DIR/issue-32995-2.rs:16:13
2222
|
2323
LL | impl ::std::marker()::Copy for X {}
24-
| ^^
24+
| ^^^^^^^^
2525
|
2626
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
2727
= note: for more information, see issue #42238 <https://github.com/rust-lang/rust/issues/42238>

src/test/ui/issues/issue-32995.stderr

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,63 @@
11
error: parenthesized type parameters may only be used with a `Fn` trait
2-
--> $DIR/issue-32995.rs:4:17
2+
--> $DIR/issue-32995.rs:4:12
33
|
44
LL | let x: usize() = 1;
5-
| ^^
5+
| ^^^^^^^
66
|
77
= note: `#[deny(parenthesized_params_in_types_and_modules)]` on by default
88
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
99
= note: for more information, see issue #42238 <https://github.com/rust-lang/rust/issues/42238>
1010

1111
error: parenthesized type parameters may only be used with a `Fn` trait
12-
--> $DIR/issue-32995.rs:8:24
12+
--> $DIR/issue-32995.rs:8:19
1313
|
1414
LL | let b: ::std::boxed()::Box<_> = Box::new(1);
15-
| ^^
15+
| ^^^^^^^
1616
|
1717
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
1818
= note: for more information, see issue #42238 <https://github.com/rust-lang/rust/issues/42238>
1919

2020
error: parenthesized type parameters may only be used with a `Fn` trait
21-
--> $DIR/issue-32995.rs:12:25
21+
--> $DIR/issue-32995.rs:12:20
2222
|
2323
LL | let p = ::std::str::()::from_utf8(b"foo").unwrap();
24-
| ^^
24+
| ^^^^^^^
2525
|
2626
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
2727
= note: for more information, see issue #42238 <https://github.com/rust-lang/rust/issues/42238>
2828

2929
error: parenthesized type parameters may only be used with a `Fn` trait
30-
--> $DIR/issue-32995.rs:16:36
30+
--> $DIR/issue-32995.rs:16:25
3131
|
3232
LL | let p = ::std::str::from_utf8::()(b"foo").unwrap();
33-
| ^^
33+
| ^^^^^^^^^^^^^
3434
|
3535
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
3636
= note: for more information, see issue #42238 <https://github.com/rust-lang/rust/issues/42238>
3737

3838
error: parenthesized type parameters may only be used with a `Fn` trait
39-
--> $DIR/issue-32995.rs:20:35
39+
--> $DIR/issue-32995.rs:20:29
4040
|
4141
LL | let o : Box<dyn (::std::marker()::Send)> = Box::new(1);
42-
| ^^
42+
| ^^^^^^^^
4343
|
4444
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
4545
= note: for more information, see issue #42238 <https://github.com/rust-lang/rust/issues/42238>
4646

4747
error: parenthesized type parameters may only be used with a `Fn` trait
48-
--> $DIR/issue-32995.rs:24:41
48+
--> $DIR/issue-32995.rs:24:35
4949
|
5050
LL | let o : Box<dyn Send + ::std::marker()::Sync> = Box::new(1);
51-
| ^^
51+
| ^^^^^^^^
5252
|
5353
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
5454
= note: for more information, see issue #42238 <https://github.com/rust-lang/rust/issues/42238>
5555

5656
error: parenthesized type parameters may only be used with a `Fn` trait
57-
--> $DIR/issue-32995.rs:30:14
57+
--> $DIR/issue-32995.rs:30:13
5858
|
5959
LL | let d : X() = Default::default();
60-
| ^^
60+
| ^^^
6161
|
6262
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
6363
= note: for more information, see issue #42238 <https://github.com/rust-lang/rust/issues/42238>

src/test/ui/issues/issue-39687.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0229]: associated type bindings are not allowed here
2-
--> $DIR/issue-39687.rs:4:16
2+
--> $DIR/issue-39687.rs:4:14
33
|
44
LL | <fn() as Fn()>::call;
5-
| ^^ associated type not allowed here
5+
| ^^^^ associated type not allowed here
66

77
error: aborting due to previous error
88

src/test/ui/issues/issue-43623.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ LL | pub fn break_me<T, F>(f: F)
1919
| --------
2020
LL | where T: for<'b> Trait<'b>,
2121
LL | F: for<'b> FnMut(<T as Trait<'b>>::Assoc) {
22-
| ------------------------- required by this bound in `break_me`
22+
| ------------------------------ required by this bound in `break_me`
2323
LL | break_me::<Type, fn(_)>;
2424
| ^^^^^^^^^^^^^^^^^^^^^^^ expected bound lifetime parameter 'b, found concrete lifetime
2525

src/test/ui/issues/issue-60283.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ LL | pub fn foo<T, F>(_: T, _: F)
2020
| ---
2121
LL | where T: for<'a> Trait<'a>,
2222
LL | F: for<'a> FnMut(<T as Trait<'a>>::Item) {}
23-
| ------------------------ required by this bound in `foo`
23+
| ----------------------------- required by this bound in `foo`
2424
...
2525
LL | foo((), drop)
2626
| ^^^ expected bound lifetime parameter 'a, found concrete lifetime

src/test/ui/mismatched_types/closure-arg-type-mismatch.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ error[E0271]: type mismatch resolving `for<'r> <fn(*mut &'a u32) as std::ops::Fn
3838
--> $DIR/closure-arg-type-mismatch.rs:10:5
3939
|
4040
LL | fn baz<F: Fn(*mut &u32)>(_: F) {}
41-
| --- ----------- required by this bound in `baz`
41+
| --- ------------- required by this bound in `baz`
4242
LL | fn _test<'a>(f: fn(*mut &'a u32)) {
4343
LL | baz(f);
4444
| ^^^ expected bound lifetime parameter, found concrete lifetime
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
error: field expressions may not have generic arguments
2-
--> $DIR/type-parameters-in-field-exprs.rs:13:10
2+
--> $DIR/type-parameters-in-field-exprs.rs:13:7
33
|
44
LL | f.x::<isize>;
5-
| ^^^^^^^
5+
| ^^^^^^^^^^
66

77
error: field expressions may not have generic arguments
8-
--> $DIR/type-parameters-in-field-exprs.rs:15:10
8+
--> $DIR/type-parameters-in-field-exprs.rs:15:7
99
|
1010
LL | f.x::<>;
11-
| ^^
11+
| ^^^^^
1212

1313
error: field expressions may not have generic arguments
14-
--> $DIR/type-parameters-in-field-exprs.rs:17:10
14+
--> $DIR/type-parameters-in-field-exprs.rs:17:7
1515
|
1616
LL | f.x::();
17-
| ^^
17+
| ^^^^^
1818

1919
error: aborting due to 3 previous errors
2020

0 commit comments

Comments
 (0)