Commit graph

151631 commits

Author SHA1 Message Date
bors
f07feca40c 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
2021-07-14 10:10:14 +00:00
Guillaume Gomez
7593bfe1aa Add test for codeblocks overflow 2021-07-14 12:03:55 +02:00
Guillaume Gomez
0ef8988835 Fix display for non-rust code blocks 2021-07-14 12:03:55 +02:00
Aman Arora
6c3774eec4 ExprUseVisitor::Delegate consume only when moving 2021-07-14 02:21:08 -04:00
Aman Arora
36f51c96dc Add test for copy type in move closure 2021-07-14 02:16:16 -04:00
lyj
10910020ec rename possible_borrowed to possible_origin; pass dogfood 2021-07-14 13:46:33 +08:00
bors
a08f25a7ef Auto merge of #86211 - tlyu:option-result-overviews, r=joshtriplett
create method overview docs for core::option and core::result

The `Option` and `Result` types have large lists of methods. They each could use an overview page of methods grouped by category. These proposed overviews include "truth tables" for the underappreciated boolean operators/combinators of these types. The methods are already somewhat categorized in the source, but some logical groupings are broken up by the necessities of putting related methods in different `impl` blocks, for example.

This is based on #86209, but those are small changes and unlikely to conflict.
2021-07-14 05:10:57 +00:00
Joshua Nelson
1006175e22 Remove useless alias from rustc_span to itself 2021-07-13 23:38:14 -04:00
Joshua Nelson
78eae0fd4a Remove renaming of test crate
This is leftover from when `doctest` used to be called `test`. Remove it
now, it's unnecessary and makes the code harder to read.
2021-07-13 23:38:12 -04:00
lyj
251c3b64da fix 5707 2021-07-14 10:57:47 +08:00
bors
2155386f31 Auto merge of #87106 - Mark-Simulacrum:edition-no-clone, r=petrochenkov
Avoid cloning ExpnData to access Span edition

ExpnData is a fairly hefty structure to clone; cloning it may not be cheap. In
some cases this may get optimized out, but it's not clear that will always be
the case. Try to avoid that cost.

r? `@ghost` -- opening for a perf run to start with
2021-07-14 01:41:12 +00:00
Yuki Okushi
afaca5ba79
Rollup merge of #87102 - GuillaumeGomez:go-to-first-feature, r=Manisheart,notriddle
Add GUI test for "go to first" feature

It adds a test for #85876 to ensure the feature is working as expected and prevent potential regression.

cc ```@jeanlucthumm```

r? ```@Manishearth```
2021-07-14 09:35:27 +09:00
Yuki Okushi
d8943a7d52
Rollup merge of #87101 - FabianWolff:issue-87086, r=estebank
Suggest a path separator if a stray colon is found in a match arm

Attempts to fix #87086.

r? `@estebank`
2021-07-14 09:35:26 +09:00
Yuki Okushi
4ec7b489d6
Rollup merge of #87099 - JohnTitor:upgrade-cc-crate, r=alexcrichton
Upgrade `cc` crate to 1.0.69

This pulls another fix for #83043, i.e., alexcrichton/cc-rs#605.
r? ``@alexcrichton``
2021-07-14 09:35:25 +09:00
Yuki Okushi
d5e0426eab
Rollup merge of #87098 - JohnTitor:unignore-some-tests, r=petrochenkov
Unignore some pretty printing tests

Closes #37201
r? ````@petrochenkov````
2021-07-14 09:35:23 +09:00
Yuki Okushi
b115527ce4
Rollup merge of #87090 - ssomers:btree_comments, r=the8472
Make BTreeSet::split_off name elements like other set methods do

r? ````@Mark-Simulacrum````
2021-07-14 09:35:22 +09:00
Yuki Okushi
fc488d4165
Rollup merge of #87085 - GuillaumeGomez:search-result-colors, r=notriddle
Search result colors

Part of  #87072 (fixes the first and fourth regressions and add tests to prevent it from happening again).

cc ````@Nemo157````

r? ````@camelid````
2021-07-14 09:35:22 +09:00
Fabian Wolff
2362450425 Suggest a path separator if a stray colon is found in a match arm
Co-authored-by: Esteban Kuber <estebank@users.noreply.github.com>
2021-07-14 01:15:59 +02:00
bors
c7d6bcc788 Auto merge of #87044 - cjgillot:expnhash, r=petrochenkov
Cache expansion hash globally

... instead of computing it multiple times.

Split from #86676
r? `@petrochenkov`
2021-07-13 22:32:58 +00:00
Camille GILLOT
616ce3c5c0 Cache expansion hash. 2021-07-13 23:10:56 +02:00
Camille GILLOT
cff0ea5f88 Move HashStable implementations. 2021-07-13 23:10:55 +02:00
jackh726
09978bdcd1 Conditionally call normalize_erasing_regions only if polymorhization is enabled 2021-07-13 15:09:01 -04:00
Vadim Petrochenkov
6c9ea1e8a9 expand: Support helper attributes for built-in derive macros 2021-07-13 21:59:22 +03:00
Guillaume Gomez
cac0d71b6a Add test for "go to first" feature 2021-07-13 19:41:58 +02:00
Oli Scherer
587e8fd112 Loop over all opaque types instead of looking at just the first one with the same DefId 2021-07-13 15:19:35 +00:00
bors
2fd8dbc8af Auto merge of #86827 - camsteffen:hash-lint-resolved, r=oli-obk
Fix internal `default_hash_types` lint to use resolved path

I run into false positives now and then (mostly in Clippy) when I want to name some util after HashMap.
2021-07-13 15:06:10 +00:00
bors
3e1c75c6e2 Auto merge of #86827 - camsteffen:hash-lint-resolved, r=oli-obk
Fix internal `default_hash_types` lint to use resolved path

I run into false positives now and then (mostly in Clippy) when I want to name some util after HashMap.
2021-07-13 15:06:10 +00:00
Oli Scherer
95f296db63 Debug log all the things 2021-07-13 15:06:09 +00:00
Oli Scherer
692f638036 Fix VecMap Extend impl 2021-07-13 15:05:29 +00:00
Mark Rousskov
7d373c9c11 Avoid cloning ExpnData to access Span edition
ExpnData is a fairly hefty structure to clone; cloning it may not be cheap. In
some cases this may get optimized out, but it's not clear that will always be
the case. Try to avoid that cost.
2021-07-13 10:57:10 -04:00
jackh726
a9f1e1c440 WIP partial apply fix 2021-07-13 10:50:40 -04:00
bors
8131445e53 Auto merge of #7446 - Y-Nak:fix-7445, r=xFrednet,flip1995
`default_numeric_fallback`: Fix FP with floating literal

Fix #7445

changelog: `default_numeric_fallback`: Fix FP with floating literal
2021-07-13 14:31:02 +00:00
Yoshitomo Nakanishi
25e4c7d73f default_numeric_fallback: Add rustfix tests 2021-07-13 23:18:31 +09:00
bors
bf4512ef57 Auto merge of #7442 - camsteffen:format-args, r=xFrednet
Refactor `format_args!` expansion parsing

Introduces `FormatExpn::parse` and `FormatArgsExpn::parse`. Motivated by rust-lang/rust#83302, so I only have to change Clippy in one place. Fixed an FP along the way.

I also allowed `needless_bool` in macros because I often want to do `if_chain! { .. then { true } else { false } }`.

changelog: Fix false positive in `useless_format` when some text is appended or prepended to a single string with some useless formatting params
changelog: Allow `needless_bool` in macros
2021-07-13 13:58:38 +00:00
Cameron Steffen
306f9e843d Split a lint message into help 2021-07-13 08:57:16 -05:00
Cameron Steffen
73ffae6ea1 Reduce redundant code 2021-07-13 08:57:16 -05:00
Cameron Steffen
e6ab222b81 Refactor format macro parsing 2021-07-13 08:57:16 -05:00
Cameron Steffen
20dbb277cf Fix useless_format false positive 2021-07-13 08:57:16 -05:00
Cameron Steffen
3fc8dae46c Allow needless_bool in macro 2021-07-13 08:57:16 -05:00
Yoshitomo Nakanishi
4e8cd4d346 Fix NumericLiteral::format that may produce a invalid literal 2021-07-13 22:57:02 +09:00
bors
94d6be4c0a Auto merge of #7458 - flip1995:unused_unit-doc, r=giraffate
Add fixed example to unused_unit documentation

changelog: none

(don't think this is worth a changelog mention)
2021-07-13 13:43:12 +00:00
bors
ca99e3eb3a Auto merge of #86922 - joshtriplett:target-abi, r=oli-obk
target abi

Implement cfg(target_abi) (RFC 2992)

Add an `abi` field to `TargetOptions`, defaulting to "". Support using
`cfg(target_abi = "...")` for conditional compilation on that field.

Gated by `feature(cfg_target_abi)`.

Add a test for `target_abi`, and a test for the feature gate.

Add `target_abi` to tidy as a platform-specific cfg.

Update targets to use `target_abi`

All eabi targets have `target_abi = "eabi".`
All eabihf targets have `target_abi = "eabihf"`.
`armv6_unknown_freebsd` and `armv7_unknown_freebsd` have `target_abi = "eabihf"`.
All abi64 targets have `target_abi = "abi64"`.
All ilp32 targets have `target_abi = "ilp32"`.
All softfloat targets have `target_abi = "softfloat"`.
All *-uwp-windows-* targets have `target_abi = "uwp"`.
All spe targets have `target_abi = "spe"`.
All macabi targets have `target_abi = "macabi"`.
aarch64-apple-ios-sim has `target_abi = "sim"`.
`x86_64-fortanix-unknown-sgx` has `target_abi = "fortanix"`.
`x86_64-unknown-linux-gnux32` has `target_abi = "x32"`.

Add FIXME entries for targets for which existing values need to change
once `cfg_target_abi` becomes stable. (All of them are tier 3 targets.)

Add a test for `target_abi` in `--print cfg`.
2021-07-13 12:25:10 +00:00
bors
5aff6dd07a Auto merge of #87019 - nikic:clang-12.0.1, r=Mark-Simulacrum
Use clang 12.0.1 on dist-x86_64/i686-linux

The LLD + ThinLTO __morestack bug has been fixed in 12.0.1, so
we can now update our clang version. This also means that we no
longer need to build Python 2.
2021-07-13 09:40:28 +00:00
Yuki Okushi
e457c2739b
Upgrade cc crate to 1.0.69 2021-07-13 17:58:50 +09:00
flip1995
f05949f9ce
Add fixed example to unused_unit documentation 2021-07-13 10:54:29 +02:00
Guillaume Gomez
b8264a862f Add test for keyword/primitive text color 2021-07-13 10:18:24 +02:00
Guillaume Gomez
168b4d490b Fix color for keyword/primitive search result 2021-07-13 10:18:24 +02:00
Guillaume Gomez
f0169e923b Add test for search results colors 2021-07-13 10:18:23 +02:00
Guillaume Gomez
b09084cbb6 Fix search result description text color for ayu theme 2021-07-13 10:18:23 +02:00
Yuki Okushi
28a50b376a
Unignore some pretty printing tests 2021-07-13 16:55:40 +09:00