Commit Graph

2702 Commits

Author SHA1 Message Date
Daniel Keep a2489495d9 Implementation of the vis macro matcher. 2017-04-15 19:06:19 +00:00
Tim Neumann 918e35a9bd Rollup merge of #41087 - estebank:tuple-float-index, r=arielb1
Use proper span for tuple index parsed as float

Fix diagnostic suggestion from:

```rust
help: try parenthesizing the first index
  |     (1, (2, 3)).((1, (2, 3)).1).1;
```

to the correct:

```rust
help: try parenthesizing the first index
  |     ((1, (2, 3)).1).1;
```

Fix #41081.
2017-04-12 14:45:41 +02: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 44e414c477 Use proper span for tuple index parsed as float
Fix diagnostic suggestion from:

```rust
help: try parenthesizing the first index
  |     (1, (2, 3)).((1, (2, 3)).1).1;
```

to the correct:

```rust
help: try parenthesizing the first index
  |     ((1, (2, 3)).1).1;
```
2017-04-05 09:55:56 -07: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
bors 474f7a91ee Auto merge of #40620 - laumann:slash-in-diagnostics-path, r=BurntSushi
Replace hardcoded forward slash with path::MAIN_SEPARATOR

Fixes #40149
2017-03-31 03:22:39 +00:00
Niko Matsakis 56847af916 port the match code to use CoerceMany
`match { }` now (correctly?) indicates divergence, which results in more
unreachable warnings. We also avoid fallback to `!` if there is just one
arm (see new test: `match-unresolved-one-arm.rs`).
2017-03-30 07:55:29 -04: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
Corey Farwell f2290dab9a Rollup merge of #40589 - topecongiro:floating-point-literal, r=nagisa
Parse 0e+10 as a valid floating-point literal

Fixes issue #40408.
2017-03-19 10:18:18 -04: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
topecongiro 8eaac0843e Parse 0e+10 as a valid floating-point literal
Fixes issue #40408.
2017-03-18 21:16:16 +09: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 0d554139ad Fix fallout in unit tests. 2017-03-03 02:15:39 +00: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 0143774cb5 Remove lifetime parameter from syntax::tokenstream::Cursor. 2017-03-03 01:52:48 +00:00
Jeffrey Seyfried 61a9a14d29 Add warning cycle. 2017-02-28 22:15:12 +00:00
Jeffrey Seyfried 7f822c800d Refactor out parser.expect_delimited_token_tree(). 2017-02-28 22:15:11 +00:00
Jeffrey Seyfried 0cc7053efa Remove Token::MatchNt. 2017-02-28 22:15:09 +00:00