Rollup of 10 pull requests
Successful merges:
- #65136 (Update codegen option documentation.)
- #65574 (docs: improve disclaimer regarding LinkedList)
- #65720 (Add FFI bindings for LLVM's Module::getInstructionCount())
- #65905 ([doc] fixes for unix/vxworks `OpenOptionsExt::mode`)
- #65962 (Fix logic in example.)
- #66019 (Improved std::iter::Chain documentation)
- #66038 (doc(str): show example of chars().count() under len())
- #66042 (Suggest correct code when encountering an incorrect trait bound referencing the current trait)
- #66073 (Do not needlessly write-lock)
- #66096 (Add a failing UI test for multiple loops of all kinds in a `const`)
Failed merges:
r? @ghost
Add a failing UI test for multiple loops of all kinds in a `const`
This simply demonstrates the current behavior and ensures we don't allow anything by accident.
The new const checker will be able to improve the diagnostics here. While working on it, I didn't see very many tests with non-`while` loops in a `const`, and there were no tests with multiple loops.
Suggest correct code when encountering an incorrect trait bound referencing the current trait
Fixes#65985 and also improves the suggestion for code like this:
```
trait Grab {
type Value;
fn grab(&self) -> Grab::Value;
}
```
To suggest `<Self as Grab>::Value`.
I wasn't sure which of the syntax versions is better (`<Self as ..>::` vs `Self::`), so I used the former simply because it was less change to the existing code.
r? @estebank
doc(str): show example of chars().count() under len()
the docs are great at explaining that .len() isn't like in other
languages but stops short of explaining how to get the character length.
Improved std::iter::Chain documentation
Replaces `strings two iterators` by `links two iterators` in `std::iter::Chain` documentation.
I didn't find any meaning of `strings` which can be evaluated as `links` or `joins`.
I don't think that `std::iter:Chain` works as a stringer or plays billiards. (https://www.lexico.com/en/definition/string).
Add FFI bindings for LLVM's Module::getInstructionCount()
Just to make it usable for profiling and such inside
rustc itself. It was vaguely useful in
https://wiki.alopex.li/WhereRustcSpendsItsTime and I figured
I might as well upstream it; I may or may not ever get around
to doing more with it (hopefully I will), but it may be useful
for others.
Update codegen option documentation.
Some documentation updates:
- Add more detail to codegen options.
- Add missing options:
- `force-frame-pointers`
- `default-linker-libraries`
- `linker-plugin-lto`
- Add fragment anchors for all command-line-arguments.
- Add some cross links between options.
rustc_target: rename {Fn,Arg}Type to {Fn,Arg}Abi.
I was trying to tweak the API of `FnType` (now `FnAbi`) and the name kept bothering me.
`FnAbi` is to a function signature a bit like a layout is to a type, so the name still isn't perfect yet, but at least it doesn't have the misleading `Type` in it anymore.
If this can't land I think I can continue my original refactor without it, so I'm not strongly attached to it.
r? @nagisa cc @oli-obk
Clarify pattern-matching usefulness algorithm
This PR clarifies a bit the usefulness algorithm by emphasizing that each row of the matrix can be seen as a sort of stack from which we pop constructors. It also moves code around to increase separation of concerns.
This is part of my splitting of https://github.com/rust-lang/rust/pull/65160 into smaller PRs.
expand: Feature gate out-of-line modules in proc macro input
Extracted from https://github.com/rust-lang/rust/pull/64273.
We are currently gating attributes applied directly to `mod` items because there are unresolved questions about out-of-line modules and their behavior is very likely to change.
However, you can sneak an out-of-line module into an attribute macro input using modules nested into other items like
```rust
#[my_attr]
fn m() {
#[path = "zzz.rs"]
mod n; // what tokens does the `my_attr` macro see?
}
```
This PR prevents that and emits a feature gate error for this case as well.
r? @Centril
It would be great to land this before beta.
Remove LintBuffer from Session
This moves the `LintBuffer` from `Session` into the `Resolver`, where it is used until lowering is done and then consumed by early lint passes. This also happily removes the failure mode of buffering lints too late where it would have previously lead to ICEs; it is statically no longer possible to do so.
I suspect that with a bit more work a similar move could be done for the lint buffer inside `ParseSess`, but this PR doesn't touch it (in part to keep itself small).
The last commit is the "interesting" commit -- the ones before it don't work (though they compile) as they sort of prepare the various crates for the lint buffer to be passed in rather than accessed through Session.
Reduce amount of errors given unclosed delimiter
When in a file with a non-terminated item, catch the error and consume
the block instead of trying to recover it on a more granular way in order to
reduce the amount of unrelated errors that would be fixed after adding
the missing closing brace. Also point out the possible location of the
missing closing brace.
Fix#63690.
Move help popup generation code
The first commit is just a small cleanup.
The idea behind this PR is to reduce a bit more the generated HTML files by moving the duplicated code into one place instead.
r? @kinnison
Allow foreign exceptions to unwind through Rust code and Rust panics to unwind through FFI
This PR fixes interactions between Rust panics and foreign (mainly C++) exceptions.
C++ exceptions (and other FFI exceptions) can now safely unwind through Rust code:
- The FFI function causing the unwind must be marked with `#[unwind(allowed)]`. If this is not the case then LLVM may optimize landing pads away with the assumption that they are unreachable.
- Drop code will be executed as the exception unwinds through the stack, as with a Rust panic.
- `catch_unwind` will *not* catch the exception, instead the exception will silently continue unwinding past it.
Rust panics can now safely unwind through C++ code:
- C++ destructors will be called as the stack unwinds.
- The Rust panic can only be caught with `catch (...)`, after which it can be either rethrown or discarded.
- C++ cannot name the type of the Rust exception object used for unwinding, which means that it can't be caught explicitly or have its contents inspected.
Tests have been added to ensure all of the above works correctly.
Some notes about non-C++ exceptions:
- `pthread_cancel` and `pthread_exit` use unwinding on glibc. This has the same behavior as a C++ exception: destructors are run but it cannot be caught by `catch_unwind`.
- `longjmp` on Windows is implemented using unwinding. Destructors are run on MSVC, but not on MinGW. In both cases the unwind cannot be caught by `catch_unwind`.
- As with C++ exceptions, you need to mark the relevant FFI functions with `#[unwind(allowed)]`, otherwise LLVM will optimize out the destructors since they seem unreachable.
I haven't updated any of the documentation, so officially unwinding through FFI is still UB. However this is a step towards making it well-defined.
Fixes#65441
cc @gnzlbg
r? @alexcrichton
Validate error patterns and error annotation in ui tests when present
Previously, when compilation succeeded, neither error patterns nor error
annotation would be validated. Additionally, when compilation failed,
only error patterns would be validated if both error patterns and error
annotation were present.
Now both error patterns and error annotation are validated when present,
regardless of compilation status. Furthermore, for test that should run,
the error patterns are matched against executable output, which is what
some of tests already expect to happen, and when #65506 is merged even
more ui tests will.
Fixes#56277
Remove a loop which runs exactly once
Though the code seems to work properly, it is worth removing the loop entirely in order to not confuse the reader.
r? @estebank
The concrete type that will be too big is target dependent. Avoid
matching it in error annotation to make test work correctly across
different targets.
Previously, when compilation succeeded, neither error patterns nor error
annotation would be validated. Additionally, when compilation failed,
only error patterns would be validated if both error patterns and error
annotation were present.
Now both error patterns and error annotation are validated when present,
regardless of compilation status. Furthermore, for test that should run,
the error patterns are matched against executable output, which is what
some of tests already expect to happen, and when #65506 is merged even
more ui tests will.
When both error patterns and error annotations are present in an ui
test, only error patterns are validated against the output.
Replace the error pattern with an error annotation to avoid silently
ignoring the other error annotation.