Commit graph

153436 commits

Author SHA1 Message Date
bors
47ab5f7ce2 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`
2021-08-24 12:13:37 +00:00
Patrick Amrein
8f65d154c8 allow specifying an ios version for the llvm target 2021-08-24 08:23:05 +02:00
bors
f66e825f73 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.
2021-08-24 03:58:22 +00:00
bors
5ca596f486 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:
fc81ad22c4/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()`:
fc81ad22c4/compiler/rustc_passes/src/liveness.rs (L981)
fc81ad22c4/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.
2021-08-24 01:36:09 +00:00
bors
de42550d0a 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>
2021-08-23 22:55:19 +00:00
bors
a49e38e672 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
2021-08-23 20:10:29 +00:00
Mara Bos
e710132616
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`
2021-08-23 20:45:51 +02:00
Mara Bos
c31e02a24c
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`
2021-08-23 20:45:50 +02:00
Mara Bos
5cf025f076
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.
2021-08-23 20:45:49 +02:00
Mara Bos
6d1c5b6360
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`
2021-08-23 20:45:48 +02:00
Mara Bos
d486ce75bc
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.
2021-08-23 20:45:47 +02:00
Mara Bos
70aec8d7fb
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)
2021-08-23 20:45:40 +02:00
bors
9583fd1bdd 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
2021-08-23 17:27:23 +00:00
Mara Bos
908ce2fd1f Improve wording of macro-not-found-but-name-exists note. 2021-08-23 16:57:59 +02:00
Mara Bos
4e22bf47d0 Show what things are, but also what they are not. 2021-08-23 16:57:59 +02:00
Mara Bos
a13c66e0a5 Don't confuse the user with notes about tool modules. 2021-08-23 16:57:59 +02:00
Mara Bos
4bd415f70a Clarify what attribute and derive macros look like. 2021-08-23 16:57:58 +02:00
Mara Bos
5dea5d7549 Say what things are, instead of what they are not. 2021-08-23 16:57:58 +02:00
Mara Bos
d834d2a742 Silence confusing 'unused import' warnings. 2021-08-23 16:57:58 +02:00
Mara Bos
ce95a57a72 Update tests. 2021-08-23 16:43:54 +02:00
Mara Bos
11c879d209 Add tests for macro-not-found diagnostics. 2021-08-23 16:43:54 +02:00
Mara Bos
7977cb43b0 Look for macro names in all namespaces for diagnostics. 2021-08-23 16:43:54 +02:00
Mara Bos
9051c056ed Add test for macro-not-found-but-name-imported-here note. 2021-08-23 16:43:54 +02:00
Mara Bos
fed6131c41 Add note to 'macro not found' to point to identically-named imports. 2021-08-23 16:43:54 +02:00
bors
52c881ff52 Auto merge of #87661 - FabianWolff:issue-87461, r=estebank
Improve error reporting for closure return type mismatches

Fixes #87461.
2021-08-23 14:41:14 +00:00
Esteban Kuber
955e913612 review comments 2021-08-23 14:31:48 +00:00
Léo Lanteri Thauvin
6a2b448f2a Do not mark -Z thir-unsafeck as unsound anymore 2021-08-23 14:52:42 +02:00
Guillaume Gomez
b7fe005eef Greatly improve limitation handling on parallel rustdoc GUI test run 2021-08-23 14:23:59 +02:00
Esteban Kuber
31d07edc94 remove unnecessary info!() logging 2021-08-23 11:58:19 +00:00
Esteban Kuber
5626346ac9 Fixes to span locations 2021-08-23 11:58:19 +00:00
Esteban Kuber
a29a624f86 wip 2021-08-23 11:58:19 +00:00
Esteban Kuber
75fd1bf1e6 Account for tabs when highlighting multiline code suggestions 2021-08-23 11:58:18 +00:00
bors
5998c2e9ad Auto merge of #88249 - lnicola:rust-analyzer-2021-08-23, r=lnicola
⬆️ rust-analyzer
2021-08-23 10:46:31 +00:00
bors
33fdb797f5 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`
2021-08-23 07:36:49 +00:00
Laurențiu Nicola
0a3a457d54 ⬆️ rust-analyzer 2021-08-23 09:01:38 +03:00
bors
1c0485610e Auto merge of #87598 - ccqpein:master, r=yaahc
Add doctests for HashMap's into_values and into_keys methods

Fixes #87591
2021-08-23 05:06:29 +00:00
bors
49967357c5 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
2021-08-23 02:25:36 +00:00
Dan Gohman
a0ce5f25fa Remove redundant conversions. 2021-08-22 16:51:30 -07:00
bors
558553272d 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:

973cb2c326/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:

973cb2c326/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`:

b94d61e044/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.
2021-08-22 23:44:48 +00:00
bors
af140757b4 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
2021-08-22 20:23:37 +00:00
Guillaume Gomez
3e8e8d2dad
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`
2021-08-22 20:52:56 +02:00
Guillaume Gomez
518b27b57a
Rollup merge of #88229 - m-ou-se:macro-suggest-right-kind, r=estebank
Suggest importing the right kind of macro.

Fixes #88228.

r? `@estebank`
2021-08-22 20:52:55 +02:00
Guillaume Gomez
167ae26a88
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
2021-08-22 20:52:54 +02:00
Guillaume Gomez
2638d27ba5
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.
2021-08-22 20:52:53 +02:00
Guillaume Gomez
c6da5b08e0
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.
2021-08-22 20:52:52 +02:00
Guillaume Gomez
3b1e7b1fc9
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)
2021-08-22 20:52:51 +02:00
Guillaume Gomez
2627db6a3c
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`
2021-08-22 20:52:50 +02:00
bors
91f9806208 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`
2021-08-22 18:00:22 +00:00
Frank Steffahn
2f9ddf3bc7 Fix typos “an”→“a” and a few different ones that appeared in the same search 2021-08-22 18:15:49 +02:00
Frank Steffahn
2396fad095 Fix more “a”/“an” typos 2021-08-22 17:27:18 +02:00