| Age | Commit message (Collapse) | Author | Lines |
|
|
|
Deduplicate mismatched delimiter errors
Delay unmatched delimiter errors until after the parser has run to deduplicate them when parsing and attempt recovering intelligently.
Second attempt at #54029, follow up to #53949. Fix #31528.
|
|
|
|
|
|
|
|
|
|
|
|
Co-Authored-By: Gabriel Smith <yodaldevoid@users.noreply.github.com>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Delay unmatched delimiter errors until after the parser has run to
deduplicate them when parsing and attempt recovering intelligently.
|
|
|
|
Overhaul `syntax::fold::Folder`.
This PR changes `syntax::fold::Folder` from a functional style
(where most methods take a `T` and produce a new `T`) to a more
imperative style (where most methods take and modify a `&mut T`), and
renames it `syntax::mut_visit::MutVisitor`.
This makes the code faster and more concise.
|
|
This commit changes `syntax::fold::Folder` from a functional style
(where most methods take a `T` and produce a new `T`) to a more
imperative style (where most methods take and modify a `&mut T`), and
renames it `syntax::mut_visit::MutVisitor`.
The first benefit is speed. The functional style does not require any
reallocations, due to the use of `P::map` and
`MoveMap::move_{,flat_}map`. However, every field in the AST must be
overwritten; even those fields that are unchanged are overwritten with
the same value. This causes a lot of unnecessary memory writes. The
imperative style reduces instruction counts by 1--3% across a wide range
of workloads, particularly incremental workloads.
The second benefit is conciseness; the imperative style is usually more
concise. E.g. compare the old functional style:
```
fn fold_abc(&mut self, abc: ABC) {
ABC {
a: fold_a(abc.a),
b: fold_b(abc.b),
c: abc.c,
}
}
```
with the imperative style:
```
fn visit_abc(&mut self, ABC { a, b, c: _ }: &mut ABC) {
visit_a(a);
visit_b(b);
}
```
(The reductions get larger in more complex examples.)
Overall, the patch removes over 200 lines of code -- even though the new
code has more comments -- and a lot of the remaining lines have fewer
characters.
Some notes:
- The old style used methods called `fold_*`. The new style mostly uses
methods called `visit_*`, but there are a few methods that map a `T`
to something other than a `T`, which are called `flat_map_*` (`T` maps
to multiple `T`s) or `filter_map_*` (`T` maps to 0 or 1 `T`s).
- `move_map.rs`/`MoveMap`/`move_map`/`move_flat_map` are renamed
`map_in_place.rs`/`MapInPlace`/`map_in_place`/`flat_map_in_place` to
reflect their slightly changed signatures.
- Although this commit renames the `fold` module as `mut_visit`, it
keeps it in the `fold.rs` file, so as not to confuse git. The next
commit will rename the file.
|
|
|
|
|
|
|
|
Suggest removing leading left angle brackets.
Fixes #57819.
This PR adds errors and accompanying suggestions as below:
```
bar::<<<<<T as Foo>::Output>();
^^^ help: remove extra angle brackets
```
r? @estebank
|
|
Add suggestion for moving type declaration before associated type bindings in generic arguments.
Fixes #57385.
r? @estebank
|
|
This commit combines the move lifetime and move type suggestions so that
when rustfix applies them they don't conflict with each other.
|
|
This commit extends existing suggestions to move lifetimes before types
in generic arguments to also suggest moving types behind associated type
bindings.
|
|
Rollup of 9 pull requests
Successful merges:
- #57380 (Fix Instant/Duration math precision & associativity on Windows)
- #57606 (Get rid of the fake stack frame for reading from constants)
- #57803 (Several changes to libunwind for SGX target)
- #57846 (rustdoc: fix ICE from loading proc-macro stubs)
- #57860 (Add os::fortanix_sgx::ffi module)
- #57861 (Don't export table by default in wasm)
- #57863 (Add suggestion for incorrect field syntax.)
- #57867 (Fix std::future::from_generator documentation)
- #57873 (Stabilize no_panic_pow)
Failed merges:
r? @ghost
|
|
Add suggestion for incorrect field syntax.
Fixes #57684.
This commit adds a suggestion when a `=` character is used when
specifying the value of a field in a struct constructor incorrectly
instead of a `:` character.
r? @estebank
|
|
Remove quote_*! macros
This deletes a considerable amount of test cases, some of which we may want to keep. I'm not entirely certain what the primary intent of many of them was; if we should keep them I can attempt to edit each case to continue compiling without the quote_*! macros involved.
Fixes #46849.
Fixes #12265.
Fixes #12266.
Fixes #26994.
r? @Manishearth
|
|
|
|
Add error for trailing angle brackets.
Fixes #54521.
This PR adds a error (and accompanying machine applicable
suggestion) for trailing angle brackets on function calls with a
turbofish.
r? @estebank
|
|
Use structured suggestion in stead of notes
|
|
Recover from parse errors in literal struct fields and incorrect float literals
Fix #52496.
|
|
This commit adds a suggestion when a `=` character is used when
specifying the value of a field in a struct constructor incorrectly
instead of a `:` character.
|
|
This commit implements a suggestion from @estebank that optimizes the
use of snapshots.
Instead of creating a snapshot for each recursion in `parse_path_segment`
and then replacing `self` with them until the first invocation where if
leading angle brackets are detected, `self` is not replaced and instead the
snapshot is used to inform how parsing should continue.
Now, a snapshot is created in the first invocation that acts as a backup
of the parser state before any generic arguments are parsed (and
therefore, before recursion starts). This backup replaces `self` if after
all parsing of generic arguments has concluded we can determine that
there are leading angle brackets. Parsing can then proceed from the
backup state making use of the now known number of unmatched leading
angle brackets to recover.
|
|
This commit adds errors and accompanying suggestions as below:
```
bar::<<<<<T as Foo>::Output>();
^^^ help: remove extra angle brackets
```
|
|
resolves #57773
|
|
|
|
This commit extends the trailing `>` detection to also work for paths
such as `Foo::<Bar>>:Baz`.
This involves making the existing check take the token that is expected
to follow the path being checked as a parameter.
Care is taken to ensure that this only happens on the construction of a
whole path segment and not a partial path segment (during recursion).
Through this enhancement, it was also observed that the ordering of
right shift token and greater than tokens was overfitted to the examples
being tested.
In practice, given a sequence of `>` characters: `>>>>>>>>>`
..then they will be split into `>>` eagerly: `>> >> >> >> >`.
..but when a `<` is prepended, then the first `>>` is split:
`<T> > >> >> >> >`
..and then when another `<` is prepended, a right shift is first again:
`Vec<<T>> >> >> >> >`
In the previous commits, a example that had two `<<` characters was
always used and therefore it was incorrectly assumed that `>>` would
always be first - but when there is a single `<`, this is not the case.
|
|
This commit pluralizes error messages when more than a single trailing
`>` character is present.
|
|
This commit adds a error (and accompanying machine applicable
suggestion) for trailing angle brackets on function calls with a
turbofish.
|
|
|
|
Add span for bad doc comment
Fixes #57382
r? @estebank
|
|
Continue parsing after parent type args and suggest using angle brackets
```
error[E0214]: parenthesized parameters may only be used with a trait
--> $DIR/E0214.rs:2:15
|
LL | let v: Vec(&str) = vec!["foo"];
| ^^^^^^
| |
| only traits may use parentheses
| help: use angle brackets instead: `<&str>`
```
r? @zackmdavis
|
|
|
|
|
|
|
|
|
|
rustdoc: overhaul code block lexing errors
Fixes #53919.
This PR moves the reporting of code block lexing errors from rendering time to an early pass, so we can use the compiler's error reporting mechanisms. This dramatically improves the diagnostics in this situation: we now de-emphasize the lexing errors as a note under a warning that has a span and suggestion instead of just emitting errors at the top level.
Additionally, this PR generalizes the markdown -> source span calculation function, which should allow other rustdoc warnings to use better spans in the future.
Last, the PR makes sure that the code block is always emitted in the docs, even if it fails to highlight correctly.
Of note:
- The new pass unfortunately adds another pass over the docs to gather the doc blocks for syntax-checking. I wonder if this could be combined with the pass that looks for testable blocks? I'm not familiar with that code, so I don't know how feasible that is.
- `pulldown_cmark` doesn't make it easy to find the spans of the code blocks, so the code that calculates the spans is a little nasty. It works for all the test cases I threw at it, but I wouldn't be surprised if an edge case would break it. Should have a thorough review.
- This PR worsens the state of #56885, since those certain fatal lexing errors are now emitted before docs get generated at all.
|
|
|
|
Attempt to recover from parse errors while parsing a struct's literal fields
by skipping tokens until a comma or the closing brace is found. This allows
errors in other fields to be reported.
|