Commit Graph

569 Commits

Author SHA1 Message Date
Dylan DPC 84b9145076 Rollup merge of #73182 - Aaron1011:feature/call-fn-span, r=matthewjasper
Track span of function in method calls, and use this in #[track_caller]

Fixes #69977

When we parse a chain of method calls like `foo.a().b().c()`, each
`MethodCallExpr` gets assigned a span that starts at the beginning of
the call chain (`foo`). While this is useful for diagnostics, it means
that `Location::caller` will return the same location for every call
in a call chain.

This PR makes us separately record the span of the function name and
arguments for a method call (e.g. `b()` in `foo.a().b().c()`). This
`Span` is passed through HIR lowering and MIR building to
`TerminatorKind::Call`, where it is used in preference to
`Terminator.source_info.span` when determining `Location::caller`.

This new span is also useful for diagnostics where we want to emphasize
a particular method call - for an example, see
https://github.com/rust-lang/rust/pull/72389#discussion_r436035990
2020-06-11 19:04:16 +02:00
Dylan DPC 2ac1598d83 Rollup merge of #73172 - matthiaskrgr:cl9ppy, r=Dylan-DPC
Fix more clippy warnings

Fixes more of:

clippy::unused_unit
clippy::op_ref
clippy::useless_format
clippy::needless_return
clippy::useless_conversion
clippy::bind_instead_of_map
clippy::into_iter_on_ref
clippy::redundant_clone
clippy::nonminimal_bool
clippy::redundant_closure
clippy::option_as_ref_deref
clippy::len_zero
clippy::iter_cloned_collect
clippy::filter_next

r? @Dylan-DPC
2020-06-11 13:16:04 +02:00
Dylan DPC 70c14c2d43 Rollup merge of #73164 - GuillaumeGomez:add-e0761, r=petrochenkov
Add new E0762 error code
2020-06-11 13:16:02 +02:00
Aaron Hill 28946b3486 Track span of function in method calls, and use this in #[track_caller]
Fixes #69977

When we parse a chain of method calls like `foo.a().b().c()`, each
`MethodCallExpr` gets assigned a span that starts at the beginning of
the call chain (`foo`). While this is useful for diagnostics, it means
that `Location::caller` will return the same location for every call
in a call chain.

This PR makes us separately record the span of the function name and
arguments for a method call (e.g. `b()` in `foo.a().b().c()`). This
`Span` is passed through HIR lowering and MIR building to
`TerminatorKind::Call`, where it is used in preference to
`Terminator.source_info.span` when determining `Location::caller`.

This new span is also useful for diagnostics where we want to emphasize
a particular method call - for an example, see
https://github.com/rust-lang/rust/pull/72389#discussion_r436035990
2020-06-10 17:30:11 -04:00
Guillaume Gomez 50a42fe513 Create new error code E0762 for unterminated char literals 2020-06-10 11:54:09 +02:00
Dylan DPC e04e3c89cc Rollup merge of #73157 - Aaron1011:where-oh-where-has-my-little-span-gone, r=ecstatic-morse
Don't lose empty `where` clause when pretty-printing

Previously, we would parse `struct Foo where;` and `struct Foo;`
identically, leading to an 'empty' `where` clause being omitted during
pretty printing. This will cause us to lose spans when proc-macros
involved, since we will have a collected `where` token that does not
appear in the pretty-printed item.

We now explicitly track the presence of a `where` token during parsing,
so that we can distinguish between `struct Foo where;` and `struct Foo;`
during pretty-printing
2020-06-10 11:03:49 +02:00
Matthias Krüger 58023fedfc Fix more clippy warnings
Fixes more of:

clippy::unused_unit
clippy::op_ref
clippy::useless_format
clippy::needless_return
clippy::useless_conversion
clippy::bind_instead_of_map
clippy::into_iter_on_ref
clippy::redundant_clone
clippy::nonminimal_bool
clippy::redundant_closure
clippy::option_as_ref_deref
clippy::len_zero
clippy::iter_cloned_collect
clippy::filter_next
2020-06-09 18:51:08 +02:00
Aaron Hill 0fcea2e423 Don't lose empty where clause when pretty-printing
Previously, we would parse `struct Foo where;` and `struct Foo;`
identically, leading to an 'empty' `where` clause being omitted during
pretty printing. This will cause us to lose spans when proc-macros
involved, since we will have a collected `where` token that does not
appear in the pretty-printed item.

We now explicitly track the presence of a `where` token during parsing,
so that we can distinguish between `struct Foo where;` and `struct Foo;`
during pretty-printing
2020-06-08 21:09:54 -04:00
Guillaume Gomez e8fb46090e Create new error code E0758 for unterminated multi-line comments 2020-06-07 14:57:53 +02:00
Julian Wollersberger 7be8077b3f Cleanup: Inline struct_span_fatal(), which is only called once, and remove an outdated FIXME. 2020-06-01 22:01:30 +02:00
Julian Wollersberger 5fbbfbbfa9 Simplify raw string error reporting.
This makes `UnvalidatedRawStr` and `ValidatedRawStr` unnecessary and removes 70 lines.
2020-06-01 22:01:19 +02:00
Ralf Jung e4c35246fc Rollup merge of #72585 - Aaron1011:feature/opt-item-tokens, r=petrochenkov
Only capture tokens for items with outer attributes

Suggested by @petrochenkov in https://github.com/rust-lang/rust/issues/43081#issuecomment-633389225
2020-05-30 13:45:13 +02:00
Yuki Okushi 047b3bd4df Rollup merge of #72724 - Aaron1011:revert-tokenstream-expand, r=petrochenkov
Revert recursive `TokenKind::Interpolated` expansion for now

The crater run https://github.com/rust-lang/rust/issues/72622 revealed many root regressions, at least one of which is going to take some time to fix.

For now, let's revert https://github.com/rust-lang/rust/pull/72388 to allow the 709 affected crates to continue building on the latest nightly.
2020-05-30 12:39:19 +09:00
Aaron Hill b802eebc67 Fix missing import lost in revert 2020-05-29 01:11:00 -04:00
Aaron Hill 1c2b65b1e1 Revert "Move functions to librustc_parse"
This reverts commit 7a4c1865fb.
2020-05-29 00:19:11 -04:00
Aaron Hill 1ae7de9a52 Revert "Recursively expand nonterminals"
This reverts commit 2af0218bf1.
2020-05-29 00:19:10 -04:00
Aaron Hill ed503acb46 Revert "Fix rebase fallout"
This reverts commit 5685e4dd90.
2020-05-29 00:19:06 -04:00
Chris Simpkins 593d1eed82 improve diagnostics suggestion for missing @ in slice id binding to rest pattern
add issue 72373 tests


fmt test


fix suggestion format

Replacement, not insertion of suggested string

implement review changes

refactor to span_suggestion_verbose, improve suggestion message,  change id @ pattern space formatting

fmt


fix diagnostics spacing between ident and @


refactor reference
2020-05-27 14:10:41 -04:00
Dylan DPC cbe7b908b1 Rollup merge of #72348 - chrissimpkins:fix-72253, r=estebank
Fix confusing error message for comma typo in multiline statement

Fixes #72253.  Expands on the issue with a colon typo check.

r? @estebank

cc @ehuss
2020-05-27 03:09:11 +02:00
Chris Simpkins f384cdcbec improve error message for unexpected comma token in multiline block
confusing diagnostics, issue #72253

add test for confusing error message, issue-72253


remove is_multiline check, refactor to self.expect(&token:Semi)


update issue-72253 tests


return Ok
2020-05-26 16:52:16 -04:00
Aaron Hill 4e2696f54a Only capture tokens for items with outer attributes
Suggested by @petrochenkov in https://github.com/rust-lang/rust/issues/43081#issuecomment-633389225
2020-05-25 23:44:40 -04:00
Aaron Hill 14382c6437 Collect tokens for ast::Expr 2020-05-24 15:54:48 -04:00
bors 94fccccd2c Auto merge of #72529 - RalfJung:rollup-ydthv90, r=RalfJung
Rollup of 3 pull requests

Successful merges:

 - #72284 (Remove `macro_defs` map)
 - #72393 (Rewrite `Parser::collect_tokens`)
 - #72528 (Fix typo in doc comment.)

Failed merges:

r? @ghost
2020-05-24 11:02:23 +00:00
Aaron Hill 5685e4dd90 Fix rebase fallout 2020-05-22 15:12:11 -04:00
Aaron Hill 2af0218bf1 Recursively expand nonterminals 2020-05-22 15:07:36 -04:00
Aaron Hill 7a4c1865fb Move functions to librustc_parse 2020-05-22 15:01:08 -04:00
Aaron Hill 52bb09abba Rewrite Parser::collect_tokens
The previous implementation did not work when called on an opening
delimiter, or when called re-entrantly from the same `TokenCursor` stack
depth.
2020-05-22 03:26:45 -04:00
Ralf Jung 12112f4d7d Rollup merge of #72254 - ehuss:double-backtick, r=dtolnay
Remove redundant backtick in error message.

The value passed in already has backticks surrounding the text.
2020-05-16 19:46:37 +02:00
Ralf Jung ec5610ff8c Rollup merge of #72047 - Julian-Wollersberger:literal_error_reporting_cleanup, r=petrochenkov
Literal error reporting cleanup

While doing some performance work, I noticed some code duplication in `librustc_parser/lexer/mod.rs`, so I cleaned it up.

This PR is probably best reviewed commit by commit.

I'm not sure what the API stability practices for `librustc_lexer` are. Four public methods in `unescape.rs` can be removed, but two are used by clippy, so I left them in for now.
I could open a PR for Rust-Analyzer when this one lands.

But how do I open a PR for clippy? (Git submodules are frustrating to work with)
2020-05-16 19:46:31 +02:00
Eric Huss 004f4f389e Remove redundant backtick in error message.
The value passed in already has backticks surrounding the text.
2020-05-15 20:51:12 -07:00
sergey-melnychuk 0dc74dc0c6 cleanup stale FIXME(#64197) 2020-05-14 20:02:40 +02:00
Julian Wollersberger 18cc63d693 Unified validate_{byte,str,raw_str,raw_byte_str}_escape methods into one method validate_literal_escape with a mode argument.
This enables simplifying the `match` in `cook_lexer_literal()`
and it eliminates 90 lines of repetition :)
2020-05-13 09:52:01 +02:00
Camille GILLOT d4e143ed2f Remove ast::{Ident, Name} reexports. 2020-05-08 13:13:15 +02:00
Esteban Küber 3cf556939e Detect errors caused by async block in 2015 edition 2020-05-05 19:35:20 -07:00
Charles Lew c05961c2db Implement confusable_idents lint. 2020-05-03 02:30:50 +08:00
Dylan DPC be3faf3f30 Rollup merge of #71433 - antoyo:error/missing-right-operand, r=Dylan-DPC
Add help message for missing right operand in condition

closes #30035
2020-04-30 20:15:22 +02:00
Josh Stone 2325c20925 Avoid unused Option::map results
These are changes that would be needed if we add `#[must_use]` to
`Option::map`, per #71484.
2020-04-24 13:58:41 -07:00
Dylan DPC 1d3d80f773 Rollup merge of #70633 - kper:master, r=estebank
Confusing suggestion on incorrect closing `}`

Compiler returns
```
error: unexpected closing delimiter: `}`
  --> main.rs:20:1
   |
9  |             ErrorHandled::Reported => {}
   |                                       -- this block is empty, you might have not meant to close it temp
...
20 | }
   | ^ unexpected closing delimiter

error: aborting due to previous error
```
2020-04-23 20:34:57 +02:00
Dylan DPC 10e47f5b7b Rollup merge of #71256 - cuviper:must_use_replace, r=estebank
Lint must_use on mem::replace

This adds a hint on `mem::replace`, "if you don't need the old value,
you can just assign the new value directly". This is in similar spirit
to the `must_use` on `ManuallyDrop::take`.
2020-04-22 23:19:19 +02:00
Antoni Boucher f8f0f7b228 Add help message for missing right operand in condition 2020-04-22 11:57:40 -04:00
Guillaume Gomez 3390ff97b2 Add error code to inner doc comment attribute error 2020-04-22 11:08:50 +02:00
Shotaro Yamada 33905adc5f Remove unused dependencies 2020-04-20 17:59:27 +09:00
Josh Stone 7b005c5fcb Dogfood more or_patterns in the compiler 2020-04-19 07:33:58 -07:00
Tshepang Lekhonkhobe fcbefae017 remove build warnings
Code blocks that are not annotated are assumed to be Rust
2020-04-18 22:32:23 +02:00
Josh Stone ccecae5fdd Fix unused results from mem::replace 2020-04-17 13:59:14 -07:00
Duddino 79abac863e Improved try_macro_suggestion function 2020-04-17 20:14:27 +02:00
Duddino 67128f1e4a Improved try_macro_suggestion 2020-04-17 19:10:29 +02:00
Duddino d3f5c274c6 Moved is_try check into try_macro_suggestion 2020-04-17 18:26:39 +02:00
Duddino ba61fe432a Account for use of try!() in 2018 edition and guide users in the right direction 2020-04-17 14:08:08 +02:00
Bastian Kauschke 81a3cd7278 allow try as scrutinee, e.g. match try ... 2020-04-14 18:39:20 +02:00