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

Adjust turbofish help message for const generics #78460

Merged
merged 2 commits into from
Oct 29, 2020
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
2 changes: 0 additions & 2 deletions compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,8 +678,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {

pub fn unsolved_variables(&self) -> Vec<Ty<'tcx>> {
let mut inner = self.inner.borrow_mut();
// FIXME(const_generics): should there be an equivalent function for const variables?
Copy link
Member Author

@varkor varkor Oct 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also took the opportunity to remove this FIXME. This doesn't require any handling for const variables, because there's no notion of fallback for const generics.


let mut vars: Vec<Ty<'_>> = inner
.type_variables()
.unsolved_variables()
Expand Down
9 changes: 5 additions & 4 deletions compiler/rustc_parse/src/parser/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ use rustc_span::{MultiSpan, Span, SpanSnippetError, DUMMY_SP};

use tracing::{debug, trace};

const TURBOFISH: &str = "use `::<...>` instead of `<...>` to specify type arguments";
const TURBOFISH_SUGGESTION_STR: &str =
"use `::<...>` instead of `<...>` to specify type or const arguments";

/// Creates a placeholder argument.
pub(super) fn dummy_arg(ident: Ident) -> Param {
Expand Down Expand Up @@ -659,7 +660,7 @@ impl<'a> Parser<'a> {
Ok(_) => {
e.span_suggestion_verbose(
binop.span.shrink_to_lo(),
"use `::<...>` instead of `<...>` to specify type arguments",
TURBOFISH_SUGGESTION_STR,
"::".to_string(),
Applicability::MaybeIncorrect,
);
Expand Down Expand Up @@ -814,7 +815,7 @@ impl<'a> Parser<'a> {
let suggest = |err: &mut DiagnosticBuilder<'_>| {
err.span_suggestion_verbose(
op.span.shrink_to_lo(),
TURBOFISH,
TURBOFISH_SUGGESTION_STR,
"::".to_string(),
Applicability::MaybeIncorrect,
);
Expand Down Expand Up @@ -888,7 +889,7 @@ impl<'a> Parser<'a> {
{
// All we know is that this is `foo < bar >` and *nothing* else. Try to
// be helpful, but don't attempt to recover.
err.help(TURBOFISH);
err.help(TURBOFISH_SUGGESTION_STR);
err.help("or use `(...)` if you meant to specify fn arguments");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error: comparison operators cannot be chained
LL | foo<BAR + 3>();
| ^ ^
|
help: use `::<...>` instead of `<...>` to specify type arguments
help: use `::<...>` instead of `<...>` to specify type or const arguments
|
LL | foo::<BAR + 3>();
| ^^
Expand All @@ -15,7 +15,7 @@ error: comparison operators cannot be chained
LL | foo<BAR + BAR>();
| ^ ^
|
help: use `::<...>` instead of `<...>` to specify type arguments
help: use `::<...>` instead of `<...>` to specify type or const arguments
|
LL | foo::<BAR + BAR>();
| ^^
Expand All @@ -26,7 +26,7 @@ error: comparison operators cannot be chained
LL | foo<3 + 3>();
| ^ ^
|
help: use `::<...>` instead of `<...>` to specify type arguments
help: use `::<...>` instead of `<...>` to specify type or const arguments
|
LL | foo::<3 + 3>();
| ^^
Expand All @@ -37,7 +37,7 @@ error: comparison operators cannot be chained
LL | foo<BAR - 3>();
| ^ ^
|
help: use `::<...>` instead of `<...>` to specify type arguments
help: use `::<...>` instead of `<...>` to specify type or const arguments
|
LL | foo::<BAR - 3>();
| ^^
Expand All @@ -48,7 +48,7 @@ error: comparison operators cannot be chained
LL | foo<BAR - BAR>();
| ^ ^
|
help: use `::<...>` instead of `<...>` to specify type arguments
help: use `::<...>` instead of `<...>` to specify type or const arguments
|
LL | foo::<BAR - BAR>();
| ^^
Expand All @@ -59,7 +59,7 @@ error: comparison operators cannot be chained
LL | foo<100 - BAR>();
| ^ ^
|
help: use `::<...>` instead of `<...>` to specify type arguments
help: use `::<...>` instead of `<...>` to specify type or const arguments
|
LL | foo::<100 - BAR>();
| ^^
Expand All @@ -70,7 +70,7 @@ error: comparison operators cannot be chained
LL | foo<bar<i32>()>();
| ^ ^
|
help: use `::<...>` instead of `<...>` to specify type arguments
help: use `::<...>` instead of `<...>` to specify type or const arguments
|
LL | foo::<bar<i32>()>();
| ^^
Expand All @@ -87,7 +87,7 @@ error: comparison operators cannot be chained
LL | foo<bar::<i32>()>();
| ^ ^
|
help: use `::<...>` instead of `<...>` to specify type arguments
help: use `::<...>` instead of `<...>` to specify type or const arguments
|
LL | foo::<bar::<i32>()>();
| ^^
Expand All @@ -98,7 +98,7 @@ error: comparison operators cannot be chained
LL | foo<bar::<i32>() + BAR>();
| ^ ^
|
help: use `::<...>` instead of `<...>` to specify type arguments
help: use `::<...>` instead of `<...>` to specify type or const arguments
|
LL | foo::<bar::<i32>() + BAR>();
| ^^
Expand All @@ -109,7 +109,7 @@ error: comparison operators cannot be chained
LL | foo<bar::<i32>() - BAR>();
| ^ ^
|
help: use `::<...>` instead of `<...>` to specify type arguments
help: use `::<...>` instead of `<...>` to specify type or const arguments
|
LL | foo::<bar::<i32>() - BAR>();
| ^^
Expand All @@ -120,7 +120,7 @@ error: comparison operators cannot be chained
LL | foo<BAR - bar::<i32>()>();
| ^ ^
|
help: use `::<...>` instead of `<...>` to specify type arguments
help: use `::<...>` instead of `<...>` to specify type or const arguments
|
LL | foo::<BAR - bar::<i32>()>();
| ^^
Expand All @@ -131,7 +131,7 @@ error: comparison operators cannot be chained
LL | foo<BAR - bar::<i32>()>();
| ^ ^
|
help: use `::<...>` instead of `<...>` to specify type arguments
help: use `::<...>` instead of `<...>` to specify type or const arguments
|
LL | foo::<BAR - bar::<i32>()>();
| ^^
Expand Down
14 changes: 7 additions & 7 deletions src/test/ui/did_you_mean/issue-40396.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error: comparison operators cannot be chained
LL | (0..13).collect<Vec<i32>>();
| ^ ^
|
help: use `::<...>` instead of `<...>` to specify type arguments
help: use `::<...>` instead of `<...>` to specify type or const arguments
|
LL | (0..13).collect::<Vec<i32>>();
| ^^
Expand All @@ -15,7 +15,7 @@ error: comparison operators cannot be chained
LL | Vec<i32>::new();
| ^ ^
|
help: use `::<...>` instead of `<...>` to specify type arguments
help: use `::<...>` instead of `<...>` to specify type or const arguments
|
LL | Vec::<i32>::new();
| ^^
Expand All @@ -26,7 +26,7 @@ error: comparison operators cannot be chained
LL | (0..13).collect<Vec<i32>();
| ^ ^
|
help: use `::<...>` instead of `<...>` to specify type arguments
help: use `::<...>` instead of `<...>` to specify type or const arguments
|
LL | (0..13).collect::<Vec<i32>();
| ^^
Expand All @@ -37,7 +37,7 @@ error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, or an operator, found `,`
LL | let x = std::collections::HashMap<i128, i128>::new();
| ^ expected one of 7 possible tokens
|
help: use `::<...>` instead of `<...>` to specify type arguments
help: use `::<...>` instead of `<...>` to specify type or const arguments
|
LL | let x = std::collections::HashMap::<i128, i128>::new();
| ^^
Expand All @@ -48,7 +48,7 @@ error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found
LL | std::collections::HashMap<i128, i128>::new()
| ^ expected one of 8 possible tokens
|
help: use `::<...>` instead of `<...>` to specify type arguments
help: use `::<...>` instead of `<...>` to specify type or const arguments
|
LL | std::collections::HashMap::<i128, i128>::new()
| ^^
Expand All @@ -59,7 +59,7 @@ error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found
LL | std::collections::HashMap<i128, i128>::new();
| ^ expected one of 8 possible tokens
|
help: use `::<...>` instead of `<...>` to specify type arguments
help: use `::<...>` instead of `<...>` to specify type or const arguments
|
LL | std::collections::HashMap::<i128, i128>::new();
| ^^
Expand All @@ -70,7 +70,7 @@ error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found
LL | std::collections::HashMap<i128, i128>::new(1, 2);
| ^ expected one of 8 possible tokens
|
help: use `::<...>` instead of `<...>` to specify type arguments
help: use `::<...>` instead of `<...>` to specify type or const arguments
|
LL | std::collections::HashMap::<i128, i128>::new(1, 2);
| ^^
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/parser/require-parens-for-chained-comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ fn main() {

f<X>();
//~^ ERROR comparison operators cannot be chained
//~| HELP use `::<...>` instead of `<...>` to specify type arguments
//~| HELP use `::<...>` instead of `<...>` to specify type or const arguments

f<Result<Option<X>, Option<Option<X>>>(1, 2);
//~^ ERROR comparison operators cannot be chained
//~| HELP use `::<...>` instead of `<...>` to specify type arguments
//~| HELP use `::<...>` instead of `<...>` to specify type or const arguments

use std::convert::identity;
let _ = identity<u8>;
//~^ ERROR comparison operators cannot be chained
//~| HELP use `::<...>` instead of `<...>` to specify type arguments
//~| HELP use `::<...>` instead of `<...>` to specify type or const arguments
//~| HELP or use `(...)` if you meant to specify fn arguments
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ error: comparison operators cannot be chained
LL | f<X>();
| ^ ^
|
help: use `::<...>` instead of `<...>` to specify type arguments
help: use `::<...>` instead of `<...>` to specify type or const arguments
|
LL | f::<X>();
| ^^
Expand All @@ -37,7 +37,7 @@ error: comparison operators cannot be chained
LL | f<Result<Option<X>, Option<Option<X>>>(1, 2);
| ^ ^
|
help: use `::<...>` instead of `<...>` to specify type arguments
help: use `::<...>` instead of `<...>` to specify type or const arguments
|
LL | f::<Result<Option<X>, Option<Option<X>>>(1, 2);
| ^^
Expand All @@ -48,7 +48,7 @@ error: comparison operators cannot be chained
LL | let _ = identity<u8>;
| ^ ^
|
= help: use `::<...>` instead of `<...>` to specify type arguments
= help: use `::<...>` instead of `<...>` to specify type or const arguments
= help: or use `(...)` if you meant to specify fn arguments

error: aborting due to 5 previous errors
Expand Down