optimize redundant borrows and escaping paths in NLL
This builds on https://github.com/rust-lang/rust/pull/53168 and adds a commit that addresses https://github.com/rust-lang/rust/issues/53176 -- or at least I think it does. I marked this as WIP because I want to see the test results (and measure the performance). I also want to double check we're not adding in any unsoundness here.
As explained by eddyb in #53221, "An &ArchiveChild doesn't point into the archive itself, it points to an owned object that itself points to the archive, and LLVMRustArchiveMemberNew copies the ArchiveChild (whereas the current signature suggests it keeps the &ArchiveChild)."
Cleanup to librustc::session and related code
No functional changes, just some cleanup.
This also creates the `rustc_fs_util` crate, but I can remove that change if desired. It felt a little odd to force crates to depend on librustc for some fs utilities; and also seemed good to generally keep the size of librustc lower (for compile times); fs_util will compile in parallel with essentially the first crate since it has no dependencies beyond std.
This hack was removed in #50949, but without it I found that building
`std` with full debuginfo would print many LLVM `DW_OP_LLVM_fragment`
errors, then die `LLVM ERROR: Failed to strip malformed debug info`.
It doesn't seem to be a problem for LLVM 6, so we can re-enable the hack
just for older LLVM.
This reverts commit da579ef75e.
Fixes#53204.
r? @eddyb
Add help message for missing `IndexMut` impl
Code:
```rust
let mut map = HashMap::new();
map.insert("peter", 23);
map["peter"] = 27;
```
Before:
```
error[E0594]: cannot assign to immutable indexed content
--> src/main.rs:7:5
|
7 | map["peter"] = 27;
| ^^^^^^^^^^^^^^^^^ cannot borrow as mutable
```
With this change (just the `help` was added):
```
error[E0594]: cannot assign to immutable indexed content
--> index-error.rs:7:5
|
7 | map["peter"] = 27;
| ^^^^^^^^^^^^^^^^^ cannot borrow as mutable
|
= help: trait `IndexMut` is required to modify indexed content, but it is not implemented for std::collections::HashMap<&str, i32>
```
---
Yesterday I did some pair programming with a Rust-beginner. We created a type and implemented `Index` for it. Trying to modify the value returned by the index operation returns in a rather vague error that was not very clear for the Rust beginner. So I tried to improve the situation.
## Notes/questions for reviewers:
- Is the formulation OK like that? I'm fine with changing it.
- Can we be absolutely sure that `IndexMut` is actually not implemented in the case my `help` message is added? I'm fairly sure myself, but there could be some cases I didn't think of. Also, I don't know the compiler very well, so I don't know what exactly certain enum variants are used for.
- It would be nice to test if `IndexMut` is in fact not implemented for the type, but I couldn't figure out how to check that. If you think that additional check would be beneficial, could you tell me how to check if a trait is implemented?
- Do you think I should change the error message instead of only adding an additional help message?
Rollup of 15 pull requests
Successful merges:
- #52773 (Avoid unnecessary pattern matching against Option and Result)
- #53082 (Fix doc link (again))
- #53094 (Automatically expand section if url id point to one of its component)
- #53106 (atomic ordering docs)
- #53110 (Account for --remap-path-prefix in save-analysis)
- #53116 (NetBSD: fix signedess of char)
- #53179 (Whitelist wasm32 simd128 target feature)
- #53183 (Suggest comma when missing in macro call)
- #53207 (Add individual docs for rotate_{left, right})
- #53211 ([nll] enable feature(nll) on various crates for bootstrap)
- #53214 ([nll] enable feature(nll) on various crates for bootstrap: part 2)
- #53215 (Slightly refactor syntax_ext/format)
- #53217 (inline some short functions)
- #53219 ([nll] enable feature(nll) on various crates for bootstrap: part 3)
- #53222 (A few cleanups for rustc_target)
A few cleanups for rustc_target
- remove redundant struct field names
- shorten a self-assignment
- prefer `unwrap_or_else` in case of function calls
- collapse an `if`
- collapse a double `map()`
- match on dereferenced objects
- consume `self` if it implements `Copy`
Slightly refactor syntax_ext/format
expand_preparsed_format_args:
- move a potential error `return` earlier in the processing
- pre-allocate some of the required space for `cx.pieces` and `cx.str_pieces`
- create `cx`-independent objects before `cx`
- build `pieces` and `errs` using `collect` instead of a `push` loop
describe_num_args:
- return `Cow<str>` instead of `String`