Commit graph

148845 commits

Author SHA1 Message Date
Jason Newcomb
760f70312e
Improve multiple_inherent_impl lint
Treat different generic arguments as different types.
Allow the lint to be ignored on the type definition, or any impl blocks.
2021-05-18 11:45:51 -04:00
bors
36be8ba642 Auto merge of #7242 - Jarcho:implicit_return_ice, r=flip1995
Fix ICE in `implicit_return`

fixes: #7231

changelog: Fix ICE in `implicit_return` for async functions
2021-05-18 15:40:17 +00:00
Jason Newcomb
a149ba26fa
Fix ICE in implicit_return
async functions always return a value
2021-05-18 10:51:59 -04:00
bors
a5560a6a90 Auto merge of #85437 - GuillaumeGomez:rollup-3jcirty, r=GuillaumeGomez
Rollup of 7 pull requests

Successful merges:

 - #84587 (rustdoc: Make "rust code block is empty" and "could not parse code block" warnings a lint (`INVALID_RUST_CODEBLOCKS`))
 - #85280 (Toggle-wrap items differently than top-doc.)
 - #85338 (Implement more Iterator methods on core::iter::Repeat)
 - #85339 (Report an error if a lang item has the wrong number of generic arguments)
 - #85369 (Suggest borrowing if a trait implementation is found for &/&mut <type>)
 - #85393 (Suppress spurious errors inside `async fn`)
 - #85415 (Clean up remnants of BorrowOfPackedField)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-05-18 14:48:53 +00:00
Mateusz Gacek
d730cc6646 Add diagnostic item to CStr 2021-05-18 15:45:30 +02:00
bors
98cddc5d3a Auto merge of #7241 - flip1995:warn-deny-warnings, r=camsteffen
Deny warnings in every main sub-crate

Pointed out by `@xFrednet` in https://github.com/rust-lang/rust-clippy/pull/7229#issuecomment-842978909

This enables the same (rustc) lints in every main sub-crate:

- `clippy`
- `clippy_lints`
- `clippy_utils`
- `clippy_dev`

In addition it forwards the `deny-warnings` feature to those sub-crates, so we don't miss warnings that then become a problem during sync. (I wanted to fix that before, but forgot about it, so thanks for pointing it out `@xFrednet!)`

changelog: none
2021-05-18 13:31:18 +00:00
Guillaume Gomez
d314b065e7 Add GUI tests for escape handling 2021-05-18 14:51:54 +02:00
Guillaume Gomez
281dea47ce Fix escape handling on search results 2021-05-18 14:32:20 +02:00
Guillaume Gomez
f4a0d97def
Rollup merge of #85415 - LeSeulArtichaut:no-packed-borrow-unsafeck, r=RalfJung
Clean up remnants of BorrowOfPackedField

cc #82525 which removed `BorrowOfPackedField` from unsafety-checking
r? `@RalfJung`
2021-05-18 14:08:57 +02:00
Guillaume Gomez
5f544bcf70
Rollup merge of #85393 - Aaron1011:async-type-err, r=varkor
Suppress spurious errors inside `async fn`

Fixes #73741
2021-05-18 14:08:56 +02:00
Guillaume Gomez
fad04ff60e
Rollup merge of #85369 - FabianWolff:issue-84973, r=jackh726
Suggest borrowing if a trait implementation is found for &/&mut <type>

This pull request fixes #84973 by suggesting to borrow if a trait is not implemented for some type `T`, but it is for `&T` or `&mut T`. For instance:
```rust
trait Ti {}
impl<T> Ti for &T {}
fn foo<T: Ti>(_: T) {}

trait Tm {}
impl<T> Tm for &mut T {}
fn bar<T: Tm>(_: T) {}

fn main() {
    let a: i32 = 5;
    foo(a);

    let b: Box<i32> = Box::new(42);
    bar(b);
}
```
gives, on current nightly:
```
error[E0277]: the trait bound `i32: Ti` is not satisfied
  --> t2.rs:11:9
   |
3  | fn foo<T: Ti>(_: T) {}
   |           -- required by this bound in `foo`
...
11 |     foo(a);
   |         ^ the trait `Ti` is not implemented for `i32`

error[E0277]: the trait bound `Box<i32>: Tm` is not satisfied
  --> t2.rs:14:9
   |
7  | fn bar<T: Tm>(_: T) {}
   |           -- required by this bound in `bar`
...
14 |     bar(b);
   |         ^ the trait `Tm` is not implemented for `Box<i32>`

error: aborting due to 2 previous errors
```
whereas with my changes, I get:
```
error[E0277]: the trait bound `i32: Ti` is not satisfied
  --> t2.rs:11:9
   |
3  | fn foo<T: Ti>(_: T) {}
   |           -- required by this bound in `foo`
...
11 |     foo(a);
   |         ^
   |         |
   |         expected an implementor of trait `Ti`
   |         help: consider borrowing here: `&a`

error[E0277]: the trait bound `Box<i32>: Tm` is not satisfied
  --> t2.rs:14:9
   |
7  | fn bar<T: Tm>(_: T) {}
   |           -- required by this bound in `bar`
...
14 |     bar(b);
   |         ^
   |         |
   |         expected an implementor of trait `Tm`
   |         help: consider borrowing mutably here: `&mut b`

error: aborting due to 2 previous errors
```
In my implementation, I have added a "blacklist" to make these suggestions flexible. In particular, suggesting to borrow can interfere with other suggestions, such as to add another trait bound to a generic argument. I have tried to configure this blacklist to cause the least amount of test case failures, i.e. to model the current behavior as closely as possible (I only had to change one existing test case, and this change was quite clearly an improvement).
2021-05-18 14:08:55 +02:00
Guillaume Gomez
1bfd987f69
Rollup merge of #85339 - FabianWolff:issue-83893, r=varkor
Report an error if a lang item has the wrong number of generic arguments

This pull request fixes #83893. The issue is that the lang item code currently checks whether the lang item has the correct item kind (e.g. a `#[lang="add"]` has to be a trait), but not whether the item has the correct number of generic arguments.

This can lead to an "index out of bounds" ICE when the compiler tries to create more substitutions than there are suitable types available (if the lang item was declared with too many generic arguments).

For instance, here is a reduced ("reduced" in the sense that it does not trigger additional errors) version of the example given in #83893:
```rust
#![feature(lang_items,no_core)]
#![no_core]
#![crate_type="lib"]

#[lang = "sized"]
trait MySized {}

#[lang = "add"]
trait MyAdd<'a, T> {}

fn ice() {
    let r = 5;
    let a = 6;
    r + a
}
```
On current nightly, this immediately causes an ICE without any warnings or errors emitted. With the changes in this PR, however, I get no ICE and two errors:
```
error[E0718]: `add` language item must be applied to a trait with 1 generic argument
 --> pr-ex.rs:8:1
  |
8 | #[lang = "add"]
  | ^^^^^^^^^^^^^^^
9 | trait MyAdd<'a, T> {}
  |            ------- this trait has 2 generic arguments, not 1

error[E0369]: cannot add `{integer}` to `{integer}`
  --> pr-ex.rs:14:7
   |
14 |     r + a
   |     - ^ - {integer}
   |     |
   |     {integer}

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0369, E0718.
For more information about an error, try `rustc --explain E0369`.
```
2021-05-18 14:08:51 +02:00
Guillaume Gomez
a181806b8c
Rollup merge of #85338 - lopopolo:core-iter-repeat-gh-81292, r=joshtriplett
Implement more Iterator methods on core::iter::Repeat

`core::iter::Repeat` always returns the same element, which means we can
do better than implementing most `Iterator` methods in terms of
`Iterator::next`.

Fixes #81292.

#81292 raises the question of whether these changes violate the contract of `core::iter::Repeat`, but as far as I can tell `core::iter::repeat` doesn't make any guarantees around how it calls `Clone::clone`.
2021-05-18 14:08:46 +02:00
Guillaume Gomez
d151ed8699
Rollup merge of #85280 - jsha:move-trait-toggles, r=GuillaumeGomez
Toggle-wrap items differently than top-doc.

This makes sure things like trait methods get wrapped at the
`<h3><code>` level rather than at the `.docblock` level. Also it ensures
that only the actual top documentation gets the `.top-doc` class.

Fixes #85167

Before:

![image](https://user-images.githubusercontent.com/220205/117743384-98790200-b1bb-11eb-8804-588530842514.png)

https://doc.rust-lang.org/nightly/std/io/trait.Read.html#tymethod.read

After:

![image](https://user-images.githubusercontent.com/220205/118410882-98a75080-b646-11eb-949d-ca688bab6923.png)
2021-05-18 14:08:42 +02:00
Guillaume Gomez
07d11cf95c
Rollup merge of #84587 - jyn514:rustdoc-lint-block, r=CraftSpider
rustdoc: Make "rust code block is empty" and "could not parse code block" warnings a lint (`INVALID_RUST_CODEBLOCKS`)

Fixes https://github.com/rust-lang/rust/issues/79792. This already went through FCP in https://github.com/rust-lang/rust/pull/79816, so it only needs final review.

This is mostly a rebase of https://github.com/rust-lang/rust/pull/79816 - thank you ``@poliorcetics`` for doing most of the work!
2021-05-18 14:08:41 +02:00
bors
70b9d1e102 Auto merge of #85313 - jackh726:region_eq, r=nikomatsakis
Unify Regions with RegionVids in UnificationTable

A few test output changes; might be able to revert those but figured I would open this for perf and comments.

r? `@nikomatsakis`
2021-05-18 12:07:56 +00:00
Luqman Aden
ac5fd90d82 Don't pass -pie to linker on windows targets. 2021-05-18 03:57:53 -07:00
Luqman Aden
e0d5872503 Undo unnecessary changes. 2021-05-18 02:44:07 -07:00
Guillaume Gomez
5d004c1e20 Improve display for "copy-path" button, making it more discrete 2021-05-18 11:16:07 +02:00
flip1995
9586ddb046
Fix fallout from not ignoring warnings anymore 2021-05-18 11:08:19 +02:00
flip1995
ff452d5ba6
Deny warning in every main sub-crate
This enables the same warnings that are enabled in `clippy_lints` also
in `clippy_utils` and `clippy_dev`. Then it makes sure, that the
`deny-warnings` feature is passed down to `clippy_lints` and
`clippy_utils` when compiling Clippy.
2021-05-18 11:05:48 +02:00
bors
213b8d9a2b Auto merge of #7240 - flip1995:rollup-6nwjgyp, r=flip1995
Rollup of 3 pull requests

Successful merges:

 - #7235 (Fix another manual_unwrap_or deref FP)
 - #7237 (Add the command to add upstream remote)
 - #7239 (CI: update rustup before installing the toolchain on windows)

Failed merges:

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

changelog: rollup
2021-05-18 08:24:04 +00:00
Philipp Krones
70c552b5af
Rollup merge of #7239 - flip1995:ci-windows-rustup, r=flip1995
CI: update rustup before installing the toolchain on windows

Ok, fine windows, if this is what you want, take it...

r? `@ghost`

changelog: none
2021-05-18 10:21:56 +02:00
Philipp Krones
591145c28f
Rollup merge of #7237 - hi-rustin:rustin-patch-command, r=flip1995
Add the command to add upstream remote

changelog: none

Adding this command should better help new contributors.
2021-05-18 10:21:55 +02:00
Philipp Krones
99fb776ace
Rollup merge of #7235 - camsteffen:manual-unwrap-or-deref, r=flip1995
Fix another manual_unwrap_or deref FP

changelog: none (since this just piggybacks on #7233)

Fixes #6960
2021-05-18 10:21:55 +02:00
flip1995
716d03f86b
CI: update rustup before installing the toolchain on windows 2021-05-18 10:03:36 +02:00
bors
25a277f03d Auto merge of #82973 - ijackson:exitstatuserror, r=yaahc
Provide ExitStatusError

Closes #73125

In MR #81452 "Add #[must_use] to [...] process::ExitStatus" we concluded that the existing arrangements in are too awkward so adding that `#[must_use]` is blocked on improving the ergonomics.

I wrote a mini-RFC-style discusion of the approach in https://github.com/rust-lang/rust/issues/73125#issuecomment-771092741
2021-05-18 08:01:32 +00:00
Lee Bradley
4c12a5dc6c Add x.py pre-setup instructions
This change adds pre-setup instructions that outline how x.py requires
python to be setup and how to work around the problem of x.py failing to
locate python, especially now that Ubuntu 20.04's dropped default python
command is causing people to encounter this issue regularly.

See also: #71818
2021-05-18 01:01:28 -05:00
bors
9028173b24 Auto merge of #7201 - mucinoab:master, r=giraffate
Remove powi, "square can be computed more efficiently"

powi(2) produces exactly the same native code as x * x
powi was part of the [`suboptimal_flops`] lint

fixes #7058
changelog: Remove powi [`suboptimal_flops`], "square can be computed more efficiently"
2021-05-18 05:28:42 +00:00
Joshua Nelson
e48b6b4599 Stabilize extended_key_value_attributes
# Stabilization report

 ## Summary

This stabilizes using macro expansion in key-value attributes, like so:

 ```rust
 #[doc = include_str!("my_doc.md")]
 struct S;

 #[path = concat!(env!("OUT_DIR"), "/generated.rs")]
 mod m;
 ```

See the changes to the reference for details on what macros are allowed;
see Petrochenkov's excellent blog post [on internals](https://internals.rust-lang.org/t/macro-expansion-points-in-attributes/11455)
for alternatives that were considered and rejected ("why accept no more
and no less?")

This has been available on nightly since 1.50 with no major issues.

 ## Notes

 ### Accepted syntax

The parser accepts arbitrary Rust expressions in this position, but any expression other than a macro invocation will ultimately lead to an error because it is not expected by the built-in expression forms (e.g., `#[doc]`).  Note that decorators and the like may be able to observe other expression forms.

 ### Expansion ordering

Expansion of macro expressions in "inert" attributes occurs after decorators have executed, analogously to macro expressions appearing in the function body or other parts of decorator input.

There is currently no way for decorators to accept macros in key-value position if macro expansion must be performed before the decorator executes (if the macro can simply be copied into the output for later expansion, that can work).

 ## Test cases

 - https://github.com/rust-lang/rust/blob/master/src/test/ui/attributes/key-value-expansion-on-mac.rs
 - https://github.com/rust-lang/rust/blob/master/src/test/rustdoc/external-doc.rs

The feature has also been dogfooded extensively in the compiler and
standard library:

- https://github.com/rust-lang/rust/pull/83329
- https://github.com/rust-lang/rust/pull/83230
- https://github.com/rust-lang/rust/pull/82641
- https://github.com/rust-lang/rust/pull/80534

 ## Implementation history

- Initial proposal: https://github.com/rust-lang/rust/issues/55414#issuecomment-554005412
- Experiment to see how much code it would break: https://github.com/rust-lang/rust/pull/67121
- Preliminary work to restrict expansion that would conflict with this
feature: https://github.com/rust-lang/rust/pull/77271
- Initial implementation: https://github.com/rust-lang/rust/pull/78837
- Fix for an ICE: https://github.com/rust-lang/rust/pull/80563

 ## Unresolved Questions

~~https://github.com/rust-lang/rust/pull/83366#issuecomment-805180738 listed some concerns, but they have been resolved as of this final report.~~

 ## Additional Information

 There are two workarounds that have a similar effect for `#[doc]`
attributes on nightly. One is to emulate this behavior by using a limited version of this feature that was stabilized for historical reasons:

```rust
macro_rules! forward_inner_docs {
    ($e:expr => $i:item) => {
        #[doc = $e]
        $i
    };
}

forward_inner_docs!(include_str!("lib.rs") => struct S {});
```

This also works for other attributes (like `#[path = concat!(...)]`).
The other is to use `doc(include)`:

```rust
 #![feature(external_doc)]
 #[doc(include = "lib.rs")]
 struct S {}
```

The first works, but is non-trivial for people to discover, and
difficult to read and maintain. The second is a strange special-case for
a particular use of the macro. This generalizes it to work for any use
case, not just including files.

I plan to remove `doc(include)` when this is stabilized. The
`forward_inner_docs` workaround will still compile without warnings, but
I expect it to be used less once it's no longer necessary.
2021-05-18 01:01:36 -04:00
hi-rustin
fd442c3f11 Add the command to add upstream remote 2021-05-18 11:47:53 +08:00
mbartlett21
18b0e7bf2c
Fix must_use on Option::is_none
This fixes the `#[must_use = ...]` on `Option::is_none` to have a working suggestion.
2021-05-18 13:40:26 +10:00
Joshua Nelson
587c50452f Fix rebase conflicts 2021-05-17 23:33:04 -04:00
Bruno A. Muciño
be540e6596 Remove powi, "square can be computed more efficiently"
powi(2) produces exactly the same native code as x * x
2021-05-17 21:59:08 -05:00
Satyarth Agrahari
85e4177184 adding algorithm explanation for partition_in_place iter method and bounding complexity to current implementation 2021-05-18 07:59:16 +05:30
Joshua Nelson
28c9c04325 Don't require cmake on Windows when LLVM isn't being built
Previously, setting `download-ci-llvm = true` when cmake wasn't
installed would give the following error:

```
failed to execute command: "cmake" "--help"
error: The system cannot find the file specified. (os error 2)
```
2021-05-17 22:08:20 -04:00
Joshua Nelson
18f6922d8c Address review comments
- Simplify boolean expression
- Give an example of invalid syntax
- Remove explanation of why code block is text
2021-05-17 21:31:05 -04:00
Joshua Nelson
b885d81a4a Rename INVALID_RUST_CODEBLOCK{,S} 2021-05-17 21:31:04 -04:00
Joshua Nelson
4120f7561c Add back missing help for ignore blocks
This also gives a better error message when a span is missing.
2021-05-17 21:31:03 -04:00
Alexis Bourget
b574c67b93 New rustdoc lint to respect -Dwarnings correctly
This adds a new lint to `rustc` that is used in rustdoc when a code
block is empty or cannot be parsed as valid Rust code.

Previously this was unconditionally a warning. As such some
documentation comments were (unknowingly) abusing this to pass despite
the `-Dwarnings` used when compiling `rustc`, this should not be the
case anymore.
2021-05-17 21:31:01 -04:00
bors
5f10d310f4 Auto merge of #85402 - RalfJung:miri, r=RalfJung
update Miri

Fixes https://github.com/rust-lang/rust/issues/85397
2021-05-18 00:32:19 +00:00
Luqman Aden
a862b1f6cc Adjust linker_is_gnu branches for cases that don't work on windows. 2021-05-17 16:14:13 -07:00
Ralf Jung
a05dd06cc0 update Miri 2021-05-18 00:48:05 +02:00
bors
6fcdb8a297 Auto merge of #7234 - camsteffen:if-let-else-braces, r=flip1995
Remove dead code after #7216

changelog: none
2021-05-17 21:42:21 +00:00
Fabian Wolff
572bb13ae5 Implement jackh726's suggestions 2021-05-17 23:13:04 +02:00
Cameron Steffen
8356c485a9 Fix manual_unwrap_or FP deref reference 2021-05-17 14:20:26 -05:00
bors
3e99439f4d Auto merge of #85414 - RalfJung:rollup-ueqcik4, r=RalfJung
Rollup of 8 pull requests

Successful merges:

 - #85087 (`eval_fn_call`: check the ABI of `body.source`)
 - #85302 (Expand WASI abbreviation in docs)
 - #85355 (More tests for issue-85255)
 - #85367 (Fix invalid input:disabled CSS selector)
 - #85374 (mark internal inplace_iteration traits as hidden)
 - #85408 (remove size field from Allocation)
 - #85409 (Simplify `cfg(any(unix, target_os="redox"))` in example to just `cfg(unix)`)
 - #85412 (remove some functions that were only used by Miri)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-05-17 19:15:21 +00:00
Cameron Steffen
ca0f0002a4 Remove dead code after not linting else if let 2021-05-17 14:09:54 -05:00
bors
a3223af9fe Auto merge of #7133 - arya-k:master, r=llogiq
Add `needless_bitwise_bool` lint

fixes #6827
fixes #1594

changelog: Add ``[`needless_bitwise_bool`]`` lint

Creates a new `bitwise_bool` lint to convert `x & y` to `x && y` when both `x` and `y` are booleans. I also had to adjust thh `needless_bool` lint slightly, and fix a couple failing dogfood tests. I made it a correctness lint as per flip1995's comment [here](https://github.com/rust-lang/rust-clippy/pull/3385#issuecomment-434715723), from a previous WIP attempt at this lint.
2021-05-17 18:57:14 +00:00
Cameron Steffen
b2270e1f45 Simplify manual_unwrap_or 2021-05-17 13:54:25 -05:00