File tree Expand file tree Collapse file tree 3 files changed +55
-1
lines changed
compiler/rustc_parse/src/parser
src/test/ui/const-generics/issues Expand file tree Collapse file tree 3 files changed +55
-1
lines changed Original file line number Diff line number Diff line change @@ -1950,7 +1950,19 @@ impl<'a> Parser<'a> {
19501950 }
19511951 match self . parse_expr_res ( Restrictions :: CONST_EXPR , None ) {
19521952 Ok ( expr) => {
1953- if token:: Comma == self . token . kind || self . token . kind . should_end_const_arg ( ) {
1953+ // Find a mistake like `MyTrait<Assoc == S::Assoc>`.
1954+ if token:: EqEq == snapshot. token . kind {
1955+ err. span_suggestion (
1956+ snapshot. token . span ,
1957+ "if you meant to use an associated type binding, replace `==` with `=`" ,
1958+ "=" . to_string ( ) ,
1959+ Applicability :: MaybeIncorrect ,
1960+ ) ;
1961+ let value = self . mk_expr_err ( start. to ( expr. span ) ) ;
1962+ err. emit ( ) ;
1963+ return Ok ( GenericArg :: Const ( AnonConst { id : ast:: DUMMY_NODE_ID , value } ) ) ;
1964+ } else if token:: Comma == self . token . kind || self . token . kind . should_end_const_arg ( )
1965+ {
19541966 // Avoid the following output by checking that we consumed a full const arg:
19551967 // help: expressions must be enclosed in braces to be used as const generic
19561968 // arguments
Original file line number Diff line number Diff line change 1+ pub trait MyTrait {
2+ type Assoc ;
3+ }
4+
5+ pub fn foo < S , T > ( _s : S , _t : T )
6+ where
7+ S : MyTrait ,
8+ T : MyTrait < Assoc == S :: Assoc > ,
9+ //~^ ERROR: expected one of `,` or `>`, found `==`
10+ //~| ERROR: this trait takes 0 generic arguments but 1 generic argument was supplied
11+ {
12+ }
13+
14+ fn main ( ) { }
Original file line number Diff line number Diff line change 1+ error: expected one of `,` or `>`, found `==`
2+ --> $DIR/issue-87493.rs:8:22
3+ |
4+ LL | T: MyTrait<Assoc == S::Assoc>,
5+ | ^^ expected one of `,` or `>`
6+ |
7+ help: if you meant to use an associated type binding, replace `==` with `=`
8+ |
9+ LL | T: MyTrait<Assoc = S::Assoc>,
10+ | ~
11+
12+ error[E0107]: this trait takes 0 generic arguments but 1 generic argument was supplied
13+ --> $DIR/issue-87493.rs:8:8
14+ |
15+ LL | T: MyTrait<Assoc == S::Assoc>,
16+ | ^^^^^^^------------------- help: remove these generics
17+ | |
18+ | expected 0 generic arguments
19+ |
20+ note: trait defined here, with 0 generic parameters
21+ --> $DIR/issue-87493.rs:1:11
22+ |
23+ LL | pub trait MyTrait {
24+ | ^^^^^^^
25+
26+ error: aborting due to 2 previous errors
27+
28+ For more information about this error, try `rustc --explain E0107`.
You can’t perform that action at this time.
0 commit comments