]> git.lizzy.rs Git - rust.git/log
rust.git
2 years agoCorrect typo
est31 [Sun, 5 Sep 2021 06:04:20 +0000 (08:04 +0200)]
Correct typo

2 years agoAuto merge of #87699 - ubamrein:use-iphone-deployment-target-for-llvm, r=petrochenkov
bors [Tue, 24 Aug 2021 12:13:37 +0000 (12:13 +0000)]
Auto merge of #87699 - ubamrein:use-iphone-deployment-target-for-llvm, r=petrochenkov

Allow specifying an deployment target version for all iOS llvm targets

Closes: https://github.com/rust-lang/rust/issues/79408
This pull requests adds the same procedure to define the iOS-version for the LLVM-target as was used for the simulator target and the desktop target.

This then closes the original problem mentioned in the above issue. The problem with incompatible bitcode remains, but is probably not easy fixable.

I realised that something is still not right. Try to fix that.

r? `@petrochenkov`

2 years agoallow specifying an ios version for the llvm target
Patrick Amrein [Mon, 2 Aug 2021 13:26:24 +0000 (15:26 +0200)]
allow specifying an ios version for the llvm target

2 years agoAuto merge of #87739 - Aaron1011:remove-used-attrs, r=wesleywiser
bors [Tue, 24 Aug 2021 03:58:22 +0000 (03:58 +0000)]
Auto merge of #87739 - Aaron1011:remove-used-attrs, r=wesleywiser

Remove `Session.used_attrs` and move logic to `CheckAttrVisitor`

Instead of updating global state to mark attributes as used,
we now explicitly emit a warning when an attribute is used in
an unsupported position. As a side effect, we are to emit more
detailed warning messages (instead of just a generic "unused" message).

`Session.check_name` is removed, since its only purpose was to mark
the attribute as used. All of the callers are modified to use
`Attribute.has_name`

Additionally, `AttributeType::AssumedUsed` is removed - an 'assumed
used' attribute is implemented by simply not performing any checks
in `CheckAttrVisitor` for a particular attribute.

We no longer emit unused attribute warnings for the `#[rustc_dummy]`
attribute - it's an internal attribute used for tests, so it doesn't
mark sense to treat it as 'unused'.

With this commit, a large source of global untracked state is removed.

2 years agoAuto merge of #85556 - FabianWolff:issue-85071, r=estebank,jackh726
bors [Tue, 24 Aug 2021 01:36:09 +0000 (01:36 +0000)]
Auto merge of #85556 - FabianWolff:issue-85071, r=estebank,jackh726

Warn about unreachable code following an expression with an uninhabited type

This pull request fixes #85071. The issue is that liveness analysis currently is "smarter" than reachability analysis when it comes to detecting uninhabited types: Unreachable code is detected during type checking, where full type information is not yet available. Therefore, the check for type inhabitedness is quite crude:
https://github.com/rust-lang/rust/blob/fc81ad22c453776de16acf9938976930cf8c9401/compiler/rustc_typeck/src/check/expr.rs#L202-L205

i.e. it only checks for `!`, but not other, non-trivially uninhabited types, such as empty enums, structs containing an uninhabited type, etc. By contrast, liveness analysis, which runs after type checking, can benefit from the more sophisticated `tcx.is_ty_uninhabited_from()`:
https://github.com/rust-lang/rust/blob/fc81ad22c453776de16acf9938976930cf8c9401/compiler/rustc_passes/src/liveness.rs#L981
https://github.com/rust-lang/rust/blob/fc81ad22c453776de16acf9938976930cf8c9401/compiler/rustc_passes/src/liveness.rs#L996

This can lead to confusing warnings when a variable is reported as unused, but the use of the variable is not reported as unreachable. For instance:
```rust
enum Foo {}
fn f() -> Foo {todo!()}

fn main() {
    let x = f();
    let _ = x;
}
```
currently leads to
```
warning: unused variable: `x`
 --> t1.rs:5:9
  |
5 |     let x = f();
  |         ^ help: if this is intentional, prefix it with an underscore: `_x`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: 1 warning emitted
```
which is confusing, because `x` _appears_ to be used in line 6. With my changes, I get:
```
warning: unreachable expression
 --> t1.rs:6:13
  |
5 |     let x = f();
  |             --- any code following this expression is unreachable
6 |     let _ = x;
  |             ^ unreachable expression
  |
  = note: `#[warn(unreachable_code)]` on by default
note: this expression has type `Foo`, which is uninhabited
 --> t1.rs:5:13
  |
5 |     let x = f();
  |             ^^^

warning: unused variable: `x`
 --> t1.rs:5:9
  |
5 |     let x = f();
  |         ^ help: if this is intentional, prefix it with an underscore: `_x`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: 2 warnings emitted
```
My implementation is slightly inelegant because unreachable code warnings can now be issued in two different places (during type checking and during liveness analysis), but I think it is the solution with the least amount of unnecessary code duplication, given that the new warning integrates nicely with liveness analysis, where unreachable code is already implicitly detected for the purpose of finding unused variables.

2 years agoAuto merge of #83302 - camsteffen:write-piece-unchecked, r=dtolnay
bors [Mon, 23 Aug 2021 22:55:19 +0000 (22:55 +0000)]
Auto merge of #83302 - camsteffen:write-piece-unchecked, r=dtolnay

Get piece unchecked in `write`

We already use specialized `zip`, but it seems like we can do a little better by not checking `pieces` length at all.

`Arguments` constructors are now unsafe. So the `format_args!` expansion now includes an `unsafe` block.

<details>
<summary>Local Bench Diff</summary>

```text
 name                        before ns/iter  after ns/iter  diff ns/iter   diff %  speedup
 fmt::write_str_macro1       22,967          19,718               -3,249  -14.15%   x 1.16
 fmt::write_str_macro2       35,527          32,654               -2,873   -8.09%   x 1.09
 fmt::write_str_macro_debug  571,953         575,973               4,020    0.70%   x 0.99
 fmt::write_str_ref          9,579           9,459                  -120   -1.25%   x 1.01
 fmt::write_str_value        9,573           9,572                    -1   -0.01%   x 1.00
 fmt::write_u128_max         176             173                      -3   -1.70%   x 1.02
 fmt::write_u128_min         138             134                      -4   -2.90%   x 1.03
 fmt::write_u64_max          139             136                      -3   -2.16%   x 1.02
 fmt::write_u64_min          129             135                       6    4.65%   x 0.96
 fmt::write_vec_macro1       24,401          22,273               -2,128   -8.72%   x 1.10
 fmt::write_vec_macro2       37,096          35,602               -1,494   -4.03%   x 1.04
 fmt::write_vec_macro_debug  588,291         589,575               1,284    0.22%   x 1.00
 fmt::write_vec_ref          9,568           9,732                   164    1.71%   x 0.98
 fmt::write_vec_value        9,516           9,625                   109    1.15%   x 0.99
```
</details>

2 years agoAuto merge of #88265 - m-ou-se:rollup-soymv20, r=m-ou-se
bors [Mon, 23 Aug 2021 20:10:29 +0000 (20:10 +0000)]
Auto merge of #88265 - m-ou-se:rollup-soymv20, r=m-ou-se

Rollup of 6 pull requests

Successful merges:

 - #87976 (Account for tabs when highlighting multiline code suggestions)
 - #88174 (Clarify some wording in Rust 2021 lint docs)
 - #88188 (Greatly improve limitation handling on parallel rustdoc GUI test run)
 - #88230 (Fix typos “a”→“an”)
 - #88232 (Add notes to macro-not-found diagnostics to point out how things with the same name were not a match.)
 - #88259 (Do not mark `-Z thir-unsafeck` as unsound anymore)

Failed merges:

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

2 years agoRollup merge of #88259 - LeSeulArtichaut:complete-thir-unsafeck, r=oli-obk
Mara Bos [Mon, 23 Aug 2021 18:45:51 +0000 (20:45 +0200)]
Rollup merge of #88259 - LeSeulArtichaut:complete-thir-unsafeck, r=oli-obk

Do not mark `-Z thir-unsafeck` as unsound anymore

The initial implementation of the THIR unsafety checker is now complete (rust-lang/project-thir-unsafeck#7).

r? `@oli-obk`

2 years agoRollup merge of #88232 - m-ou-se:macro-name-imported-but-not-macro, r=estebank
Mara Bos [Mon, 23 Aug 2021 18:45:50 +0000 (20:45 +0200)]
Rollup merge of #88232 - m-ou-se:macro-name-imported-but-not-macro, r=estebank

Add notes to macro-not-found diagnostics to point out how things with the same name were not a match.

This adds notes like:
```
error: cannot find derive macro `Serialize` in this scope
  --> $DIR/issue-88206.rs:22:10
   |
LL | #[derive(Serialize)]
   |          ^^^^^^^^^
   |
note: `Serialize` is imported here, but it is not a derive macro
  --> $DIR/issue-88206.rs:17:11
   |
LL | use hey::{Serialize, Deserialize};
   |           ^^^^^^^^^
```

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

Includes https://github.com/rust-lang/rust/pull/88229

r? `@estebank`

2 years agoRollup merge of #88230 - steffahn:a_an, r=oli-obk
Mara Bos [Mon, 23 Aug 2021 18:45:49 +0000 (20:45 +0200)]
Rollup merge of #88230 - steffahn:a_an, r=oli-obk

Fix typos “a”→“an”

Fix typos in comments; found using a regex to find some easy instance of incorrect usage of a vs. an.

While automation was used to find these, every change was checked manually.

Changes in submodules get separate PRs:
* https://github.com/rust-lang/stdarch/pull/1201
* https://github.com/rust-lang/cargo/pull/9821
* https://github.com/rust-lang/miri/pull/1874
* https://github.com/rust-lang/rls/pull/1746
* https://github.com/rust-analyzer/rust-analyzer/pull/9984
  _folks @ rust-analyzer are fast at merging…_
  * https://github.com/rust-analyzer/rust-analyzer/pull/9985
  * https://github.com/rust-analyzer/rust-analyzer/pull/9987
  * https://github.com/rust-analyzer/rust-analyzer/pull/9989

_For `clippy`, I don’t know if the changes should better better be moved to a PR to the original repo._

<hr>

This has some overlap with #88226, but neither is a strict superset of the other.

If you want multiple commits, I can split it up; in that case, make sure to suggest a criterion for splitting.

2 years agoRollup merge of #88188 - GuillaumeGomez:rustdoc-gui-parallel-limit, r=dns2utf8
Mara Bos [Mon, 23 Aug 2021 18:45:48 +0000 (20:45 +0200)]
Rollup merge of #88188 - GuillaumeGomez:rustdoc-gui-parallel-limit, r=dns2utf8

Greatly improve limitation handling on parallel rustdoc GUI test run

Follow-up of https://github.com/rust-lang/rust/pull/88082.

r? `@dns2utf8`

2 years agoRollup merge of #88174 - camelid:clarify-rust-2021-lint-docs, r=m-ou-se
Mara Bos [Mon, 23 Aug 2021 18:45:47 +0000 (20:45 +0200)]
Rollup merge of #88174 - camelid:clarify-rust-2021-lint-docs, r=m-ou-se

Clarify some wording in Rust 2021 lint docs

Also added some inline code styling.

2 years agoRollup merge of #87976 - estebank:fix-suggestion-span-coloring, r=m-ou-se
Mara Bos [Mon, 23 Aug 2021 18:45:40 +0000 (20:45 +0200)]
Rollup merge of #87976 - estebank:fix-suggestion-span-coloring, r=m-ou-se

Account for tabs when highlighting multiline code suggestions

Address `'\t'` case in #87972.

Before:

![Screen Shot 2021-08-12 at 8 52 27 AM](https://user-images.githubusercontent.com/1606434/129228214-e5cfd203-9aa8-41c7-acd9-ce255ef8a21e.png)

After:

![Screen Shot 2021-08-12 at 8 52 15 AM](https://user-images.githubusercontent.com/1606434/129228236-57c951fc-c8cf-4901-989f-b9b5aa5eebca.png)

2 years agoAuto merge of #87676 - sexxi-goose:truncate_unique, r=nikomatsakis
bors [Mon, 23 Aug 2021 17:27:23 +0000 (17:27 +0000)]
Auto merge of #87676 - sexxi-goose:truncate_unique, r=nikomatsakis

2229: Handle MutBorrow/UniqueImmBorrow better

We only want to use UniqueImmBorrow when the capture place is truncated and we
drop Deref of a MutRef.

r? `@nikomatsakis`

Fixes: https://github.com/rust-lang/project-rfc-2229/issues/56
2 years agoImprove wording of macro-not-found-but-name-exists note.
Mara Bos [Sun, 22 Aug 2021 16:22:06 +0000 (18:22 +0200)]
Improve wording of macro-not-found-but-name-exists note.

2 years agoShow what things are, but also what they are not.
Mara Bos [Sun, 22 Aug 2021 16:15:07 +0000 (18:15 +0200)]
Show what things are, but also what they are not.

2 years agoDon't confuse the user with notes about tool modules.
Mara Bos [Sun, 22 Aug 2021 15:41:22 +0000 (17:41 +0200)]
Don't confuse the user with notes about tool modules.

2 years agoClarify what attribute and derive macros look like.
Mara Bos [Sun, 22 Aug 2021 15:26:19 +0000 (17:26 +0200)]
Clarify what attribute and derive macros look like.

2 years agoSay what things are, instead of what they are not.
Mara Bos [Sun, 22 Aug 2021 15:16:24 +0000 (17:16 +0200)]
Say what things are, instead of what they are not.

2 years agoSilence confusing 'unused import' warnings.
Mara Bos [Sun, 22 Aug 2021 14:33:21 +0000 (16:33 +0200)]
Silence confusing 'unused import' warnings.

2 years agoUpdate tests.
Mara Bos [Sun, 22 Aug 2021 13:05:35 +0000 (15:05 +0200)]
Update tests.

2 years agoAdd tests for macro-not-found diagnostics.
Mara Bos [Sun, 22 Aug 2021 13:05:13 +0000 (15:05 +0200)]
Add tests for macro-not-found diagnostics.

2 years agoLook for macro names in all namespaces for diagnostics.
Mara Bos [Sun, 22 Aug 2021 13:02:35 +0000 (15:02 +0200)]
Look for macro names in all namespaces for diagnostics.

2 years agoAdd test for macro-not-found-but-name-imported-here note.
Mara Bos [Sun, 22 Aug 2021 11:37:27 +0000 (13:37 +0200)]
Add test for macro-not-found-but-name-imported-here note.

2 years agoAdd note to 'macro not found' to point to identically-named imports.
Mara Bos [Sun, 22 Aug 2021 11:35:51 +0000 (13:35 +0200)]
Add note to 'macro not found' to point to identically-named imports.

2 years agoAuto merge of #87661 - FabianWolff:issue-87461, r=estebank
bors [Mon, 23 Aug 2021 14:41:14 +0000 (14:41 +0000)]
Auto merge of #87661 - FabianWolff:issue-87461, r=estebank

Improve error reporting for closure return type mismatches

Fixes #87461.

2 years agoreview comments
Esteban Kuber [Mon, 23 Aug 2021 12:42:08 +0000 (12:42 +0000)]
review comments

2 years agoDo not mark `-Z thir-unsafeck` as unsound anymore
Léo Lanteri Thauvin [Mon, 23 Aug 2021 12:52:42 +0000 (14:52 +0200)]
Do not mark `-Z thir-unsafeck` as unsound anymore

2 years agoGreatly improve limitation handling on parallel rustdoc GUI test run
Guillaume Gomez [Fri, 20 Aug 2021 18:55:48 +0000 (20:55 +0200)]
Greatly improve limitation handling on parallel rustdoc GUI test run

2 years agoremove unnecessary `info!()` logging
Esteban Kuber [Tue, 17 Aug 2021 16:06:18 +0000 (16:06 +0000)]
remove unnecessary `info!()` logging

2 years agoFixes to span locations
Esteban Kuber [Tue, 17 Aug 2021 15:46:42 +0000 (15:46 +0000)]
Fixes to span locations

2 years agowip
Esteban Kuber [Sat, 14 Aug 2021 13:31:48 +0000 (13:31 +0000)]
wip

2 years agoAccount for tabs when highlighting multiline code suggestions
Esteban Kuber [Thu, 12 Aug 2021 19:33:19 +0000 (19:33 +0000)]
Account for tabs when highlighting multiline code suggestions

2 years agoAuto merge of #88249 - lnicola:rust-analyzer-2021-08-23, r=lnicola
bors [Mon, 23 Aug 2021 10:46:31 +0000 (10:46 +0000)]
Auto merge of #88249 - lnicola:rust-analyzer-2021-08-23, r=lnicola

:arrow_up: rust-analyzer

2 years agoAuto merge of #88220 - sunfishcode:sunfishcode/unix-listener-io-safety, r=joshtriplett
bors [Mon, 23 Aug 2021 07:36:49 +0000 (07:36 +0000)]
Auto merge of #88220 - sunfishcode:sunfishcode/unix-listener-io-safety, r=joshtriplett

Implement `AsFd` etc. for `UnixListener`.

Implement `AsFd`, `From<OwnedFd>`, and `Into<OwnedFd>` for
`UnixListener`. This is a follow-up to #87329.

r? `@joshtriplett`

2 years ago:arrow_up: rust-analyzer
Laurențiu Nicola [Mon, 23 Aug 2021 06:01:38 +0000 (09:01 +0300)]
:arrow_up: rust-analyzer

2 years agoAuto merge of #87598 - ccqpein:master, r=yaahc
bors [Mon, 23 Aug 2021 05:06:29 +0000 (05:06 +0000)]
Auto merge of #87598 - ccqpein:master, r=yaahc

Add doctests for HashMap's into_values and into_keys methods

Fixes #87591

2 years agoAuto merge of #88210 - spastorino:diff-lifetimes-def-use-test, r=oli-obk
bors [Mon, 23 Aug 2021 02:25:36 +0000 (02:25 +0000)]
Auto merge of #88210 - spastorino:diff-lifetimes-def-use-test, r=oli-obk

Test TAITs different lifetimes in defining uses fail

r? `@oli-obk`

Related to #86727

2 years agoRemove redundant conversions.
Dan Gohman [Sun, 22 Aug 2021 23:51:30 +0000 (16:51 -0700)]
Remove redundant conversions.

2 years agoAuto merge of #88200 - pcwalton:no-dso-local-on-mach-o, r=nagisa
bors [Sun, 22 Aug 2021 23:44:48 +0000 (23:44 +0000)]
Auto merge of #88200 - pcwalton:no-dso-local-on-mach-o, r=nagisa

Stop emitting the `dso_local` LLVM attribute for external symbols under the static relocation model on macOS.

This matches Clang's behavior:

https://github.com/llvm/llvm-project/blob/973cb2c326be9f256da0897c4d2ef117dc22761d/clang/lib/CodeGen/CodeGenModule.cpp#L1038-L1040

Even if `dso_local` were properly supported in this way on macOS, it seems
incorrect to add this annotation as liberally as we did. The `dso_local`
annotation is for symbols that ultimately end up in the same linkage unit, but
we were adding this annotation even for `static` values inside `extern` blocks
marked with `#[link(type="framework")]`, which should be considered dynamically
linked.  Note that Clang likewise avoids emitting `dso_local` for `dllimport`
symbols:

https://github.com/llvm/llvm-project/blob/973cb2c326be9f256da0897c4d2ef117dc22761d/clang/lib/CodeGen/CodeGenModule.cpp#L1005-L1007

This issue caused breakage in the `ring` crate, which links to a symbol defined
in `Security.framework` that ultimately resolves to address `0x0`:

https://github.com/briansmith/ring/blob/b94d61e044b42827fefd71d5f61e8c58a7659870/src/rand.rs#L390

For this symbol, the use of `dso_local` causes LLVM to emit a relocation of
type `X86_64_RELOC_SIGNED`, which is a 32-bit signed PC-relative offset. If the
binary is large enough, `0x0` might be out of range, and the link will fail.
Avoiding `dso_local` causes LLVM to use the GOT instead, emitting a relocation
of type `X86_64_RELOC_GOT_LOAD`, which will properly handle the large offset
and cause the link to succeed.

As a side note, the static relocation model is effectively deprecated for
security reasons on macOS, as it prohibits PIE. It's also completely
unsupported on Apple Silicon, so I don't think it's worth going to the effort
of properly supporting this model on that platform.

2 years agoAuto merge of #88240 - GuillaumeGomez:rollup-wdom91m, r=GuillaumeGomez
bors [Sun, 22 Aug 2021 20:23:37 +0000 (20:23 +0000)]
Auto merge of #88240 - GuillaumeGomez:rollup-wdom91m, r=GuillaumeGomez

Rollup of 7 pull requests

Successful merges:

 - #86747 (Improve wording of the `drop_bounds` lint)
 - #87166 (Show discriminant before overflow in diagnostic for duplicate values.)
 - #88077 (Generate an iOS LLVM target with a specific version)
 - #88164 (PassWrapper: adapt for LLVM 14 changes)
 - #88211 (cleanup: `Span::new` -> `Span::with_lo`)
 - #88229 (Suggest importing the right kind of macro.)
 - #88238 (Stop tracking namespace in used_imports.)

Failed merges:

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

2 years agoRollup merge of #88238 - m-ou-se:used-imports-no-track-namespace, r=estebank
Guillaume Gomez [Sun, 22 Aug 2021 18:52:56 +0000 (20:52 +0200)]
Rollup merge of #88238 - m-ou-se:used-imports-no-track-namespace, r=estebank

Stop tracking namespace in used_imports.

This changes `used_imports` from a `FxHashSet<(NodeId, Namespace)>` to a `FxHashSet<NodeId>`, as the Namespace information isn't used.

The only point that uses it did three lookups, `|=`'ing them together.

r? `@estebank`

2 years agoRollup merge of #88229 - m-ou-se:macro-suggest-right-kind, r=estebank
Guillaume Gomez [Sun, 22 Aug 2021 18:52:55 +0000 (20:52 +0200)]
Rollup merge of #88229 - m-ou-se:macro-suggest-right-kind, r=estebank

Suggest importing the right kind of macro.

Fixes #88228.

r? `@estebank`

2 years agoRollup merge of #88211 - petrochenkov:withhilo, r=jyn514
Guillaume Gomez [Sun, 22 Aug 2021 18:52:54 +0000 (20:52 +0200)]
Rollup merge of #88211 - petrochenkov:withhilo, r=jyn514

cleanup: `Span::new` -> `Span::with_lo`

Extracted from https://github.com/rust-lang/rust/pull/84373 as suggested in https://github.com/rust-lang/rust/pull/84373#issuecomment-857773867.
It turned out less useful then I expected, but anyway.
r? `@cjgillot`
`@bors` rollup

2 years agoRollup merge of #88164 - durin42:llvm-14-san-opts, r=nikic
Guillaume Gomez [Sun, 22 Aug 2021 18:52:53 +0000 (20:52 +0200)]
Rollup merge of #88164 - durin42:llvm-14-san-opts, r=nikic

PassWrapper: adapt for LLVM 14 changes

These API changes appear to have all taken place in
https://reviews.llvm.org/D105007, which moved HWAddressSanitizerPass and
AddressSanitizerPass to only accept their options type as a ctor
argument instead of the sequence of bools etc. This required a couple of
parameter additions, which I made match the default prior to the
mentioned upstream LLVM change.

This patch restores rustc to building (though not quite passing all
tests, I've mailed other patches for those issues) against LLVM HEAD.

2 years agoRollup merge of #88077 - kit-981:feature/fix-minimum-os-version-in-header, r=petrochenkov
Guillaume Gomez [Sun, 22 Aug 2021 18:52:52 +0000 (20:52 +0200)]
Rollup merge of #88077 - kit-981:feature/fix-minimum-os-version-in-header, r=petrochenkov

Generate an iOS LLVM target with a specific version

This commit adds the `LC_VERSION_MIN_IPHONEOS` load command to the Mach-O header generated for `aarch64-apple-ios` binaries. The operating system will look for this load command to determine the minimum supported operating system version and will not allow the binary to run if it's absent. This logic already exists for the simulator toolchain.

I've been using `otool` from a [cctools](https://github.com/tpoechtrager/cctools-port) toolchain to parse the header and validate that this change adds the required load command.

This change appears to be enough to build Rust binaries that can run on a jailbroken iPhone.

2 years agoRollup merge of #87166 - de-vri-es:show-discriminant-before-overflow, r=jackh726
Guillaume Gomez [Sun, 22 Aug 2021 18:52:51 +0000 (20:52 +0200)]
Rollup merge of #87166 - de-vri-es:show-discriminant-before-overflow, r=jackh726

Show discriminant before overflow in diagnostic for duplicate values.

This PR adds the value before overflow for explicit discriminant values in the error for duplicate discriminant values.
I found it rather confusing to see only the overflowed value.

It only does this for literals, since overflows in const evaluated arithmetic are already a hard error.

This is my first PR to the compiler, so please let me know if the implementation can be improved :)

Before:
![image](https://user-images.githubusercontent.com/786213/125850097-bf5fb7e0-d800-4386-a738-c30f41822964.png)

After:
![image](https://user-images.githubusercontent.com/786213/125850120-e2bb765d-ad86-4888-a6cb-dec34fba3fea.png)

2 years agoRollup merge of #86747 - FabianWolff:issue-86653, r=GuillaumeGomez
Guillaume Gomez [Sun, 22 Aug 2021 18:52:50 +0000 (20:52 +0200)]
Rollup merge of #86747 - FabianWolff:issue-86653, r=GuillaumeGomez

Improve wording of the `drop_bounds` lint

This PR addresses #86653. The issue is sort of a false positive of the `drop_bounds` lint, but I would argue that the best solution for #86653 is simply a rewording of the warning message and lint description, because even if the lint is _technically_ wrong, it still forces the programmer to think about what they are doing, and they can always use `#[allow(drop_bounds)]` if they think that they really need the `Drop` bound.

There are two issues with the current warning message and lint description:
- First, it says that `Drop` bounds are "useless", which is technically incorrect because they actually do have the effect of allowing you e.g. to call methods that also have a `Drop` bound on their generic arguments for some reason. I have changed the wording to emphasize not that the bound is "useless", but that it is most likely not what was intended.
- Second, it claims that `std::mem::needs_drop` detects whether a type has a destructor. But I think this is also technically wrong: The `Drop` bound says whether the type has a destructor or not, whereas `std::mem::needs_drop` also takes nested types with destructors into account, even if the top-level type does not itself have one (although I'm not 100% sure about the exact terminology here, i.e. whether the "drop glue" of the top-level type counts as a destructor or not).

cc `@jonhoo,` does this solve the issue for you?

r? `@GuillaumeGomez`

2 years agoAuto merge of #88166 - BoxyUwU:const-equate-canon, r=lcnr
bors [Sun, 22 Aug 2021 18:00:22 +0000 (18:00 +0000)]
Auto merge of #88166 - BoxyUwU:const-equate-canon, r=lcnr

canonicalize consts before calling try_unify_abstract_consts query

Fixes #88022
Fixes #86953
Fixes #77708
Fixes #82034
Fixes #85031

these ICEs were all caused by calling the `try_unify_abstract_consts` query with inference vars in substs

r? `@lcnr`

2 years agoFix typos “an”→“a” and a few different ones that appeared in the same search
Frank Steffahn [Sun, 22 Aug 2021 16:15:49 +0000 (18:15 +0200)]
Fix typos “an”→“a” and a few different ones that appeared in the same search

2 years agoFix more “a”/“an” typos
Frank Steffahn [Sun, 22 Aug 2021 15:27:18 +0000 (17:27 +0200)]
Fix more “a”/“an” typos

2 years agoStop tracking namespce in used_imports.
Mara Bos [Sun, 22 Aug 2021 14:50:59 +0000 (16:50 +0200)]
Stop tracking namespce in used_imports.

The information was tracked, but unused.

2 years agoTest TAITs different lifetimes in defining uses fail
Santiago Pastorino [Sat, 21 Aug 2021 15:26:25 +0000 (12:26 -0300)]
Test TAITs different lifetimes in defining uses fail

2 years agoRevert a change of “an --extern” (can be read with “dash dash”)
Frank Steffahn [Sun, 22 Aug 2021 14:37:47 +0000 (16:37 +0200)]
Revert a change of “an --extern” (can be read with “dash dash”)

2 years agoFix more “a”/“an” typos
Frank Steffahn [Sun, 22 Aug 2021 14:20:58 +0000 (16:20 +0200)]
Fix more “a”/“an” typos

2 years agoFix typos “a”→“an”
Frank Steffahn [Sun, 22 Aug 2021 12:46:15 +0000 (14:46 +0200)]
Fix typos “a”→“an”

2 years agoAuto merge of #88163 - camsteffen:collapsible-match-fix, r=Manishearth
bors [Sun, 22 Aug 2021 13:26:32 +0000 (13:26 +0000)]
Auto merge of #88163 - camsteffen:collapsible-match-fix, r=Manishearth

Fix clippy::collapsible_match with let expressions

This fixes rust-lang/rust-clippy#7575 which is a regression from #80357. I am fixing the bug here instead of in the clippy repo (if that's okay) because a) the regression has not been synced yet and b) I would like to land the fix on nightly asap.

The fix is basically to re-generalize `match` and `if let` for the lint implementation (they were split because `if let` no longer desugars to `match` in the HIR).

Also fixes rust-lang/rust-clippy#7586 and fixes rust-lang/rust-clippy#7591
cc `@rust-lang/clippy`
`@xFrednet` do you want to review this?

2 years agoAdd doctests for 's into_values and into_keys methods
ccQpein [Thu, 29 Jul 2021 17:24:25 +0000 (13:24 -0400)]
Add doctests for 's into_values and into_keys methods

2 years agoSuggest importing the right kind of macro.
Mara Bos [Sun, 22 Aug 2021 12:06:45 +0000 (14:06 +0200)]
Suggest importing the right kind of macro.

2 years agoAuto merge of #88139 - lcnr:marker-trait-attr, r=nikomatsakis
bors [Sun, 22 Aug 2021 10:44:38 +0000 (10:44 +0000)]
Auto merge of #88139 - lcnr:marker-trait-attr, r=nikomatsakis

marker_traits: require `EvaluatedToOk` during winnowing

closes #84955, while it doesn't really fix it in a way that makes me happy it should prevent the issue for now and this
test can't be reproduced anyways, so it doesn't make much sense to keep it open.

fixes #84917 as only one of the impls depends on regions, so we now drop the ambiguous one instead of the correct one.

cc https://rust-lang.zulipchat.com/#narrow/stream/144729-wg-traits/topic/winnowing.20soundly/near/247899832

r? `@nikomatsakis`

2 years agoAuto merge of #88122 - Seppel3210:master, r=dtolnay
bors [Sun, 22 Aug 2021 08:03:47 +0000 (08:03 +0000)]
Auto merge of #88122 - Seppel3210:master, r=dtolnay

Fix example in `Extend<(A, B)>` impl

After looking over the examples in my last PR (#85835) on doc.rust-lang.org/nightly I realized that the example didn't actually show what I wanted it to show 😅
So here's the better example

2 years agoAuto merge of #85166 - mbhall88:file-prefix, r=dtolnay
bors [Sun, 22 Aug 2021 05:19:48 +0000 (05:19 +0000)]
Auto merge of #85166 - mbhall88:file-prefix, r=dtolnay

add file_prefix method to std::path

This is an initial implementation of `std::path::Path::file_prefix`. It is effectively a "left" variant of the existing [`file_stem`](https://doc.rust-lang.org/std/path/struct.Path.html#method.file_stem) method. An illustration of the difference is

```rust
use std::path::Path;

let path = Path::new("foo.tar.gz");
assert_eq!(path.file_stem(), Some("foo.tar"));
assert_eq!(path.file_prefix(), Some("foo"));
```

In my own development, I generally find I almost always want the prefix, rather than the stem, so I thought it might be best to suggest it's addition to libstd.

Of course, as this is my first contribution, I expect there is probably more work that needs to be done. Additionally, if the libstd team feel this isn't appropriate then so be it.

There has been some [discussion about this on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/file_lstem/near/238076313) and a user there suggested I open a PR to see whether someone in the libstd team thinks it is worth pursuing.

2 years agoImplement `AsFd` etc. for `UnixListener`.
Dan Gohman [Sun, 22 Aug 2021 02:42:30 +0000 (19:42 -0700)]
Implement `AsFd` etc. for `UnixListener`.

Implement `AsFd`, `From<OwnedFd>`, and `Into<OwnedFd>` for
`UnixListener`. This is a follow-up to #87329.

2 years agoAuto merge of #88217 - jackh726:rollup-3k74o2m, r=jackh726
bors [Sun, 22 Aug 2021 02:16:35 +0000 (02:16 +0000)]
Auto merge of #88217 - jackh726:rollup-3k74o2m, r=jackh726

Rollup of 13 pull requests

Successful merges:

 - #87604 (CI: Verify commits in beta & stable are in upstream branches.)
 - #88057 (Update RELEASES to clarify attribute macro values.)
 - #88072 (Allow the iOS toolchain to be built on Linux)
 - #88170 (Update release note for 1.55.0.)
 - #88172 (Test that type alias impl trait happens in a submodule)
 - #88179 (Mailmap entry for myself)
 - #88182 (We meant to use a trait instead of lifetime here)
 - #88183 (test TAIT in different positions)
 - #88189 (Add TAIT struct test)
 - #88192 (Use of impl trait in an impl as the value for an associated type in a dyn)
 - #88194 (Test use of impl Trait in an impl as the value for an associated type in an impl trait)
 - #88197 (Test tait use in a fn type)
 - #88201 (Test that incomplete inference for TAITs fail)

Failed merges:

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

2 years agoRollup merge of #88201 - spastorino:tait-incomplete-inference-test, r=oli-obk
Jack Huey [Sun, 22 Aug 2021 00:56:39 +0000 (20:56 -0400)]
Rollup merge of #88201 - spastorino:tait-incomplete-inference-test, r=oli-obk

Test that incomplete inference for TAITs fail

r? `@oli-obk`

Related to #86727

2 years agoRollup merge of #88197 - spastorino:tait-test-fn-type, r=oli-obk
Jack Huey [Sun, 22 Aug 2021 00:56:38 +0000 (20:56 -0400)]
Rollup merge of #88197 - spastorino:tait-test-fn-type, r=oli-obk

Test tait use in a fn type

r? `@oli-obk`

I thought this was going to work but doesn't, quickly checked with Niko and he told me that we ruled this out for now. I'm not exactly sure why and how but here we have a test with a FIXME :)

Related to #86727

2 years agoRollup merge of #88194 - spastorino:test-tait-assoc-impl-trait, r=oli-obk
Jack Huey [Sun, 22 Aug 2021 00:56:37 +0000 (20:56 -0400)]
Rollup merge of #88194 - spastorino:test-tait-assoc-impl-trait, r=oli-obk

Test use of impl Trait in an impl as the value for an associated type in an impl trait

r? `@oli-obk`

Related to #86727

2 years agoRollup merge of #88192 - spastorino:add-tait-test-for-assoc-dyn, r=oli-obk
Jack Huey [Sun, 22 Aug 2021 00:56:36 +0000 (20:56 -0400)]
Rollup merge of #88192 - spastorino:add-tait-test-for-assoc-dyn, r=oli-obk

Use of impl trait in an impl as the value for an associated type in a dyn

r? `@oli-obk`

Related to #86727

2 years agoRollup merge of #88189 - spastorino:add-tait-struct-test, r=oli-obk
Jack Huey [Sun, 22 Aug 2021 00:56:35 +0000 (20:56 -0400)]
Rollup merge of #88189 - spastorino:add-tait-struct-test, r=oli-obk

Add TAIT struct test

r? `@oli-obk`

Related to #86727

2 years agoRollup merge of #88183 - spastorino:add-tait-in-different-tuple-position, r=oli-obk
Jack Huey [Sun, 22 Aug 2021 00:56:34 +0000 (20:56 -0400)]
Rollup merge of #88183 - spastorino:add-tait-in-different-tuple-position, r=oli-obk

test TAIT in different positions

r? `@oli-obk`

Related to #86727

2 years agoRollup merge of #88182 - spastorino:use-trait-in-tait-tests, r=oli-obk
Jack Huey [Sun, 22 Aug 2021 00:56:33 +0000 (20:56 -0400)]
Rollup merge of #88182 - spastorino:use-trait-in-tait-tests, r=oli-obk

We meant to use a trait instead of lifetime here

r? `@oli-obk`

Related to #86727

2 years agoRollup merge of #88179 - steffahn:mailmap, r=Mark-Simulacrum
Jack Huey [Sun, 22 Aug 2021 00:56:32 +0000 (20:56 -0400)]
Rollup merge of #88179 - steffahn:mailmap, r=Mark-Simulacrum

Mailmap entry for myself

2 years agoRollup merge of #88172 - spastorino:tait-defining-use-submodule-test, r=oli-obk
Jack Huey [Sun, 22 Aug 2021 00:56:31 +0000 (20:56 -0400)]
Rollup merge of #88172 - spastorino:tait-defining-use-submodule-test, r=oli-obk

Test that type alias impl trait happens in a submodule

r? `@oli-obk`

Related to #86727

2 years agoRollup merge of #88170 - nebkor:release-note-1.55, r=Mark-Simulacrum
Jack Huey [Sun, 22 Aug 2021 00:56:29 +0000 (20:56 -0400)]
Rollup merge of #88170 - nebkor:release-note-1.55, r=Mark-Simulacrum

Update release note for 1.55.0.

Added a line about new formatting option, `{lib}`, for `cargo
tree` (https://github.com/rust-lang/cargo/pull/9663).

2 years agoRollup merge of #88072 - kit-981:feature/build-ios-toolchain-on-linux, r=Mark-Simulacrum
Jack Huey [Sun, 22 Aug 2021 00:56:29 +0000 (20:56 -0400)]
Rollup merge of #88072 - kit-981:feature/build-ios-toolchain-on-linux, r=Mark-Simulacrum

Allow the iOS toolchain to be built on Linux

The iOS toolchain can be built on Linux with minor changes. The compilation will invoke `xcrun` to find the path to the iPhone SDK but a fake `xcrun` executable can be used.

```
#!/bin/sh
echo "/path/to/sdk"
```

The iOS toolchain can then be built and linked with rustup.

```
$ ./x.py build --stage 2 --host x86_64-unknown-linux-gnu \
    --target aarch64-apple-ios
$ rustup toolchain link stage1 build/x86_64-unknown-linux-gnu/stage1
```

It's possible to take this toolchain and compile an iOS executable with it. This requires the ld64 linker and an iOS SDK. The ld64 linker can be taken from [cctools](https://github.com/tpoechtrager/cctools-port). A project's .cargo/config can then be edited to use the linker for this target.

```
[target.aarch64-apple-ios]
linker = "/path/to/cctools/bin/arm-apple-darwin-ld"
rustflags = [
    "-C",
    """
link-args=
    -F/path/to/sdk/System/Library/Frameworks
    -L/path/to/sdk/usr/lib
    -L/path/to/sdk/usr/lib/system/
    -adhoc_codesign
    """,
]
```

2 years agoRollup merge of #88057 - ehuss:releases-doc-macros, r=Mark-Simulacrum
Jack Huey [Sun, 22 Aug 2021 00:56:28 +0000 (20:56 -0400)]
Rollup merge of #88057 - ehuss:releases-doc-macros, r=Mark-Simulacrum

Update RELEASES to clarify attribute macro values.

As noted in #87681, macros do not work with the `#[path]` attribute.  Since the places where macros *can* be used is very limited, I have changed this to just focus on `#[doc]` which is the only attribute where this is really useful.

2 years agoRollup merge of #87604 - yaymukund:verify-backported-commits, r=Mark-Simulacrum
Jack Huey [Sun, 22 Aug 2021 00:56:27 +0000 (20:56 -0400)]
Rollup merge of #87604 - yaymukund:verify-backported-commits, r=Mark-Simulacrum

CI: Verify commits in beta & stable are in upstream branches.

Closes #74721

I think this does the trick. https://github.com/rust-lang/rust/pull/87597 is an example of it failing as it should.

2 years agoAuto merge of #88075 - Xuanwo:vec_deque_retain, r=dtolnay
bors [Sat, 21 Aug 2021 23:35:54 +0000 (23:35 +0000)]
Auto merge of #88075 - Xuanwo:vec_deque_retain, r=dtolnay

Optimize unnecessary check in VecDeque::retain

This pr is highly inspired by https://github.com/rust-lang/rust/pull/88060 which shared the same idea: we can split the `for` loop into stages so that we can remove unnecessary checks like `del > 0`.

## Benchmarks

Before

```rust
test collections::vec_deque::tests::bench_retain_half_10000  ... bench:     290,125 ns/iter (+/- 8,717)
test collections::vec_deque::tests::bench_retain_odd_10000   ... bench:     291,588 ns/iter (+/- 9,621)
test collections::vec_deque::tests::bench_retain_whole_10000 ... bench:     287,426 ns/iter (+/- 9,009)
```

After

```rust
test collections::vec_deque::tests::bench_retain_half_10000  ... bench:     243,940 ns/iter (+/- 8,563)
test collections::vec_deque::tests::bench_retain_odd_10000   ... bench:     242,768 ns/iter (+/- 3,903)
test collections::vec_deque::tests::bench_retain_whole_10000 ... bench:     202,926 ns/iter (+/- 6,332)
```

Based on the current benchmark, this PR will improve the perf of `VecDeque::retain` by around 16%. For special cases, the improvement will be up to 30%.

Signed-off-by: Xuanwo <github@xuanwo.io>
2 years agoAuto merge of #88135 - crlf0710:trait_upcasting_part_3, r=nikomatsakis
bors [Sat, 21 Aug 2021 21:14:07 +0000 (21:14 +0000)]
Auto merge of #88135 - crlf0710:trait_upcasting_part_3, r=nikomatsakis

Trait upcasting coercion (part 3)

By using separate candidates for each possible choice, this fixes type-checking issues in previous commits.

r? `@nikomatsakis`

2 years agoAddress review comments
Aaron Hill [Sat, 21 Aug 2021 19:11:36 +0000 (14:11 -0500)]
Address review comments

2 years agoAuto merge of #82776 - jyn514:extern-url-fallback, r=GuillaumeGomez
bors [Sat, 21 Aug 2021 18:32:37 +0000 (18:32 +0000)]
Auto merge of #82776 - jyn514:extern-url-fallback, r=GuillaumeGomez

Give precedence to `html_root_url` over `--extern-html-root-url` by default, but add a way to opt-in to the previous behavior

## What is an HTML root url?

It tells rustdoc where it should link when documentation for a crate is
not available locally; for example, when a crate is a dependency of a
crate documented with `cargo doc --no-deps`.

 ## What is the difference between `html_root_url` and `--extern-html-root-url`?

Both of these tell rustdoc what the HTML root should be set to.
`doc(html_root_url)` is set by the crate author, while
`--extern-html-root-url` is set by the person documenting the crate.
These are often different. For example, docs.rs uses
`--extern-html-root-url https://docs.rs/crate-name/version` to ensure
all crates have documentation, even if `html_root_url` is not set.
Conversely, crates such as Rocket set `doc(html_root_url =
"https://api.rocket.rs")`, because they prefer users to view the
documentation on their own site.

Crates also set `html_root_url` to ensure they have
documentation when building locally when offline. This is unfortunate to
require, because it's more work from the library author. It also makes
it impossible to distinguish between crates that want to be viewed on a
different site (e.g. Rocket) and crates that just want documentation to
be visible offline at all (e.g. Tokio). I have authored a separate
change to the API guidelines to no longer recommend doing this:
rust-lang/api-guidelines#230.

 ## Why change the default?

In the past, docs.rs has been the main user of `--extern-html-root-url`.
However, it's useful for other projects as well. In particular, Cargo
wants to pass it by default when running `--no-deps`
(rust-lang/cargo#8296).

Unfortunately, for these other use cases, the priority order is
inverted. They want to give *precedence* to the URL the crate picks, and
only fall back to the `--extern-html-root` if no `html_root_url` is
present. That allows passing `--extern-html-root` unconditionally,
without having to parse the source code to see what attributes are
present.

For docs.rs, however, we still want to keep the old behavior, so that
all links on docs.rs stay on the site.

2 years agoRemove `NonMacroAttr.mark_used`
Aaron Hill [Thu, 5 Aug 2021 22:58:59 +0000 (17:58 -0500)]
Remove `NonMacroAttr.mark_used`

2 years agoRemove `Session.used_attrs` and move logic to `CheckAttrVisitor`
Aaron Hill [Thu, 29 Jul 2021 17:00:41 +0000 (12:00 -0500)]
Remove `Session.used_attrs` and move logic to `CheckAttrVisitor`

Instead of updating global state to mark attributes as used,
we now explicitly emit a warning when an attribute is used in
an unsupported position. As a side effect, we are to emit more
detailed warning messages (instead of just a generic "unused" message).

`Session.check_name` is removed, since its only purpose was to mark
the attribute as used. All of the callers are modified to use
`Attribute.has_name`

Additionally, `AttributeType::AssumedUsed` is removed - an 'assumed
used' attribute is implemented by simply not performing any checks
in `CheckAttrVisitor` for a particular attribute.

We no longer emit unused attribute warnings for the `#[rustc_dummy]`
attribute - it's an internal attribute used for tests, so it doesn't
mark sense to treat it as 'unused'.

With this commit, a large source of global untracked state is removed.

2 years agoAuto merge of #88134 - rylev:force-warn-improvements, r=nikomatsakis
bors [Sat, 21 Aug 2021 15:51:50 +0000 (15:51 +0000)]
Auto merge of #88134 - rylev:force-warn-improvements, r=nikomatsakis

Force warn improvements

As part of stablization of the `--force-warn` option (#86516) I've made the following changes:
* Error when the `warnings` lint group is based to the `--force-warn` option
* Tests have been updated to make it easier to understand the semantics of `--force-warn`

r? `@nikomatsakis`

2 years agocleanup: `Span::new` -> `Span::with_lo`
Vadim Petrochenkov [Sat, 21 Aug 2021 15:07:21 +0000 (18:07 +0300)]
cleanup: `Span::new` -> `Span::with_lo`

2 years agoAuto merge of #88128 - cuviper:needs-asm-support, r=Mark-Simulacrum
bors [Sat, 21 Aug 2021 12:57:00 +0000 (12:57 +0000)]
Auto merge of #88128 - cuviper:needs-asm-support, r=Mark-Simulacrum

Add needs-asm-support to more tests

These were found as test failures on s390x for RHEL and Fedora.

2 years agoAuto merge of #87570 - nikic:llvm-13, r=nagisa
bors [Sat, 21 Aug 2021 09:25:28 +0000 (09:25 +0000)]
Auto merge of #87570 - nikic:llvm-13, r=nagisa

Upgrade to LLVM 13

Work in progress update to LLVM 13. Main changes:

 * InlineAsm diagnostics reported using SrcMgr diagnostic kind are now handled. Previously these used a separate diag handler.
 * Codegen tests are updated for additional attributes.
 * Some data layouts have changed.
 * Switch `#[used]` attribute from `llvm.used` to `llvm.compiler.used` to avoid SHF_GNU_RETAIN flag introduced in https://reviews.llvm.org/D97448, which appears to trigger a bug in older versions of gold.
 * Set `LLVM_INCLUDE_TESTS=OFF` to avoid Python 3.6 requirement.

Upstream issues:

 * ~~https://bugs.llvm.org/show_bug.cgi?id=51210 (InlineAsm diagnostic reporting for module asm)~~ Fixed by https://github.com/llvm/llvm-project/commit/1558bb80c01b695ce12642527cbfccf16cf54ece.
 * ~~https://bugs.llvm.org/show_bug.cgi?id=51476 (Miscompile on AArch64 due to incorrect comparison elimination)~~ Fixed by https://github.com/llvm/llvm-project/commit/81b106584f2baf33e09be2362c35c1bf2f6bfe94.
 * https://bugs.llvm.org/show_bug.cgi?id=51207 (Can't set custom section flags anymore). Problematic change reverted in our fork, https://reviews.llvm.org/D107216 posted for upstream revert.
 * https://bugs.llvm.org/show_bug.cgi?id=51211 (Regression in codegen for #83623). This is an optimization regression that we may likely have to eat for this release. The fix for #83623 was based on an incorrect premise, and this needs to be properly addressed in the MergeICmps pass.

The [compile-time impact](https://perf.rust-lang.org/compare.html?start=ef9549b6c0efb7525c9b012148689c8d070f9bc0&end=0983094463497eec22d550dad25576a894687002) is mixed, but quite positive as LLVM upgrades go.

The LLVM 13 final release is scheduled for Sep 21st. The current nightly is scheduled for stable release on Oct 21st.

r? `@ghost`

2 years agoAlways use llvm.used for coverage symbols
Nikita Popov [Fri, 20 Aug 2021 19:13:18 +0000 (21:13 +0200)]
Always use llvm.used for coverage symbols

This follows what clang does in CoverageMappingGen. Using just
llvm.compiler.used is insufficient at least for MSVC targets.

2 years agoAuto merge of #88073 - lnicola:rust-analyzer-2021-08-16, r=lnicola
bors [Sat, 21 Aug 2021 04:20:33 +0000 (04:20 +0000)]
Auto merge of #88073 - lnicola:rust-analyzer-2021-08-16, r=lnicola

:arrow_up: rust-analyzer

2 years agoTest that incomplete inference for TAITs fail
Santiago Pastorino [Sat, 21 Aug 2021 01:50:13 +0000 (22:50 -0300)]
Test that incomplete inference for TAITs fail

2 years agoAuto merge of #88149 - Mark-Simulacrum:prep-never-type, r=jackh726
bors [Sat, 21 Aug 2021 01:29:12 +0000 (01:29 +0000)]
Auto merge of #88149 - Mark-Simulacrum:prep-never-type, r=jackh726

Refactor fallback code to prepare for never type

This PR contains cherry-picks of some of `@nikomatsakis's` work from #79366, and shouldn't (AFAICT) represent any change in behavior. However, the refactoring is good regardless of the never type work being landed, and will reduce the size of those eventual PR(s) (and rebase pain).

I am not personally an expert on this code, and the commits are essentially 100% `@nikomatsakis's,` but they do seem reasonable to me by my understanding. Happy to edit with review, of course. Commits are best reviewed in sequence rather than all together.

r? `@jackh726` perhaps?

2 years agoTest use of impl Trait in an impl as the value for an associated type in an impl...
Santiago Pastorino [Fri, 20 Aug 2021 21:06:31 +0000 (18:06 -0300)]
Test use of impl Trait in an impl as the value for an associated type in an impl trait

2 years agoStop emitting the `dso_local` LLVM attribute for external symbols under the static...
Patrick Walton [Fri, 20 Aug 2021 23:42:45 +0000 (16:42 -0700)]
Stop emitting the `dso_local` LLVM attribute for external symbols under the static relocation model on macOS.

This matches Clang's behavior:

https://github.com/llvm/llvm-project/blob/973cb2c326be9f256da0897c4d2ef117dc22761d/clang/lib/CodeGen/CodeGenModule.cpp#L1038-L1040

Even if `dso_local` were properly supported in this way on macOS, it seems
incorrect to add this annotation as liberally as we did. The `dso_local`
annotation is for symbols that ultimately end up in the same linkage unit, but
we were adding this annotation even for `static` values inside `extern` blocks
marked with `#[link(type="framework")]`, which should be considered dynamically
linked.  Note that Clang likewise avoids emitting `dso_local` for `dllimport`
symbols:

https://github.com/llvm/llvm-project/blob/973cb2c326be9f256da0897c4d2ef117dc22761d/clang/lib/CodeGen/CodeGenModule.cpp#L1005-L1007

This issue caused breakage in the `ring` crate, which links to a symbol defined
in `Security.framework` that ultimately resolves to address `0x0`:

https://github.com/briansmith/ring/blob/b94d61e044b42827fefd71d5f61e8c58a7659870/src/rand.rs#L390

For this symbol, the use of `dso_local` causes LLVM to emit a relocation of
type `X86_64_RELOC_SIGNED`, which is a 32-bit signed PC-relative offset. If the
binary is large enough, `0x0` might be out of range, and the link will fail.
Avoiding `dso_local` causes LLVM to use the GOT instead, emitting a relocation
of type `X86_64_RELOC_GOT_LOAD`, which will properly handle the large offset
and cause the link to succeed.

As a side note, the static relocation model is effectively deprecated for
security reasons on macOS, as it prohibits PIE. It's also completely
unsupported on Apple Silicon, so I don't think it's worth going to the effort
of properly supporting this model on that platform.

2 years agoAuto merge of #88087 - jesyspa:issue-87935-box, r=jackh726
bors [Fri, 20 Aug 2021 23:04:57 +0000 (23:04 +0000)]
Auto merge of #88087 - jesyspa:issue-87935-box, r=jackh726

Check that a box expression's type is Sized

This resolves [issue 87935](https://github.com/rust-lang/rust/issues/87935).

This makes E0161 (move from an unsized rvalue) much less common.  I've replaced the test to use [this case](https://github.com/rust-lang/rust/blob/master/src/test/ui/object-safety/object-safety-by-value-self-use.rs), when a boxed `dyn` trait is passed by value, but that isn't an error when `unsized_locals` is enabled.  I think it may be possible to get rid of E0161 entirely by checking that case earlier, but I'm not sure if that's desirable?

2 years agoImprove error reporting for closure return type mismatches
Fabian Wolff [Sat, 31 Jul 2021 13:46:03 +0000 (15:46 +0200)]
Improve error reporting for closure return type mismatches

2 years agoTest tait use in a fn type
Santiago Pastorino [Fri, 20 Aug 2021 21:32:57 +0000 (18:32 -0300)]
Test tait use in a fn type

2 years agomove `fallback_if_possible` and friends to fallback.rs
Niko Matsakis [Sun, 22 Nov 2020 11:10:50 +0000 (06:10 -0500)]
move `fallback_if_possible` and friends to fallback.rs

Along the way, simplify and document the logic more clearly.

2 years agocreate `Coercion` obligations given 2 unbound type variables
Niko Matsakis [Sat, 21 Nov 2020 20:47:14 +0000 (15:47 -0500)]
create `Coercion` obligations given 2 unbound type variables

Motivation: in upcoming commits, we are going to create a graph of the
coercion relationships between variables. We want to
distinguish *coercion* specifically from other sorts of subtyping, as
it indicates values flowing from one place to another via assignment.

2 years agomove the `sub-unify` check and extend the documentation a bit
Niko Matsakis [Sat, 21 Nov 2020 20:33:36 +0000 (15:33 -0500)]
move the `sub-unify` check and extend the documentation a bit

I didn't like the sub-unify code executing when a predicate was
ENQUEUED, that felt fragile. I would have preferred to move the
sub-unify code so that it only occurred during generalization, but
that impacted diagnostics, so having it also occur when we process
subtype predicates felt pretty reasonable. (I guess we only need one
or the other, but I kind of prefer both, since the generalizer
ultimately feels like the *right* place to guarantee the properties we
want.)

2 years agoUse of impl trait in an impl as the valoe for an associated type in a dyn
Santiago Pastorino [Fri, 20 Aug 2021 20:33:21 +0000 (17:33 -0300)]
Use of impl trait in an impl as the valoe for an associated type in a dyn