rustbuild fixes
When upgrading Debian's rustc to 1.38 I needed these patches:
(1) In order to cross-compile rustc 1.38 and take it through the full rustbuild process including install, I needed the first patch.
(2) In order to build rustc 1.38 using rustc 1.38 itself I need to set --cap-lints warn, otherwise I get this error:
~~~~
error: unnecessary `unsafe` block
--> src/bootstrap/builder.rs:148:19
|
148 | name: unsafe { ::std::intrinsics::type_name::<S>() },
| ^^^^^^ unnecessary `unsafe` block
|
note: lint level defined here
--> src/bootstrap/lib.rs:107:9
|
107 | #![deny(warnings, rust_2018_idioms, unused_lifetimes)]
| ^^^^^^^^
= note: `#[deny(unused_unsafe)]` implied by `#[deny(warnings)]`
error: aborting due to previous error
error: could not compile `bootstrap`.
~~~~
In order to set --cap-lints warn however, I need bootstrap.py not to clobber RUSTFLAGS. (This worked previously, not sure if it was broken intentionally but we would like support for it.)
handle diverging functions forwarding their return place
Fixes https://github.com/rust-lang/miri/issues/1075: the shim around diverging closures turned into function pointers actually "obtains" a return place inside a diverging function, but just uses it as the return place for a diverging callee. Handle this by using NULL places.
This is kind of a hack as it breaks our invariant that all places are dereferencable, but we'd eventually let raw pointers break that anyway I assume so that seems fine.
r? @oli-obk
libunwind_panic: adjust miri panic hack
We adjust the Miri hack in libpanic_unwind such that even with `cfg(miri)`, we build a version of libpanic_unwind that actually works.
This is needed to resolve https://github.com/integer32llc/rust-playground/issues/548.
r? @oli-obk @alexcrichton
Handle const-checks for `&mut` outside of `HasMutInterior`
Addresses [this comment](https://github.com/rust-lang/rust/pull/64470#discussion_r328200508).
Const-checking relied on `HasMutInterior` to forbid `&mut` in a const context. This was strange because all we needed to do was look for an `Rvalue::Ref` with a certain `BorrowKind`, whereas the `Qualif` traits are specifically meant to get the qualifs for a *value*. This PR removes that logic from `HasMutInterior` and moves it into `check_consts::Validator`.
As a result, we can now properly handle qualifications for `static`s, which had to be ignored previously since you can e.g. borrow a static `Cell` from another `static`. We also remove the `derived_from_illegal_borrow` logic, since it is no longer necessary; we give good errors for subsequent reborrows/borrows of illegal borrows.
Conditional compilation for sanitizers
Configure sanitize option when compiling with a sanitizer to make
it possible to execute different code depending on whether given
sanitizer is enabled or not.
Rollup of 7 pull requests
Successful merges:
- #66346 (Replace .unwrap() with ? in std::os::unix::net)
- #66789 (rustc: move mir::SourceScopeLocalData to a field of SourceScopeData.)
- #66850 (rustc: hide HirId's fmt::Debug output from -Z span_free_formats.)
- #66905 (rustc_plugin: Remove some remaining plugin features)
- #66907 (rustc: don't just show raw DefIndex's in BrNamed's fmt::Debug impl.)
- #66918 (Add crc and crypto to target feature whitelist on arm)
- #66926 (add reusable MachineStop variant to Miri engine error enum)
Failed merges:
r? @ghost
add reusable MachineStop variant to Miri engine error enum
Replace the Miri-tool-specific `Exit` error variant with something dynamically typed that all clients of the Miri engine can use.
r? @oli-obk
Cc https://github.com/rust-lang/rust/issues/66902
rustc: don't just show raw DefIndex's in BrNamed's fmt::Debug impl.
Context: these `fmt::Debug` impls only get used with `-Z verbose` (which some tests use).
I was going to print the path like in #66850 (or rather, use `DefId`'s `fmt::Debug`, which is close but not as nice), but then I realized that most of the `DefId`s were `crate0:DefIndex(0)`, i.e. the crate root.
As the crate root is not a lifetime, they're clearly dummies of some sort, and we don't have to print anything other than the name for them.
This means that out of all the tests, there's only 5 instances of `BrNamed` that now print the full path to the lifetime parameter, and everything else is shorter instead, which doesn't feel too bad.
cc @nikomatsakis
rustc_plugin: Remove some remaining plugin features
- Plugin arguments (`#![plugin(my_plugin(args))]`) are no longer supported.
- Registering additional plugins from command line (`-Z extra-plugins=my_plugin`) is no longer supported, `-Z crate-attr=plugin(my_plugin)` can be used instead.
- Lint `plugin_as_library` is removed as mostly useless now, when plugins exist as a compatibility feature with greatly reduced functionality.
- Plugins registering additional LLVM passes (`Registry::register_llvm_pass`) are no longer supported, `-C passes=my_passes` can be used instead.
r? @Centril
rustc: hide HirId's fmt::Debug output from -Z span_free_formats.
This replaces the only occurrences of `HirId {...}` from tests with paths, i.e.:
```rust
[closure@HirId { owner: DefIndex(4), local_id: 15 } q:&i32, t:&T]
```
becomes, after this PR:
```rust
[closure@foo<T>::{{closure}}#0 q:&i32, t:&T]
```
r? @oli-obk cc @michaelwoerister
rustc: move mir::SourceScopeLocalData to a field of SourceScopeData.
By having one `ClearCrossCrate<SourceScopeLocalData>` for each scope, as opposed to a single `ClearCrossCrate` for all the `SourceScopeLocalData`s, we can represent the fact that some scopes have `SourceScopeLocalData` associated with them, and some don't.
This is useful when doing MIR inlining across crates, because the `ClearCrossCrate` will be `Clear` for the cross-crate MIR scopes and `Set` for the local ones.
Also see https://github.com/rust-lang/rust/pull/66203#issuecomment-555589574 for some context around this approach.
Fixes#51314.
Configure sanitize option when compiling with a sanitizer to make
it possible to execute different code depending on whether given
sanitizer is enabled or not.
Format liballoc with rustfmt
Same strategy as #66691 -- as with my previous formatting PRs, I am avoiding causing merge conflicts in other PRs by only touches those files that are not involved in any currently open PR. Files that appear in new PRs between when this PR is opened and when it makes it to the top of the bors queue will be reverted from this PR.
The list of files involved in open PRs is determined by querying GitHub's GraphQL API [with this script](https://gist.github.com/dtolnay/aa9c34993dc051a4f344d1b10e4487e8).
With the list of files from the script in outstanding_files, the relevant commands were:
```
$ find src/liballoc -name '*.rs' \
| xargs rustfmt --edition=2018 --unstable-features --skip-children
$ rg liballoc outstanding_files | xargs git checkout --
```
To confirm no funny business:
```
$ git checkout $THIS_COMMIT^
$ git show --pretty= --name-only $THIS_COMMIT \
| xargs rustfmt --edition=2018 --unstable-features --skip-children
$ git diff $THIS_COMMIT # there should be no difference
```
r? @Dylan-DPC
Use recursion_limit for const eval stack limit
cc https://github.com/rust-lang/miri/issues/643 @orium @RalfJung
I'm really not certain how exactly to handle this change, but it looks like it's that simple.
Reuse `recursion_limit` ("The maximum recursion limit for potentially infinitely recursive operations such as auto-dereference and monomorphization") which is configurable by the user for the const evaluation stack frame limit.
The other option is to make `const_eval_stack_frame_limit` configurable in the same way as `recursion_limit` (but I'm not sure how to do that and it'd be a bigger change).
Fixes https://github.com/rust-lang/miri/issues/643.
Improve lifetime errors with implicit trait object lifetimes
r? @matthewjasper
cc @estebank
I still think the ideal solution would be to construct a `BrAnon`, but that seems like a more invasive change, and can be done later. This at least gets rid of the hack in `OutliveSuggestion` and is slightly more principled.
Miri: run panic-catching tests in liballoc
I also converted two tests from using `thread::spawn(...).join()` just for catching panics, to `catch_panic`, so that Miri can run them.
More useful test error messages on should_panic(expected=...) mismatch
Fixes #66304
r? @gilescope
Shows both the actual as well as the expected panic value when a test with `should_panic(expected=...)` fails.
This makes `should_panic` more consistent with `assert_eq`.
I am not sure whether printing the `Any::type_id()` is useful, is there something better that we could print for non-string panic values?
Feature gating *declarations* => new crate `rustc_feature`
This PR moves the data-oriented parts of feature gating into its own crate, `rustc_feature`.
The parts consist of some data types as well as `accepted`, `active`, `removed`, and `builtin_attrs`.
Feature gate checking itself remains in `syntax::feature_gate::check`. The parts which define how to emit feature gate errors could probably be moved to `rustc_errors` or to the new `rustc_session` crate introduced in #66878. The visitor itself could probably be moved as a pass in `rustc_passes` depending on how the dependency edges work out.
The PR also contains some drive-by cleanup of feature gate checking. As such, the PR probably best read commit-by-commit.
r? @oli-obk
cc @petrochenkov
cc @Mark-Simulacrum
Remove unneeded prelude imports in libcore tests
These three lines are from c82da7a54b dating back to 2015.
They cause problems when applying rustfmt to the codebase, because reordering wildcard imports can trigger new unused import warnings.
As a minimized example, the following program compiles successfully:
```rust
#![deny(unused_imports)]
use std::fmt::Debug;
use std::marker::Send;
pub mod repro {
use std::prelude::v1::*;
use super::*;
pub type D = dyn Debug;
pub type S = dyn Send;
}
pub type S = dyn Send;
```
but putting it through rustfmt produces a program that fails to compile:
```rust
#![deny(unused_imports)]
use std::fmt::Debug;
use std::marker::Send;
pub mod repro {
use super::*;
use std::prelude::v1::*;
pub type D = dyn Debug;
pub type S = dyn Send;
}
pub type S = dyn Send;
```
The error is:
```console
error: unused import: `std::prelude::v1::*`
--> src/main.rs:8:9
|
8 | use std::prelude::v1::*;
| ^^^^^^^^^^^^^^^^^^^
```
Make python-generated source files compatible with rustfmt
This PR adjusts the generators for src/libcore/num/dec2flt/table.rs, src/libcore/unicode/printable.rs, and src/libcore/unicode/tables.rs to make it so running `rustfmt` on the generated files no longer needs to apply any changes.
This involves tweaking the python scripts where reasonable to better match rustfmt's style, and adding `#[rustfmt::skip]` to big constant tables that there's no point having rustfmt rewrap.
r? @Dylan-DPC