Commit Graph

1909 Commits

Author SHA1 Message Date
Ariel Ben-Yehuda d648c10e5b libsyntax/parse: improve associated item error reporting
Fixes #41161.
Fixes #41239.
2017-04-17 21:25:35 +03:00
Esteban Küber 4c80170782 Point at only one char on Span::next_point
Avoid pointing at two chars so the diagnostic output doesn't display a
multiline span when starting beyond a line end.
2017-04-10 14:03:17 -07:00
Esteban Küber 8c31412c2f Merge branch 'master' into ty-placeholder 2017-04-07 14:55:45 -07:00
Corey Farwell 89b364d687 Rollup merge of #41050 - jseyfried:fix_derive_parsing, r=petrochenkov
macros: fix bug parsing `#[derive]` invocations

Fixes #40962 (introduced in #40346).
r? @nrc
2017-04-05 23:51:43 -04:00
Ariel Ben-Yehuda cee0508021 Rollup merge of #40815 - estebank:issue-40006, r=GuillaumeGomez
Identify missing item category in `impl`s

```rust
struct S;
impl S {
    pub hello_method(&self) {
        println!("Hello");
    }
}
fn main() { S.hello_method(); }
```

```rust
error: missing `fn` for method declaration
 --> file.rs:3:4
  |
3 |     pub hello_method(&self) {
  |        ^ missing `fn`
```

Fix #40006. r? @pnkfelix CC @jonathandturner @GuillaumeGomez
2017-04-05 23:01:06 +00:00
Esteban Küber dedb7bbbbf Merge branch 'master' into issue-32540 2017-04-04 08:13:27 -07:00
Jeffrey Seyfried 6a9448b523 Fix bug parsing #[derive] macro invocations. 2017-04-03 23:02:49 +00:00
Esteban Küber 8f31e191c6 Merge branch 'master' into issue-40006 2017-04-03 05:07:49 -07:00
Esteban Küber b83352e44c Introduce TyErr independent from TyInfer
Add a `TyErr` type to represent unknown types in places where
parse errors have happened, while still able to build the AST.

Initially only used to represent incorrectly written fn arguments and
avoid "expected X parameters, found Y" errors when called with the
appropriate amount of parameters. We cannot use `TyInfer` for this as
`_` is not allowed as a valid argument type.

Example output:

```rust
error: expected one of `:` or `@`, found `,`
  --> file.rs:12:9
   |
12 | fn bar(x, y: usize) {}
   |         ^

error[E0061]: this function takes 2 parameters but 3 parameters were supplied
  --> file.rs:19:9
   |
12 | fn bar(x, y) {}
   | --------------- defined here
...
19 |     bar(1, 2, 3);
   |         ^^^^^^^ expected 2 parameters
```
2017-04-02 09:45:57 -07:00
Thomas Jespersen b376386228 Replace hardcoded forward slash with path::MAIN_SEPARATOR
Fixes #40149
2017-03-30 13:51:16 +02:00
Jeffrey Seyfried 8fde04b4a2 Improve Path spans. 2017-03-30 05:44:56 +00:00
Jeffrey Seyfried f08d5ad4c5 Refactor how spans are combined in the parser. 2017-03-29 11:17:59 +00:00
Jeffrey Seyfried ec7c0aece1 Merge ExpnId and SyntaxContext. 2017-03-29 00:41:10 +00:00
Esteban Küber b477682dca Fix unittests 2017-03-27 19:13:03 -07:00
Esteban Küber c963d613a2 Simplify error output 2017-03-27 17:15:16 -07:00
Oliver Schneider eb447f4ef4 Fix various useless derefs and slicings 2017-03-27 08:58:00 +02:00
Esteban Küber 78ae8feebb Improve wording and spans for unexpected token
* Point at where the token was expected instead of the last token
  successfuly parsed.
* Only show `unexpected token` if the next char and the unexpected token
  don't have the same span.
* Change some cfail and pfail tests to ui test.
* Don't show all possible tokens in span label if they are more than 6.
2017-03-25 15:36:59 -07:00
Esteban Küber 03eca71381 Point at last valid token on failed expect_one_of
```rust
error: expected one of `.`, `;`, `?`, `}`, or an operator, found `)`
  --> $DIR/token-error-correct-3.rs:29:9
   |
25 |         foo()
   |             - expected one of `.`, `;`, `?`, `}`, or an operator after this
...
29 |     } else {
   |     ^ unexpected token
```
2017-03-24 23:37:25 -07:00
Esteban Küber 57009caabd Identify missing item category in impls
```rust
struct S;
impl S {
    pub hello_method(&self) {
        println!("Hello");
    }
}
fn main() { S.hello_method(); }
```

```rust
error: can't qualify macro invocation with `pub`
 --> file.rs:3:4
  |
3 |     pub hello_method(&self) {
  |     ^^^-            - expected `!` here for a macro invocation
  |        |
  |        did you mean to write `fn` here for a method declaration?
  |
  = help: try adjusting the macro to put `pub` inside the invocation
```
2017-03-24 23:06:00 -07:00
Esteban Küber 769b95dc9f Add diagnostic for incorrect pub (restriction)
Given the following statement

```rust
pub (a) fn afn() {}
```

Provide the following diagnostic:

```rust
error: incorrect restriction in `pub`
  --> file.rs:15:1
   |
15 | pub (a) fn afn() {}
   | ^^^^^^^
   |
   = help: some valid visibility restrictions are:
           `pub(crate)`: visible only on the current crate
           `pub(super)`: visible only in the current module's parent
           `pub(in path::to::module)`: visible only on the specified path
help: to make this visible only to module `a`, add `in` before the path:
   | pub (in a) fn afn() {}
```

Remove cruft from old `pub(path)` syntax.
2017-03-22 22:51:45 -07:00
Vadim Petrochenkov b5e889791a Refactor parsing of trait object types 2017-03-21 23:01:53 +03:00
bors 9c15de4fd5 Auto merge of #40346 - jseyfried:path_and_tokenstream_attr, r=nrc
`TokenStream`-based attributes, paths in attribute and derive macro invocations

This PR
 - refactors `Attribute` to use  `Path` and `TokenStream` instead of `MetaItem`.
 - supports macro invocation paths for attribute procedural macros.
   - e.g. `#[::foo::attr_macro] struct S;`, `#[cfg_attr(all(), foo::attr_macro)] struct S;`
 - supports macro invocation paths for derive procedural macros.
   - e.g. `#[derive(foo::Bar, super::Baz)] struct S;`
 - supports arbitrary tokens as arguments to attribute procedural macros.
   - e.g. `#[foo::attr_macro arbitrary + tokens] struct S;`
 - supports using arbitrary tokens in "inert attributes" with derive procedural macros.
   - e.g. `#[derive(Foo)] struct S(#[inert arbitrary + tokens] i32);`
where `#[proc_macro_derive(Foo, attributes(inert))]`

r? @nrc
2017-03-19 10:56:08 +00:00
Esteban Küber e3b8550a60 Point out correct turbofish usage on Foo<Bar<Baz>>
Whenever we parse a chain of binary operations, as long as the first
operation is `<` and the subsequent operations are either `>` or `<`,
present the following diagnostic help:

    use `::<...>` instead of `<...>` if you meant to specify type arguments

This will lead to spurious recommendations on situations like
`2 < 3 < 4` but should be clear from context that the help doesn't apply
in that case.
2017-03-14 12:09:21 -07:00
bors 6f10e2f63d Auto merge of #39921 - cramertj:add-catch-to-ast, r=nikomatsakis
Add catch {} to AST

Part of #39849. Builds on #39864.
2017-03-14 10:40:09 +00:00
Jeffrey Seyfried 839c2860cc Liberalize attributes. 2017-03-14 04:39:21 +00:00
Jeffrey Seyfried 68c1cc68b4 Refactor Attribute to use Path and TokenStream instead of MetaItem. 2017-03-14 04:03:43 +00:00
Jeffrey Seyfried 460bf55f8a Cleanup. 2017-03-14 03:35:16 +00:00
Corey Farwell 8d1c5700f0 Rollup merge of #40369 - petrochenkov:segspan, r=eddyb
Give spans to individual path segments in AST

And use these spans in path resolution diagnostics.

The spans are spans of identifiers in segments, not whole segments. I'm not sure what spans are more useful in general, but identifier spans are a better fit for resolve errors.

HIR still doesn't have spans.

Fixes https://github.com/rust-lang/rust/pull/38927#discussion_r95336667 https://github.com/rust-lang/rust/pull/38890#issuecomment-271731008

r? @nrc @eddyb
2017-03-12 12:48:46 -04:00
bors f88b24b34c Auto merge of #40340 - petrochenkov:restricted, r=nikomatsakis
Update syntax for `pub(restricted)`

Update the syntax before stabilization.

cc https://github.com/rust-lang/rust/issues/32409
r? @nikomatsakis
2017-03-12 11:08:44 +00:00
Taylor Cramer ea4e8b0a81 Temporarily prefix catch block with do keyword 2017-03-11 22:26:57 -08:00
Taylor Cramer d95c543722 Add catch expr to AST and disallow catch as a struct name 2017-03-11 22:26:52 -08:00
Vadim Petrochenkov 32575a0487 Give spans to individual path segments in AST 2017-03-10 08:21:45 -08:00
Vadim Petrochenkov 880262a2bc Update syntax for pub(restricted) 2017-03-10 08:19:20 -08:00
Jeffrey Seyfried 8c98996934 Avoid using Mark and Invocation for macro defs. 2017-03-10 08:08:32 -08:00
Jeffrey Seyfried 212b6c2550 Refactor out ast::ItemKind::MacroDef. 2017-03-10 08:08:32 -08:00
Mark Simulacrum 69899b7f27 Inline function to avoid naming confusion. 2017-03-04 18:02:04 -07:00
Jeffrey Seyfried a02c18aa52 Fix token::Eof spans. 2017-03-03 02:15:39 +00:00
Jeffrey Seyfried f6eaaf350e Integrate TokenStream. 2017-03-03 02:15:37 +00:00
Jeffrey Seyfried 8cd0c0885f Introduce syntax::parse::parser::TokenCursor. 2017-03-03 02:05:57 +00:00
Jeffrey Seyfried 7f822c800d Refactor out parser.expect_delimited_token_tree(). 2017-02-28 22:15:11 +00:00
Jeffrey Seyfried d8b34e9a74 Add syntax::ext::tt::quoted::{TokenTree, ..} and remove tokenstream::TokenTree::Sequence. 2017-02-28 22:14:29 +00:00
Jeffrey Seyfried 2471888033 Avoid Token::{OpenDelim, CloseDelim}. 2017-02-28 22:13:39 +00:00
Guillaume Gomez b6818be41d Add long error explanations 2017-02-21 15:52:14 +01:00
Guillaume Gomez ea2a684099 Add error codes for errors in libsyntax 2017-02-20 17:47:44 +01:00
Jeffrey Seyfried b3d73995da Fix ICE on certain sequence repetitions. 2017-02-10 23:58:18 +00:00
Jeffrey Seyfried 66bd8eede5 Fix ICE when parsing token trees after an error. 2017-02-09 03:01:54 +00:00
Corey Farwell ece9240824 Rollup merge of #39453 - nrc:save-path, r=nikomatsakis
save-analysis: be more paranoid about generated paths

fixes https://github.com/rust-lang-nursery/rls/issues/160
2017-02-05 09:14:49 -05:00
Alex Crichton 626e754473 Bump version, upgrade bootstrap
This commit updates the version number to 1.17.0 as we're not on that version of
the nightly compiler, and at the same time this updates src/stage0.txt to
bootstrap from freshly minted beta compiler and beta Cargo.
2017-02-03 13:25:46 -08:00
Nick Cameron 395f23c9f7 save-analysis: be more paranoid about generated paths
fixes https://github.com/rust-lang-nursery/rls/issues/160
2017-02-02 16:23:27 +13:00
Oliver Schneider d73e84d2e7 use suggestions instead of helps with code in them 2017-01-31 14:45:08 +01:00