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

diagnostics: single colon within <> probably, not type ascription #94865

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 13 additions & 0 deletions compiler/rustc_parse/src/parser/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2073,6 +2073,19 @@ impl<'a> Parser<'a> {
let value = self.mk_expr_err(start.to(expr.span));
err.emit();
return Ok(GenericArg::Const(AnonConst { id: ast::DUMMY_NODE_ID, value }));
} else if token::Colon == snapshot.token.kind
&& expr.span.lo() == snapshot.token.span.hi()
&& matches!(expr.kind, ExprKind::Path(..))
{
// Find a mistake like "foo::var:A".
err.span_suggestion(
snapshot.token.span,
"you might have meant to write a path",
notriddle marked this conversation as resolved.
Show resolved Hide resolved
"::".to_string(),
Applicability::MaybeIncorrect,
);
err.emit();
return Ok(GenericArg::Type(self.mk_ty(start.to(expr.span), TyKind::Err)));
} else if token::Comma == self.token.kind || self.token.kind.should_end_const_arg()
{
// Avoid the following output by checking that we consumed a full const arg:
Expand Down
13 changes: 13 additions & 0 deletions src/test/ui/generics/single-colon-path-not-const-generics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
pub mod foo {
pub mod bar {
pub struct A;
}
}

pub struct Foo {
a: Vec<foo::bar:A>,
//~^ ERROR expected
//~| HELP you might have meant to write a path
}

fn main() {}
11 changes: 11 additions & 0 deletions src/test/ui/generics/single-colon-path-not-const-generics.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error: expected one of `,` or `>`, found `:`
--> $DIR/single-colon-path-not-const-generics.rs:8:18
|
LL | a: Vec<foo::bar:A>,
| ^
| |
| expected one of `,` or `>`
| help: you might have meant to write a path: `::`

error: aborting due to previous error