]> git.lizzy.rs Git - rust.git/log
rust.git
3 years agoRollup merge of #85339 - FabianWolff:issue-83893, r=varkor
Guillaume Gomez [Tue, 18 May 2021 12:08:51 +0000 (14:08 +0200)]
Rollup merge of #85339 - FabianWolff:issue-83893, r=varkor

Report an error if a lang item has the wrong number of generic arguments

This pull request fixes #83893. The issue is that the lang item code currently checks whether the lang item has the correct item kind (e.g. a `#[lang="add"]` has to be a trait), but not whether the item has the correct number of generic arguments.

This can lead to an "index out of bounds" ICE when the compiler tries to create more substitutions than there are suitable types available (if the lang item was declared with too many generic arguments).

For instance, here is a reduced ("reduced" in the sense that it does not trigger additional errors) version of the example given in #83893:
```rust
#![feature(lang_items,no_core)]
#![no_core]
#![crate_type="lib"]

#[lang = "sized"]
trait MySized {}

#[lang = "add"]
trait MyAdd<'a, T> {}

fn ice() {
    let r = 5;
    let a = 6;
    r + a
}
```
On current nightly, this immediately causes an ICE without any warnings or errors emitted. With the changes in this PR, however, I get no ICE and two errors:
```
error[E0718]: `add` language item must be applied to a trait with 1 generic argument
 --> pr-ex.rs:8:1
  |
8 | #[lang = "add"]
  | ^^^^^^^^^^^^^^^
9 | trait MyAdd<'a, T> {}
  |            ------- this trait has 2 generic arguments, not 1

error[E0369]: cannot add `{integer}` to `{integer}`
  --> pr-ex.rs:14:7
   |
14 |     r + a
   |     - ^ - {integer}
   |     |
   |     {integer}

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0369, E0718.
For more information about an error, try `rustc --explain E0369`.
```

3 years agoRollup merge of #85338 - lopopolo:core-iter-repeat-gh-81292, r=joshtriplett
Guillaume Gomez [Tue, 18 May 2021 12:08:46 +0000 (14:08 +0200)]
Rollup merge of #85338 - lopopolo:core-iter-repeat-gh-81292, r=joshtriplett

Implement more Iterator methods on core::iter::Repeat

`core::iter::Repeat` always returns the same element, which means we can
do better than implementing most `Iterator` methods in terms of
`Iterator::next`.

Fixes #81292.

#81292 raises the question of whether these changes violate the contract of `core::iter::Repeat`, but as far as I can tell `core::iter::repeat` doesn't make any guarantees around how it calls `Clone::clone`.

3 years agoRollup merge of #85280 - jsha:move-trait-toggles, r=GuillaumeGomez
Guillaume Gomez [Tue, 18 May 2021 12:08:42 +0000 (14:08 +0200)]
Rollup merge of #85280 - jsha:move-trait-toggles, r=GuillaumeGomez

Toggle-wrap items differently than top-doc.

This makes sure things like trait methods get wrapped at the
`<h3><code>` level rather than at the `.docblock` level. Also it ensures
that only the actual top documentation gets the `.top-doc` class.

Fixes #85167

Before:

![image](https://user-images.githubusercontent.com/220205/117743384-98790200-b1bb-11eb-8804-588530842514.png)

https://doc.rust-lang.org/nightly/std/io/trait.Read.html#tymethod.read

After:

![image](https://user-images.githubusercontent.com/220205/118410882-98a75080-b646-11eb-949d-ca688bab6923.png)

3 years agoRollup merge of #84587 - jyn514:rustdoc-lint-block, r=CraftSpider
Guillaume Gomez [Tue, 18 May 2021 12:08:41 +0000 (14:08 +0200)]
Rollup merge of #84587 - jyn514:rustdoc-lint-block, r=CraftSpider

rustdoc: Make "rust code block is empty" and "could not parse code block" warnings a lint (`INVALID_RUST_CODEBLOCKS`)

Fixes https://github.com/rust-lang/rust/issues/79792. This already went through FCP in https://github.com/rust-lang/rust/pull/79816, so it only needs final review.

This is mostly a rebase of https://github.com/rust-lang/rust/pull/79816 - thank you ``@poliorcetics`` for doing most of the work!

3 years agoAuto merge of #85313 - jackh726:region_eq, r=nikomatsakis
bors [Tue, 18 May 2021 12:07:56 +0000 (12:07 +0000)]
Auto merge of #85313 - jackh726:region_eq, r=nikomatsakis

Unify Regions with RegionVids in UnificationTable

A few test output changes; might be able to revert those but figured I would open this for perf and comments.

r? `@nikomatsakis`

3 years agoDon't pass -pie to linker on windows targets.
Luqman Aden [Tue, 18 May 2021 10:57:53 +0000 (03:57 -0700)]
Don't pass -pie to linker on windows targets.

3 years agoUndo unnecessary changes.
Luqman Aden [Tue, 18 May 2021 09:42:29 +0000 (02:42 -0700)]
Undo unnecessary changes.

3 years agoImprove display for "copy-path" button, making it more discrete
Guillaume Gomez [Mon, 17 May 2021 11:26:58 +0000 (13:26 +0200)]
Improve display for "copy-path" button, making it more discrete

3 years agoAuto merge of #82973 - ijackson:exitstatuserror, r=yaahc
bors [Tue, 18 May 2021 08:01:32 +0000 (08:01 +0000)]
Auto merge of #82973 - ijackson:exitstatuserror, r=yaahc

Provide ExitStatusError

Closes #73125

In MR #81452 "Add #[must_use] to [...] process::ExitStatus" we concluded that the existing arrangements in are too awkward so adding that `#[must_use]` is blocked on improving the ergonomics.

I wrote a mini-RFC-style discusion of the approach in https://github.com/rust-lang/rust/issues/73125#issuecomment-771092741

3 years agoAdd x.py pre-setup instructions
Lee Bradley [Tue, 18 May 2021 05:33:17 +0000 (00:33 -0500)]
Add x.py pre-setup instructions

This change adds pre-setup instructions that outline how x.py requires
python to be setup and how to work around the problem of x.py failing to
locate python, especially now that Ubuntu 20.04's dropped default python
command is causing people to encounter this issue regularly.

See also: #71818

3 years agoStabilize extended_key_value_attributes
Joshua Nelson [Mon, 22 Mar 2021 05:10:10 +0000 (01:10 -0400)]
Stabilize extended_key_value_attributes

 # Stabilization report

 ## Summary

This stabilizes using macro expansion in key-value attributes, like so:

 ```rust
 #[doc = include_str!("my_doc.md")]
 struct S;

 #[path = concat!(env!("OUT_DIR"), "/generated.rs")]
 mod m;
 ```

See the changes to the reference for details on what macros are allowed;
see Petrochenkov's excellent blog post [on internals](https://internals.rust-lang.org/t/macro-expansion-points-in-attributes/11455)
for alternatives that were considered and rejected ("why accept no more
and no less?")

This has been available on nightly since 1.50 with no major issues.

 ## Notes

 ### Accepted syntax

The parser accepts arbitrary Rust expressions in this position, but any expression other than a macro invocation will ultimately lead to an error because it is not expected by the built-in expression forms (e.g., `#[doc]`).  Note that decorators and the like may be able to observe other expression forms.

 ### Expansion ordering

Expansion of macro expressions in "inert" attributes occurs after decorators have executed, analogously to macro expressions appearing in the function body or other parts of decorator input.

There is currently no way for decorators to accept macros in key-value position if macro expansion must be performed before the decorator executes (if the macro can simply be copied into the output for later expansion, that can work).

 ## Test cases

 - https://github.com/rust-lang/rust/blob/master/src/test/ui/attributes/key-value-expansion-on-mac.rs
 - https://github.com/rust-lang/rust/blob/master/src/test/rustdoc/external-doc.rs

The feature has also been dogfooded extensively in the compiler and
standard library:

- https://github.com/rust-lang/rust/pull/83329
- https://github.com/rust-lang/rust/pull/83230
- https://github.com/rust-lang/rust/pull/82641
- https://github.com/rust-lang/rust/pull/80534

 ## Implementation history

- Initial proposal: https://github.com/rust-lang/rust/issues/55414#issuecomment-554005412
- Experiment to see how much code it would break: https://github.com/rust-lang/rust/pull/67121
- Preliminary work to restrict expansion that would conflict with this
feature: https://github.com/rust-lang/rust/pull/77271
- Initial implementation: https://github.com/rust-lang/rust/pull/78837
- Fix for an ICE: https://github.com/rust-lang/rust/pull/80563

 ## Unresolved Questions

~~https://github.com/rust-lang/rust/pull/83366#issuecomment-805180738 listed some concerns, but they have been resolved as of this final report.~~

 ## Additional Information

 There are two workarounds that have a similar effect for `#[doc]`
attributes on nightly. One is to emulate this behavior by using a limited version of this feature that was stabilized for historical reasons:

```rust
macro_rules! forward_inner_docs {
    ($e:expr => $i:item) => {
        #[doc = $e]
        $i
    };
}

forward_inner_docs!(include_str!("lib.rs") => struct S {});
```

This also works for other attributes (like `#[path = concat!(...)]`).
The other is to use `doc(include)`:

```rust
 #![feature(external_doc)]
 #[doc(include = "lib.rs")]
 struct S {}
```

The first works, but is non-trivial for people to discover, and
difficult to read and maintain. The second is a strange special-case for
a particular use of the macro. This generalizes it to work for any use
case, not just including files.

I plan to remove `doc(include)` when this is stabilized. The
`forward_inner_docs` workaround will still compile without warnings, but
I expect it to be used less once it's no longer necessary.

3 years agoFix must_use on `Option::is_none`
mbartlett21 [Tue, 18 May 2021 03:40:26 +0000 (13:40 +1000)]
Fix must_use on `Option::is_none`

This fixes the `#[must_use = ...]` on `Option::is_none` to have a working suggestion.

3 years agoFix rebase conflicts
Joshua Nelson [Tue, 18 May 2021 03:31:48 +0000 (23:31 -0400)]
Fix rebase conflicts

3 years agoadding algorithm explanation for partition_in_place iter method and bounding complexi...
Satyarth Agrahari [Tue, 18 May 2021 02:29:16 +0000 (07:59 +0530)]
adding algorithm explanation for partition_in_place iter method and bounding complexity to current implementation

3 years agoDon't require cmake on Windows when LLVM isn't being built
Joshua Nelson [Tue, 18 May 2021 02:07:30 +0000 (22:07 -0400)]
Don't require cmake on Windows when LLVM isn't being built

Previously, setting `download-ci-llvm = true` when cmake wasn't
installed would give the following error:

```
failed to execute command: "cmake" "--help"
error: The system cannot find the file specified. (os error 2)
```

3 years agoAddress review comments
Joshua Nelson [Tue, 4 May 2021 02:19:49 +0000 (22:19 -0400)]
Address review comments

- Simplify boolean expression
- Give an example of invalid syntax
- Remove explanation of why code block is text

3 years agoRename INVALID_RUST_CODEBLOCK{,S}
Joshua Nelson [Sat, 1 May 2021 01:28:32 +0000 (21:28 -0400)]
Rename INVALID_RUST_CODEBLOCK{,S}

3 years agoAdd back missing help for ignore blocks
Joshua Nelson [Mon, 26 Apr 2021 13:11:08 +0000 (09:11 -0400)]
Add back missing help for ignore blocks

This also gives a better error message when a span is missing.

3 years agoNew rustdoc lint to respect -Dwarnings correctly
Alexis Bourget [Mon, 28 Dec 2020 22:07:20 +0000 (23:07 +0100)]
New rustdoc lint to respect -Dwarnings correctly

This adds a new lint to `rustc` that is used in rustdoc when a code
block is empty or cannot be parsed as valid Rust code.

Previously this was unconditionally a warning. As such some
documentation comments were (unknowingly) abusing this to pass despite
the `-Dwarnings` used when compiling `rustc`, this should not be the
case anymore.

3 years agoAuto merge of #85402 - RalfJung:miri, r=RalfJung
bors [Tue, 18 May 2021 00:32:19 +0000 (00:32 +0000)]
Auto merge of #85402 - RalfJung:miri, r=RalfJung

update Miri

Fixes https://github.com/rust-lang/rust/issues/85397

3 years agoAdjust linker_is_gnu branches for cases that don't work on windows.
Luqman Aden [Mon, 17 May 2021 23:14:13 +0000 (16:14 -0700)]
Adjust linker_is_gnu branches for cases that don't work on windows.

3 years agoupdate Miri
Ralf Jung [Mon, 17 May 2021 22:47:52 +0000 (00:47 +0200)]
update Miri

3 years agoImplement jackh726's suggestions
Fabian Wolff [Mon, 17 May 2021 20:58:09 +0000 (22:58 +0200)]
Implement jackh726's suggestions

3 years agoAuto merge of #85414 - RalfJung:rollup-ueqcik4, r=RalfJung
bors [Mon, 17 May 2021 19:15:21 +0000 (19:15 +0000)]
Auto merge of #85414 - RalfJung:rollup-ueqcik4, r=RalfJung

Rollup of 8 pull requests

Successful merges:

 - #85087 (`eval_fn_call`: check the ABI of `body.source`)
 - #85302 (Expand WASI abbreviation in docs)
 - #85355 (More tests for issue-85255)
 - #85367 (Fix invalid input:disabled CSS selector)
 - #85374 (mark internal inplace_iteration traits as hidden)
 - #85408 (remove size field from Allocation)
 - #85409 (Simplify `cfg(any(unix, target_os="redox"))` in example to just `cfg(unix)`)
 - #85412 (remove some functions that were only used by Miri)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup

3 years agoPassWrapper: update for LLVM change D102093
Augie Fackler [Mon, 17 May 2021 18:12:38 +0000 (14:12 -0400)]
PassWrapper: update for LLVM change D102093

In https://reviews.llvm.org/D102093 lots of things stopped taking the
DebugLogging boolean parameter. Mercifully we appear to always set
DebugPassManager to false, so I don't think we're losing anything by not
passing this parameter.

3 years agoRemove remnants of BorrowOfPackedField
LeSeulArtichaut [Mon, 17 May 2021 17:32:14 +0000 (19:32 +0200)]
Remove remnants of BorrowOfPackedField

3 years agoruntest: correctly guard against LLVM version 13
Augie Fackler [Mon, 17 May 2021 17:08:42 +0000 (13:08 -0400)]
runtest: correctly guard against LLVM version 13

3 years agoRollup merge of #85412 - RalfJung:c_str, r=oli-obk
Ralf Jung [Mon, 17 May 2021 16:52:17 +0000 (18:52 +0200)]
Rollup merge of #85412 - RalfJung:c_str, r=oli-obk

remove some functions that were only used by Miri

and Miri does not need them any more with https://github.com/rust-lang/miri/pull/1805.

r? ``@oli-obk``

3 years agoRollup merge of #85409 - CDirkx:cfg_redox, r=nagisa
Ralf Jung [Mon, 17 May 2021 16:52:13 +0000 (18:52 +0200)]
Rollup merge of #85409 - CDirkx:cfg_redox, r=nagisa

Simplify `cfg(any(unix, target_os="redox"))` in example to just `cfg(unix)`

Update example for `OsString` that handled `redox` seperately from `unix`: Redox has been completely integrated under `target_family="unix"`, so `cfg(unix)` implies `target_os="redox"`

https://github.com/rust-lang/rust/blob/35dbef235048f9a2939dc20effe083ca483c37ff/compiler/rustc_target/src/spec/redox_base.rs#L26

3 years agoRollup merge of #85408 - RalfJung:alloc-size, r=oli-obk
Ralf Jung [Mon, 17 May 2021 16:52:11 +0000 (18:52 +0200)]
Rollup merge of #85408 - RalfJung:alloc-size, r=oli-obk

remove size field from Allocation

This is a part of https://github.com/rust-lang/rust/pull/85376 that can be easily split out.
r? ``@oli-obk``

3 years agoRollup merge of #85374 - the8472:hide-internal-traits, r=SimonSapin
Ralf Jung [Mon, 17 May 2021 16:52:10 +0000 (18:52 +0200)]
Rollup merge of #85374 - the8472:hide-internal-traits, r=SimonSapin

mark internal inplace_iteration traits as hidden

resolves #85373

r? ``@SimonSapin``

3 years agoRollup merge of #85367 - GuillaumeGomez:fix-css-rule, r=jsha
Ralf Jung [Mon, 17 May 2021 16:52:09 +0000 (18:52 +0200)]
Rollup merge of #85367 - GuillaumeGomez:fix-css-rule, r=jsha

Fix invalid input:disabled CSS selector

For some reason, we used "search-focus" instead of "search-input"...

r? ``@jsha``

3 years agoRollup merge of #85355 - hi-rustin:rustin-patch-issue-85255, r=varkor
Ralf Jung [Mon, 17 May 2021 16:52:08 +0000 (18:52 +0200)]
Rollup merge of #85355 - hi-rustin:rustin-patch-issue-85255, r=varkor

More tests for issue-85255

Add more test for `pub(crate)`.

r? ``@varkor``

3 years agoRollup merge of #85302 - r00ster91:patch-7, r=joshtriplett
Ralf Jung [Mon, 17 May 2021 16:52:04 +0000 (18:52 +0200)]
Rollup merge of #85302 - r00ster91:patch-7, r=joshtriplett

Expand WASI abbreviation in docs

I was pretty sure this was related to something for WebAssembly but wasn't 100% sure so I checked but even on these top-level docs I couldn't find the abbreviation expanded. I'm normally used to Rust docs being detailed and explanatory and writing abbreviations like this out in full at least once so I thought it was worth the change. Feel free to close this if it's too much.

3 years agoRollup merge of #85087 - hyd-dev:lots-of-abis, r=RalfJung
Ralf Jung [Mon, 17 May 2021 16:51:59 +0000 (18:51 +0200)]
Rollup merge of #85087 - hyd-dev:lots-of-abis, r=RalfJung

`eval_fn_call`: check the ABI of `body.source`

And stop checking `instance_ty.fn_sig(*self.tcx).abi()`, if the function is not an intrinsic.
Addresses https://github.com/rust-lang/miri/pull/1776#discussion_r615381169.
No idea how to test this without Miri...

3 years agoAuto merge of #85352 - Xanewok:update-rls, r=Xanewok
bors [Mon, 17 May 2021 16:34:11 +0000 (16:34 +0000)]
Auto merge of #85352 - Xanewok:update-rls, r=Xanewok

Update RLS

Contains https://github.com/rust-lang/rls/pull/1736. With #82208 merged, this should now close https://github.com/rust-lang/rust/issues/85225. Tested locally with `./x.py test src/tools/rls` and seems to be working as expected.

I noticed the rustfmt merge didn't trigger toolstate upgrade (because we pruned most but not all of the related machinery?), so I'd rather get this rubber-stamped by someone more knowledgeable with infra/the merged changes in case I missed something and need to include something else here to unbreak the RLS toolstate.

r? `@Mark-Simulacrum`

3 years agoAvoid zero-length write_str in fmt::write
Mark Rousskov [Mon, 17 May 2021 13:30:58 +0000 (09:30 -0400)]
Avoid zero-length write_str in fmt::write

3 years agoOptimize default ToString impl
Mark Rousskov [Mon, 17 May 2021 01:31:18 +0000 (21:31 -0400)]
Optimize default ToString impl

This avoids a zero-length write_str call, which boils down to a zero-length
memmove and ultimately costs quite a few instructions on some workloads.

This is approximately a 0.33% instruction count win on diesel-check.

3 years agoRemove legacy for trait object mangling test and replace crate hash
Jack Huey [Sun, 16 May 2021 03:18:59 +0000 (23:18 -0400)]
Remove legacy for trait object mangling test and replace crate hash

3 years agoAdd a comment for `check_abi()`
hyd-dev [Mon, 17 May 2021 12:54:31 +0000 (20:54 +0800)]
Add a comment for `check_abi()`

3 years agoremove some functions that were only used by Miri
Ralf Jung [Mon, 17 May 2021 12:42:27 +0000 (14:42 +0200)]
remove some functions that were only used by Miri

3 years agoAuto merge of #84571 - jedel1043:issue-49804-impl, r=petrochenkov
bors [Mon, 17 May 2021 12:15:26 +0000 (12:15 +0000)]
Auto merge of #84571 - jedel1043:issue-49804-impl, r=petrochenkov

Parse unnamed fields of struct and union type

Added the `unnamed_fields` feature gate.

This is a prototype of [RFC 2102](https://github.com/rust-lang/rust/issues/49804), so any suggestions are greatly appreciated.

r? `@petrochenkov`

3 years agoTwo minor changes for readability and efficiency
Fabian Wolff [Mon, 17 May 2021 11:56:11 +0000 (13:56 +0200)]
Two minor changes for readability and efficiency

3 years agoSimplify `cfg(any(unix, target_os="redox"))` to just `cfg(unix)`
Christiaan Dirkx [Mon, 17 May 2021 11:49:14 +0000 (13:49 +0200)]
Simplify `cfg(any(unix, target_os="redox"))` to just `cfg(unix)`

3 years agomir-opt bless for Size field being removed from Allocation
Ralf Jung [Sun, 16 May 2021 17:44:19 +0000 (19:44 +0200)]
mir-opt bless for Size field being removed from Allocation

3 years agoremove size field from Allocation
Ralf Jung [Mon, 17 May 2021 11:30:16 +0000 (13:30 +0200)]
remove size field from Allocation

3 years agobackport 1.52.1 release notes
Pietro Albini [Mon, 17 May 2021 10:03:49 +0000 (12:03 +0200)]
backport 1.52.1 release notes

3 years ago:arrow_up: rust-analyzer
Laurențiu Nicola [Mon, 17 May 2021 06:56:57 +0000 (09:56 +0300)]
:arrow_up: rust-analyzer

3 years agoAuto merge of #85353 - jonas-schievink:async-blocks-in-ctfe, r=oli-obk
bors [Mon, 17 May 2021 04:53:30 +0000 (04:53 +0000)]
Auto merge of #85353 - jonas-schievink:async-blocks-in-ctfe, r=oli-obk

Allow `async {}` expressions in const contexts

Gated behind a new `const_async_blocks` feature.

3 years agorustdoc: restore header sizes
Jacob Hoffman-Andrews [Mon, 17 May 2021 03:47:03 +0000 (20:47 -0700)]
rustdoc: restore header sizes

3 years agoAllow formatting `Anonymous{Struct, Union}` declarations
jedel1043 [Mon, 17 May 2021 03:13:38 +0000 (22:13 -0500)]
Allow formatting `Anonymous{Struct, Union}` declarations

3 years agoSuppress spurious errors inside `async fn`
Aaron Hill [Mon, 17 May 2021 02:26:57 +0000 (22:26 -0400)]
Suppress spurious errors inside `async fn`

Fixes #73741

3 years agoAuto merge of #85178 - cjgillot:local-crate, r=oli-obk
bors [Mon, 17 May 2021 01:42:03 +0000 (01:42 +0000)]
Auto merge of #85178 - cjgillot:local-crate, r=oli-obk

Remove CrateNum parameter for queries that only work on local crate

The pervasive `CrateNum` parameter is a remnant of the multi-crate rustc idea.

Using `()` as query key in those cases avoids having to worry about the validity of the query key.

3 years agoAuto merge of #84993 - eddyb:cg-ssa-on-demand-blocks, r=nagisa
bors [Sun, 16 May 2021 23:00:53 +0000 (23:00 +0000)]
Auto merge of #84993 - eddyb:cg-ssa-on-demand-blocks, r=nagisa

rustc_codegen_ssa: only create backend `BasicBlock`s as-needed.

Instead of creating one backend (e.g. LLVM) block per MIR block ahead of time, and then deleting the ones that weren't visited, this PR moves to creating the blocks as they're needed (either reached via the RPO visit, or used as the target of a branch from a different block).

As deleting a block was the only `unsafe` builder method (generally we only *create* backend objects, not *remove* them), that's gone now and codegen is overall a bit safer.

The only change in output is the order of LLVM blocks (which AFAIK has no semantic meaning, other than the first block being the entry block). This happens because the blocks are now created due to control-flow edges, rather than MIR block order.

I'm making this a standalone PR because I keep getting wild perf results when I change *anything* in codegen, but if you want to read more about my plans in this area, see https://github.com/rust-lang/rust/pull/84771#issuecomment-830636256 (and https://github.com/rust-lang/rust/pull/84771#issue-628295651 - but that may be a bit outdated).

(You may notice some of the APIs in this PR, like `append_block`, don't help with the future plans - but I didn't want to include the necessary refactors that pass a build around everywhere, in this PR, so it's a small compromise)

r? `@nagisa` `@bjorn3`

3 years agoAlways produce sub-obligations when using cached projection result
Aaron Hill [Sun, 16 May 2021 21:18:17 +0000 (17:18 -0400)]
Always produce sub-obligations when using cached projection result

3 years agorustc_codegen_ssa: append blocks to functions w/o creating a builder.
Eduard-Mihai Burtescu [Thu, 6 May 2021 15:57:04 +0000 (18:57 +0300)]
rustc_codegen_ssa: append blocks to functions w/o creating a builder.

3 years agorustc_codegen_ssa: only create backend `BasicBlock`s as-needed.
Eduard-Mihai Burtescu [Thu, 6 May 2021 14:37:19 +0000 (17:37 +0300)]
rustc_codegen_ssa: only create backend `BasicBlock`s as-needed.

3 years agoAuto merge of #85312 - ehuss:macro_use-unused-attr, r=petrochenkov
bors [Sun, 16 May 2021 20:19:45 +0000 (20:19 +0000)]
Auto merge of #85312 - ehuss:macro_use-unused-attr, r=petrochenkov

Fix unused attributes on macro_rules.

The `unused_attributes` lint wasn't firing on attributes of `macro_rules` definitions. The consequence is that many attributes are silently ignored on `macro_rules`. The reason is that `unused_attributes` is a late-lint pass, and only has access to the HIR, which does not have macro_rules definitions.

My solution here is to change `non_exported_macro_attrs` to be `macro_attrs` (a list of all attributes used for `macro_rules`, instead of just those for `macro_export`), and then to check this list in the `unused_attributes` lint. There are a number of alternate approaches, but this seemed the most reliable and least invasive. I am open to completely different approaches, though.

One concern is that I don't fully understand the implications of extending `non_exported_macro_attrs` to include non-exported macros. That list was originally added in #62042 to handle stability attributes, so I suspect it was just an optimization since that was all that was needed. It was later extended to be included in SVH in #83901. #80641 also added a use to check for `invalid` attributes, which seems a little odd to me (it didn't validate non-exported macros, and seems highly specific).

Overall, there doesn't seem to be a clear story of when `unused_attributes` should be used versus an error like E0518. I considered alternatively using an "allow list" of built-in attributes that can be used on macro_rules (allow, warn, deny, forbid, cfg, cfg_attr, macro_export, deprecated, doc), but I feel like that could be a pain to maintain.

Some built-in attributes already present hard-errors when used with macro_rules. These are each hard-coded in various places:
- `derive`
- `test` and `bench`
- `proc_macro` and `proc_macro_derive`
- `inline`
- `global_allocator`

The primary motivation is that I sometimes see people use `#[macro_use]` in front of `macro_rules`, which indicates there is some confusion out there (evident that there was even a case of it in rustc).

3 years agoAdd tracking issue
Jonas Schievink [Sun, 16 May 2021 12:59:32 +0000 (14:59 +0200)]
Add tracking issue

3 years agoAdd test for trait toggle location
Jacob Hoffman-Andrews [Sun, 16 May 2021 19:50:15 +0000 (12:50 -0700)]
Add test for trait toggle location

3 years agoAuto merge of #85290 - Amanieu:asm_const_int, r=nagisa
bors [Sun, 16 May 2021 17:52:52 +0000 (17:52 +0000)]
Auto merge of #85290 - Amanieu:asm_const_int, r=nagisa

Remove support for floating-point constants in asm!

Floating-point constants aren't very useful anyways and this simplifies
the code since the type check can now be done in typeck.

cc `@rust-lang/wg-inline-asm`

r? `@nagisa`

3 years agomark internal inplace_iteration traits as hidden
The8472 [Sun, 16 May 2021 16:48:35 +0000 (18:48 +0200)]
mark internal inplace_iteration traits as hidden

3 years agoAdd regression test
Giacomo Stevanato [Sun, 16 May 2021 16:33:41 +0000 (18:33 +0200)]
Add regression test

3 years agoConsider edge cases in missing lifetime diagnostics
Giacomo Stevanato [Sun, 16 May 2021 16:33:32 +0000 (18:33 +0200)]
Consider edge cases in missing lifetime diagnostics

3 years agoImplement changes suggested by varkor
Fabian Wolff [Sun, 16 May 2021 16:16:00 +0000 (18:16 +0200)]
Implement changes suggested by varkor

3 years agoAuto merge of #84549 - tmiasko:static-initializer, r=varkor
bors [Sun, 16 May 2021 15:11:48 +0000 (15:11 +0000)]
Auto merge of #84549 - tmiasko:static-initializer, r=varkor

Reachable statics have reachable initializers

Static initializer can read other statics. Initializers are evaluated at
compile time, and so their content could become inlined into another
crate. Ensure that initializers of reachable statics are also reachable.

Previously, when an item incorrectly considered to be unreachable was
reached from another crate an attempt would be made to codegen it. The
attempt could fail with an ICE (in the case MIR wasn't available to do
so) in some circumstances the attempt could also succeed resulting in
a local codegen of non-local items, including static ones.

Fixes #84455.

3 years agoAdd test for restriction of anonymous types on validation
jedel1043 [Sun, 16 May 2021 14:53:17 +0000 (09:53 -0500)]
Add test for restriction of anonymous types on validation

3 years agoCheck and deny anonymous fields on `ast_validation`
jedel1043 [Sun, 16 May 2021 14:51:00 +0000 (09:51 -0500)]
Check and deny anonymous fields on `ast_validation`

3 years agoImplement Anonymous{Struct, Union} in the AST
jedel1043 [Sun, 16 May 2021 14:49:16 +0000 (09:49 -0500)]
Implement Anonymous{Struct, Union} in the AST

Add unnamed_fields feature gate and gate unnamed fields on parsing

3 years agoSuggest borrowing if a trait implementation is found for &/&mut <type>
Fabian Wolff [Sun, 16 May 2021 14:20:35 +0000 (16:20 +0200)]
Suggest borrowing if a trait implementation is found for &/&mut <type>

3 years agoFix invalid input:disabled CSS selector
Guillaume Gomez [Sun, 16 May 2021 12:49:44 +0000 (14:49 +0200)]
Fix invalid input:disabled CSS selector

3 years agoAuto merge of #85316 - eddyb:cg-ssa-on-demand-cleanuppad, r=nagisa
bors [Sun, 16 May 2021 12:30:07 +0000 (12:30 +0000)]
Auto merge of #85316 - eddyb:cg-ssa-on-demand-cleanuppad, r=nagisa

rustc_codegen_ssa: generate MSVC cleanup pads on demand, like GNU landing pads.

This unblocks #84993 in terms of codegen tests, as it brings the MSVC-style (`cleanup_pad`) EH (LLVM) block order in line with the GNU-style (`landing_pad`) EH (LLVM) block order, by having both of them be on-demand (instead of MSVC-style being eager and GNU-style lazy/on-demand).

It also unifies the two implementations a bit, similar to #84699, but in the opposite direction (as that attempt made both kinds of EH pads eagerly built).

~~Opening as draft because I haven't done enough Windows testing just yet, of both this PR, and of #84993 rebased on it.~~ (**EDIT**: seems to be working as expected)

r? `@nagisa`

3 years agoAuto merge of #85332 - RalfJung:ptr-in-str, r=oli-obk
bors [Sun, 16 May 2021 09:49:12 +0000 (09:49 +0000)]
Auto merge of #85332 - RalfJung:ptr-in-str, r=oli-obk

CTFE validation: handle pointers in str

I also finally learned how I can match *some* NOTEs in a ui test without matching all of them, and applied that to some const tests in the 2nd commit where I added NOTE because I did not know what I was doing. I can separate this into its own PR if you prefer.

Fixes https://github.com/rust-lang/rust/issues/83182
r? `@oli-obk`

3 years agoAuto merge of #85304 - Stupremee:crates-in-sidebar-in-root, r=Nemo157
bors [Sun, 16 May 2021 07:32:57 +0000 (07:32 +0000)]
Auto merge of #85304 - Stupremee:crates-in-sidebar-in-root, r=Nemo157

rustdoc: Call `initSidebarItems` in root module of crate

r? `@jsha`

Resolves #85301

3 years agoWindows mingw targets use gcc as the linker so the target spec should also indicate...
Luqman Aden [Sun, 16 May 2021 05:09:34 +0000 (22:09 -0700)]
Windows mingw targets use gcc as the linker so the target spec should also indicate linker_is_gnu.

3 years agoAuto merge of #85279 - DrChat:asm_powerpc64, r=Amanieu
bors [Sun, 16 May 2021 04:47:52 +0000 (04:47 +0000)]
Auto merge of #85279 - DrChat:asm_powerpc64, r=Amanieu

Add asm!() support for PowerPC64

I was anticipating this to be difficult so I didn't do it as part of #84732... but this was pretty easy to do ðŸ‘€

3 years agoAdd comments to opportunistic resolve functions
Jack Huey [Sun, 16 May 2021 03:36:10 +0000 (23:36 -0400)]
Add comments to opportunistic resolve functions

3 years agoFix comments in tests
Amanieu d'Antras [Sun, 16 May 2021 02:54:08 +0000 (03:54 +0100)]
Fix comments in tests

3 years agoMore tests for issue-85255
hi-rustin [Sun, 16 May 2021 02:18:28 +0000 (10:18 +0800)]
More tests for issue-85255

3 years agoAuto merge of #85259 - Smittyvb:thir-unsafeck-inline-asm, r=nikomatsakis
bors [Sun, 16 May 2021 00:54:01 +0000 (00:54 +0000)]
Auto merge of #85259 - Smittyvb:thir-unsafeck-inline-asm, r=nikomatsakis

Check for inline assembly in THIR unsafeck

#83129 was merged recently and added a THIR unsafe checker. This adds a check for inline assembly. (and this is 2x simpler than the MIR version, which has to check for `asm` and `llvm_asm` in two separate spots!)

 see also rust-lang/project-thir-unsafeck#7

3 years agoAllow `async {}` expressions in const contexts
Jonas Schievink [Sun, 16 May 2021 00:04:58 +0000 (02:04 +0200)]
Allow `async {}` expressions in const contexts

3 years agoUpdate RLS
Igor Matuszewski [Sat, 15 May 2021 23:30:39 +0000 (01:30 +0200)]
Update RLS

3 years agoFix unused attributes on macro_rules.
Eric Huss [Sat, 15 May 2021 23:10:17 +0000 (16:10 -0700)]
Fix unused attributes on macro_rules.

3 years agoAuto merge of #81858 - ijackson:fork-no-unwind, r=m-ou-se
bors [Sat, 15 May 2021 22:27:09 +0000 (22:27 +0000)]
Auto merge of #81858 - ijackson:fork-no-unwind, r=m-ou-se

Do not allocate or unwind after fork

### Objective scenarios

 * Make (simple) panics safe in `Command::pre_exec_hook`, including most `panic!` calls, `Option::unwrap`, and array bounds check failures.
 * Make it possible to `libc::fork` and then safely panic in the child (needed for the above, but this requirement means exposing the new raw hook API which the `Command` implementation needs).
 * In singlethreaded programs, where panic in `pre_exec_hook` is already memory-safe, prevent the double-unwinding malfunction #79740.

I think we want to make panic after fork safe even though the post-fork child environment is only experienced by users of `unsafe`, beause the subset of Rust in which any panic is UB is really far too hazardous and unnatural.

#### Approach

 * Provide a way for a program to, at runtime, switch to having panics abort.  This makes it possible to panic without making *any* heap allocations, which is needed because on some platforms malloc is UB in a child forked from a multithreaded program (see https://github.com/rust-lang/rust/pull/80263#issuecomment-774272370, and maybe also the SuS [spec](https://pubs.opengroup.org/onlinepubs/9699919799/functions/fork.html)).
 * Make that change in the child spawned by `Command`.
 * Document the rules comprehensively enough that a programmer has a fighting chance of writing correct code.
 * Test that this all works as expected (and in particular, that there aren't any heap allocations we missed)

Fixes #79740

#### Rejected (or previously attempted) approaches

 * Change the panic machinery to be able to unwind without allocating, at least when the payload and message are both `'static`.  This seems like it would be even more subtle.  Also that is a potentially-hot path which I don't want to mess with.
 * Change the existing panic hook mechanism to not convert the message to a `String` before calling the hook.  This would be a surprising change for existing code and would not be detected by the type system.
 * Provide a `raw_panic_hook` function to intercept panics in a way that doesn't allocate.  (That was an earlier version of this MR.)

### History

This MR could be considered a v2 of #80263.  Thanks to everyone who commented there.  In particular, thanks to `@m-ou-se,` `@Mark-Simulacrum` and `@hyd-dev.`  (Tagging you since I think you might be interested in this new MR.)  Compared to #80263, this MR has very substantial changes and additions.

Additionally, I have recently (2021-04-20) completely revised this series following very helpful comments from `@m-ou-se.`

r? `@m-ou-se`

3 years agoAuto merge of #84920 - Aaron1011:pretty-print-rental, r=petrochenkov
bors [Sat, 15 May 2021 19:58:59 +0000 (19:58 +0000)]
Auto merge of #84920 - Aaron1011:pretty-print-rental, r=petrochenkov

Remove some unncessary spaces from pretty-printed tokenstream output

In addition to making the output look nicer for all crates, this also
aligns the pretty-printing output with what the `rental` crate expects.
This will allow us to eventually disable a backwards-compat hack in a
follow-up PR.

See https://github.com/rust-lang/rust/issues/84428 for some background information about why we want to make this change. Note that this change would be desirable (but not particularly necessary) even if `rental` didn't exist, so we're not adding any crate-specific hacks into the compiler.

3 years agoChange to just use first binders and add test
Jack Huey [Sat, 15 May 2021 19:19:01 +0000 (15:19 -0400)]
Change to just use first binders and add test

3 years agoReport an error if a lang item has the wrong number of generic arguments
Fabian Wolff [Sat, 15 May 2021 17:53:16 +0000 (19:53 +0200)]
Report an error if a lang item has the wrong number of generic arguments

3 years agoAuto merge of #85335 - GuillaumeGomez:rollup-0tvc14g, r=GuillaumeGomez
bors [Sat, 15 May 2021 17:37:18 +0000 (17:37 +0000)]
Auto merge of #85335 - GuillaumeGomez:rollup-0tvc14g, r=GuillaumeGomez

Rollup of 4 pull requests

Successful merges:

 - #84751 (str::is_char_boundary - slight optimization)
 - #85185 (Generate not more docs than necessary)
 - #85324 (Warn about unused `pub` fields in non-`pub` structs)
 - #85329 (fix version_str comment)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup

3 years agoImplement more Iterator methods on core::iter::Repeat
Ryan Lopopolo [Sat, 15 May 2021 17:37:05 +0000 (10:37 -0700)]
Implement more Iterator methods on core::iter::Repeat

`core::iter::Repeat` always returns the same element, which means we can
do better than implementing most `Iterator` methods in terms of
`Iterator::next`.

Fixes #81292.

3 years agoCall `initSidebarItems` in root module of crate
Justus K [Fri, 14 May 2021 20:45:00 +0000 (22:45 +0200)]
Call `initSidebarItems` in root module of crate

3 years ago32bit bless
Ralf Jung [Sat, 15 May 2021 16:42:35 +0000 (18:42 +0200)]
32bit bless

3 years agoMissed a couple things
Jack Huey [Sat, 15 May 2021 16:26:50 +0000 (12:26 -0400)]
Missed a couple things

3 years agoAdd comment
Jack Huey [Sat, 15 May 2021 16:12:56 +0000 (12:12 -0400)]
Add comment

3 years agoRevert to only using opportunistic_resolve_vars for existing places
Jack Huey [Sat, 15 May 2021 16:10:56 +0000 (12:10 -0400)]
Revert to only using opportunistic_resolve_vars for existing places

3 years agoRemove some unncessary spaces from pretty-printed tokenstream output
Aaron Hill [Sat, 1 May 2021 19:54:47 +0000 (15:54 -0400)]
Remove some unncessary spaces from pretty-printed tokenstream output

In addition to making the output look nicer for all crates, this also
aligns the pretty-printing output with what the `rental` crate expects.
This will allow us to eventually disable a backwards-compat hack in a
follow-up PR.

3 years agosplit ui test stderr by bitwidth
Ralf Jung [Sat, 15 May 2021 16:02:39 +0000 (18:02 +0200)]
split ui test stderr by bitwidth

3 years agoRollup merge of #85329 - RalfJung:version, r=Mark-Simulacrum
Guillaume Gomez [Sat, 15 May 2021 15:56:50 +0000 (17:56 +0200)]
Rollup merge of #85329 - RalfJung:version, r=Mark-Simulacrum

fix version_str comment

This version string is ultimately generated here
https://github.com/rust-lang/rust/blob/87423fbc6af5aae2b5f6d0a11f2a0c60c7c22e98/src/bootstrap/channel.rs#L72
and I don't think it includes the `rustc` prefix. That also matches its use here
https://github.com/rust-lang/rust/blob/ac923d94f86a6f7c881ecbedcd0a68d7986a35bd/compiler/rustc_driver/src/lib.rs#L758

3 years agoRollup merge of #85324 - FabianWolff:issue-85255, r=varkor
Guillaume Gomez [Sat, 15 May 2021 15:56:49 +0000 (17:56 +0200)]
Rollup merge of #85324 - FabianWolff:issue-85255, r=varkor

Warn about unused `pub` fields in non-`pub` structs

This pull request fixes #85255. The current implementation of dead code analysis is too prudent because it marks all `pub` fields of structs as live, even though they cannot be accessed from outside of the current crate if the struct itself only has restricted or private visibility.

I have changed this behavior to take the containing struct's visibility into account when looking at field visibility and liveness. This also makes dead code warnings more consistent; consider the example given in #85255:
```rust
struct Foo {
    a: i32,
    pub b: i32,
}

struct Bar;

impl Bar {
    fn a(&self) -> i32 { 5 }
    pub fn b(&self) -> i32 { 6 }
}

fn main() {
    let _ = Foo { a: 1, b: 2 };
    let _ = Bar;
}
```
Current nightly already warns about `Bar::b()`, even though it is `pub` (but `Bar` is not). It should therefore also warn about `Foo::b`, which it does with the changes in this PR.

3 years agoRollup merge of #85185 - GuillaumeGomez:generate-not-more-docs-than-necessary, r...
Guillaume Gomez [Sat, 15 May 2021 15:56:48 +0000 (17:56 +0200)]
Rollup merge of #85185 - GuillaumeGomez:generate-not-more-docs-than-necessary, r=Mark-Simulacrum

Generate not more docs than necessary

This is something that `@Nemo157` was talking about: they wanted that when using `x.py doc std`, it only generated `std` (and the crates "before" it).

r? `@Mark-Simulacrum`

3 years agoRollup merge of #84751 - Soveu:is_char_boundary_opt, r=Amanieu
Guillaume Gomez [Sat, 15 May 2021 15:56:47 +0000 (17:56 +0200)]
Rollup merge of #84751 - Soveu:is_char_boundary_opt, r=Amanieu

str::is_char_boundary - slight optimization

Current `str::is_char_boundary` implementation emits slightly more instructions, because it includes an additional branch for `index == s.len()`
```rust
pub fn is_char_boundary(s: &str, index: usize) -> bool {
    if index == 0 || index == s.len() {
        return true;
    }
    match s.as_bytes().get(index) {
        None => false,
        Some(&b) => (b as i8) >= -0x40,
    }
}
```
Just changing the place of `index == s.len()` merges it with `index < s.len()` from `s.as_bytes().get(index)`
```rust
pub fn is_char_boundary2(s: &str, index: usize) -> bool {
    if index == 0 {
        return true;
    }

    match s.as_bytes().get(index) {
        // For some reason, LLVM likes this comparison here more
        None => index == s.len(),
        // This is bit magic equivalent to: b < 128 || b >= 192
        Some(&b) => (b as i8) >= -0x40,
    }
}
```
This one has better codegen on every platform, except powerpc
<details><summary>x86 codegen</summary>
<p>

```nasm
example::is_char_boundary:
        mov     al, 1
        test    rdx, rdx
        je      .LBB0_5
        cmp     rsi, rdx
        je      .LBB0_5
        cmp     rsi, rdx
        jbe     .LBB0_3
        cmp     byte ptr [rdi + rdx], -65
        setg    al
.LBB0_5:
        ret
.LBB0_3:
        xor     eax, eax
        ret

example::is_char_boundary2:
        test    rdx, rdx
        je      .LBB1_1
        cmp     rsi, rdx
        jbe     .LBB1_4
        cmp     byte ptr [rdi + rdx], -65
        setg    al
        ret
.LBB1_1:  ; technically this branch is the same as LBB1_4
        mov     al, 1
        ret
.LBB1_4:
        sete    al
        ret
 ```
</p>
</details>

<details><summary>aarch64 codegen</summary>
<p>

```as
example::is_char_boundary:
        mov     x8, x0
        mov     w0, #1
        cbz     x2, .LBB0_4
        cmp     x1, x2
        b.eq    .LBB0_4
        b.ls    .LBB0_5
        ldrsb   w8, [x8, x2]
        cmn     w8, #65
        cset    w0, gt
.LBB0_4:
        ret
.LBB0_5:
        mov     w0, wzr
        ret

example::is_char_boundary2:
        cbz     x2, .LBB1_3
        cmp     x1, x2
        b.ls    .LBB1_4
        ldrsb   w8, [x0, x2]
        cmn     w8, #65
        cset    w0, gt
        ret
.LBB1_3:
        mov     w0, #1
        ret
.LBB1_4:
        cset    w0, eq
        ret
```

</p>
</details>

<details><summary>riscv64gc codegen</summary>
<p>

example::is_char_boundary:
        seqz    a3, a2
        xor     a4, a1, a2
        seqz    a4, a4
        or      a4, a4, a3
        addi    a3, zero, 1
        bnez    a4, .LBB0_3
        bgeu    a2, a1, .LBB0_4
        add     a0, a0, a2
        lb      a0, 0(a0)
        addi    a1, zero, -65
        slt     a3, a1, a0
.LBB0_3:
        mv      a0, a3
        ret
.LBB0_4:
        mv      a0, zero
        ret

example::is_char_boundary2:
        beqz    a2, .LBB1_3
        bgeu    a2, a1, .LBB1_4
        add     a0, a0, a2
        lb      a0, 0(a0)
        addi    a1, zero, -65
        slt     a0, a1, a0
        ret
.LBB1_3:
        addi    a0, zero, 1
        ret
.LBB1_4:
        xor     a0, a1, a2
        seqz    a0, a0
        ret

</p>
</details>

[Link to godbolt](https://godbolt.org/z/K8avEz8Gr)

`@rustbot` label: A-codegen