Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Point out correct turbofish usage on Foo<Bar<Baz>> #40500

Merged
merged 1 commit into from
Mar 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2919,7 +2919,10 @@ impl<'a> Parser<'a> {
let op_span = mk_sp(op.span.lo, self.span.hi);
let mut err = self.diagnostic().struct_span_err(op_span,
"chained comparison operators require parentheses");
if op.node == BinOpKind::Lt && *outer_op == AssocOp::Greater {
if op.node == BinOpKind::Lt &&
*outer_op == AssocOp::Less || // Include `<` to provide this recommendation
*outer_op == AssocOp::Greater // even in a case like the following:
{ // Foo<Bar<Baz<Qux, ()>>>
err.help(
"use `::<...>` instead of `<...>` if you meant to specify type arguments");
}
Expand Down
23 changes: 23 additions & 0 deletions src/test/ui/did_you_mean/issue-40396.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

fn foo() {
println!("{:?}", (0..13).collect<Vec<i32>>());
}

fn bar() {
println!("{:?}", Vec<i32>::new());
}

fn qux() {
println!("{:?}", (0..13).collect<Vec<i32>());
}

fn main() {}
34 changes: 34 additions & 0 deletions src/test/ui/did_you_mean/issue-40396.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
error: chained comparison operators require parentheses
--> $DIR/issue-40396.rs:12:37
|
12 | println!("{:?}", (0..13).collect<Vec<i32>>());
| ^^^^^^^^
|
= help: use `::<...>` instead of `<...>` if you meant to specify type arguments

error: chained comparison operators require parentheses
--> $DIR/issue-40396.rs:16:25
|
16 | println!("{:?}", Vec<i32>::new());
| ^^^^^^^
|
= help: use `::<...>` instead of `<...>` if you meant to specify type arguments

error: chained comparison operators require parentheses
--> $DIR/issue-40396.rs:20:37
|
20 | println!("{:?}", (0..13).collect<Vec<i32>());
| ^^^^^^^^
|
= help: use `::<...>` instead of `<...>` if you meant to specify type arguments

error: chained comparison operators require parentheses
--> $DIR/issue-40396.rs:20:41
|
20 | println!("{:?}", (0..13).collect<Vec<i32>());
| ^^^^^^
|
= help: use `::<...>` instead of `<...>` if you meant to specify type arguments

error: aborting due to 4 previous errors