Make `Option::unwrap` unstably const
This is lumped into the `const_option` feature gate (#67441), which enables a potpourri of `Option` methods.
cc @rust-lang/wg-const-eval
r? @oli-obk
Rust function-level coverage now works on external crates
Follow-up to a known issue discussed (post-merge) in #74733:
Resolves a known issue in the coverage map where some regions had nonsensical source code locations.
External crate functions are already included in their own coverage maps, per library, and don't need to also
be added to the importing crate's coverage map. (In fact, their source start and end byte positions are not relevant to the importing crate's SourceMap.)
The fix was to simply skip trying to add imported coverage info to the coverage map if the instrumented function is not "local".
The injected counters are still relevant, however, and the LLVM `instrprof.increment` intrinsic call parameters will map those counters to the external crates' coverage maps, when generating runtime coverage data.
Now Rust Coverage can cleanly instrument and analyze coverage on an entire crate and its dependencies.
Example (instrumenting https://github.com/google/json5format):
```bash
$ ./x.py build rust-demangler # make sure the demangler is built
$ cd ~/json5format
$ RUSTC=$HOME/rust/build/x86_64-unknown-linux-gnu/stage1/bin/rustc \
RUSTFLAGS="-Zinstrument-coverage" \
cargo build --example formatjson5
$ LLVM_PROFILE_FILE="formatjson5.profraw" \
./target/debug/examples/formatjson5 session_manager.cml
$ ~/rust/build/x86_64-unknown-linux-gnu/llvm/bin/llvm-profdata merge \
-sparse formatjson5.profraw -o formatjson5.profdata
$ ~/rust/build/x86_64-unknown-linux-gnu/llvm/bin/llvm-cov show --use-color \
--instr-profile=formatjson5.profdata target/debug/examples/formatjson5 \
--show-line-counts-or-regions \
--Xdemangler=$HOME/rust/build/x86_64-unknown-linux-gnu/stage0-tools-bin/rust-demangler \
--show-instantiations \
2>&1 | less -R
```
(Scan forward for some of the non-zero coverage results, with `/^....[0-9]\| *[^ |0]`.)
<img width="1071" alt="Screen Shot 2020-07-30 at 1 21 01 PM" src="https://user-images.githubusercontent.com/3827298/88970627-97e43000-d267-11ea-8e4d-fe40a091f756.png">
Add `--output-format json` for Rustdoc on nightly
This enables the previously deprecated `--output-format` flag so it can be used on nightly to host the experimental implementation of [rfc/2963](https://github.com/rust-lang/rfcs/pull/2963). The actual implementation will come in later PRs so for now there's just a stub that gives you an ICE.
I'm _pretty_ sure that the logic I added makes it inaccessible from stable, but someone should double check that. @tmandry @jyn514
Improve diagnostics when constant pattern is too generic
This PR is a follow-up to PR #74538 and issue #73976
When constants queries Layout, TypeId or type_name of a generic parameter, instead of emitting `could not evaluate constant pattern`, we will instead emit a more detailed message `constant pattern depends on a generic parameter`.
rustc: Ignore fs::canonicalize errors in metadata
This commit updates the metadata location logic to ignore errors when
calling `fs::canonicalize`. Canonicalization was added historically so
multiple `-L` paths to the same directory don't print errors about
multiple candidates (since rustc can deduplicate same-named paths), but
canonicalization doesn't work on all filesystems. Cargo, for example,
always uses this sort of fallback where it will opportunitistically try
to canonicalize but fall back to using the input path if it otherwise
doesn't work.
If rustc is run on a filesystem that doesn't support canonicalization
then the effect of this change will be that `-L` paths which logically
point to the same directory will cause errors, but that's a rare enough
occurrence it shouldn't cause much issue in practice. Otherwise rustc
doesn't work at all today on those sorts of filesystem where
canonicalization isn't supported!
Enable docs on dist-x86_64-musl
Add the `rust-docs` component to toolchain `x86_64-unknown-linux-musl`, which allows people using rustup on their musl-based linux distribution to download the rust-docs.
`--disable-docs` is based on the assumption that `x86_64-unknown-linux-musl` is only a cross-compile target.
I have tested that the docs are built. I assume the build-system will automatically detect the docs and create a `rust-docs` component. I will [monitor](https://rust-lang.github.io/rustup-components-history/x86_64-unknown-linux-musl.html) the components and create a follow-up PR, if the docs aren't published.
See also #70619, where we enabled `rust-lld` to enable the wasm-workflow on musl-based linux distributions.
Don't use "weak count" around Weak::from_raw_ptr
As `Rc/Arc::weak_count` returns 0 when having no strong counts, this
could be confusing and it's better to avoid using that completely.
Closes#73840.
`Result::unwrap` is not eligible becuase it formats the contents of the
`Err` variant. `unwrap_or`, `unwrap_or_else` and friends are not
eligible because they drop things or invoke closures.
Fixed a known issue in the coverage map where some regions had
nonsensical source code locations. External crate functions are already
included in their own coverage maps, per library, and don't need to also
be added to the importing crate's coverage map. (In fact, their source
start and end byte positions are not relevant to the importing crate's
SourceMap.)
The fix was to simply skip trying to add imported coverage info to the
coverage map if the instrumented function is not "local".
The injected counters are still relevant, however, and the LLVM
`instrprof.increment` intrinsic call parameters will map those counters
to the external crates' coverage maps, when generating runtime coverage
data.
This commit updates the metadata location logic to ignore errors when
calling `fs::canonicalize`. Canonicalization was added historically so
multiple `-L` paths to the same directory don't print errors about
multiple candidates (since rustc can deduplicate same-named paths), but
canonicalization doesn't work on all filesystems. Cargo, for example,
always uses this sort of fallback where it will opportunitistically try
to canonicalize but fall back to using the input path if it otherwise
doesn't work.
If rustc is run on a filesystem that doesn't support canonicalization
then the effect of this change will be that `-L` paths which logically
point to the same directory will cause errors, but that's a rare enough
occurrence it shouldn't cause much issue in practice. Otherwise rustc
doesn't work at all today on those sorts of filesystem where
canonicalization isn't supported!
Fix incorrect clashing_extern_declarations warnings.
Fixes#73735, fixes#73872.
Fix clashing_extern_declarations warning for `#[repr(transparent)]` structs and safely-FFI-convertible enums, and not warning for clashes of struct members of different types, but the same size.
r? @nagisa
Make `mem::size_of_val` and `mem::align_of_val` unstably const
Implements #46571 but does not stabilize it. I wanted this while working on something today.
The only reason not to immediately stabilize are concerns around [custom DSTs](https://github.com/rust-lang/rust/issues/46571#issuecomment-387669352). That proposal has made zero progress in the last two years and const eval is rich enough to support pretty much any user-defined `len` function as long as nightly features are allowed (`raw_ptr_deref`).
Currently, this raises a `const_err` lint when passed an `extern type`.
r? @oli-obk
cc @rust-lang/wg-const-eval
- Make `is_repr_nullable_ptr` freestanding again to avoid usage of
ImproperCTypesVisitor in ClashingExternDeclarations (and don't
accidentally revert the ParamEnv::reveal_all() fix from a week earlier)
- Revise match condition for 1 Adt, 1 primitive
- Generalise check for non-null type so that it would also work for
ranges which exclude any single value (all bits set, for example)
- Make is_repr_nullable_ptr return the representable type instead of
just a boolean, to avoid adding an additional, independent "source of
truth" about the FFI-compatibility of Option-like enums. Also, rename to
`repr_nullable_ptr`.
An example of an FFI-safe enum conversion is when converting
Option<NonZeroUsize> to usize. Because the Some value must be non-zero,
rustc can use 0 to represent the None variant, making this conversion is
safe. Furthermore, it can be relied on (and removing this optimisation
already would be a breaking change).
Suppress debuginfo on naked function arguments
A function that has no prologue cannot be reasonably expected to support
debuginfo. In fact, the existing code (before this patch) would generate
invalid instructions that caused crashes. We can solve this easily by
just not emitting the debuginfo in this case.
Fixes https://github.com/rust-lang/rust/issues/42779
cc https://github.com/rust-lang/rust/issues/32408
Replace all uses of `log::log_enabled` with `Debug` printers
cc @RalfJung this touches a bunch of logging in the miri engine. There are some visual changes, mainly that in several cases we stop prepending lines with the module path and just have a newline.
Update cargo
14 commits in aa6872140ab0fa10f641ab0b981d5330d419e927..974eb438da8ced6e3becda2bbf63d9b643eacdeb
2020-07-23 13:46:27 +0000 to 2020-07-29 16:15:05 +0000
- Fix O0 build scripts by default without `[profile.release]` (rust-lang/cargo#8560)
- Emphasize git dependency version locking behavior. (rust-lang/cargo#8561)
- Update lock file encodings on changes (rust-lang/cargo#8554)
- Fix sporadic lto test failures. (rust-lang/cargo#8559)
- build-std: Fix libraries paths following upstream (rust-lang/cargo#8558)
- Flag git http errors as maybe spurious (rust-lang/cargo#8553)
- Display builtin aliases with `cargo --list` (rust-lang/cargo#8542)
- Check manifest for requiring nonexistent features (rust-lang/cargo#7950)
- Clarify test name filter usage (rust-lang/cargo#8552)
- Revert Cargo Book changes for default edition (rust-lang/cargo#8551)
- Prepare for not defaulting to master branch for git deps (rust-lang/cargo#8522)
- Include `+` for crates.io feature requirements in the Cargo Book section on features (rust-lang/cargo#8547)
- Update termcolor and fwdansi versions (rust-lang/cargo#8540)
- Cargo book nitpick in Manifest section (rust-lang/cargo#8543)
Rollup of 10 pull requests
Successful merges:
- #74742 (Remove links to rejected errata 4406 for RFC 4291)
- #74819 (Point towards `format_spec`; it is in other direction)
- #74852 (Explain why inlining default ToString impl)
- #74869 (Make closures and generators a must use types)
- #74873 (symbol mangling: use ty::print::Print for consts)
- #74902 (Remove deprecated unstable `{Box,Rc,Arc}::into_raw_non_null` functions)
- #74904 (Fix some typos in src/librustdoc/clean/auto_trait.rs)
- #74910 (fence docs: fix example Mutex)
- #74912 (Fix broken link in unstable book `plugin`)
- #74927 (Change the target data layout to specify more values)
Failed merges:
r? @ghost
Change the target data layout to specify more values
This does not actually alter the previously specified important parts, but apparently `rustc` cares about more layout components than `cargo-xbuild` ever did. This extends the data layout to be a fully specified layout, as given in the error from issue #74767
* Closes https://github.com/rust-lang/rust/issues/74767