]> git.lizzy.rs Git - rust.git/log
rust.git
2 years agoRollup merge of #88267 - sexxi-goose:truncate_unique, r=nikomatsakis
Léo Lanteri Thauvin [Wed, 25 Aug 2021 13:48:54 +0000 (15:48 +0200)]
Rollup merge of #88267 - sexxi-goose:truncate_unique, r=nikomatsakis

2229: Update signature for truncate function

r? `@nikomatsakis`

2 years agoRollup merge of #88226 - steffahn:an_rc, r=michaelwoerister
Léo Lanteri Thauvin [Wed, 25 Aug 2021 13:48:53 +0000 (15:48 +0200)]
Rollup merge of #88226 - steffahn:an_rc, r=michaelwoerister

Fix typo “a Rc” → “an Rc” (and a few more)

After stumbling about it in the dev-guide, I’ve devided to eliminate all mentions of “a Rc”, replacing it with “an Rc”. E.g.
```plain
$ rg "(^|[^'])\ba\b[^\w=:]*\bRc"
compiler/rustc_data_structures/src/owning_ref/mod.rs
1149:/// Typedef of a owning reference that uses a `Rc` as the owner.

library/std/src/ffi/os_str.rs
919:    /// Converts a [`OsString`] into a [`Rc`]`<OsStr>` without copying or allocating.

library/std/src/ffi/c_str.rs
961:    /// Converts a [`CString`] into a [`Rc`]`<CStr>` without copying or allocating.

src/doc/rustc-dev-guide/src/query.md
61:are cheaply cloneable; insert a `Rc` if necessary).

src/doc/book/src/ch15-06-reference-cycles.md
72:decreases the reference count of the `a` `Rc<List>` instance from 2 to 1 as

library/alloc/src/rc.rs
1746:    /// Converts a generic type `T` into a `Rc<T>`
```
_(the match in the book is a false positive)_
Since the dev-guide is a submodule, it’s getting a separate PR: rust-lang/rustc-dev-guide#1191

I’ve also gone ahead and done the same search for `RwLock` and hit a few cases in the `OwningRef` adaption. Then, I couldn’t keep the countless cases of “a owning …” or “a owner” unaddressed, which concludes this PR.

`@rustbot` label C-cleanup

2 years agoRollup merge of #88223 - scottmcm:fix-alias, r=yaahc
Léo Lanteri Thauvin [Wed, 25 Aug 2021 13:48:52 +0000 (15:48 +0200)]
Rollup merge of #88223 - scottmcm:fix-alias, r=yaahc

Remove the `TryV2` alias

Post-bootstrap-update cleanup.

(No more `try_trait_transition` feature.)

2 years agoRollup merge of #88218 - Aaron1011:missing-method-dyn, r=nagisa
Léo Lanteri Thauvin [Wed, 25 Aug 2021 13:48:51 +0000 (15:48 +0200)]
Rollup merge of #88218 - Aaron1011:missing-method-dyn, r=nagisa

Remove `Session.trait_methods_not_found`

Instead, avoid registering the problematic well-formed obligation
to begin with. This removes global untracked mutable state,
and avoids potential issues with incremental compilation.

2 years agoRollup merge of #88196 - asquared31415:named-asm-labels-refactor, r=Amanieu
Léo Lanteri Thauvin [Wed, 25 Aug 2021 13:48:50 +0000 (15:48 +0200)]
Rollup merge of #88196 - asquared31415:named-asm-labels-refactor, r=Amanieu

Refactor `named_asm_labels` to a HIR lint

As discussed on #88169, the `named_asm_labels` lint could be moved to a HIR lint.  That allows future lints or custom plugins or clippy lints to more easily access the `asm!` macro's data and create better error messages with the lints.

2 years agoRollup merge of #88157 - Icenowy:bootstrap-riscv64, r=Mark-Simulacrum
Léo Lanteri Thauvin [Wed, 25 Aug 2021 13:48:49 +0000 (15:48 +0200)]
Rollup merge of #88157 - Icenowy:bootstrap-riscv64, r=Mark-Simulacrum

bootstrap.py: recognize riscv64 when auto-detect

The architecture auto-detect table has no entry for riscv64 (which rustc
uses riscv64gc for the first part of triplet, assuming it's a generic
Linux distro).

Add it to the table to allow riscv64 systems to bootstrap Rust.

Signed-off-by: Icenowy Zheng <icenowy@aosc.io>
2 years agoRollup merge of #88156 - steffahn:arc_make_mut_and_weak, r=Mark-Simulacrum
Léo Lanteri Thauvin [Wed, 25 Aug 2021 13:48:48 +0000 (15:48 +0200)]
Rollup merge of #88156 - steffahn:arc_make_mut_and_weak, r=Mark-Simulacrum

Adjust / fix documentation of `Arc::make_mut`

Related discussion in the users forum:
[Whatʼs this alleged difference between Arc::make_mut and Rc::make_mut? – The Rust Programming Language Forum](https://users.rust-lang.org/t/what-s-this-alleged-difference-between-arc-make-mut-and-rc-make-mut/63747?u=steffahn)

Also includes a small formatting improvement in the documentation of `Rc::make_mut`.

This PR makes the two documentations in question complete analogs. The previously claimed point in which one “differs from the behavior of” the other turns out to be incorrect, AFAIK.

One remaining inaccuracy: `Weak` pointers aren’t disassociated from the allocation but only from the contained value, i.e. in case of outstanding `Weak` pointers there still is a new allocation created, just the call to `.clone()` is avoided, instead the value is moved from one allocation to the other.

`@rustbot` label T-libs-api, A-docs

2 years agoRollup merge of #87944 - oconnor663:as_array_of_cells, r=scottmcm
Léo Lanteri Thauvin [Wed, 25 Aug 2021 13:48:47 +0000 (15:48 +0200)]
Rollup merge of #87944 - oconnor663:as_array_of_cells, r=scottmcm

add Cell::as_array_of_cells, similar to Cell::as_slice_of_cells

I'd like to propose adding `Cell::as_array_of_cells`, as a natural analog to `Cell::as_slice_of_cells`. I don't have a specific use case in mind, other than that supporting slices but not arrays feels like a gap. Do other folks agree with that intuition? Would this addition be substantial enough to need an RFC?

---

Previously, converting `&mut [T; N]` to `&[Cell<T>; N]` looks like this:

```rust
let array = &mut [1, 2, 3];
let cells: &[Cell<i32>; 3] = Cell::from_mut(&mut array[..])
    .as_slice_of_cells()
    .try_into()
    .unwrap();
```

With this new helper method, it looks like this:

```rust
let array = &mut [1, 2, 3];
let cells = Cell::from_mut(array).as_array_of_cells();
```

2 years agoAuto merge of #85344 - cbeuw:remap-across-cwd, r=michaelwoerister
bors [Wed, 25 Aug 2021 10:58:43 +0000 (10:58 +0000)]
Auto merge of #85344 - cbeuw:remap-across-cwd, r=michaelwoerister

Correctly handle remapping from path containing the current directory with trailing paths

If we have a `auxiliary/lib.rs`, and we generate the metadata with `--remap-path-prefix $PWD/auxiliary=xyz`, the path to `$PWD/auxiliary/lib.rs` won't be correctly remapped in the metadata. This is because internally, path to the working directory itself and relative paths to files under the working directory are remapped separately (hence neither are affected since neither has `$PWD/auxiliary` as prefix), but the concatenation between the working directory and the relative path is not remapped. This PR fixes that.

2 years agoAuto merge of #87875 - asquared31415:generic-lang-items, r=cjgillot
bors [Wed, 25 Aug 2021 08:12:16 +0000 (08:12 +0000)]
Auto merge of #87875 - asquared31415:generic-lang-items, r=cjgillot

Improve detection of generics on lang items

Adds detection for the required generics for all lang items.  Many lang items require an exact or minimum amount of generic arguments and if they don't exist, the compiler will ICE.  This does not add any additional validation about bounds on generics or any other lang item restrictions.

Fixes one of the ICEs in #87573

cc `@FabianWolff`

2 years agoAuto merge of #84333 - tmiasko:liveness-yield, r=tmandry
bors [Wed, 25 Aug 2021 05:31:26 +0000 (05:31 +0000)]
Auto merge of #84333 - tmiasko:liveness-yield, r=tmandry

Improve liveness analysis for generators

Liveness analysis for generators assumes that execution always continues
normally after a yield point, not accounting for the fact that generator
could be dropped before completion.

If generators captures any variables by reference, those variables could
be used within a generator, or when the generator completes, but also
after each yield point in the case the generator is dropped.

Account for the case when generator is dropped after yielding, but
before running to the completion. This effectively considers all
variables captured by reference to be used after a yield point.

Fixes #84292.

2 years agoAuto merge of #88242 - bonega:allocation_range, r=oli-obk
bors [Wed, 25 Aug 2021 02:17:41 +0000 (02:17 +0000)]
Auto merge of #88242 - bonega:allocation_range, r=oli-obk

Use custom wrap-around type instead of RangeInclusive

Two reasons:

1. More memory is allocated than necessary for `valid_range` in `Scalar`. The range is not used as an iterator and `exhausted` is never used.
2. `contains`, `count` etc. methods in `RangeInclusive` are doing very unhelpful(and dangerous!) things when used as a wrap-around range. - In general this PR wants to limit potentially confusing methods, that have a low probability of working.

Doing a local perf run, every metric shows improvement except for instructions.
Max-rss seem to have a very consistent improvement.

Sorry - newbie here, probably doing something wrong.

2 years agoAuto merge of #88271 - sexxi-goose:liveness, r=nikomatsakis
bors [Tue, 24 Aug 2021 23:30:44 +0000 (23:30 +0000)]
Auto merge of #88271 - sexxi-goose:liveness, r=nikomatsakis

2229: Consider varaiables mentioned in closure as used

Fixes: https://github.com/rust-lang/project-rfc-2229/issues/57
r? `@nikomatsakis`

2 years agoAuto merge of #88266 - nikomatsakis:issue-87879, r=jackh726
bors [Tue, 24 Aug 2021 20:49:55 +0000 (20:49 +0000)]
Auto merge of #88266 - nikomatsakis:issue-87879, r=jackh726

resolve type variables after checking casts

r? `@jackh726`

Fixes #87814
Fixes #88118

Supercedes #87879 (cc `@ldm0)`

2 years agoMake explanations of cross-references between `make_mut` and `get_mut` more accurate
Frank Steffahn [Tue, 24 Aug 2021 19:34:12 +0000 (21:34 +0200)]
Make explanations of cross-references between `make_mut` and `get_mut` more accurate

2 years agoClarifiy weak pointers being diassociated…
Frank Steffahn [Tue, 24 Aug 2021 19:15:26 +0000 (21:15 +0200)]
Clarifiy weak pointers being diassociated…

…noting the fact that `clone` is not called.

Co-authored-by: Mark Rousskov <mark.simulacrum@gmail.com>
2 years agouse convention for with_* methods
Andreas Liljeqvist [Tue, 24 Aug 2021 17:41:58 +0000 (19:41 +0200)]
use convention for with_* methods

2 years agoAuto merge of #87472 - inquisitivecrystal:stabilize-force-warn, r=Mark-Simulacrum
bors [Tue, 24 Aug 2021 17:41:24 +0000 (17:41 +0000)]
Auto merge of #87472 - inquisitivecrystal:stabilize-force-warn, r=Mark-Simulacrum

Stabilize and document `--force-warn`

This PR will stabilize and document the `--force-warn` command line option. It is currently a draft, pending an FCP.

I've taken the liberty of tidying up the lint level command line options a bit as part of this. The changes are quite minor and should only affect rustc's help output. I'm making them here because they're trivial and, in one case, necessary to unify the way `--force-warn` with the way the other options are displayed.

I also want to mention that `@rylev` has done a ton of work on moving this along and deserves most of the credit. I'm just the one who landed up writing this particular PR.

Resolves #86516.

2 years agoUpdate tests
inquisitivecrystal [Sat, 24 Jul 2021 08:08:33 +0000 (01:08 -0700)]
Update tests

This updates tests to reflect that `force-warn` is now stable.

2 years agoDocument `force-warn`
inquisitivecrystal [Sat, 24 Jul 2021 06:31:09 +0000 (23:31 -0700)]
Document `force-warn`

Co-authored-by: Mark Rousskov <mark.simulacrum@gmail.com>
2 years agoStabilize `force-warn`
inquisitivecrystal [Sat, 24 Jul 2021 07:05:24 +0000 (00:05 -0700)]
Stabilize `force-warn`

2 years agoTidy up lint command line flags
inquisitivecrystal [Sat, 24 Jul 2021 06:59:17 +0000 (23:59 -0700)]
Tidy up lint command line flags

2 years agoAuto merge of #87900 - jackh726:issue-87429, r=nikomatsakis
bors [Tue, 24 Aug 2021 14:55:48 +0000 (14:55 +0000)]
Auto merge of #87900 - jackh726:issue-87429, r=nikomatsakis

Use bound vars for GAT params in param_env in check_type_bounds

Fixes #87429

2 years agoMove `named_asm_labels` to a HIR lint
asquared31415 [Thu, 19 Aug 2021 20:34:01 +0000 (16:34 -0400)]
Move `named_asm_labels` to a HIR lint

2 years agoIgnore test on Windows
Andy Wang [Tue, 24 Aug 2021 12:21:27 +0000 (13:21 +0100)]
Ignore test on Windows

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 agoImprove liveness analysis for generators
Tomasz Miąsko [Mon, 19 Apr 2021 00:00:00 +0000 (00:00 +0000)]
Improve liveness analysis for generators

Liveness analysis for generators assumes that execution always continues
normally after a yield point, not accounting for the fact that generator
could be dropped before completion.

If generators captures any variables by reference, those variables could
be used within a generator, or when the generator completes, but also
after each yield point in the case the generator is dropped.

Account for the case when generator is dropped after yielding, but
before running to the completion. This effectively considers all
variables captured by reference to be used after a yield point.

2 years agoForce inline: small functions and single call-site
Andreas Liljeqvist [Tue, 24 Aug 2021 08:18:07 +0000 (10:18 +0200)]
Force inline: small functions and single call-site

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 agoAlso fix “a `OwningRef`”
Frank Steffahn [Sun, 22 Aug 2021 10:41:53 +0000 (12:41 +0200)]
Also fix “a `OwningRef`”

2 years agoAlso fix “a RwLock*”
Frank Steffahn [Sun, 22 Aug 2021 10:39:39 +0000 (12:39 +0200)]
Also fix “a RwLock*”

2 years agoFix typo “a Rc” → “an Rc”
Frank Steffahn [Sun, 22 Aug 2021 10:33:27 +0000 (12:33 +0200)]
Fix typo “a Rc” → “an Rc”

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 ago2229: Consider varaiables mentioned in closure as used
Aman Arora [Mon, 23 Aug 2021 22:47:38 +0000 (18:47 -0400)]
2229: Consider varaiables mentioned in closure as used

2 years agofix test
Niko Matsakis [Mon, 23 Aug 2021 22:25:55 +0000 (22:25 +0000)]
fix test

2 years agox.py fmt
Niko Matsakis [Mon, 23 Aug 2021 22:21:21 +0000 (22:21 +0000)]
x.py fmt

2 years agoAdd comment and extra test
jackh726 [Mon, 23 Aug 2021 20:39:11 +0000 (16:39 -0400)]
Add comment and extra test

2 years agoAdd a couple more tests
jackh726 [Mon, 16 Aug 2021 14:49:36 +0000 (10:49 -0400)]
Add a couple more tests

2 years agoWhen checking associated type bounds, use bound vars for GAT params in param_env
jackh726 [Mon, 9 Aug 2021 23:26:13 +0000 (19:26 -0400)]
When checking associated type bounds, use bound vars for GAT params in param_env

2 years ago2229: Update signature for truncate function
Aman Arora [Mon, 23 Aug 2021 19:59:46 +0000 (15:59 -0400)]
2229: Update signature for truncate function

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 agoadd trailing newline
Niko Matsakis [Mon, 23 Aug 2021 19:53:18 +0000 (19:53 +0000)]
add trailing newline

2 years agouseful debug printouts
Niko Matsakis [Mon, 23 Aug 2021 19:14:06 +0000 (19:14 +0000)]
useful debug printouts

The changes to dumping expressions seem particularly useful

2 years agofix apparent typo in resolving variables
Niko Matsakis [Mon, 23 Aug 2021 19:07:14 +0000 (19:07 +0000)]
fix apparent typo in resolving variables

2 years agoselect obligations after `check_casts`
liudingming [Mon, 9 Aug 2021 12:25:57 +0000 (20:25 +0800)]
select obligations after `check_casts`

Otherwise, we can get into a situation where you have
a subtype obligation `#1 <: #2` pending, #1 is constrained
by `check_casts`, but #2` is unaffected.

Co-authored-by: Niko Matsakis <niko@alum.mit.edu>
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 agoDetect incorrect number of lang item generics
asquared31415 [Sun, 15 Aug 2021 01:38:37 +0000 (21:38 -0400)]
Detect incorrect number of lang item generics

2 years agoSimplify zero check
Andreas Liljeqvist [Mon, 23 Aug 2021 13:52:47 +0000 (15:52 +0200)]
Simplify zero check

2 years agoadd `with_start` and `with_end`
Andreas Liljeqvist [Mon, 23 Aug 2021 13:44:56 +0000 (15:44 +0200)]
add `with_start` and `with_end`

2 years agoimplement debug in similar way to RangeInclusive
Andreas Liljeqvist [Mon, 23 Aug 2021 13:05:40 +0000 (15:05 +0200)]
implement debug in similar way to RangeInclusive

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 agoRename to WrappingRange
Andreas Liljeqvist [Mon, 23 Aug 2021 12:24:34 +0000 (14:24 +0200)]
Rename to WrappingRange

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 agoimplement contains_zero method
Andreas Liljeqvist [Mon, 23 Aug 2021 12:20:38 +0000 (14:20 +0200)]
implement contains_zero method

2 years agoUse ref
Andreas Liljeqvist [Mon, 23 Aug 2021 12:18:48 +0000 (14:18 +0200)]
Use ref

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 agoRemoved fixed fixme
Andreas Liljeqvist [Mon, 23 Aug 2021 11:56:28 +0000 (13:56 +0200)]
Removed fixed fixme

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 agoremove commented code
Andreas Liljeqvist [Mon, 23 Aug 2021 09:21:27 +0000 (11:21 +0200)]
remove commented code

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 agoadd Cell::as_array_of_cells, similar to Cell::as_slice_of_cells
Jack O'Connor [Wed, 11 Aug 2021 18:38:20 +0000 (14:38 -0400)]
add Cell::as_array_of_cells, similar to Cell::as_slice_of_cells

Previously, converting `&mut [T; N]` to `&[Cell<T>; N]` looks like this:

    let array = &mut [1, 2, 3];
    let cells: &[Cell<i32>; 3] = Cell::from_mut(&mut array[..])
        .as_slice_of_cells()
        .try_into()
        .unwrap();

With this new helper method, it looks like this:

    let array = &mut [1, 2, 3];
    let cells: &[Cell<i32>; 3] = Cell::from_mut(array).as_array_of_cells();

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 agofix 32bit err
Andreas Liljeqvist [Sun, 22 Aug 2021 20:45:51 +0000 (22:45 +0200)]
fix 32bit err

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 agoUse custom wrap-around type instead of Range
Andreas Liljeqvist [Sun, 22 Aug 2021 19:46:03 +0000 (21:46 +0200)]
Use custom wrap-around type instead of Range

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`