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.
The layout of a extern_type static is unsized, but may pass the
Well-Formed check in typeck. As a result, we cannot assume that
a static is sized when generating the `Place` for an r-value.
Don't try to clean predicates involving ReErased
There's nothing to render when we have a bound involving ReErased (either
a type or region outliving it), so we don't attempt to generate a clean
WherePredicate
Fixes#57806
I haven't been able to come up with a minimized reproduction for the issue, but I've confirmed that this allows the docs to build for `parqet-rs`
update split docs
Some confusion about split popped up at https://news.ycombinator.com/item?id=19080931 since the docs sorta sound like `&str`, `char` and closures are the only types that can be patterns.
cc @steveklabnik
Remove stray FIXME
These were copied from the WebAssembly implementation, and later commented. There is nothing to be fixed, RWLock is Send/Sync because all member fields are Send/Sync.
r? @joshtriplett
Remove weasel word in docs for iter's take_while()
The phrase "... or some similar thing." is very vague and contributes nothing to understanding the example. Simply removed.
hir: add more HirId methods
Adds a few more methods operating on `HirId` instead of `NodeId` with the intention of replacing the old ones in the near future.
r? @Zoxc
Include the span of attributes of the lhs to the span of the assignment expression
This PR adds the span of attributes of the lhs to the span of the assignment expression. Currently with the following code, `#[attr]` is not included to the span of the assignment (`foo = true`).
```rust
#[attr]
foo = true;
```
The rational behind this change is that as libsyntax user I expect the span of the parent node includes every span of child nodes.
cc https://github.com/rust-lang/rustfmt/issues/3313, https://github.com/rust-lang/rust/issues/15701.
Add NVPTX target to a build manifest
Include `nvptx64-nvidia-cuda` target to a build manifest. I forgot this step at my first take on adding the target (#57937).
Hopefully, this is the only reason why `rustup target add nvptx64-nvidia-cuda` doesn't work 🙁
r? @alexcrichton
proc_macro: make `TokenStream::from_streams` pre-allocate its vector.
This requires a pre-pass over the input streams. But that is cheap compared to the quadratic blowup associated with reallocating the accumulating vector on-the-fly.
Fix#57735
Add suggestion for duplicated import.
Fixes#52891.
This PR adds a suggestion when a import is duplicated (ie. the same name
is used twice trying to import the same thing) to remove the second
import.
Initial addition of the Embedded Rust Book
This PR adds the Embedded Rust Book to the bookshelf as a submodule, and adds text for the bookshelf page. I have added a new section after "Master Rust" called "Specialize Rust", with the plan that future domain WG books can also reside here. This now extends the titles down to H3, where formerly only H1 and H2 were used.
The added submodule tracks the master branch of the Embedded WG repo.
If there are additional steps necessary to make this work in CI (perhaps adding this to `src/ci/docker/x86_64-gnu-tools/checktools.sh:32` or so?), please let me know.
CC @steveklabnik @japaric
Also CC issue https://github.com/rust-embedded/wg/issues/257
Some confusion about split popped up at https://news.ycombinator.com/item?id=19080931 since the docs sorta sound like `&str`, `char` and closures are the only types that can be patterns.
cc @steveklabnik