bors [Fri, 3 Jun 2022 07:27:09 +0000 (07:27 +0000)]
Auto merge of #96296 - cjgillot:remove-label-lt-shadow, r=petrochenkov
Remove label/lifetime shadowing warnings
This PR removes some pre-1.0 shadowing warnings for labels and lifetimes.
The current behaviour of the compiler is to warn
* labels that shadow unrelated labels in the same function --> removed
```rust
'a: loop {}
'a: loop {} // STOP WARNING
```
* labels that shadow enclosing labels --> kept, but only if shadowing is hygienic
```rust
'a: loop {
'a: loop {} // KEEP WARNING
}
```
From `@petrochenkov` in https://github.com/rust-lang/rust/pull/95781#issuecomment-1105199014
> I think we should remove these silly checks entirely.
> They were introduced long time ago in case some new language features appear and require this space.
> Now we have another mechanism for such language changes - editions, and if "lifetimes in expressions" or something like that needs to be introduced it could be introduced as an edition change.
> However, there was no plans to introduce anything like for years, so it's unlikely that even the edition mechanism will be necessary.
bors [Fri, 3 Jun 2022 00:21:29 +0000 (00:21 +0000)]
Auto merge of #97667 - matthiaskrgr:rollup-5cfxc85, r=matthiaskrgr
Rollup of 5 pull requests
Successful merges:
- #97502 (rustdoc: Add more test coverage)
- #97627 (update explicit impls error msg)
- #97640 (Fix wrong suggestion for adding where clauses)
- #97645 (don't use a `span_note` for ignored impls)
- #97655 (Improve documentation for constructors of pinned `Box`es)
Matthias Krüger [Thu, 2 Jun 2022 21:39:07 +0000 (23:39 +0200)]
Rollup merge of #97655 - steffahn:better-pin-box-construction-docs, r=thomcc
Improve documentation for constructors of pinned `Box`es
Adds a cross-references between `Box::pin` and `Box::into_pin` (and other related methods, i.e. the equivalent `From` implementation, and the unstable `pin_in` method), in particular now that `into_pin` [was stabilized](https://github.com/rust-lang/rust/pull/97397). The main goal is to further improve visibility of the fact that `Box<T> -> Pin<Box<T>>` conversion exits in the first place, and that `Box::pin(x)` is – essentially – just a convenience function for `Box::into_pin(Box::new(x))`
The motivating context why I think this is important is even experienced Rust users overlooking the existence this kind of conversion, [e.g. in this thread on IRLO](https://internals.rust-lang.org/t/pre-rfc-function-variants/16732/7?u=steffahn); and also the fact that that discussion brought up that there would be a bunch of Box-construction methods "missing" such as e.g. methods with fallible allocation a la "`Box::try_pin`", and similar; while those are in fact *not* necessary, because you can use `Box::into_pin(Box::try_new(x)?)` instead.
I have *not* included explicit mention of methods (e.g. `try_new`) in the docs of stable methods (e.g. `into_pin`). (Referring to unstable API in stable API docs would be bad style IMO.) Stable examples I have in mind with the statement "constructing a (pinned) Box in a different way than with `Box::new`" are things like cloning a `Box`, or `Box::from_raw`. If/when `try_new` would get stabilized, it would become a very good concrete example use-case of `Box::into_pin` IMO.
Matthias Krüger [Thu, 2 Jun 2022 21:39:06 +0000 (23:39 +0200)]
Rollup merge of #97645 - lcnr:derived-impl-debug, r=cjgillot
don't use a `span_note` for ignored impls
Searching for the `derive` isn't too difficult as it's right above the field definition.
By using a span these errors are a lot more verbose than they should be, which is especially annoying as one can end up with a lot of `dead_code` warnings.
bors [Thu, 2 Jun 2022 18:45:29 +0000 (18:45 +0000)]
Auto merge of #97575 - nnethercote:lazify-SourceFile-lines, r=Mark-Simulacrum
Lazify `SourceFile::lines`.
`SourceFile::lines` is a big part of metadata. It's stored in a compressed form
(a difference list) to save disk space. Decoding it is a big fraction of
compile time for very small crates/programs.
This commit introduces a new type `SourceFileLines` which has a `Lines`
form and a `Diffs` form. The latter is used when the metadata is first
read, and it is only decoded into the `Lines` form when line data is
actually needed. This avoids the decoding cost for many files,
especially in `std`. It's a performance win of up to 15% for tiny
crates/programs where metadata decoding is a high part of compilation
costs.
A `RefCell` is needed because the methods that access lines data (which can
trigger decoding) take `&self` rather than `&mut self`. To allow for this,
`SourceFile::lines` now takes a `FnMut` that operates on the lines slice rather
than returning the lines slice.
Dylan DPC [Thu, 2 Jun 2022 13:27:01 +0000 (15:27 +0200)]
Rollup merge of #97636 - nnethercote:revert-96682, r=dtolnay
Revert #96682.
The change was "Show invisible delimiters (within comments) when pretty
printing". It's useful to show these delimiters, but is a breaking
change for some proc macros.
The problem was that the ID was conflicting because the reexports have the same one. To fix it, I "extended" it by adding the `Symbol` into it as well.
Dylan DPC [Thu, 2 Jun 2022 13:26:58 +0000 (15:26 +0200)]
Rollup merge of #97450 - c410-f3r:assert-compiler, r=oli-obk
[RFC 2011] Basic compiler infrastructure
Splitting https://github.com/rust-lang/rust/pull/96496 into smaller pieces as was done in https://github.com/rust-lang/rust/pull/97233. Hope review will be easier.
This PR practically contains no logic and only serves as a building ground for the actual code that will be placed in a posterior step.
* Adds `context.rs` to place the new `assert!` logic. Has a lot of unused elements but all of them are used by the implementation.
* Creates an unstable flag because the feature is not yet complete and also to allow external feedback.
* Creates the necessary `sym` identifiers that are mostly based on the library elements -> https://github.com/rust-lang/rust/blob/master/library/core/src/asserting.rs
* Modifies `assert.rs` to branch to `context.rs` if the unstable flag is enabled.
* Adds a test to satisfy tidy but the test does nothing in reality.
bors [Thu, 2 Jun 2022 13:20:19 +0000 (13:20 +0000)]
Auto merge of #97293 - est31:remove_box, r=oli-obk
Add #[rustc_box] and use it inside alloc
This commit adds an alternative content boxing syntax, and uses it inside alloc.
```Rust
#![feature(box_syntax)]
fn foo() {
let foo = box bar;
}
```
is equivalent to
```Rust
#![feature(rustc_attrs)]
fn foo() {
let foo = #[rustc_box] Box::new(bar);
}
```
The usage inside the very performance relevant code in
liballoc is the only remaining relevant usage of box syntax
in the compiler (outside of tests, which are comparatively easy to port).
box syntax was originally designed to be used by all Rust
developers. This introduces a replacement syntax more tailored
to only being used inside the Rust compiler, and with it,
lays the groundwork for eventually removing box syntax.
[Earlier work](https://github.com/rust-lang/rust/pull/87781#issuecomment-894714878) by `@nbdd0121` to lower `Box::new` to `box` during THIR -> MIR building ran into borrow checker problems, requiring the lowering to be adjusted in a way that led to [performance regressions](https://github.com/rust-lang/rust/pull/87781#issuecomment-894872367). The proposed change in this PR lowers `#[rustc_box] Box::new` -> `box` in the AST -> HIR lowering step, which is way earlier in the compiler, and thus should cause less issues both performance wise as well as regarding type inference/borrow checking/etc. Hopefully, future work can move the lowering further back in the compiler, as long as there are no performance regressions.
bors [Thu, 2 Jun 2022 10:39:24 +0000 (10:39 +0000)]
Auto merge of #97644 - Dylan-DPC:rollup-xaeio91, r=Dylan-DPC
Rollup of 6 pull requests
Successful merges:
- #96894 (Apply track_caller to closure on `expect_non_local()`)
- #97023 (Diagnose anonymous lifetimes errors more uniformly between async and regular fns)
- #97397 (Stabilize `box_into_pin`)
- #97587 (Migrate more diagnostics to use the `#[derive(SessionDiagnostic)]`)
- #97603 (Arc make_mut doc comment spelling correction.)
- #97635 (Fix file metadata documentation for Windows)
Dylan DPC [Thu, 2 Jun 2022 09:13:26 +0000 (11:13 +0200)]
Rollup merge of #97635 - rgwood:patch-1, r=ChrisDenton
Fix file metadata documentation for Windows
I noticed that the documentation for `fs::symlink_metadata()` and `fs::metadata()` is incorrect; [the underlying code](https://github.com/rust-lang/rust/blob/481db40311cdd241ae4d33f34f2f75732e44d8e8/library/std/src/sys/windows/fs.rs#L334) calls [`GetFileInformationByHandle()`](https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfileinformationbyhandle) on Windows, not [`GetFileAttributesEx()`](https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfileattributesexw). There are currently [no uses of `GetFileAttributesEx()` in this repo](https://github.com/rust-lang/rust/search?q=GetFileAttributesEx).
Dylan DPC [Thu, 2 Jun 2022 09:13:23 +0000 (11:13 +0200)]
Rollup merge of #97397 - JohnTitor:stabilize-box-into-pin, r=Mark-Simulacrum
Stabilize `box_into_pin`
FCP has been completed: https://github.com/rust-lang/rust/issues/62370#issuecomment-1012162279
Also, adds notes as per https://github.com/rust-lang/rust/issues/62370#issuecomment-1004108116
Closes #62370
Dylan DPC [Thu, 2 Jun 2022 09:13:22 +0000 (11:13 +0200)]
Rollup merge of #97023 - cjgillot:uniform-anon, r=estebank
Diagnose anonymous lifetimes errors more uniformly between async and regular fns
Async fns and regular fns are desugared differently. For the former, we create a generic parameter at HIR level. For the latter, we just create an anonymous region for typeck.
I plan to migrate regular fns to the async fn desugaring.
Before that, this PR attempts to merge the diagnostics for both cases.
bors [Thu, 2 Jun 2022 07:58:29 +0000 (07:58 +0000)]
Auto merge of #96737 - ChrisDenton:win-manifest, r=wesleywiser
Add Windows application manifest to rustc-main
Windows allows setting some runtime options using a manifest file. The format of the XML file is documented here: https://docs.microsoft.com/en-us/windows/win32/sbscs/application-manifests
The manifest file in this PR does three things:
* Declares which Windows versions we support. This may help avoid unnecessary compatibility shims.
* Uses the UTF-8 code page. While Rust itself uses UTF-16 APIs, other code may rely on the code page.
* Makes the application long path aware (if also enabled by the user). This allows for the current directory to be longer than `PATH_MAX`.
These changes only affect the `rustc` process and not any other DLLs or compiled programs.
The change was "Show invisible delimiters (within comments) when pretty
printing". It's useful to show these delimiters, but is a breaking
change for some proc macros.
Yuki Okushi [Wed, 1 Jun 2022 21:44:29 +0000 (06:44 +0900)]
Rollup merge of #97613 - jsha:implementation-is-on-local-type, r=GuillaumeGomez
rustdoc: Improve calculation of "Impls on Foreign Types"
The existing code to calculate whether an implementation was on a "Foreign Type" was duplicated across the sidebar generation and the page generation. It also came to the wrong conclusion for some cases where both the trait and the "for" type were re-exports.
This PR extracts the logic into a method of `Impl`, breaks it into a multi-line method so it can be commented, and adds a case for when the trait and the "for" type came from the same crate. This fixes some cases - like the platform-specific integer types (`__m256`, `__m128`, etc). But it doesn't fix all cases. See the screenshots below.
The remaining types (`CString`, `NulError`, etc) are all from the `alloc` crate, while the `Clone` trait is from the `core` crate. Since `CString` and `Clone` are both re-exported by `std`, they are logically local to each other, but I couldn't figure out a good way to detect that in this code. I figure this is still a good step forward.
Yuki Okushi [Wed, 1 Jun 2022 21:44:27 +0000 (06:44 +0900)]
Rollup merge of #97166 - nnethercote:move-conditions-out, r=estebank
Move conditions out of recover/report functions.
`Parser` has six recover/report functions that are passed a boolean, and
nothing is done if the boolean has a particular value.
This PR moves the tests outside the functions. This has the following effects.
- The number of lines of code goes down.
- Some `use` items become shorter.
- Avoids the strangeness whereby 11 out of 12 calls to
`maybe_recover_from_bad_qpath` pass `true` as the second argument.
- Makes it clear at the call site that only one of
`maybe_recover_from_bad_type_plus` and `maybe_report_ambiguous_plus` will be
run.
bors [Wed, 1 Jun 2022 20:06:14 +0000 (20:06 +0000)]
Auto merge of #97612 - ehuss:update-cargo, r=ehuss
Update cargo
5 commits in 39ad1039d9e3e1746177bf5d134af4c164f95528..38472bc19f2f76e245eba54a6e97ee6821b3c1db
2022-05-25 00:50:02 +0000 to 2022-05-31 02:03:24 +0000
- Emit warning upon encountering multiple packages with the same name (rust-lang/cargo#10701)
- Guide new users to add use `super::*;` to `mod test` (rust-lang/cargo#10706)
- Document how to debug change detection events (rust-lang/cargo#10708)
- fix(publish): add more check when use `publish -p <SPEC>` (rust-lang/cargo#10677)
- fix key formatting when switching to a dotted `WorkspaceSource` (rust-lang/cargo#10705)
bors [Wed, 1 Jun 2022 17:25:29 +0000 (17:25 +0000)]
Auto merge of #97624 - matthiaskrgr:rollup-rtcqjx9, r=matthiaskrgr
Rollup of 4 pull requests
Successful merges:
- #96271 (suggest `?` when method is missing on `Result<T, _>` but found on `T`)
- #97264 (Suggest `extern crate foo` when failing to resolve `use foo`)
- #97592 (rustdoc: also index impl trait and raw pointers)
- #97621 (update Miri)
bors [Wed, 1 Jun 2022 14:44:20 +0000 (14:44 +0000)]
Auto merge of #97622 - JohnTitor:rollup-4qoxrjn, r=JohnTitor
Rollup of 9 pull requests
Successful merges:
- #94647 (Expose `get_many_mut` and `get_many_unchecked_mut` to HashMap)
- #97216 (Ensure we never consider the null pointer dereferencable)
- #97399 (simplify code of finding arg index in `opt_const_param_of`)
- #97470 (rustdoc: add more test coverage)
- #97498 (Corrected EBNF grammar for from_str)
- #97562 (Fix comment in `poly_project_and_unify_type`)
- #97580 (Add regression test for #71546)
- #97611 (Tweak insert docs)
- #97616 (Remove an unnecessary `Option`)
Yuki Okushi [Wed, 1 Jun 2022 14:36:52 +0000 (23:36 +0900)]
Rollup merge of #97611 - azdavis:master, r=Dylan-DPC
Tweak insert docs
For `{Hash, BTree}Map::insert`, I always have to take a few extra seconds to think about the slight weirdness about the fact that if we "did not" insert (which "sounds" false), we return true, and if we "did" insert, (which "sounds" true), we return false.
This tweaks the doc comments for the `insert` methods of those types (as well as what looks like a rustc internal data structure that I found just by searching the codebase for "If the set did") to first use the "Returns whether _something_" pattern used in e.g. `remove`, where we say that `remove` "returns whether the value was present".
Yuki Okushi [Wed, 1 Jun 2022 14:36:49 +0000 (23:36 +0900)]
Rollup merge of #97498 - ijchen:master, r=Mark-Simulacrum
Corrected EBNF grammar for from_str
Hello! This is my first time contributing to an open-source project. I'm excited to have the chance to contribute to the rust community 🥳
I noticed an issue with the documentation for `from_str` in `f32` and `f64`. It states that "All strings that adhere to the following [EBNF](https://www.w3.org/TR/REC-xml/#sec-notation) grammar when lowercased will result in an `Ok` being returned. I believe this is incorrect for the string `"."`, which is valid for the given EBNF grammar, but does not result in an `Ok` being returned ([playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=09f891aa87963a56d3b0d715d8cbc2b4)). I have simplified the grammar in a way which fixes that, but is otherwise identical.
Previously, the `Number` part of the EBNF grammar had an option for `'.' Digit*`, which would include the string `"."`. This is not valid, and does not return an Ok as stated. The corrected version removes this, and still allows for the `'.' Digit+` case with the already existing `Digit* '.' Digit+` case.
Yuki Okushi [Wed, 1 Jun 2022 14:36:47 +0000 (23:36 +0900)]
Rollup merge of #97399 - SparrowLii:arg_index, r=oli-obk
simplify code of finding arg index in `opt_const_param_of`
From the FIXME in the impl of `opt_const_param_of`. Part of the code is simplified by blending two iterator statements and using `let...else` statement.
Yuki Okushi [Wed, 1 Jun 2022 14:36:45 +0000 (23:36 +0900)]
Rollup merge of #94647 - Urgau:hash-map-many-mut, r=Amanieu
Expose `get_many_mut` and `get_many_unchecked_mut` to HashMap
This pull-request expose the function [`get_many_mut`](https://docs.rs/hashbrown/0.12.0/hashbrown/struct.HashMap.html#method.get_many_mut) and [`get_many_unchecked_mut`](https://docs.rs/hashbrown/0.12.0/hashbrown/struct.HashMap.html#method.get_many_unchecked_mut) from `hashbrown` to the standard library `HashMap` type. They obviously keep the same API and are added under the (new) `map_many_mut` feature.
- `get_many_mut`: Attempts to get mutable references to `N` values in the map at once.
- `get_many_unchecked_mut`: Attempts to get mutable references to `N` values in the map at once, without validating that the values are unique.
bors [Wed, 1 Jun 2022 01:49:04 +0000 (01:49 +0000)]
Auto merge of #97435 - Patryk27:bump-compiler-builtins, r=Dylan-DPC
library/std: Bump compiler_builtins
Some neat changes include faster float conversions & fixes for AVR 🙂
(note that's it's my first time upgrading `compiler_builtins`, so I'm not 100% sure if bumping `library/std/Cargo.toml` is enough; certainly seems to be so, though.)
`SourceFile::lines` is a big part of metadata. It's stored in a compressed form
(a difference list) to save disk space. Decoding it is a big fraction of
compile time for very small crates/programs.
This commit introduces a new type `SourceFileLines` which has a `Lines`
form and a `Diffs` form. The latter is used when the metadata is first
read, and it is only decoded into the `Lines` form when line data is
actually needed. This avoids the decoding cost for many files,
especially in `std`. It's a performance win of up to 15% for tiny
crates/programs where metadata decoding is a high part of compilation
costs.
A `Lock` is needed because the methods that access lines data (which can
trigger decoding) take `&self` rather than `&mut self`. To allow for this,
`SourceFile::lines` now takes a `FnMut` that operates on the lines slice rather
than returning the lines slice.
est31 [Sun, 22 May 2022 21:10:27 +0000 (23:10 +0200)]
Add #[rustc_box]
This commit adds an alternative content boxing syntax,
and uses it inside alloc.
The usage inside the very performance relevant code in
liballoc is the only remaining relevant usage of box syntax
in the compiler (outside of tests, which are comparatively
easy to port).
box syntax was originally designed to be used by all Rust
developers. This introduces a replacement syntax more tailored
to only being used inside the Rust compiler, and with it,
lays the groundwork for eventually removing box syntax.
bors [Tue, 31 May 2022 23:24:39 +0000 (23:24 +0000)]
Auto merge of #97600 - matthiaskrgr:rollup-yivyeu5, r=matthiaskrgr
Rollup of 4 pull requests
Successful merges:
- #97316 (Put a bound on collection misbehavior)
- #97578 (alloc: remove repeated word in comment)
- #97593 (:arrow_up: rust-analyzer)
- #97596 (Fixup feature name to be more consistent with others)