Point at correct span for parenthesized types

This commit is contained in:
Esteban Küber 2019-09-04 17:36:01 -07:00
parent b370c111fd
commit c9d05aa9ce
23 changed files with 95 additions and 91 deletions

View File

@ -1893,10 +1893,13 @@ impl<'a> LoweringContext<'a> {
if let Ok(snippet) = self.sess.source_map().span_to_snippet(data.span) {
// Do not suggest going from `Trait()` to `Trait<>`
if data.inputs.len() > 0 {
let split = snippet.find('(').unwrap();
let trait_name = &snippet[0..split];
let args = &snippet[split + 1 .. snippet.len() - 1];
err.span_suggestion(
data.span,
"use angle brackets instead",
format!("<{}>", &snippet[1..snippet.len() - 1]),
format!("{}<{}>", trait_name, args),
Applicability::MaybeIncorrect,
);
}

View File

@ -129,10 +129,11 @@ impl<'a> Parser<'a> {
self.parse_path(style)
}
crate fn parse_path_segments(&mut self,
segments: &mut Vec<PathSegment>,
style: PathStyle)
-> PResult<'a, ()> {
crate fn parse_path_segments(
&mut self,
segments: &mut Vec<PathSegment>,
style: PathStyle,
) -> PResult<'a, ()> {
loop {
let segment = self.parse_path_segment(style)?;
if style == PathStyle::Expr {
@ -196,12 +197,12 @@ impl<'a> Parser<'a> {
let (args, constraints) =
self.parse_generic_args_with_leaning_angle_bracket_recovery(style, lo)?;
self.expect_gt()?;
let span = lo.to(self.prev_span);
let span = ident.span.to(self.prev_span);
AngleBracketedArgs { args, constraints, span }.into()
} else {
// `(T, U) -> R`
let (inputs, _) = self.parse_paren_comma_seq(|p| p.parse_ty())?;
let span = lo.to(self.prev_span);
let span = ident.span.to(self.prev_span);
let output = if self.eat(&token::RArrow) {
Some(self.parse_ty_common(false, false, false)?)
} else {

View File

@ -18,7 +18,7 @@ LL | f1(|_: (), _: ()| {});
| expected signature of `fn(&(), &()) -> _`
...
LL | fn f1<F>(_: F) where F: Fn(&(), &()) {}
| -- ---------- required by this bound in `f1`
| -- ------------ required by this bound in `f1`
error[E0631]: type mismatch in closure arguments
--> $DIR/anonymous-higher-ranked-lifetime.rs:4:5
@ -40,7 +40,7 @@ LL | f2(|_: (), _: ()| {});
| expected signature of `fn(&'a (), &()) -> _`
...
LL | fn f2<F>(_: F) where F: for<'a> Fn(&'a (), &()) {}
| -- ------------- required by this bound in `f2`
| -- --------------- required by this bound in `f2`
error[E0631]: type mismatch in closure arguments
--> $DIR/anonymous-higher-ranked-lifetime.rs:6:5
@ -62,7 +62,7 @@ LL | f3(|_: (), _: ()| {});
| expected signature of `fn(&(), &()) -> _`
...
LL | fn f3<'a, F>(_: F) where F: Fn(&'a (), &()) {}
| -- ------------- required by this bound in `f3`
| -- --------------- required by this bound in `f3`
error[E0631]: type mismatch in closure arguments
--> $DIR/anonymous-higher-ranked-lifetime.rs:8:5
@ -84,7 +84,7 @@ LL | f4(|_: (), _: ()| {});
| expected signature of `fn(&(), &'r ()) -> _`
...
LL | fn f4<F>(_: F) where F: for<'r> Fn(&(), &'r ()) {}
| -- ------------- required by this bound in `f4`
| -- --------------- required by this bound in `f4`
error[E0631]: type mismatch in closure arguments
--> $DIR/anonymous-higher-ranked-lifetime.rs:10:5
@ -106,7 +106,7 @@ LL | f5(|_: (), _: ()| {});
| expected signature of `fn(&'r (), &'r ()) -> _`
...
LL | fn f5<F>(_: F) where F: for<'r> Fn(&'r (), &'r ()) {}
| -- ---------------- required by this bound in `f5`
| -- ------------------ required by this bound in `f5`
error[E0631]: type mismatch in closure arguments
--> $DIR/anonymous-higher-ranked-lifetime.rs:12:5
@ -128,7 +128,7 @@ LL | g1(|_: (), _: ()| {});
| expected signature of `fn(&(), std::boxed::Box<(dyn for<'r> std::ops::Fn(&'r ()) + 'static)>) -> _`
...
LL | fn g1<F>(_: F) where F: Fn(&(), Box<dyn Fn(&())>) {}
| -- ----------------------- required by this bound in `g1`
| -- ------------------------- required by this bound in `g1`
error[E0631]: type mismatch in closure arguments
--> $DIR/anonymous-higher-ranked-lifetime.rs:14:5
@ -150,7 +150,7 @@ LL | g2(|_: (), _: ()| {});
| expected signature of `fn(&(), for<'r> fn(&'r ())) -> _`
...
LL | fn g2<F>(_: F) where F: Fn(&(), fn(&())) {}
| -- -------------- required by this bound in `g2`
| -- ---------------- required by this bound in `g2`
error[E0631]: type mismatch in closure arguments
--> $DIR/anonymous-higher-ranked-lifetime.rs:16:5
@ -172,7 +172,7 @@ LL | g3(|_: (), _: ()| {});
| expected signature of `fn(&'s (), std::boxed::Box<(dyn for<'r> std::ops::Fn(&'r ()) + 'static)>) -> _`
...
LL | fn g3<F>(_: F) where F: for<'s> Fn(&'s (), Box<dyn Fn(&())>) {}
| -- -------------------------- required by this bound in `g3`
| -- ---------------------------- required by this bound in `g3`
error[E0631]: type mismatch in closure arguments
--> $DIR/anonymous-higher-ranked-lifetime.rs:18:5
@ -194,7 +194,7 @@ LL | g4(|_: (), _: ()| {});
| expected signature of `fn(&(), for<'r> fn(&'r ())) -> _`
...
LL | fn g4<F>(_: F) where F: Fn(&(), for<'r> fn(&'r ())) {}
| -- ------------------------- required by this bound in `g4`
| -- --------------------------- required by this bound in `g4`
error[E0631]: type mismatch in closure arguments
--> $DIR/anonymous-higher-ranked-lifetime.rs:20:5
@ -216,7 +216,7 @@ LL | h1(|_: (), _: (), _: (), _: ()| {});
| expected signature of `fn(&(), std::boxed::Box<(dyn for<'r> std::ops::Fn(&'r ()) + 'static)>, &(), for<'r, 's> fn(&'r (), &'s ())) -> _`
...
LL | fn h1<F>(_: F) where F: Fn(&(), Box<dyn Fn(&())>, &(), fn(&(), &())) {}
| -- ------------------------------------------ required by this bound in `h1`
| -- -------------------------------------------- required by this bound in `h1`
error[E0631]: type mismatch in closure arguments
--> $DIR/anonymous-higher-ranked-lifetime.rs:22:5
@ -238,7 +238,7 @@ LL | h2(|_: (), _: (), _: (), _: ()| {});
| expected signature of `fn(&(), std::boxed::Box<(dyn for<'r> std::ops::Fn(&'r ()) + 'static)>, &'t0 (), for<'r, 's> fn(&'r (), &'s ())) -> _`
...
LL | fn h2<F>(_: F) where F: for<'t0> Fn(&(), Box<dyn Fn(&())>, &'t0 (), fn(&(), &())) {}
| -- ---------------------------------------------- required by this bound in `h2`
| -- ------------------------------------------------ required by this bound in `h2`
error: aborting due to 22 previous errors

View File

@ -42,7 +42,7 @@ error[E0631]: type mismatch in closure arguments
LL | fn with_closure_expecting_fn_with_free_region<F>(_: F)
| ------------------------------------------
LL | where F: for<'a> FnOnce(fn(&'a u32), &i32)
| ------------------- required by this bound in `with_closure_expecting_fn_with_free_region`
| ------------------------- required by this bound in `with_closure_expecting_fn_with_free_region`
...
LL | with_closure_expecting_fn_with_free_region(|x: fn(&u32), y| {});
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ---------------- found signature of `fn(for<'r> fn(&'r u32), _) -> _`
@ -55,7 +55,7 @@ error[E0631]: type mismatch in closure arguments
LL | fn with_closure_expecting_fn_with_bound_region<F>(_: F)
| -------------------------------------------
LL | where F: FnOnce(fn(&u32), &i32)
| ---------------- required by this bound in `with_closure_expecting_fn_with_bound_region`
| ---------------------- required by this bound in `with_closure_expecting_fn_with_bound_region`
...
LL | with_closure_expecting_fn_with_bound_region(|x: fn(&'x u32), y| {});
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ------------------- found signature of `fn(fn(&'x u32), _) -> _`
@ -68,7 +68,7 @@ error[E0631]: type mismatch in closure arguments
LL | fn with_closure_expecting_fn_with_bound_region<F>(_: F)
| -------------------------------------------
LL | where F: FnOnce(fn(&u32), &i32)
| ---------------- required by this bound in `with_closure_expecting_fn_with_bound_region`
| ---------------------- required by this bound in `with_closure_expecting_fn_with_bound_region`
...
LL | with_closure_expecting_fn_with_bound_region(|x: Foo<'_>, y| {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ --------------- found signature of `for<'r> fn(fn(&'r u32), _) -> _`

View File

@ -1,11 +1,11 @@
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
--> $DIR/E0214.rs:2:15
--> $DIR/E0214.rs:2:12
|
LL | let v: Vec(&str) = vec!["foo"];
| ^^^^^^
| |
| only `Fn` traits may use parentheses
| help: use angle brackets instead: `<&str>`
| ^^^^^^^^^
| |
| only `Fn` traits may use parentheses
| help: use angle brackets instead: `Vec<&str>`
error: aborting due to previous error

View File

@ -44,10 +44,10 @@ LL | impl Fn<()> for Foo {
= help: add `#![feature(unboxed_closures)]` to the crate attributes to enable
error[E0229]: associated type bindings are not allowed here
--> $DIR/feature-gate-unboxed-closures-manual-impls.rs:15:12
--> $DIR/feature-gate-unboxed-closures-manual-impls.rs:15:6
|
LL | impl FnOnce() for Foo1 {
| ^^ associated type not allowed here
| ^^^^^^^^ associated type not allowed here
error[E0658]: the precise format of `Fn`-family traits' type parameters is subject to change. Use parenthetical notation (Fn(Foo, Bar) -> Baz) instead
--> $DIR/feature-gate-unboxed-closures-manual-impls.rs:21:6

View File

@ -1,11 +1,11 @@
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
--> $DIR/issue-23589.rs:2:15
--> $DIR/issue-23589.rs:2:12
|
LL | let v: Vec(&str) = vec!['1', '2'];
| ^^^^^^
| |
| only `Fn` traits may use parentheses
| help: use angle brackets instead: `<&str>`
| ^^^^^^^^^
| |
| only `Fn` traits may use parentheses
| help: use angle brackets instead: `Vec<&str>`
error[E0308]: mismatched types
--> $DIR/issue-23589.rs:2:29

View File

@ -1,27 +1,27 @@
error: parenthesized type parameters may only be used with a `Fn` trait
--> $DIR/issue-32995-2.rs:4:28
--> $DIR/issue-32995-2.rs:4:22
|
LL | { fn f<X: ::std::marker()::Send>() {} }
| ^^
| ^^^^^^^^
|
= note: `#[deny(parenthesized_params_in_types_and_modules)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #42238 <https://github.com/rust-lang/rust/issues/42238>
error: parenthesized type parameters may only be used with a `Fn` trait
--> $DIR/issue-32995-2.rs:8:35
--> $DIR/issue-32995-2.rs:8:29
|
LL | { fn f() -> impl ::std::marker()::Send { } }
| ^^
| ^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #42238 <https://github.com/rust-lang/rust/issues/42238>
error: parenthesized type parameters may only be used with a `Fn` trait
--> $DIR/issue-32995-2.rs:16:19
--> $DIR/issue-32995-2.rs:16:13
|
LL | impl ::std::marker()::Copy for X {}
| ^^
| ^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #42238 <https://github.com/rust-lang/rust/issues/42238>

View File

@ -1,63 +1,63 @@
error: parenthesized type parameters may only be used with a `Fn` trait
--> $DIR/issue-32995.rs:4:17
--> $DIR/issue-32995.rs:4:12
|
LL | let x: usize() = 1;
| ^^
| ^^^^^^^
|
= note: `#[deny(parenthesized_params_in_types_and_modules)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #42238 <https://github.com/rust-lang/rust/issues/42238>
error: parenthesized type parameters may only be used with a `Fn` trait
--> $DIR/issue-32995.rs:8:24
--> $DIR/issue-32995.rs:8:19
|
LL | let b: ::std::boxed()::Box<_> = Box::new(1);
| ^^
| ^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #42238 <https://github.com/rust-lang/rust/issues/42238>
error: parenthesized type parameters may only be used with a `Fn` trait
--> $DIR/issue-32995.rs:12:25
--> $DIR/issue-32995.rs:12:20
|
LL | let p = ::std::str::()::from_utf8(b"foo").unwrap();
| ^^
| ^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #42238 <https://github.com/rust-lang/rust/issues/42238>
error: parenthesized type parameters may only be used with a `Fn` trait
--> $DIR/issue-32995.rs:16:36
--> $DIR/issue-32995.rs:16:25
|
LL | let p = ::std::str::from_utf8::()(b"foo").unwrap();
| ^^
| ^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #42238 <https://github.com/rust-lang/rust/issues/42238>
error: parenthesized type parameters may only be used with a `Fn` trait
--> $DIR/issue-32995.rs:20:35
--> $DIR/issue-32995.rs:20:29
|
LL | let o : Box<dyn (::std::marker()::Send)> = Box::new(1);
| ^^
| ^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #42238 <https://github.com/rust-lang/rust/issues/42238>
error: parenthesized type parameters may only be used with a `Fn` trait
--> $DIR/issue-32995.rs:24:41
--> $DIR/issue-32995.rs:24:35
|
LL | let o : Box<dyn Send + ::std::marker()::Sync> = Box::new(1);
| ^^
| ^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #42238 <https://github.com/rust-lang/rust/issues/42238>
error: parenthesized type parameters may only be used with a `Fn` trait
--> $DIR/issue-32995.rs:30:14
--> $DIR/issue-32995.rs:30:13
|
LL | let d : X() = Default::default();
| ^^
| ^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #42238 <https://github.com/rust-lang/rust/issues/42238>

View File

@ -1,8 +1,8 @@
error[E0229]: associated type bindings are not allowed here
--> $DIR/issue-39687.rs:4:16
--> $DIR/issue-39687.rs:4:14
|
LL | <fn() as Fn()>::call;
| ^^ associated type not allowed here
| ^^^^ associated type not allowed here
error: aborting due to previous error

View File

@ -19,7 +19,7 @@ LL | pub fn break_me<T, F>(f: F)
| --------
LL | where T: for<'b> Trait<'b>,
LL | F: for<'b> FnMut(<T as Trait<'b>>::Assoc) {
| ------------------------- required by this bound in `break_me`
| ------------------------------ required by this bound in `break_me`
LL | break_me::<Type, fn(_)>;
| ^^^^^^^^^^^^^^^^^^^^^^^ expected bound lifetime parameter 'b, found concrete lifetime

View File

@ -20,7 +20,7 @@ LL | pub fn foo<T, F>(_: T, _: F)
| ---
LL | where T: for<'a> Trait<'a>,
LL | F: for<'a> FnMut(<T as Trait<'a>>::Item) {}
| ------------------------ required by this bound in `foo`
| ----------------------------- required by this bound in `foo`
...
LL | foo((), drop)
| ^^^ expected bound lifetime parameter 'a, found concrete lifetime

View File

@ -38,7 +38,7 @@ error[E0271]: type mismatch resolving `for<'r> <fn(*mut &'a u32) as std::ops::Fn
--> $DIR/closure-arg-type-mismatch.rs:10:5
|
LL | fn baz<F: Fn(*mut &u32)>(_: F) {}
| --- ----------- required by this bound in `baz`
| --- ------------- required by this bound in `baz`
LL | fn _test<'a>(f: fn(*mut &'a u32)) {
LL | baz(f);
| ^^^ expected bound lifetime parameter, found concrete lifetime

View File

@ -1,20 +1,20 @@
error: field expressions may not have generic arguments
--> $DIR/type-parameters-in-field-exprs.rs:13:10
--> $DIR/type-parameters-in-field-exprs.rs:13:7
|
LL | f.x::<isize>;
| ^^^^^^^
| ^^^^^^^^^^
error: field expressions may not have generic arguments
--> $DIR/type-parameters-in-field-exprs.rs:15:10
--> $DIR/type-parameters-in-field-exprs.rs:15:7
|
LL | f.x::<>;
| ^^
| ^^^^^
error: field expressions may not have generic arguments
--> $DIR/type-parameters-in-field-exprs.rs:17:10
--> $DIR/type-parameters-in-field-exprs.rs:17:7
|
LL | f.x::();
| ^^
| ^^^^^
error: aborting due to 3 previous errors

View File

@ -1,14 +1,14 @@
error: generic arguments in macro path
--> $DIR/macro-ty-params.rs:10:10
--> $DIR/macro-ty-params.rs:10:5
|
LL | foo::<T>!();
| ^^^
| ^^^^^^^^
error: generic arguments in macro path
--> $DIR/macro-ty-params.rs:11:10
--> $DIR/macro-ty-params.rs:11:5
|
LL | foo::<>!();
| ^^
| ^^^^^^^
error: unexpected generic arguments in path
--> $DIR/macro-ty-params.rs:12:8
@ -17,10 +17,10 @@ LL | m!(Default<>);
| ^^^^^^^^^
error: generic arguments in macro path
--> $DIR/macro-ty-params.rs:12:15
--> $DIR/macro-ty-params.rs:12:8
|
LL | m!(Default<>);
| ^^
| ^^^^^^^^^
error: aborting due to 4 previous errors

View File

@ -5,10 +5,10 @@ LL | input_cells: Vec::new()
| ^^^^^^^^^^^ a field by this name exists in `Self`
error: parenthesized type parameters may only be used with a `Fn` trait
--> $DIR/issue-34255-1.rs:7:30
--> $DIR/issue-34255-1.rs:7:27
|
LL | input_cells: Vec::new()
| ^^
| ^^^^^
|
= note: `#[deny(parenthesized_params_in_types_and_modules)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!

View File

@ -1,8 +1,8 @@
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
--> $DIR/unboxed-closure-sugar-used-on-struct-1.rs:8:19
--> $DIR/unboxed-closure-sugar-used-on-struct-1.rs:8:16
|
LL | let x: Box<Bar()> = panic!();
| ^^ only `Fn` traits may use parentheses
| ^^^^^ only `Fn` traits may use parentheses
error[E0107]: wrong number of type arguments: expected 1, found 0
--> $DIR/unboxed-closure-sugar-used-on-struct-1.rs:8:16

View File

@ -1,11 +1,11 @@
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
--> $DIR/unboxed-closure-sugar-used-on-struct-3.rs:14:18
--> $DIR/unboxed-closure-sugar-used-on-struct-3.rs:14:13
|
LL | let b = Bar::(isize, usize)::new(); // OK too (for the parser)
| ^^^^^^^^^^^^^^
| |
| only `Fn` traits may use parentheses
| help: use angle brackets instead: `<isize, usize>`
| ^^^^^^^^^^^^^^^^^^^
| |
| only `Fn` traits may use parentheses
| help: use angle brackets instead: `Bar::<isize, usize>`
error: aborting due to previous error

View File

@ -1,8 +1,8 @@
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
--> $DIR/unboxed-closure-sugar-used-on-struct.rs:7:18
--> $DIR/unboxed-closure-sugar-used-on-struct.rs:7:15
|
LL | fn foo(b: Box<Bar()>) {
| ^^ only `Fn` traits may use parentheses
| ^^^^^ only `Fn` traits may use parentheses
error[E0107]: wrong number of type arguments: expected 1, found 0
--> $DIR/unboxed-closure-sugar-used-on-struct.rs:7:15

View File

@ -1,8 +1,8 @@
error[E0220]: associated type `Output` not found for `One<()>`
--> $DIR/unboxed-closure-sugar-wrong-number-number-type-parameters-1.rs:5:19
--> $DIR/unboxed-closure-sugar-wrong-number-number-type-parameters-1.rs:5:16
|
LL | fn foo(_: &dyn One())
| ^^ associated type `Output` not found
| ^^^^^ associated type `Output` not found
error: aborting due to previous error

View File

@ -5,10 +5,10 @@ LL | fn foo(_: &dyn Three())
| ^^^^^^^ expected 3 type arguments
error[E0220]: associated type `Output` not found for `Three<(), [type error], [type error]>`
--> $DIR/unboxed-closure-sugar-wrong-number-number-type-parameters-3.rs:5:21
--> $DIR/unboxed-closure-sugar-wrong-number-number-type-parameters-3.rs:5:16
|
LL | fn foo(_: &dyn Three())
| ^^ associated type `Output` not found
| ^^^^^^^ associated type `Output` not found
error: aborting due to 2 previous errors

View File

@ -1,14 +1,14 @@
error[E0107]: wrong number of type arguments: expected 0, found 1
--> $DIR/unboxed-closure-sugar-wrong-number-number-type-parameters.rs:5:19
--> $DIR/unboxed-closure-sugar-wrong-number-number-type-parameters.rs:5:15
|
LL | fn foo(_: dyn Zero())
| ^^ unexpected type argument
| ^^^^^^ unexpected type argument
error[E0220]: associated type `Output` not found for `Zero`
--> $DIR/unboxed-closure-sugar-wrong-number-number-type-parameters.rs:5:19
--> $DIR/unboxed-closure-sugar-wrong-number-number-type-parameters.rs:5:15
|
LL | fn foo(_: dyn Zero())
| ^^ associated type `Output` not found
| ^^^^^^ associated type `Output` not found
error: aborting due to 2 previous errors

View File

@ -1,8 +1,8 @@
error[E0107]: wrong number of type arguments: expected 0, found 1
--> $DIR/unboxed-closure-sugar-wrong-trait.rs:5:13
--> $DIR/unboxed-closure-sugar-wrong-trait.rs:5:8
|
LL | fn f<F:Trait(isize) -> isize>(x: F) {}
| ^^^^^^^ unexpected type argument
| ^^^^^^^^^^^^ unexpected type argument
error[E0220]: associated type `Output` not found for `Trait`
--> $DIR/unboxed-closure-sugar-wrong-trait.rs:5:24