since it sorts a [`ConstraintCategory::ClosureUpvar(HirId)`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/enum.ConstraintCategory.html#variant.ClosureUpvar).
This PR makes that variant take a [`Field`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/struct.Field.html) instead.
Matthias Krüger [Sat, 19 Feb 2022 05:45:30 +0000 (06:45 +0100)]
Rollup merge of #93979 - SUPERCILEX:debug_check, r=dtolnay
Add debug assertions to validate NUL terminator in c strings
The `unchecked` variants from the stdlib usually perform the check anyway if debug assertions are on (for example, `unwrap_unchecked`). This PR does the same thing for `CStr` and `CString`, validating the correctness for the NUL byte in debug mode.
bors [Sat, 19 Feb 2022 05:08:13 +0000 (05:08 +0000)]
Auto merge of #94105 - 5225225:destabilise-entry-insert, r=Mark-Simulacrum
Destabilise entry_insert
See: https://github.com/rust-lang/rust/pull/90345
I didn't revert the rename that was done in that PR, I left it as `entry_insert`.
Additionally, before that PR, `VacantEntry::insert_entry` seemingly had no stability attribute on it? I kept the attribute, just made it an unstable one, same as the one on `Entry`.
There didn't seem to be any mention of this in the RELEASES.md, so I don't think there's anything for me to do other than this?
bors [Sat, 19 Feb 2022 02:07:43 +0000 (02:07 +0000)]
Auto merge of #94134 - matthiaskrgr:rollup-b132kjz, r=matthiaskrgr
Rollup of 10 pull requests
Successful merges:
- #89892 (Suggest `impl Trait` return type when incorrectly using a generic return type)
- #91675 (Add MemTagSanitizer Support)
- #92806 (Add more information to `impl Trait` error)
- #93497 (Pass `--test` flag through rustdoc to rustc so `#[test]` functions can be scraped)
- #93814 (mips64-openwrt-linux-musl: correct soft-foat)
- #93847 (kmc-solid: Use the filesystem thread-safety wrapper)
- #93877 (asm: Allow the use of r8-r14 as clobbers on Thumb1)
- #93892 (Only mark projection as ambiguous if GAT substs are constrained)
- #93915 (Implement --check-cfg option (RFC 3013), take 2)
- #93953 (Add the `known-bug` test directive, use it, and do some cleanup)
Matthias Krüger [Fri, 18 Feb 2022 22:23:11 +0000 (23:23 +0100)]
Rollup merge of #93953 - jackh726:known_bug, r=Mark-Simulacrum
Add the `known-bug` test directive, use it, and do some cleanup
cc rust-lang/compiler-team#476
Now tests can be annotated with `known-bug`, which should indicate that the test *should* pass (or at least that the current output is a bug). Adding it relaxes the requirement to add error annotations to the test (though it is still allowed). In the future, this could be extended with further relaxations - with the goal to make adding these tests need minimal effort.
I've used this attribute for the GAT tests added in #93757.
Finally, I've also cleaned up `header.rs` in compiletest a bit, by extracting out a bit of common logic. I've also split out some of the directives into their own consts. This removes a lot of very similar functions from `Config` and makes `TestProps::load_from` read nicer.
I've split these into separate commits, so I in theory could split these into separate PRs if they're controversial, but I think they're pretty straightforward.
Matthias Krüger [Fri, 18 Feb 2022 22:23:10 +0000 (23:23 +0100)]
Rollup merge of #93915 - Urgau:rfc-3013, r=petrochenkov
Implement --check-cfg option (RFC 3013), take 2
This pull-request implement RFC 3013: Checking conditional compilation at compile time (https://github.com/rust-lang/rfcs/pull/3013) and is based on the previous attempt https://github.com/rust-lang/rust/pull/89346 by `@mwkmwkmwk` that was closed due to inactivity.
I have address all the review comments from the previous attempt and added some more tests.
cc https://github.com/rust-lang/rust/issues/82450
r? `@petrochenkov`
Matthias Krüger [Fri, 18 Feb 2022 22:23:09 +0000 (23:23 +0100)]
Rollup merge of #93892 - compiler-errors:issue-92917, r=jackh726,nikomatsakis
Only mark projection as ambiguous if GAT substs are constrained
A slightly more targeted version of #92917, where we only give up with ambiguity if we infer something about the GATs substs when probing for a projection candidate.
fixes #93874
also note (but like the previous PR, does not fix) #91762
r? `@jackh726`
cc `@nikomatsakis` who reviewed #92917
Matthias Krüger [Fri, 18 Feb 2022 22:23:07 +0000 (23:23 +0100)]
Rollup merge of #93847 - solid-rs:fix-kmc-solid-fs-ts, r=yaahc
kmc-solid: Use the filesystem thread-safety wrapper
Fixes the thread unsafety of the `std::fs` implementation used by the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets.
Neither the SOLID filesystem API nor built-in filesystem drivers guarantee thread safety by default. Although this may suffice in general embedded-system use cases, and in fact the API can be used from multiple threads without any problems in many cases, this has been a source of unsoundness in `std::sys::solid::fs`.
This commit updates the implementation to leverage the filesystem thread-safety wrapper (which uses a pluggable synchronization mechanism) to enforce thread safety. This is done by prefixing all paths passed to the filesystem API with `\TS`. (Note that relative paths aren't supported in this platform.)
Matthias Krüger [Fri, 18 Feb 2022 22:23:05 +0000 (23:23 +0100)]
Rollup merge of #93497 - willcrichton:rustdoc-scrape-test, r=GuillaumeGomez
Pass `--test` flag through rustdoc to rustc so `#[test]` functions can be scraped
As a part of stabilizing the scrape examples extension in Cargo, I uncovered a bug where examples cannot be scraped from tests. See this test: https://github.com/rust-lang/cargo/pull/10343/files#diff-27aa4f012ebfebaaee61498d91d2370de460628405d136b05e77efe61e044679R2496
The issue is that when rustdoc is run on a test file, because `--test` is not passed as a rustc option, then functions annotated with `#[test]` are ignored by the compiler. So this PR changes rustdoc so when `--test` is passed in conjunction with a `--scrape-example-<suffix>` flag, then the `test` field of `rustc_interface::Config` is true.
Matthias Krüger [Fri, 18 Feb 2022 22:23:03 +0000 (23:23 +0100)]
Rollup merge of #91675 - ivanloz:memtagsan, r=nagisa
Add MemTagSanitizer Support
Add support for the LLVM [MemTagSanitizer](https://llvm.org/docs/MemTagSanitizer.html).
On hardware which supports it (see caveats below), the MemTagSanitizer can catch bugs similar to AddressSanitizer and HardwareAddressSanitizer, but with lower overhead.
On a tag mismatch, a SIGSEGV is signaled with code SEGV_MTESERR / SEGV_MTEAERR.
# Usage
`-Zsanitizer=memtag -C target-feature="+mte"`
# Comments/Caveats
* MemTagSanitizer is only supported on AArch64 targets with hardware support
* Requires `-C target-feature="+mte"`
* LLVM MemTagSanitizer currently only performs stack tagging.
Matthias Krüger [Fri, 18 Feb 2022 22:23:02 +0000 (23:23 +0100)]
Rollup merge of #89892 - Nilstrieb:suggest-return-impl-trait, r=jackh726
Suggest `impl Trait` return type when incorrectly using a generic return type
Address #85991
When there is a type mismatch error and the return type is generic, and that generic parameter is not used in the function parameters, suggest replacing that generic with the `impl Trait` syntax.
Nilstrieb [Thu, 14 Oct 2021 19:44:43 +0000 (21:44 +0200)]
Suggest `impl Trait` return type
Address #85991
Suggest the `impl Trait` return type syntax if the user tried to return a generic parameter and we get a type mismatch
The suggestion is not emitted if the param appears in the function parameters, and only get the bounds that actually involve `T: ` directly
It also checks whether the generic param is contained in any where bound (where it isn't the self type), and if one is found (like `Option<T>: Send`), it is not suggested.
This also adds `TyS::contains`, which recursively vistits the type and looks if the other type is contained anywhere
bors [Fri, 18 Feb 2022 18:49:25 +0000 (18:49 +0000)]
Auto merge of #94121 - matthiaskrgr:rollup-6ps95da, r=matthiaskrgr
Rollup of 6 pull requests
Successful merges:
- #92683 (Suggest copying trait associated type bounds on lifetime error)
- #92933 (Deny mixing bin crate type with lib crate types)
- #92959 (Add more info and suggestions to use of #[test] on invalid items)
- #93024 (Do not ICE when inlining a function with un-satisfiable bounds)
- #93613 (Move `{core,std}::stream::Stream` to `{core,std}::async_iter::AsyncIterator`)
- #93634 (compiler: clippy::complexity fixes)
Matthias Krüger [Fri, 18 Feb 2022 15:23:30 +0000 (16:23 +0100)]
Rollup merge of #93024 - compiler-errors:inline-mir-bad-bounds, r=estebank
Do not ICE when inlining a function with un-satisfiable bounds
Fixes #93008
This is kinda a hack... but it's the fix I thought had the least blast-radius.
We use `normalize_param_env_or_error` to verify that the predicates in the param env are self-consistent, since with RevealAll, a bad predicate like `<&'static () as Clone>` will be evaluated with an empty ParamEnv (since it references no generics), and we'll raise an error for it.
Matthias Krüger [Fri, 18 Feb 2022 15:23:29 +0000 (16:23 +0100)]
Rollup merge of #92959 - asquared31415:test-non-fn-help, r=estebank
Add more info and suggestions to use of #[test] on invalid items
This pr changes the diagnostics for using `#[test]` on an item that can't be used as a test to explain that the attribute has no meaningful effect on non-functions and suggests the use of `#[cfg(test)]` for conditional compilation instead.
Example change:
```rs
#[test]
mod test {}
```
previously output
```
error: only functions may be used as tests
--> src/lib.rs:2:1
|
2 | mod test {}
| ^^^^^^^^^^^
```
now outputs
```
error: the `#[test]` attribute may only be used on a non-associated function
--> $DIR/test-on-not-fn.rs:3:1
|
LL | #[test]
| ^^^^^^^
LL | mod test {}
| ----------- expected a non-associated function, found a module
|
= note: the `#[test]` macro causes a a function to be run on a test and has no effect on non-functions
help: replace with conditional compilation to make the item only exist when tests are being run
|
LL | #[cfg(test)]
| ~~~~~~~~~~~~
```
Matthias Krüger [Fri, 18 Feb 2022 15:23:28 +0000 (16:23 +0100)]
Rollup merge of #92683 - jackh726:issue-92033, r=estebank
Suggest copying trait associated type bounds on lifetime error
Closes #92033
Kind of the most simple suggestion to make - we don't try to be fancy. Turns out, it's still pretty useful (the couple existing tests that trigger this error end up fixed - for this error - upon applying the fix).
Jakob Degen [Sun, 12 Dec 2021 02:32:08 +0000 (21:32 -0500)]
Extend uninhabited match branch optimization to also work on fallthrough.
The `uninhabited_enum_branch` miropt now also checks whether the fallthrough
case is inhabited, and if not will ensure that it points to an unreachable
block.
bors [Fri, 18 Feb 2022 10:26:45 +0000 (10:26 +0000)]
Auto merge of #93766 - petrochenkov:doclinkregr, r=camelid,GuillaumeGomez
rustdoc: Collect traits in scope for lang items
Inherent impls on primitive types are not included in the list of all inherent impls in the crate (`inherent_impls_in_crate_untracked`), they are taken from the list of lang items instead, but such impls can also be inlined by rustdoc, e.g. if something derefs to a primitive type.
Mario Carneiro [Fri, 18 Feb 2022 04:27:53 +0000 (20:27 -0800)]
Optimize char_try_from_u32
The optimization was proposed by @falk-hueffner in https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Micro-optimizing.20char.3A.3Afrom_u32/near/272146171, and I simplified it a bit and added an explanation of why the optimization is correct.
bors [Thu, 17 Feb 2022 22:54:18 +0000 (22:54 +0000)]
Auto merge of #94103 - matthiaskrgr:rollup-cd70ofn, r=matthiaskrgr
Rollup of 9 pull requests
Successful merges:
- #93337 (Update tracking issue numbers for inline assembly sub-features)
- #93758 (Improve comments about type folding/visiting.)
- #93780 (Generate list instead of div items in sidebar)
- #93976 (Add MAIN_SEPARATOR_STR)
- #94011 (Even more let_else adoptions)
- #94041 (Add a `try_collect()` helper method to `Iterator`)
- #94043 (Fix ICE when using Box<T, A> with pointer sized A)
- #94082 (Remove CFG_PLATFORM)
- #94085 (Clippy: Don't lint `needless_borrow` in method receiver positions)
Matthias Krüger [Thu, 17 Feb 2022 22:01:01 +0000 (23:01 +0100)]
Rollup merge of #94043 - DrMeepster:box_alloc_ice, r=oli-obk
Fix ICE when using Box<T, A> with pointer sized A
Fixes #78459
Note that using `Box<T, A>` with a more than pointer sized `A` or using a pointer sized `A` with a Box of a DST will produce a different ICE (#92054) which is not fixed by this PR.
Matthias Krüger [Thu, 17 Feb 2022 22:01:00 +0000 (23:01 +0100)]
Rollup merge of #94041 - a-lafrance:try-collect, r=scottmcm
Add a `try_collect()` helper method to `Iterator`
Implement `Iterator::try_collect()` as a helper around `Iterator::collect()` as discussed [here](https://internals.rust-lang.org/t/idea-fallible-iterator-mapping-with-try-map/15715/5?u=a.lafrance).
First time contributor so definitely open to any feedback about my implementation! Specifically wondering if I should open a tracking issue for the unstable feature I introduced.
As the main participant in the internals discussion: r? `@scottmcm`
Matthias Krüger [Thu, 17 Feb 2022 22:00:55 +0000 (23:00 +0100)]
Rollup merge of #93758 - nnethercote:improve-folding-comments, r=BoxyUwU
Improve comments about type folding/visiting.
I have found this code confusing for years. I've always roughly
understood it, but never exactly. I just made my fourth(?) attempt and
finally cracked it.
This commit improves the comments. In particular, it explicitly
describes how you can't do a custom fold/visit of any type; there are
actually a handful of "types of interest" (e.g. `Ty`, `Predicate`,
`Region`, `Const`) that can be custom folded/visted, and all other types
just get a generic traversal. I think this was the part that eluded me
on all my prior attempts at understanding.
The commit also updates comments to account for some newer changes such
as the fallible/infallible folding distinction, does some minor
reorderings, and moves one `impl` to a better place.
Matthias Krüger [Thu, 17 Feb 2022 22:00:55 +0000 (23:00 +0100)]
Rollup merge of #93337 - Amanieu:asm_tracking, r=tmiasko
Update tracking issue numbers for inline assembly sub-features
The main tracking issue for inline assembly is [closed](https://github.com/rust-lang/rust/issues/72016#issuecomment-1022332954), further tracking of the remaining sub-features has been moved to separate tracking issues.
I have found this code confusing for years. I've always roughly
understood it, but never exactly. I just made my fourth(?) attempt and
finally cracked it.
This commit improves the comments. In particular, it explicitly
describes how you can't do a custom fold/visit of any type; there are
actually a handful of "types of interest" (e.g. `Ty`, `Predicate`,
`Region`, `Const`) that can be custom folded/visted, and all other types
just get a generic traversal. I think this was the part that eluded me
on all my prior attempts at understanding.
The commit also updates comments to account for some newer changes such
as the fallible/infallible folding distinction, does some minor
reorderings, and moves one `impl` to a better place.
bors [Thu, 17 Feb 2022 09:13:18 +0000 (09:13 +0000)]
Auto merge of #94072 - matthiaskrgr:rollup-7uu2286, r=matthiaskrgr
Rollup of 8 pull requests
Successful merges:
- #89869 (Add documentation to more `From::from` implementations.)
- #93479 (Use `optflag` for `--report-time`)
- #93693 (Suggest deriving required supertraits)
- #93981 (Fix suggestion to slice if scurtinee is a reference to `Result` or `Option`)
- #93996 (Do not suggest "is a function" for free variables)
- #94030 (Correctly mark the span of captured arguments in `format_args!()`)
- #94031 ([diagnostics] Add mentions to `Copy` types being valid for `union` fields)
- #94064 (Update dist-x86_64-musl to Ubuntu 20.04)
Matthias Krüger [Thu, 17 Feb 2022 05:30:05 +0000 (06:30 +0100)]
Rollup merge of #94064 - nikic:update-musl-image, r=Mark-Simulacrum
Update dist-x86_64-musl to Ubuntu 20.04
This updates the dist-x86_64-musl image to use Ubuntu 20.04. The current Ubuntu 16.04 based image only works due to the Docker cache, it's not possible anymore to run it locally because of the usual certificate expiration issue.
I believe updating the OS here is relatively safe because this targets musl, so there are no concerns about raising the glibc baseline. There is some risk here in that it updates the compiler toolchain used to produce artifacts, though I'm not aware of any specific issues that could cause.
Matthias Krüger [Thu, 17 Feb 2022 05:30:03 +0000 (06:30 +0100)]
Rollup merge of #94031 - danielhenrymantilla:diagnostics/union-drop-suggest-copy-bound-alternative, r=davidtwco
[diagnostics] Add mentions to `Copy` types being valid for `union` fields
This came up from some user on Discord which was using a `T : PrimitiveInt` generic type, and they wanted to use in a `union`. Rather than adding a `Copy` bound, they started pondering about the `ManuallyDrop<T>` road, and how to correctly use `unsafe` to perform the drops.
<img width="648" alt="Screen Shot 2022-02-15 at 22 28 34" src="https://user-images.githubusercontent.com/9920355/154152496-8f9be74b-ad59-4724-8f9e-48b446774e06.png">
So, it seemed like the error message for types with potential drop glue on `union` fields could be improved to also mention the `Copy` alternative, since in many cases where `union`s are concerned, people are dealing with PODs / `Copy` types anyways 🙂
I chose to just hardcode handling for PartialOrd and PartialEq because that should be robust enough and I dont know how to go about doing it generically
Matthias Krüger [Thu, 17 Feb 2022 05:29:59 +0000 (06:29 +0100)]
Rollup merge of #93479 - smoelius:master, r=yaahc
Use `optflag` for `--report-time`
Essentially, what is described here:
https://github.com/rust-lang/rust/issues/64888#issuecomment-1008047228
There is one difference. The comment proposes to add a
`--report-time-color` option. This change instead uses libtest's
existing `--color` option for that purpose.
Matthias Krüger [Thu, 17 Feb 2022 05:29:57 +0000 (06:29 +0100)]
Rollup merge of #89869 - kpreid:from-doc, r=yaahc
Add documentation to more `From::from` implementations.
For users looking at documentation through IDE popups, this gives them relevant information rather than the generic trait documentation wording “Performs the conversion”. For users reading the documentation for a specific type for any reason, this informs them when the conversion may allocate or copy significant memory versus when it is always a move or cheap copy.
Notes on specific cases:
* The new documentation for `From<T> for T` explains that it is not a conversion at all.
* Also documented `impl<T, U> Into<U> for T where U: From<T>`, the other central blanket implementation of conversion.
* The new documentation for construction of maps and sets from arrays of keys mentions the handling of duplicates. Future work could be to do this for *all* code paths that convert an iterable to a map or set.
* I did not add documentation to conversions of a specific error type to a more general error type.
* I did not add documentation to unstable code.
This change was prepared by searching for the text "From<... for" and so may have missed some cases that for whatever reason did not match. I also looked for `Into` impls but did not find any worth documenting by the above criteria.
This keeps the cfg_target_has_atomic feature gate name since compiler-builtins otherwise depends on it and I'd rather not try to manage a bump across a crates.io published repository given the time-sensitivity here (we need to land this quickly to avoid a beta backport).
bors [Wed, 16 Feb 2022 22:11:22 +0000 (22:11 +0000)]
Auto merge of #91182 - ChrisDenton:command-broken-symlink, r=m-ou-se
Maintain broken symlink behaviour for the Windows exe resolver
When the resolver was updated to remove the current directory from the search path (see #87704), care was take to avoid unintentional changes that hadn't been discussed. However, I missed the broken symlink behaviour. This PR fixes that.
**Edit** This turned out to be more important than I first realised. There are some types of application stubs that will redirect to the actual process when run using `CreateProcessW`, but due to the way they're implemented they cannot be opened normally using a `File::open` that follows reparse points. So this doesn't work with our current `exists` and `try_exists` methods.
Matthias Krüger [Wed, 16 Feb 2022 17:59:35 +0000 (18:59 +0100)]
Rollup merge of #94045 - ehuss:update-books, r=ehuss
Update books
## nomicon
3 commits in 9493715a6280a1f74be759c7e1ef9999b5d13e6f..90993eeac93dbf9388992de92965f99cf6f29a03
2022-01-27 19:00:32 -0800 to 2022-02-13 12:44:12 +0900
- Fix a small typo in exception-safety.md (rust-lang/nomicon#341)
- Make `Vec::new` public in vec-alloc.md (rust-lang/nomicon#336)
- Fix a syntax error in leaking.md (rust-lang/nomicon#335)
## reference
6 commits in 411c2f0d5cebf48453ae2d136ad0c5e611d39aec..70fc73a6b908e08e66aa0306856c5211312f6c05
2022-01-30 12:46:37 -0800 to 2022-02-14 19:33:01 -0800
- Document pre-Rust-2021 special case for IntoIterator method lookup (rust-lang/reference#1154)
- Mention std::is_aarch64_feature_detected (rust-lang/reference#1061)
- Fix link to the Bastion of the Turbofish (rust-lang/reference#1161)
- Improve associated constant item CTFE timing section (rust-lang/reference#1147)
- document `#![feature(const_generics_defaults)]` (rust-lang/reference#1098)
- Update patterns allowed in @ patterns (rust-lang/reference#1158)
## book
6 commits in 98904efaa4fc968db8ff59cf2744d9f7ed158166..67b768c0b660a069a45f0e5d8ae2f679df1022ab
2022-01-29 21:22:31 -0500 to 2022-02-09 21:52:41 -0500
- Snapshot of ch18 for nostarch
- Remove mention of destructuring references as that's not covered currently
- Add note that exhaustiveness checking doesn't extend to match guards
- Change match guard example to actually be unexpressable with patterns alone
- Corrected listing number from 9-10 to 9-13
- Remove duplicate paragraph after No Starch related changes
## rustc-dev-guide
3 commits in 8763adb62c712df69b1d39ea3e692b6d696cc4d9..62f58394ba7b203f55ac35ddcc4c0b79578f5706
2022-01-26 14:01:40 -0800 to 2022-02-11 08:42:50 -0500
- Correction, building stage3 compiler (rust-lang/rustc-dev-guide#1298)
- Triage some date references (rust-lang/rustc-dev-guide#1293)
- mention test folders for cfg(bootstrap) (rust-lang/rustc-dev-guide#1294)
Matthias Krüger [Wed, 16 Feb 2022 17:59:34 +0000 (18:59 +0100)]
Rollup merge of #94037 - tmiasko:verbose, r=Mark-Simulacrum
Fix inconsistent symbol mangling with -Zverbose
Always skip arguments that are the defaults of their respective
parameters, to avoid generating inconsistent symbols for builds
with `-Zverbose` flag and without it.