Commit Graph

174 Commits

Author SHA1 Message Date
Samy Kacimi
41e71b0c93
normalize use of backticks in compiler messages for libsyntax/feature_gate
https://github.com/rust-lang/rust/issues/60532
2019-07-09 14:13:28 +02:00
Mazdak Farrokhzad
919349701a
Rollup merge of #62317 - JohnTitor:move-tests-to-build-pass, r=Centril
Migrate `compile-pass` annotations to `build-pass`

This is a part of #62277.

As a first step, the `compile-pass` tests are migrated to `build-pass`.

r? @cramertj
cc @Centril
2019-07-04 01:38:58 +02:00
Yuki Okushi
c004451a20 Migrate compile-pass annotations to build-pass 2019-07-03 06:30:28 +09:00
Vadim Petrochenkov
3f39dc1b90 syntax: Unsupport foo! bar { ... } macros in the parser
Unreserve `macro_rules` as a macro name
2019-07-01 12:20:54 +03:00
John Wrenn
ac98342e84 Implement arbitrary_enum_discriminant 2019-06-21 11:00:10 -04:00
bors
4edff843dd Auto merge of #61347 - Centril:stabilize-underscore_const_names, r=petrochenkov
Stabilize underscore_const_names in 1.37.0

You are now permitted to write:

```rust
const _: $type_expression = $term_expression;
```

That is, we change the [grammar of items](9d1984d7ae/grammar/item.lyg (L3-L42)), as written in [the *`.lyg`* notation](263bf161da (grammar)), from:

```java
Item = attrs:OuterAttr* vis:Vis? kind:ItemKind;
ItemKind =
  | ...
  | Const:{ "const" name:IDENT ":" ty:Type "=" value:Expr ";" }
  | ...
  ;
```

into:

```java
Item = attrs:OuterAttr* vis:Vis? kind:ItemKind;
ItemKind =
  | ...
  | Const:{ "const" name:IdentOrUnderscore ":" ty:Type "=" value:Expr ";" }
  | ...
  ;

IdentOrUnderscore =
  | Named:IDENT
  | NoName:"_"
  ;
```

r? @petrochenkov
2019-06-16 20:33:55 +00:00
bors
3f511ade5b Auto merge of #60669 - c410-f3r:attrs-fn, r=petrochenkov
Allow attributes in formal function parameters

Implements https://github.com/rust-lang/rust/issues/60406.

This is my first contribution to the compiler and since this is a large and complex project, I am not fully aware of the consequences of the changes I have made.

**TODO**

- [x] Forbid some built-in attributes.
- [x] Expand cfg/cfg_attr
2019-06-12 07:38:01 +00:00
bors
5e2c11034f Auto merge of #60793 - Xanewok:raw-string-cleanup, r=petrochenkov
lexer: Disallow bare CR in raw byte strings

Handles bare CR ~but doesn't translate `\r\n` to `\n` yet in raw strings yet~ and translates CRLF to LF in raw strings.

As a side-note I think it'd be good to change the `unescape_` to return plain iterators to reduce some boilerplate (e.g. `has_error` could benefit from collecting `Result<T>` and aborting early on errors) but will do that separately, unless I missed something here that prevents it.

@matklad @petrochenkov thoughts?
2019-06-10 23:32:12 +00:00
Igor Matuszewski
630d5f355f Don't suggest using \r in raw strings 2019-06-10 17:32:15 +02:00
Mazdak Farrokhzad
48e863ed69 Harden non-const items to not accept underscore names. 2019-06-10 06:17:39 +02:00
Caio
1eaaf440d5 Allow attributes in formal function parameters 2019-06-09 07:58:40 -03:00
Mazdak Farrokhzad
1e793c71b5 Update tests since ? macro op is supported on 2015. 2019-06-09 04:16:34 +02:00
Igor Matuszewski
49d62e8d5a Prohibit bare CRs in raw byte strings 2019-06-08 22:58:53 +02:00
Igor Matuszewski
cab7e7fe76 Validate and transcribe raw strings via unescape module 2019-06-08 22:58:53 +02:00
bors
c57ed9d947 Auto merge of #61331 - estebank:fn-arg-parse-recovery, r=varkor
Recover gracefully from argument with missing type or param name
2019-06-03 05:40:53 +00:00
Mazdak Farrokhzad
23de376572
Rollup merge of #61403 - estebank:test-cleanup, r=petrochenkov
Remove unnecessary `-Z continue-parse-after-error` from tests

r? @petrochenkov
2019-06-01 06:50:10 +02:00
Esteban Küber
d6ea6b972d fix tidy 2019-05-31 13:50:04 -07:00
Esteban Küber
860dce794c Remove unecessary -Z continue-parse-after-error from tests 2019-05-30 18:57:17 -07:00
Esteban Küber
b3ac88ad92 Recover gracefully from argument with missing type or param name 2019-05-30 17:59:05 -07:00
Janusz Marcinkiewicz
4c5eb8ecfc Explicitly suggest 'type_ascription' feature 2019-05-30 22:44:39 +02:00
memoryruins
a1d1d7a2c6 Update test/ui/parser for bare_trait_object warnings 2019-05-28 14:45:27 -04:00
Esteban Küber
4e68ddca90 review comments: move back some methods and clean up wording 2019-05-25 12:15:06 -07:00
Esteban Küber
976541884f Tweak self arg not as first argument of a method diagnostic
Mention that `self` is only valid on "associated functions"
```
error: unexpected `self` argument in function
  --> $DIR/self-in-function-arg.rs:1:15
   |
LL | fn foo(x:i32, self: i32) -> i32 { self }
   |               ^^^^ not valid as function argument
   |
   = note: `self` is only valid as the first argument of an associated function
```

When it is a method, mention it must be first
```
error: unexpected `self` argument in function
  --> $DIR/trait-fn.rs:4:20
   |
LL |     fn c(foo: u32, self) {}
   |                    ^^^^ must be the first associated function argument
```
2019-05-25 12:05:18 -07:00
Esteban Küber
5c5fa775e5 review comments 2019-05-24 11:50:21 -07:00
Esteban Küber
24160171e4 Tweak macro parse errors when reaching EOF during macro call parse
- Add detail on origin of current parser when reaching EOF and stop
  saying "found <eof>" and point at the end of macro calls
- Handle empty `cfg_attr` attribute
- Reword empty `derive` attribute error
2019-05-24 11:49:33 -07:00
bors
d96c01e77c Auto merge of #60803 - varkor:remove-in-place-syntax, r=petrochenkov
Remove `ObsoleteInPlace`

The in place syntax has been deprecated for over a year. As it is, this is accumulated cruft: the error messages are unlikely to be helpful any more and it conflicts with some useful syntax (e.g. const generics in some instances).

It may be that removing `Token::LArrow` is backwards-incompatible. We should do a crater run to check.

cc @eddyb
2019-05-24 09:54:17 +00:00
varkor
36f654262d Update tests 2019-05-24 01:27:32 +01:00
Mazdak Farrokhzad
26f3528434
Rollup merge of #61056 - euclio:custom-discriminant-error, r=estebank
tweak discriminant on non-nullary enum diagnostic

Adds notes pointing at the non-nullary variants, and uses "custom
discriminant" language to be consistent with the Reference.

Fixes #61039.

r? @estebank
2019-05-24 01:30:21 +02:00
Andy Russell
3cbf5864a6
tweak discriminant on non-nullary enum diagnostic
Adds notes pointing at the non-nullary variants, and uses "custom
discriminant" language to be consistent with the Reference.
2019-05-23 11:13:48 -04:00
Vadim Petrochenkov
90d15e7704 syntax: Some code cleanup 2019-05-23 12:46:41 +03:00
Vadim Petrochenkov
694f76d561 syntax: More consistent wording for some literal parsing errors 2019-05-23 12:44:05 +03:00
Vadim Petrochenkov
fcc2f92f45 syntax: Return named errors from literal parsing functions 2019-05-23 12:44:05 +03:00
Alexander Regueiro
ce75a23c0d Reinstated shallow disallowing of maybe bounds in trait objects. 2019-05-20 16:12:49 +01:00
Alexander Regueiro
fd7c253acc Update tests. 2019-05-20 16:12:49 +01:00
Vadim Petrochenkov
3f064cae3d Move literal parsing code into a separate file
Remove some dead code
2019-05-11 16:03:16 +03:00
Mazdak Farrokhzad
39edc68c69
Rollup merge of #60188 - estebank:recover-block, r=varkor
Identify when a stmt could have been parsed as an expr

There are some expressions that can be parsed as a statement without
a trailing semicolon depending on the context, which can lead to
confusing errors due to the same looking code being accepted in some
places and not others. Identify these cases and suggest enclosing in
parenthesis making the parse non-ambiguous without changing the
accepted grammar.

Fix #54186, cc #54482, fix #59975, fix #47287.
2019-05-09 23:56:09 +02:00
Esteban Küber
e0cef5cf40 fix typo 2019-05-02 15:53:09 -07:00
Aleksey Kladov
bfa5f27847 introduce unescape module
Currently, we deal with escape sequences twice: once when we lex a
string, and a second time when we unescape literals. This PR aims to
remove this duplication, by introducing a new `unescape` mode as a
single source of truth for character escaping rules
2019-05-02 15:31:57 +03:00
Esteban Küber
617ce2b7ee Reword ambigous parse error to fit with the current error 2019-04-30 20:37:42 -07:00
Esteban Küber
bff0be3784 Add test case for #47287 2019-04-29 14:35:09 -07:00
Esteban Küber
f007e6f442 Identify when a stmt could have been parsed as an expr
There are some expressions that can be parsed as a statement without
a trailing semicolon depending on the context, which can lead to
confusing errors due to the same looking code being accepted in some
places and not others. Identify these cases and suggest enclosing in
parenthesis making the parse non-ambiguous without changing the
accepted grammar.
2019-04-29 14:07:02 -07:00
Mazdak Farrokhzad
a4ef188ab6
Rollup merge of #60160 - xldenis:fix-overlapping-zero-width-annotation, r=estebank
Fix #58270, fix off-by-one error in error diagnostics.

This fixes #58270 by checking if two diagnostics overlap completely when we're calculating the line offset for each message.
2019-04-25 03:05:24 +02:00
varkor
5392f44a92 Remove unnecessary tidy ignore directives 2019-04-23 11:42:15 +01:00
Xavier Denis
4a073dda93 Fix #58270, fix off-by-one error in error diagnostics. 2019-04-22 18:14:45 -05:00
Vadim Petrochenkov
aa393b0cde Some cleanup to maybe_parse_struct_expr 2019-04-19 10:32:44 -07:00
Esteban Küber
2f36b54f0f Emit specific error for struct literal in conditions 2019-04-19 10:13:44 -07:00
Andy Russell
b6f148c8bd
hide --explain hint if error has no extended info 2019-04-18 13:29:28 -04:00
Esteban Küber
9b6b3d618c review comments 2019-04-11 14:45:23 -07:00
Esteban Küber
ac037c1359 Recover from missing semicolon based on the found token
When encountering one of a few keywords when a semicolon was
expected, suggest the semicolon and recover:

```
error: expected one of `.`, `;`, `?`, or an operator, found `let`
  --> $DIR/recover-missing-semi.rs:4:5
   |
LL |     let _: usize = ()
   |                      - help: missing semicolon here
LL |
LL |     let _ = 3;
   |     ^^^

error[E0308]: mismatched types
  --> $DIR/recover-missing-semi.rs:2:20
   |
LL |     let _: usize = ()
   |                    ^^ expected usize, found ()
   |
   = note: expected type `usize`
              found type `()`
```
2019-04-10 18:07:52 -07:00
Mazdak Farrokhzad
d2fd3fe957
Rollup merge of #59041 - saleemjaffer:trait_doc_comment_better_error_msg, r=pnkfelix
fixes rust-lang#56766

fixes #56766
2019-04-01 17:29:53 +02:00