]> git.lizzy.rs Git - rust.git/log
rust.git
2 years agoSome perf optimizations and logging
jackh726 [Fri, 16 Jul 2021 20:23:42 +0000 (16:23 -0400)]
Some perf optimizations and logging

3 years agoAuto merge of #83898 - Aaron1011:feature/hir-wf, r=estebank
bors [Fri, 16 Jul 2021 21:54:42 +0000 (21:54 +0000)]
Auto merge of #83898 - Aaron1011:feature/hir-wf, r=estebank

Add initial implementation of HIR-based WF checking for diagnostics

During well-formed checking, we walk through all types 'nested' in
generic arguments. For example, WF-checking `Option<MyStruct<u8>>`
will cause us to check `MyStruct<u8>` and `u8`. However, this is done
on a `rustc_middle::ty::Ty`, which has no span information. As a result,
any errors that occur will have a very general span (e.g. the
definintion of an associated item).

This becomes a problem when macros are involved. In general, an
associated type like `type MyType = Option<MyStruct<u8>>;` may
have completely different spans for each nested type in the HIR. Using
the span of the entire associated item might end up pointing to a macro
invocation, even though a user-provided span is available in one of the
nested types.

This PR adds a framework for HIR-based well formed checking. This check
is only run during error reporting, and is used to obtain a more precise
span for an existing error. This is accomplished by individually
checking each 'nested' type in the HIR for the type, allowing us to
find the most-specific type (and span) that produces a given error.

The majority of the changes are to the error-reporting code. However,
some of the general trait code is modified to pass through more
information.

Since this has no soundness implications, I've implemented a minimal
version to begin with, which can be extended over time. In particular,
this only works for HIR items with a corresponding `DefId` (e.g. it will
not work for WF-checking performed within function bodies).

3 years agoAdd initial implementation of HIR-based WF checking for diagnostics
Aaron Hill [Sun, 4 Apr 2021 20:55:39 +0000 (16:55 -0400)]
Add initial implementation of HIR-based WF checking for diagnostics

During well-formed checking, we walk through all types 'nested' in
generic arguments. For example, WF-checking `Option<MyStruct<u8>>`
will cause us to check `MyStruct<u8>` and `u8`. However, this is done
on a `rustc_middle::ty::Ty`, which has no span information. As a result,
any errors that occur will have a very general span (e.g. the
definintion of an associated item).

This becomes a problem when macros are involved. In general, an
associated type like `type MyType = Option<MyStruct<u8>>;` may
have completely different spans for each nested type in the HIR. Using
the span of the entire associated item might end up pointing to a macro
invocation, even though a user-provided span is available in one of the
nested types.

This PR adds a framework for HIR-based well formed checking. This check
is only run during error reporting, and is used to obtain a more precise
span for an existing error. This is accomplished by individually
checking each 'nested' type in the HIR for the type, allowing us to
find the most-specific type (and span) that produces a given error.

The majority of the changes are to the error-reporting code. However,
some of the general trait code is modified to pass through more
information.

Since this has no soundness implications, I've implemented a minimal
version to begin with, which can be extended over time. In particular,
this only works for HIR items with a corresponding `DefId` (e.g. it will
not work for WF-checking performed within function bodies).

3 years agoAuto merge of #87201 - GuillaumeGomez:rollup-4loi2q9, r=GuillaumeGomez
bors [Fri, 16 Jul 2021 19:04:16 +0000 (19:04 +0000)]
Auto merge of #87201 - GuillaumeGomez:rollup-4loi2q9, r=GuillaumeGomez

Rollup of 7 pull requests

Successful merges:

 - #87107 (Loop over all opaque types instead of looking at just the first one with the same DefId)
 - #87158 (Suggest full enum variant for local modules)
 - #87174 (Stabilize `[T; N]::map()`)
 - #87179 (Mark `const_trait_impl` as active)
 - #87180 (feat(rustdoc): open sidebar menu when links inside it are focused)
 - #87188 (Add GUI test for auto-hide-trait-implementations setting)
 - #87200 (TAIT: Infer all inference variables in opaque type substitutions via InferCx)

Failed merges:

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

3 years agoRollup merge of #87200 - oli-obk:fixup_fixup_opaque_types, r=nikomatsakis
Guillaume Gomez [Fri, 16 Jul 2021 17:54:12 +0000 (19:54 +0200)]
Rollup merge of #87200 - oli-obk:fixup_fixup_opaque_types, r=nikomatsakis

TAIT: Infer all inference variables in opaque type substitutions via InferCx

The previous algorithm was correct for the example given in its
documentation, but when the TAIT was declared as a free item
instead of an associated item, the generic parameters were the
wrong ones.

cc `@spastorino`

r? `@nikomatsakis`

3 years agoRollup merge of #87188 - GuillaumeGomez:gui-test-auto-hide-trait-impl, r=notriddle
Guillaume Gomez [Fri, 16 Jul 2021 17:54:10 +0000 (19:54 +0200)]
Rollup merge of #87188 - GuillaumeGomez:gui-test-auto-hide-trait-impl, r=notriddle

Add GUI test for auto-hide-trait-implementations setting

Fixes #85592.

r? ``@notriddle``

3 years agoRollup merge of #87180 - notriddle:notriddle/sidebar-keyboard-mobile, r=GuillaumeGomez
Guillaume Gomez [Fri, 16 Jul 2021 17:54:08 +0000 (19:54 +0200)]
Rollup merge of #87180 - notriddle:notriddle/sidebar-keyboard-mobile, r=GuillaumeGomez

feat(rustdoc): open sidebar menu when links inside it are focused

Fixes #87172

Based on #87167 (which should be merged first)

r? ``@GuillaumeGomez``

Preview it at https://notriddle.com/notriddle-rustdoc-test/std/index.html

3 years agoRollup merge of #87179 - fee1-dead:active-const-impl, r=oli-obk
Guillaume Gomez [Fri, 16 Jul 2021 17:54:06 +0000 (19:54 +0200)]
Rollup merge of #87179 - fee1-dead:active-const-impl, r=oli-obk

Mark `const_trait_impl` as active

See [this zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/146212-t-compiler.2Fconst-eval/topic/implementation.20path.20for.20const.20trait.20impls).

r? ``@oli-obk``

3 years agoRollup merge of #87174 - inquisitivecrystal:array-map, r=kennytm
Guillaume Gomez [Fri, 16 Jul 2021 17:54:04 +0000 (19:54 +0200)]
Rollup merge of #87174 - inquisitivecrystal:array-map, r=kennytm

Stabilize `[T; N]::map()`

This stabilizes the `[T; N]::map()` function, gated by the `array_map` feature. The FCP has [already completed.](https://github.com/rust-lang/rust/issues/75243#issuecomment-878448138)

Closes #75243.

3 years agoRollup merge of #87158 - In-line:suggest-full-enum-variant-for-local-module, r=estebank
Guillaume Gomez [Fri, 16 Jul 2021 17:54:02 +0000 (19:54 +0200)]
Rollup merge of #87158 - In-line:suggest-full-enum-variant-for-local-module, r=estebank

Suggest full enum variant for local modules

3 years agoRollup merge of #87107 - oli-obk:tait_double, r=nikomatsakis
Guillaume Gomez [Fri, 16 Jul 2021 17:53:59 +0000 (19:53 +0200)]
Rollup merge of #87107 - oli-obk:tait_double, r=nikomatsakis

Loop over all opaque types instead of looking at just the first one with the same DefId

This exposed a bug in VecMap and is needed for https://github.com/rust-lang/rust/pull/86410 anyway

r? ``@spastorino``

cc ``@nikomatsakis``

3 years agoInfer all inference variables via InferCx
Oli Scherer [Fri, 16 Jul 2021 17:34:23 +0000 (17:34 +0000)]
Infer all inference variables via InferCx

The previous algorithm was correct for the example given in its
documentation, but when the TAIT was declared as a free item
instead of an associated item, the generic parameters were the
wrong ones.

3 years agoAdd some more tracing instrumentation
Oli Scherer [Fri, 16 Jul 2021 17:34:17 +0000 (17:34 +0000)]
Add some more tracing instrumentation

3 years agoAuto merge of #84623 - jackh726:gats-incomplete, r=nikomatsakis
bors [Fri, 16 Jul 2021 16:23:15 +0000 (16:23 +0000)]
Auto merge of #84623 - jackh726:gats-incomplete, r=nikomatsakis

Make GATs no longer an incomplete feature

Blocked on ~#84622~, ~#82272~, ~#76826~

r? `@nikomatsakis`

3 years agofeat(rustdoc): open sidebar menu when links inside it are focused
Michael Howell [Fri, 16 Jul 2021 15:04:49 +0000 (08:04 -0700)]
feat(rustdoc): open sidebar menu when links inside it are focused

Fixes #87172

Based on #87167 (which should be merged first)

Preview it at https://notriddle.com/notriddle-rustdoc-test/std/index.html

Co-authored-by: Guillaume Gomez <guillaume.gomez@huawei.com>
3 years agoAuto merge of #87140 - camsteffen:pat-slice-refs, r=oli-obk
bors [Fri, 16 Jul 2021 13:35:48 +0000 (13:35 +0000)]
Auto merge of #87140 - camsteffen:pat-slice-refs, r=oli-obk

Remove refs from Pat slices

Changes `PatKind::Or(&'hir [&'hir Pat<'hir>])` to `PatKind::Or(&'hir [Pat<'hir>])` and others. This is more consistent with `ExprKind`, saves a little memory, and is a little easier to use.

3 years agoAdd GUI test for auto-hide-trait-implementations setting
Guillaume Gomez [Fri, 16 Jul 2021 13:15:23 +0000 (15:15 +0200)]
Add GUI test for auto-hide-trait-implementations setting

3 years agoAuto merge of #87182 - GuillaumeGomez:rollup-whwohua, r=GuillaumeGomez
bors [Fri, 16 Jul 2021 09:28:22 +0000 (09:28 +0000)]
Auto merge of #87182 - GuillaumeGomez:rollup-whwohua, r=GuillaumeGomez

Rollup of 7 pull requests

Successful merges:

 - #86983 (Add or improve natvis definitions for common standard library types)
 - #87069 (ExprUseVisitor: Treat ByValue use of Copy types as ImmBorrow)
 - #87138 (Correct invariant documentation for `steps_between`)
 - #87145 (Make --cap-lints and related options leave crate hash alone)
 - #87161 (RFC2229: Use the correct place type)
 - #87162 (Fix type decl layout "overflow")
 - #87167 (Fix sidebar display on small devices)

Failed merges:

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

3 years agoRollup merge of #87167 - GuillaumeGomez:sidebar-display-mobile, r=notriddle
Guillaume Gomez [Fri, 16 Jul 2021 08:08:11 +0000 (10:08 +0200)]
Rollup merge of #87167 - GuillaumeGomez:sidebar-display-mobile, r=notriddle

Fix sidebar display on small devices

Part of #87059.

Instead of hiding the sidebar on small devices, we instead move it out of the viewport so that it remains "visible" to our text only users.

Could you confirm it works for you `@ahicks92` and `@DataTriny` please? You can give it a try at [this URL](https://guillaume-gomez.fr/rustdoc-test/test_docs/index.html).

r? `@notriddle`

3 years agoRollup merge of #87162 - GuillaumeGomez:type-decl-overflow, r=notriddle
Guillaume Gomez [Fri, 16 Jul 2021 08:08:09 +0000 (10:08 +0200)]
Rollup merge of #87162 - GuillaumeGomez:type-decl-overflow, r=notriddle

Fix type decl layout "overflow"

Before:

![Screenshot from 2021-07-15 17-56-12](https://user-images.githubusercontent.com/3050060/125822644-c4595211-d75e-4dd7-ba44-183197ee836c.png)

After:

![Screenshot from 2021-07-15 17-56-17](https://user-images.githubusercontent.com/3050060/125822648-7b363847-e153-4ff3-9fba-59478e32eced.png)

cc ```@SergioBenitez```

r? ```@notriddle```

3 years agoRollup merge of #87161 - sexxi-goose:fix-issue-87097, r=nikomatsakis
Guillaume Gomez [Fri, 16 Jul 2021 08:08:08 +0000 (10:08 +0200)]
Rollup merge of #87161 - sexxi-goose:fix-issue-87097, r=nikomatsakis

RFC2229: Use the correct place type

Closes https://github.com/rust-lang/rust/issues/87097

The ICE occurred because instead of looking at the type of the place after all the projections are applied, we instead looked at the `base_ty` of the Place to decide whether a discriminant should be read of not. This lead to two issues:

1. the kind of the type is not necessarily `Adt` since we only look at the `base_ty`, it could be instead `Ref` for example
2. if the kind of the type is `Adt` you could still be looking at the wrong variant to make a decision on whether the discriminant should be read or not

r? `@nikomatsakis`

3 years agoRollup merge of #87145 - jsgf:fix-lint-opt-hash, r=michaelwoerister
Guillaume Gomez [Fri, 16 Jul 2021 08:08:07 +0000 (10:08 +0200)]
Rollup merge of #87145 - jsgf:fix-lint-opt-hash, r=michaelwoerister

Make --cap-lints and related options leave crate hash alone

Closes: #87144
3 years agoRollup merge of #87138 - dhwthompson:fix-range-invariant, r=JohnTitor
Guillaume Gomez [Fri, 16 Jul 2021 08:08:06 +0000 (10:08 +0200)]
Rollup merge of #87138 - dhwthompson:fix-range-invariant, r=JohnTitor

Correct invariant documentation for `steps_between`

Given that the previous example involves stepping forward from A to B, the equivalent example on this line would make most sense as stepping backward from B to A.

I should probably add a caveat here that I’m fairly new to Rust, and this is my first contribution to this repo, so it’s very possible that I’ve misunderstood how this is supposed to work (either on a technical level or a social one). If this is the case, please do let me know.

3 years agoRollup merge of #87069 - sexxi-goose:copy_ref_always, r=nikomatsakis
Guillaume Gomez [Fri, 16 Jul 2021 08:08:05 +0000 (10:08 +0200)]
Rollup merge of #87069 - sexxi-goose:copy_ref_always, r=nikomatsakis

ExprUseVisitor: Treat ByValue use of Copy types as ImmBorrow

r? ```@nikomatsakis```

3 years agoRollup merge of #86983 - wesleywiser:natvis_std_types, r=michaelwoerister
Guillaume Gomez [Fri, 16 Jul 2021 08:07:59 +0000 (10:07 +0200)]
Rollup merge of #86983 - wesleywiser:natvis_std_types, r=michaelwoerister

Add or improve natvis definitions for common standard library types

Natvis definitions are used by Windows debuggers to provide a better experience when inspecting a value for types with natvis definitions. Many of our standard library types and intrinsic Rust types like slices and `str` already have natvis definitions.

This PR adds natvis definitions for missing types (like all of the `Atomic*` types) and improves some of the existing ones (such as showing the ref count on `Arc<T>` and `Rc<T>` and showing the borrow state of `RefCell<T>`). I've also added cdb tests to cover these definitions and updated existing tests with the new visualizations.

With this PR, the following types now visualize in a much more intuitive way:

### Type: `NonZero{I,U}{8,16,32,64,128,size}`, `Atomic{I,U}{8,16,32,64,size}`, `AtomicBool` and `Wrapping<T>`

<details><summary>Example:</summary>

```rust
let a_u32 = AtomicU32::new(32i32);
```

```
0:000> dx a_u32
a_u32            : 32 [Type: core::sync::atomic::AtomicU32]
    [<Raw View>]     [Type: core::sync::atomic::AtomicU32]
```

</details>

### Type: `Cell<T>` and `UnsafeCell<T>`
<details><summary>Example:</summary>

```rust
let cell = Cell::new(123u8);
let unsafecell = UnsafeCell::new((42u16, 30u16));
```

```
0:000> dx cell
cell             : 123 [Type: core::cell::Cell<u8>]
    [<Raw View>]     [Type: core::cell::Cell<u8>]

0:000> dx unsafecell
unsafecell       : (42, 30) [Type: core::cell::UnsafeCell<tuple<u16, u16>>]
    [<Raw View>]     [Type: core::cell::UnsafeCell<tuple<u16, u16>>]
    [0]              : 42 [Type: unsigned short]
    [1]              : 30 [Type: unsigned short]
```

</details>

### Type: `RefCell<T>`

<details><summary>Example:</summary>

```rust
let refcell = RefCell::new((123u16, 456u32));
```

```
0:000> dx refcell
refcell          : (123, 456) [Type: core::cell::RefCell<tuple<u16, u32>>]
    [<Raw View>]     [Type: core::cell::RefCell<tuple<u16, u32>>]
    [Borrow state]   : Unborrowed
    [0]              : 123 [Type: unsigned short]
    [1]              : 456 [Type: unsigned int]
```

</details>

### Type: `NonNull<T>` and `Unique<T>`
<details><summary>Example:</summary>

```rust
let nonnull: NonNull<_> = (&(10, 20)).into();
```

```
0:000> dx nonnull
nonnull          : NonNull(0x7ff6a5d9c390: (10, 20)) [Type: core::ptr::non_null::NonNull<tuple<i32, i32>>]
    [<Raw View>]     [Type: core::ptr::non_null::NonNull<tuple<i32, i32>>]
    [0]              : 10 [Type: int]
    [1]              : 20 [Type: int]
```

</details>

### Type: `Range<T>`, `RangeFrom<T>`, `RangeInclusive<T>`, `RangeTo<T>` and `RangeToInclusive<T>`
<details><summary>Example:</summary>

```rust
let range = (1..12);
let rangefrom = (9..);
let rangeinclusive = (32..=80);
let rangeto = (..42);
let rangetoinclusive = (..=120);
```

```
0:000> dx range
range            : (1..12) [Type: core::ops::range::Range<i32>]
    [<Raw View>]     [Type: core::ops::range::Range<i32>]

0:000> dx rangefrom
rangefrom        : (9..) [Type: core::ops::range::RangeFrom<i32>]
    [<Raw View>]     [Type: core::ops::range::RangeFrom<i32>]

0:000> dx rangeinclusive
rangeinclusive   : (32..=80) [Type: core::ops::range::RangeInclusive<i32>]
    [<Raw View>]     [Type: core::ops::range::RangeInclusive<i32>]

0:000> dx rangeto
rangeto          : (..42) [Type: core::ops::range::RangeTo<i32>]
    [<Raw View>]     [Type: core::ops::range::RangeTo<i32>]

0:000> dx rangetoinclusive
rangetoinclusive : (..=120) [Type: core::ops::range::RangeToInclusive<i32>]
    [<Raw View>]     [Type: core::ops::range::RangeToInclusive<i32>]
```

</details>

### Type: `Duration`
<details><summary>Example:</summary>

```rust
let duration = Duration::new(5, 12);
```

```
0:000> dx duration
duration         : 5s 12ns [Type: core::time::Duration]
    [<Raw View>]     [Type: core::time::Duration]
    seconds          : 5 [Type: unsigned __int64]
    nanoseconds      : 12 [Type: unsigned int]
```

</details>

### Type: `ManuallyDrop<T>`
<details><summary>Example:</summary>

```rust
let manuallydrop = ManuallyDrop::new((123, 456));
```

```
0:000> dx manuallydrop
manuallydrop     : (123, 456) [Type: core::mem::manually_drop::ManuallyDrop<tuple<i32, i32>>]
    [<Raw View>]     [Type: core::mem::manually_drop::ManuallyDrop<tuple<i32, i32>>]
    [0]              : 123 [Type: int]
    [1]              : 456 [Type: int]
```

</details>

### Type: `Pin<T>`
<details><summary>Example:</summary>

```rust
let mut s = "this".to_string();
let pin = Pin::new(&mut s);
```

```
0:000> dx pin
pin              : Pin(0x11a0ff6f0: "this") [Type: core::pin::Pin<mut alloc::string::String*>]
    [<Raw View>]     [Type: core::pin::Pin<mut alloc::string::String*>]
    [len]            : 4 [Type: unsigned __int64]
    [capacity]       : 4 [Type: unsigned __int64]
    [chars]
```

</details>

### Type: `Rc<T>` and `Arc<T>`
<details><summary>Example:</summary>

```rust
let rc = Rc::new(42i8);
let rc_weak = Rc::downgrade(&rc);
```

```
0:000> dx rc
rc               : 42 [Type: alloc::rc::Rc<i8>]
    [<Raw View>]     [Type: alloc::rc::Rc<i8>]
    [Reference count] : 1 [Type: core::cell::Cell<usize>]

0:000> dx rc_weak
rc_weak          : 42 [Type: alloc::rc::Weak<i8>]
    [<Raw View>]     [Type: alloc::rc::Weak<i8>]
```

</details>

r? ```@michaelwoerister```
cc ```@nanguye2496```

3 years agoAuto merge of #86662 - mockersf:fix-86620-link-unknown-location, r=jyn514
bors [Fri, 16 Jul 2021 06:44:10 +0000 (06:44 +0000)]
Auto merge of #86662 - mockersf:fix-86620-link-unknown-location, r=jyn514

fix dead link for method in trait of blanket impl from third party crate

fix #86620

* changes `href` method to raise the actual error it had instead of an `Option`
* set the href link correctly in case of an error

I did not manage to make a small reproducer, I think it happens in a situation where
* crate A expose a trait with a blanket impl
* crate B use the trait from crate A
* crate C use types from crate B
* building docs for crate C without dependencies

r? `@jyn514`

3 years agoMake GATs no longer incomplete
Jack Huey [Tue, 27 Apr 2021 18:55:38 +0000 (14:55 -0400)]
Make GATs no longer incomplete

3 years agoAuto merge of #87177 - ehuss:update-cargo, r=ehuss
bors [Fri, 16 Jul 2021 04:03:12 +0000 (04:03 +0000)]
Auto merge of #87177 - ehuss:update-cargo, r=ehuss

Update cargo

6 commits in 66a6737a0c9f3a974af2dd032a65d3e409c77aac..27277d966b3cfa454d6dea7f724cb961c036251c
2021-07-14 20:54:28 +0000 to 2021-07-16 00:50:39 +0000
- Flag another curl error as possibly spurious (rust-lang/cargo#9695)
- Add `d` as an alias for `doc` (rust-lang/cargo#9680)
- `cargo fix --edition`: extend warning when on latest edition (rust-lang/cargo#9694)
- Update env_logger requirement from 0.8.1 to 0.9.0 (rust-lang/cargo#9688)
- Document cargo limitation w/ workspaces & configs (rust-lang/cargo#9674)
- Change some warnings to errors (rust-lang/cargo#9689)

3 years agoMark `const_trait_impl` as active
Deadbeef [Fri, 16 Jul 2021 03:54:00 +0000 (11:54 +0800)]
Mark `const_trait_impl` as active

3 years agoUpdate cargo
Eric Huss [Fri, 16 Jul 2021 02:27:11 +0000 (19:27 -0700)]
Update cargo

3 years agoAuto merge of #86993 - jackh726:project-gat-binders, r=nikomatsakis
bors [Fri, 16 Jul 2021 01:11:37 +0000 (01:11 +0000)]
Auto merge of #86993 - jackh726:project-gat-binders, r=nikomatsakis

Replace associated item bound vars with placeholders when projecting

Fixes #76407
Fixes #76826

Similar, but more limited, to #85499. This allows us to handle things like `for<'a> <T as Trait>::Assoc<'a>` but not `for<'a> <T as Trait<'a>>::Assoc`, unblocking GATs.

r? `@nikomatsakis`

3 years agoStabilize `[T; N]::map()`
inquisitivecrystal [Thu, 15 Jul 2021 23:27:08 +0000 (16:27 -0700)]
Stabilize `[T; N]::map()`

3 years agoRemove refs from pat slices
Cameron Steffen [Wed, 14 Jul 2021 21:17:04 +0000 (16:17 -0500)]
Remove refs from pat slices

3 years agoAdd test for sidebar display value on mobile
Guillaume Gomez [Thu, 15 Jul 2021 20:12:28 +0000 (22:12 +0200)]
Add test for sidebar display value on mobile

3 years agoDo not hide the sidebar on mobile, move it outside of the viewport instead
Guillaume Gomez [Thu, 15 Jul 2021 20:06:53 +0000 (22:06 +0200)]
Do not hide the sidebar on mobile, move it outside of the viewport instead

3 years agoAuto merge of #83319 - tmiasko:packed-aligned, r=jackh726
bors [Thu, 15 Jul 2021 19:51:17 +0000 (19:51 +0000)]
Auto merge of #83319 - tmiasko:packed-aligned, r=jackh726

Layout error instead of an ICE for packed and aligned types

Fixes #83107.

3 years agoAuto merge of #87152 - flip1995:clippyup, r=Manishearth
bors [Thu, 15 Jul 2021 17:10:09 +0000 (17:10 +0000)]
Auto merge of #87152 - flip1995:clippyup, r=Manishearth

Update Clippy

r? `@Manishearth`

3 years agoAdd regression test for type declaration layout overflow
Guillaume Gomez [Thu, 15 Jul 2021 16:19:25 +0000 (18:19 +0200)]
Add regression test for type declaration layout overflow

3 years agoFix layout overflow in type declaration
Guillaume Gomez [Thu, 15 Jul 2021 16:19:07 +0000 (18:19 +0200)]
Fix layout overflow in type declaration

3 years agoLayout error instead of an ICE for packed and aligned types
Tomasz Miąsko [Sat, 20 Mar 2021 00:00:00 +0000 (00:00 +0000)]
Layout error instead of an ICE for packed and aligned types

3 years agoRemove failed and review comments
jackh726 [Thu, 15 Jul 2021 14:41:35 +0000 (10:41 -0400)]
Remove failed and review comments

3 years agoGet the right place type
Roxane [Thu, 15 Jul 2021 14:33:51 +0000 (10:33 -0400)]
Get the right place type

3 years agoAuto merge of #87156 - JohnTitor:rollup-osuhe53, r=JohnTitor
bors [Thu, 15 Jul 2021 14:29:07 +0000 (14:29 +0000)]
Auto merge of #87156 - JohnTitor:rollup-osuhe53, r=JohnTitor

Rollup of 8 pull requests

Successful merges:

 - #85579 (Added Arc::try_pin)
 - #86478 (Add -Zfuture-incompat-test to assist with testing future-incompat reports.)
 - #86947 (Move assert_matches to an inner module)
 - #87081 (Add tracking issue number to `wasi_ext`)
 - #87127 (Add safety comments in private core::slice::rotate::ptr_rotate function)
 - #87134 (Make SelfInTyParamDefault wording not be specific to type defaults)
 - #87147 (Update cargo)
 - #87154 (Fix misuse of rev attribute on <a> tag)

Failed merges:

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

3 years agoSuggest full enum variant for local modules
Alik Aslanyan [Thu, 15 Jul 2021 12:34:45 +0000 (16:34 +0400)]
Suggest full enum variant for local modules

3 years agoRollup merge of #87154 - GuillaumeGomez:rev-attr-a, r=JohnTitor
Yuki Okushi [Thu, 15 Jul 2021 12:19:22 +0000 (21:19 +0900)]
Rollup merge of #87154 - GuillaumeGomez:rev-attr-a, r=JohnTitor

Fix misuse of rev attribute on <a> tag

The `rev` attribute is supposed to talk about "ownership" as far as I could found out. This attribute seems not very well defined in the HTML spec and its usage in rustdoc is suboptimal.

It was found out in https://github.com/rust-lang/rust/pull/87149.

r? `@JohnTitor`

3 years agoRollup merge of #87147 - ehuss:update-cargo, r=ehuss
Yuki Okushi [Thu, 15 Jul 2021 12:19:21 +0000 (21:19 +0900)]
Rollup merge of #87147 - ehuss:update-cargo, r=ehuss

Update cargo

13 commits in 3ebb5f15a940810f250b68821149387af583a79e..66a6737a0c9f3a974af2dd032a65d3e409c77aac
2021-07-02 20:35:38 +0000 to 2021-07-14 20:54:28 +0000
- Add format option to `cargo tree` to print the lib_name (rust-lang/cargo#9663)
- Prefer patched versions of dependencies (rust-lang/cargo#9639)
- When a dependency does not have a version, git or path, fails directly (rust-lang/cargo#9686)
- Spot the crate typo easily (rust-lang/cargo#9665)
- remove unnecessary 'collect' (rust-lang/cargo#9616)
- Make it easier to run testsuite with a custom toolchain. (rust-lang/cargo#9679)
- Serialize `cargo fix` (rust-lang/cargo#9677)
- Don't recommend filing issues on rust-lang/cargo for Cargo.toml errors. (rust-lang/cargo#9658)
- Update nightly failure notification. (rust-lang/cargo#9657)
- Update Windows env uppercase key check. (rust-lang/cargo#9654)
- Unignore fix_edition_2021. (rust-lang/cargo#9662)
- Warning when using features in patch (rust-lang/cargo#9666)
- Unify cargo and rustc's error reporting (rust-lang/cargo#9655)

3 years agoRollup merge of #87134 - BoxyUwU:cgd-self-ty-error, r=lcnr
Yuki Okushi [Thu, 15 Jul 2021 12:19:20 +0000 (21:19 +0900)]
Rollup merge of #87134 - BoxyUwU:cgd-self-ty-error, r=lcnr

Make SelfInTyParamDefault wording not be specific to type defaults

r? ```@lcnr```

3 years agoRollup merge of #87127 - poliorcetics:ptr-rotate-safety, r=scottmcm
Yuki Okushi [Thu, 15 Jul 2021 12:19:19 +0000 (21:19 +0900)]
Rollup merge of #87127 - poliorcetics:ptr-rotate-safety, r=scottmcm

Add safety comments in private core::slice::rotate::ptr_rotate function

Helps with #66219.

```@rustbot``` label C-cleanup T-compiler T-libs

3 years agoRollup merge of #87081 - a1phyr:add_wasi_ext_tracking_issue, r=dtolnay
Yuki Okushi [Thu, 15 Jul 2021 12:19:18 +0000 (21:19 +0900)]
Rollup merge of #87081 - a1phyr:add_wasi_ext_tracking_issue, r=dtolnay

Add tracking issue number to `wasi_ext`

Feature `wasi_ext` is tracked by #71213 but is was not in the source code.

3 years agoRollup merge of #86947 - m-ou-se:assert-matches-to-submodule, r=yaahc
Yuki Okushi [Thu, 15 Jul 2021 12:19:16 +0000 (21:19 +0900)]
Rollup merge of #86947 - m-ou-se:assert-matches-to-submodule, r=yaahc

Move assert_matches to an inner module

Fixes #82913

3 years agoRollup merge of #86478 - ehuss:future-incompat-test, r=oli-obk
Yuki Okushi [Thu, 15 Jul 2021 12:19:11 +0000 (21:19 +0900)]
Rollup merge of #86478 - ehuss:future-incompat-test, r=oli-obk

Add -Zfuture-incompat-test to assist with testing future-incompat reports.

This adds a `-Zfuture-incompat-test` cli flag to assist with testing future-incompatible reports. This flag causes all lints to be treated as a future-incompatible lint, and will emit a report for them. This is being added so that Cargo's testsuite can reliably test the reporting infrastructure.  Right now, Cargo relies on using array_into_iter as a test subject. Since the breaking "future incompatible" lints are never intended to last forever, this means Cargo's testsuite would always need to keep changing to choose different lints (for example, #86330 proposed dropping that moniker for array_into_iter). With this flag, Cargo's tests can trigger any lint and check for the report.

3 years agoRollup merge of #85579 - alex:patch-1, r=yaahc
Yuki Okushi [Thu, 15 Jul 2021 12:19:10 +0000 (21:19 +0900)]
Rollup merge of #85579 - alex:patch-1, r=yaahc

Added Arc::try_pin

This helper is in line with other other allocation helpers on Arc.

I didn't think this would require an RFC or broader discussion, let me know if that's incorrect.

3 years agoAdded Arc::try_pin
Alex Gaynor [Sat, 22 May 2021 14:24:50 +0000 (10:24 -0400)]
Added Arc::try_pin

This helper is in line with other other allocation helpers on Arc.

3 years agoFix misuse of rev attribute on <a> tag
Guillaume Gomez [Thu, 15 Jul 2021 11:05:15 +0000 (13:05 +0200)]
Fix misuse of rev attribute on <a> tag

3 years agoMerge commit '54a20a02ecd0e1352a871aa0990bcc8b8b03173e' into clippyup
flip1995 [Thu, 15 Jul 2021 08:44:10 +0000 (10:44 +0200)]
Merge commit '54a20a02ecd0e1352a871aa0990bcc8b8b03173e' into clippyup

3 years agoAuto merge of #7468 - flip1995:rustup, r=flip1995
bors [Thu, 15 Jul 2021 08:37:36 +0000 (08:37 +0000)]
Auto merge of #7468 - flip1995:rustup, r=flip1995

Rustup

r? `@ghost`

changelog: none

3 years agoBump nightly version -> 2021-07-15
flip1995 [Thu, 15 Jul 2021 08:32:21 +0000 (10:32 +0200)]
Bump nightly version -> 2021-07-15

3 years agoMerge remote-tracking branch 'upstream/master' into rustup
flip1995 [Thu, 15 Jul 2021 08:21:01 +0000 (10:21 +0200)]
Merge remote-tracking branch 'upstream/master' into rustup

3 years agoUpdate compiler/rustc_typeck/src/expr_use_visitor.rs
Niko Matsakis [Thu, 15 Jul 2021 08:13:20 +0000 (04:13 -0400)]
Update compiler/rustc_typeck/src/expr_use_visitor.rs

3 years agoPR feedback
Aman Arora [Thu, 15 Jul 2021 04:54:18 +0000 (00:54 -0400)]
PR feedback

3 years agoAuto merge of #7308 - lengyijun:redundant_allocation_arc, r=xFrednet,flip1995
bors [Thu, 15 Jul 2021 07:20:37 +0000 (07:20 +0000)]
Auto merge of #7308 - lengyijun:redundant_allocation_arc, r=xFrednet,flip1995

add Arc to `redundant_allocation`

 fixes #7303
changelog:  add Arc to `redundant_allocation`

3 years agoUpdate cargo
Eric Huss [Thu, 15 Jul 2021 02:56:42 +0000 (19:56 -0700)]
Update cargo

3 years agoAuto merge of #86876 - jyn514:56935-target-crate-num, r=petrochenkov
bors [Thu, 15 Jul 2021 02:39:38 +0000 (02:39 +0000)]
Auto merge of #86876 - jyn514:56935-target-crate-num, r=petrochenkov

Reuse CrateNum for proc-macro crates even when cross-compiling

Proc-macros are always compiled for the host, so this should be the same
in every way as recompiling the crate.

I am not sure why the previous code special-cased the target, since the
compiler properly gives an error when trying to load a crate for a
different host:

```
error[E0461]: couldn't find crate `dependency` with expected target triple x86_64-unknown-linux-gnu
  --> /home/joshua/rustc4/src/test/ui/cfg-dependent.rs:8:2
   |
LL |     dependency::is_64();
   |     ^^^^^^^^^^
   |
   = note: the following crate versions were found:
           crate `dependency`, target triple i686-unknown-linux-gnu: /home/joshua/rustc4/build/x86_64-unknown-linux-gnu/test/ui/cfg-dependent/auxiliary/libdependency.so
```

I think another possible fix is to remove the check altogether. But I'm
not sure, and this fix works, so I'm not making the larger change here.

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

r? `@petrochenkov` cc `@alexcrichton`

3 years agoReuse CrateNum for proc-macro crates even when cross-compiling
Joshua Nelson [Sun, 4 Jul 2021 03:35:24 +0000 (23:35 -0400)]
Reuse CrateNum for proc-macro crates even when cross-compiling

Proc-macros are always compiled for the host, so this should be the same
in every way as recompiling the crate.

I am not sure why the previous code special-cased the target, since the
compiler properly gives an error when trying to load a crate for a
different host:

```
error[E0461]: couldn't find crate `dependency` with expected target triple x86_64-unknown-linux-gnu
  --> /home/joshua/rustc4/src/test/ui/cfg-dependent.rs:8:2
   |
LL |     dependency::is_64();
   |     ^^^^^^^^^^
   |
   = note: the following crate versions were found:
           crate `dependency`, target triple i686-unknown-linux-gnu: /home/joshua/rustc4/build/x86_64-unknown-linux-gnu/test/ui/cfg-dependent/auxiliary/libdependency.so
```

I think another possible fix is to remove the check altogether. But I'm
not sure, and this fix works, so I'm not making the larger change here.

3 years agoMake --cap-lints and related options leave crate hash alone
Jeremy Fitzhardinge [Wed, 14 Jul 2021 23:39:17 +0000 (16:39 -0700)]
Make --cap-lints and related options leave crate hash alone

Closes: #87144
3 years agoAuto merge of #87137 - richkadel:compiler-builtins-0.1.47, r=tmandry
bors [Wed, 14 Jul 2021 23:58:43 +0000 (23:58 +0000)]
Auto merge of #87137 - richkadel:compiler-builtins-0.1.47, r=tmandry

Update compiler-builtins to 0.1.47

  Bumped to `0.1.47` to resolve missing symbols on `aarch` when linking
  `cargo`. This was due to a recent change in a `cargo` dependency on
  `curl` (upstream C library added code that uses the uncommon `long
  double` type).

r? `@tmandry`

3 years agoredundant_allocation: add Arc; some refractoring.
lyj [Wed, 2 Jun 2021 05:41:52 +0000 (13:41 +0800)]
redundant_allocation: add Arc; some refractoring.

3 years agoadd assertions on existing tests with missing doc source
François Mockers [Wed, 14 Jul 2021 22:30:11 +0000 (00:30 +0200)]
add assertions on existing tests with missing doc source

3 years agoAuto merge of #86765 - cuviper:fuse-less-specialized, r=joshtriplett
bors [Wed, 14 Jul 2021 21:17:52 +0000 (21:17 +0000)]
Auto merge of #86765 - cuviper:fuse-less-specialized, r=joshtriplett

Make the specialized Fuse still deal with None

Fixes #85863 by removing the assumption that we'll never see a cleared iterator in the `I: FusedIterator` specialization. Now all `Fuse` methods check for the possibility that `self.iter` is `None`, and the specialization only avoids _setting_ that to `None` in `&mut self` methods.

3 years agoFix tests for i686
Wesley Wiser [Wed, 14 Jul 2021 20:50:11 +0000 (16:50 -0400)]
Fix tests for i686

3 years agoCorrect invariant documentation for `steps_between`
David Thompson [Wed, 14 Jul 2021 20:48:18 +0000 (13:48 -0700)]
Correct invariant documentation for `steps_between`

Given that the previous example involves stepping forward from A to B,
the equivalent example on this line would make most sense as stepping
backward from B to A.

3 years agoUpdate compiler-builtins to 0.1.47
Rich Kadel [Wed, 14 Jul 2021 20:45:16 +0000 (13:45 -0700)]
Update compiler-builtins to 0.1.47

  Bumped to `0.1.47` to resolve missing symbols on `aarch` when linking
  `cargo`. This was due to a recent change in a `cargo` dependency on
  `curl` (upstream C library added code that uses the uncommon `long
  double` type).

3 years agoAuto merge of #7462 - xFrednet:7369-branches-sharing-code-else-expr-fp, r=camsteffen
bors [Wed, 14 Jul 2021 20:29:56 +0000 (20:29 +0000)]
Auto merge of #7462 - xFrednet:7369-branches-sharing-code-else-expr-fp, r=camsteffen

FP fix and documentation for `branches_sharing_code` lint

Closes rust-lang/rust-clippy#7369

Related rust-lang/rust-clippy#7452 I'm still thinking about the best way to fix this. I could simply add another visitor to ensure that the moved expressions don't modify values being used in the condition, but I'm not totally happy with this due to the complexity. I therefore only documented it for now

changelog: [`branches_sharing_code`] fixed false positive where block expressions would sometimes be ignored.

3 years agoFixed `branches_sharing_code` FP with block expressions in else
xFrednet [Tue, 13 Jul 2021 21:27:19 +0000 (23:27 +0200)]
Fixed `branches_sharing_code` FP with block expressions in else

And added `branches_sharing_code` PF note to lint doc for `rust-clippy#7452`

3 years agoOOPS
Ellen [Wed, 14 Jul 2021 18:38:58 +0000 (19:38 +0100)]
OOPS

3 years agoAuto merge of #87133 - GuillaumeGomez:rollup-pfz9jbk, r=GuillaumeGomez
bors [Wed, 14 Jul 2021 18:36:44 +0000 (18:36 +0000)]
Auto merge of #87133 - GuillaumeGomez:rollup-pfz9jbk, r=GuillaumeGomez

Rollup of 6 pull requests

Successful merges:

 - #87027 (expand: Support helper attributes for built-in derive macros)
 - #87056 (Fix codeblocks overflow)
 - #87117 (Shrink the CrateStore dynamic interface.)
 - #87120 (rustdoc: Remove unnecessary `extern crate` aliases)
 - #87125 (Fix Ayu theme `<code>` color)
 - #87130 (Update browser-ui-test package version)

Failed merges:

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

3 years agoChange type param -> generic param
Ellen [Wed, 14 Jul 2021 18:22:32 +0000 (19:22 +0100)]
Change type param -> generic param

3 years agoRollup merge of #87130 - GuillaumeGomez:update-browser-ui-test, r=Mark-Simulacrum
Guillaume Gomez [Wed, 14 Jul 2021 17:53:41 +0000 (19:53 +0200)]
Rollup merge of #87130 - GuillaumeGomez:update-browser-ui-test, r=Mark-Simulacrum

Update browser-ui-test package version

It adds a check to prevent to have empty CSS values in `assert-css` command.

r? `@Mark-Simulacrum`

3 years agoRollup merge of #87125 - GuillaumeGomez:ayu-code-color, r=notriddle
Guillaume Gomez [Wed, 14 Jul 2021 17:53:40 +0000 (19:53 +0200)]
Rollup merge of #87125 - GuillaumeGomez:ayu-code-color, r=notriddle

Fix Ayu theme <code> color

Fixes #87072 (the second regression).

r? `@notriddle`

3 years agoRollup merge of #87120 - jyn514:rustdoc-cleanup, r=CraftSpider
Guillaume Gomez [Wed, 14 Jul 2021 17:53:38 +0000 (19:53 +0200)]
Rollup merge of #87120 - jyn514:rustdoc-cleanup, r=CraftSpider

rustdoc: Remove unnecessary `extern crate` aliases

3 years agoRollup merge of #87117 - cjgillot:cstore, r=petrochenkov
Guillaume Gomez [Wed, 14 Jul 2021 17:53:37 +0000 (19:53 +0200)]
Rollup merge of #87117 - cjgillot:cstore, r=petrochenkov

Shrink the CrateStore dynamic interface.

The information is either accessible through queries or by crates which already depend on rustc_metadata.

3 years agoRollup merge of #87056 - GuillaumeGomez:fix-codeblocks-overflow, r=notriddle
Guillaume Gomez [Wed, 14 Jul 2021 17:53:36 +0000 (19:53 +0200)]
Rollup merge of #87056 - GuillaumeGomez:fix-codeblocks-overflow, r=notriddle

Fix codeblocks overflow

Fixes #87043.

Instead of completely relying on `pulldown-cmark` (and its potential changes), I decided to move the generation of codeblocks HTML directly in rustdoc so we can unify the DOM and the CSS classes.

r? `@Nemo157`

3 years agoRollup merge of #87027 - petrochenkov:builderhelp, r=oli-obk
Guillaume Gomez [Wed, 14 Jul 2021 17:53:35 +0000 (19:53 +0200)]
Rollup merge of #87027 - petrochenkov:builderhelp, r=oli-obk

expand: Support helper attributes for built-in derive macros

This is needed for https://github.com/rust-lang/rust/pull/86735 (derive macro `Default` should have a helper attribute `default`).

With this PR we can specify helper attributes for built-in derives using syntax `#[rustc_builtin_macro(MacroName, attributes(attr1, attr2, ...))]` which mirrors equivalent syntax for proc macros `#[proc_macro_derive(MacroName, attributes(attr1, attr2, ...))]`.
Otherwise expansion infra was already ready for this.
The attribute parsing code is shared between proc macro derives and built-in macros (`fn parse_macro_name_and_helper_attrs`).

3 years agoAdd -Zfuture-incompat-test to assist with testing future-incompat reports.
Eric Huss [Sun, 20 Jun 2021 00:06:46 +0000 (17:06 -0700)]
Add -Zfuture-incompat-test to assist with testing future-incompat reports.

3 years agoAuto merge of #87082 - michaelwoerister:const-in-debuginfo-type-names-fix, r=oli...
bors [Wed, 14 Jul 2021 15:18:27 +0000 (15:18 +0000)]
Auto merge of #87082 - michaelwoerister:const-in-debuginfo-type-names-fix, r=oli-obk,wesleywiser

Handle non-integer const generic parameters in debuginfo type names.

This PR fixes an ICE introduced by https://github.com/rust-lang/rust/pull/85269 which started emitting const generic arguments for debuginfo names but did not cover the case where such an argument could not be evaluated to a flat string of bits.

The fix implemented in this PR is very basic: If `try_eval_bits()` fails for the constant in question, we fall back to generating a stable hash of the constant and emit that instead. This way we get a (virtually) unique name and side step the problem of generating a string representation of a potentially complex value.

The downside is that the generated name will be rather opaque. E.g. the regression test adds a function `const_generic_fn_non_int<()>` which is then rendered as `const_generic_fn_non_int<{CONST#fe3cfa0214ac55c7}>`. I think it's an open question how to deal with this more gracefully.

I'd be interested in ideas on how to do this better.

r? `@wesleywiser`

cc `@dpaoliello` (do you see any problems with this approach?)
cc `@Mark-Simulacrum` & `@nagisa` (who I've seen comment on debuginfo issues recently -- anyone else?)

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

3 years agoAuto merge of #7437 - ebobrow:redundant-closure-move, r=flip1995
bors [Wed, 14 Jul 2021 15:15:28 +0000 (15:15 +0000)]
Auto merge of #7437 - ebobrow:redundant-closure-move, r=flip1995

suggest `&mut` for redundant FnMut closures

fixes #6903

changelog: suggest `&mut` for redundant FnMut closures

3 years agosuggest `&mut` for redundant FnMut closures
Elliot Bobrow [Sat, 3 Jul 2021 03:25:55 +0000 (20:25 -0700)]
suggest `&mut` for redundant FnMut closures

3 years agoShrink the CrateStore dynamic interface.
Camille GILLOT [Mon, 12 Jul 2021 19:20:16 +0000 (21:20 +0200)]
Shrink the CrateStore dynamic interface.

3 years agoUpdate browser-ui-test package version
Guillaume Gomez [Wed, 14 Jul 2021 14:28:15 +0000 (16:28 +0200)]
Update browser-ui-test package version

3 years agoHandle non-integer const generic parameters in debuginfo type names.
Michael Woerister [Mon, 12 Jul 2021 13:12:49 +0000 (15:12 +0200)]
Handle non-integer const generic parameters in debuginfo type names.

3 years agoAdd safety comments in private core::slice::rotate::ptr_rotate function
Alexis Bourget [Wed, 14 Jul 2021 13:31:12 +0000 (15:31 +0200)]
Add safety comments in private core::slice::rotate::ptr_rotate function

3 years agoAdd GUI test to check ayu <code> colors
Guillaume Gomez [Wed, 14 Jul 2021 13:00:12 +0000 (15:00 +0200)]
Add GUI test to check ayu <code> colors

3 years agoAuto merge of #87118 - JohnTitor:rollup-8ltidsq, r=JohnTitor
bors [Wed, 14 Jul 2021 12:49:45 +0000 (12:49 +0000)]
Auto merge of #87118 - JohnTitor:rollup-8ltidsq, r=JohnTitor

Rollup of 6 pull requests

Successful merges:

 - #87085 (Search result colors)
 - #87090 (Make BTreeSet::split_off name elements like other set methods do)
 - #87098 (Unignore some pretty printing tests)
 - #87099 (Upgrade `cc` crate to 1.0.69)
 - #87101 (Suggest a path separator if a stray colon is found in a match arm)
 - #87102 (Add GUI test for "go to first" feature)

Failed merges:

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

3 years agoFix color for <code> which are not in doc blocks
Guillaume Gomez [Wed, 14 Jul 2021 12:47:54 +0000 (14:47 +0200)]
Fix color for <code> which are not in doc blocks

3 years agoAuto merge of #7346 - lengyijun:redundant_clone_5707, r=oli-obk
bors [Wed, 14 Jul 2021 10:10:14 +0000 (10:10 +0000)]
Auto merge of #7346 - lengyijun:redundant_clone_5707, r=oli-obk

fix 5707

changelog: ``[`redundant_clone`]``, fix #5707

# Root problem of #5707 :
```
&2:&mut HashMap = &mut _4;
&3:&str = & _5;
_1 = HashMap::insert(move _2,move _3, _);
```

generate PossibleBorrower(_2,_1) and PossibleBorrower(_3,_1).

However, it misses PossibleBorrower(_3,_2).

# My solution to #5707 :

When meet a function call, we should:
1. build PossibleBorrower between borrow parameters and return value (currently)
2. build PossibleBorrower between immutable borrow parameters and mutable borrow parameters (*add*)
3. build PossibleBorrower inside mutable borrow parameters (*add*)

For example:
```
_2: &mut _22;
_3: &mut _;
_4: & _;
_5: & _;
_1 = call(move _2, move _3, move _4, move _5);
```
we need to build
1. return value with parameter(current implementataion)
 PossibleBorrower(_2,_1)
 PossibleBorrower(_3,_1)
 PossibleBorrower(_4,_1)
 PossibleBorrower(_5,_1)

2. between mutable borrow and immutable borrow
PossibleBorrower(_4,_2)
PossibleBorrower(_5,_2)
PossibleBorrower(_4,_3)
PossibleBorrower(_5,_3)

3. between mutable borrow and mutable borrow
PossibleBorrower(_3,_2)
PossibleBorrower(_2,_3)

  But that's not enough.
 Modification to _2 actually apply to _22.
  So I write a `PossibleBorrowed` visitor, which tracks (borrower => possible borrowed) relation.
  For example (_2 => _22).
  However, a lot of problems exist here.

## Known Problems:
  1. not sure all `&mut`'s origin are collected.
  I'm not sure how to deal with `&mut` when meet a function call, so I didn't do it currently.
  Also, my implement is not flow sensitive, so it's not accurate.

```
foo(_2:&mut _, _3: &_)
```
This pr doesn't count _3 as origin of _2.

 2. introduce false negative
`foo(_2, _3)` will  emit PossibleBorrower(_3,_2) in this pr, but _3 and _2 may not have relation.
Clippy may feel that _3 is still in use because of _2, but actually, _3 is on longer needed and can be moved.

## Insight
  The key problem is determine where every `&mut` come from accurately.
  I think Polonius is an elegant solution to it. Polonius is flow sensitive and accurate.
  But I'm uncertain about whether we can import Polonius in rust-clippy currently.
  This pr actually is part of Polonius' functionality, I think.

# TODO
1. `cargo test` can't pass yet due to similar variable name

3 years agoAdd test for codeblocks overflow
Guillaume Gomez [Sun, 11 Jul 2021 11:06:48 +0000 (13:06 +0200)]
Add test for codeblocks overflow

3 years agoFix display for non-rust code blocks
Guillaume Gomez [Sun, 11 Jul 2021 10:40:31 +0000 (12:40 +0200)]
Fix display for non-rust code blocks

3 years agoExprUseVisitor::Delegate consume only when moving
Aman Arora [Wed, 14 Jul 2021 06:21:08 +0000 (02:21 -0400)]
ExprUseVisitor::Delegate consume only when moving

3 years agoAdd test for copy type in move closure
Aman Arora [Wed, 14 Jul 2021 04:27:39 +0000 (00:27 -0400)]
Add test for copy type in move closure

3 years agorename possible_borrowed to possible_origin; pass dogfood
lyj [Wed, 14 Jul 2021 03:29:39 +0000 (11:29 +0800)]
rename possible_borrowed to possible_origin; pass dogfood