Skip to content

Commit f103b29

Browse files
committed
Auto merge of #94865 - notriddle:notriddle/single-colon-path-not-const-generics, r=cjgillot
diagnostics: single colon within `<>` probably, not type ascription Fixes #94812
2 parents 22a20e3 + 26e299a commit f103b29

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

Diff for: compiler/rustc_parse/src/parser/diagnostics.rs

+13
Original file line numberDiff line numberDiff line change
@@ -2073,6 +2073,19 @@ impl<'a> Parser<'a> {
20732073
let value = self.mk_expr_err(start.to(expr.span));
20742074
err.emit();
20752075
return Ok(GenericArg::Const(AnonConst { id: ast::DUMMY_NODE_ID, value }));
2076+
} else if token::Colon == snapshot.token.kind
2077+
&& expr.span.lo() == snapshot.token.span.hi()
2078+
&& matches!(expr.kind, ExprKind::Path(..))
2079+
{
2080+
// Find a mistake like "foo::var:A".
2081+
err.span_suggestion(
2082+
snapshot.token.span,
2083+
"write a path separator here",
2084+
"::".to_string(),
2085+
Applicability::MaybeIncorrect,
2086+
);
2087+
err.emit();
2088+
return Ok(GenericArg::Type(self.mk_ty(start.to(expr.span), TyKind::Err)));
20762089
} else if token::Comma == self.token.kind || self.token.kind.should_end_const_arg()
20772090
{
20782091
// Avoid the following output by checking that we consumed a full const arg:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
pub mod foo {
2+
pub mod bar {
3+
pub struct A;
4+
}
5+
}
6+
7+
pub struct Foo {
8+
a: Vec<foo::bar:A>,
9+
//~^ ERROR expected
10+
//~| HELP path separator
11+
}
12+
13+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error: expected one of `,` or `>`, found `:`
2+
--> $DIR/single-colon-path-not-const-generics.rs:8:18
3+
|
4+
LL | a: Vec<foo::bar:A>,
5+
| ^
6+
| |
7+
| expected one of `,` or `>`
8+
| help: write a path separator here: `::`
9+
10+
error: aborting due to previous error
11+

0 commit comments

Comments
 (0)