Commit graph

919 commits

Author SHA1 Message Date
Yuki Okushi
af3c1544e2
Rollup merge of #86673 - m-ou-se:disjoint-capture-edition-lint, r=nikomatsakis
Make disjoint_capture_migration an edition lint.

This turns the disjoint capture lint into an edition lint, and changes all the wording to refer to the edition.

This includes the same first commit as https://github.com/rust-lang/rust/pull/86671. See https://github.com/rust-lang/rust/pull/86671.

Fixes most of https://github.com/rust-lang/project-rfc-2229/issues/43#issuecomment-869188197
2021-06-29 08:46:15 +09:00
Yuki Okushi
5028581a1f
Rollup merge of #86657 - jam1garner:future_prelude_false_positive, r=nikomatsakis
Fix `future_prelude_collision` false positive

Fixes #86633

The lint for checking if method resolution of methods named `try_into` will fail in 2021 edition previously would fire on all inherent methods, however for inherent methods that consume `self`, this takes priority over `TryInto::try_into` due to being inherent, while trait method and methods that take `&self` or `&mut self` don't take priority, and thus aren't affected by this false positive.

This fix is rather simple: simply checking if the inherent method doesn't auto-deref or auto-ref (and thus takes `self`) and if so, prevents the lint from firing.
2021-06-29 08:46:11 +09:00
Yuki Okushi
4afdef07d9
Rollup merge of #86206 - FabianWolff:issue-86188, r=Mark-Simulacrum
Fix type checking of return expressions outside of function bodies

This pull request fixes #86188. The problem is that the current code for type-checking `return` expressions stops if the `return` occurs outside of a function body, while the correct behavior is to continue type-checking the return value expression (otherwise an ICE happens later on because variables declared in the return value expression don't have a type).

Also, I have noticed that it is sometimes not obvious why a `return` is outside of a function body; for instance, in the example from #86188 (which currently causes an ICE):
```rust
fn main() {
    [(); return || {
        let tx;
    }]
}
```
I have changed the error message to also explain why the `return` is considered outside of the function body:
```
error[E0572]: return statement outside of function body
 --> ice0.rs:2:10
  |
1 |  / fn main() {
2 |  |     [(); return || {
  |  |__________^
3 | ||         let tx;
4 | ||     }]
  | ||_____^ the return is part of this body...
5 |  | }
  |  |_- ...not the enclosing function body
```
2021-06-29 00:26:54 +09:00
bors
a4f832b275 Auto merge of #86445 - sexxi-goose:box_fix, r=nikomatsakis
2229: Capture box completely in move closures

Even if the content from box is used in a sharef-ref context,
we capture the box entirerly.

This is motivated by:
1) We only capture data that is on the stack.
2) Capturing data from within the box might end up moving more data than
the user anticipated.

Closes https://github.com/rust-lang/project-rfc-2229/issues/50

r? `@nikomatsakis`
2021-06-27 18:10:35 +00:00
Mara Bos
3c95a28f4c Make disjoint_capture_migration an edition lint. 2021-06-27 16:54:48 +00:00
jam1garner
bf0da4418f Fix future_prelude_collision false positive 2021-06-27 00:28:07 -04:00
bors
117799b73c Auto merge of #86505 - JohnTitor:fix-86483, r=jackh726
Do not panic in `return_type_impl_trait`

Fixes #86483
2021-06-25 09:28:17 +00:00
Aman Arora
d37a07ffbe fixup! 2229: Capture box completely in move closures
fixup! 2229: Capture box completely in move closures
2021-06-24 21:45:29 -04:00
Aman Arora
de2052af9c 2229: Capture box completely in move closures
Even if the content from box is used in a sharef-ref context,
we capture the box entirerly.

This is motivated by:
1) We only capture data that is on the stack.
2) Capturing data from within the box might end up moving more data than
the user anticipated.
2021-06-24 19:39:51 -04:00
bors
d95745e5fa Auto merge of #85427 - ehuss:fix-use-placement, r=jackh726
Fix use placement for suggestions near main.

This fixes an edge case for the suggestion to add a `use`. When running with `--test`, the `main` function will be annotated with an `#[allow(dead_code)]` attribute. The `UsePlacementFinder` would end up using the dummy span of that synthetic attribute. If there are top-level inner attributes, this would place the `use` in the wrong position. The solution here is to ignore attributes with dummy spans.

In the process of working on this, I discovered that the `use_suggestion_placement` test was broken. `UsePlacementFinder` is unaware of active attributes. Attributes like `#[derive]` don't exist in the AST since they are removed. Fixing that is difficult, since the AST does not retain enough information. I considered trying to place the `use` towards the top of the module after any `extern crate` items, but I couldn't find a way to get a span for the start of a module block (the `mod` span starts at the `mod` keyword, and it seems tricky to find the spot just after the opening bracket and past inner attributes). For now, I just put some comments about the issue. This appears to have been a known issue in #44215 where the test for it was introduced, and the fix seemed to be deferred to later.
2021-06-24 14:56:28 +00:00
bors
456a03227e Auto merge of #86279 - JohnTitor:transparent-zero-size-fields, r=nikomatsakis
Permit zero non-zero-field on transparent types

Fixes #77841

This makes the transparent fields meet the below:
> * A `repr(transparent)` type `T` must meet the following rules:
>   * It may have any number of 1-ZST fields
>   * In addition, it may have at most one other field of type U

r? `@nikomatsakis`
2021-06-24 07:29:59 +00:00
Yuki Okushi
462c74007e
Rename function name in comments 2021-06-24 14:21:50 +09:00
Yuki Okushi
3998c03a65
Rollup merge of #86536 - sexxi-goose:edition, r=nikomatsakis
Edition 2021 enables disjoint capture

First part for https://github.com/rust-lang/project-rfc-2229/issues/43
2021-06-24 13:47:36 +09:00
Dylan DPC
af9e5d1a14
Rollup merge of #86223 - fee1-dead:better-E0121, r=petrochenkov
Specify the kind of the item for E0121

Fixes #86005
2021-06-23 00:20:18 +02:00
Aman Arora
f265997b82 Edition 2021 enables disjoint capture 2021-06-22 06:00:12 -04:00
bors
44f4a87d70 Auto merge of #85707 - jam1garner:future_prelude_collision_lint, r=nikomatsakis
Add `future_prelude_collision` lint

Implements #84594. (RFC rust-lang/rfcs#3114 ([rendered](https://github.com/rust-lang/rfcs/blob/master/text/3114-prelude-2021.md))) Not entirely complete but wanted to have my progress decently available while I finish off the last little bits.

Things left to implement:

* [x] UI tests for lints
* [x] Only emit lint for 2015 and 2018 editions
* [ ] Lint name/message bikeshedding
* [x] Implement for `FromIterator` (from best I can tell, the current approach as mentioned from [this comment](https://github.com/rust-lang/rust/issues/84594#issuecomment-847288288) won't work due to `FromIterator` instances not using dot-call syntax, but if I'm correct about this then that would also need to be fixed for `TryFrom`/`TryInto`)*
* [x] Add to `rust-2021-migration` group? (See #85512) (added to `rust-2021-compatibility` group)
* [ ] Link to edition guide in lint docs

*edit: looked into it, `lookup_method` will also not be hit for `TryFrom`/`TryInto` for non-dotcall syntax. If anyone who is more familiar with typecheck knows the equivalent for looking up associated functions, feel free to chime in.
2021-06-22 07:01:54 +00:00
Yuki Okushi
4495ce75d9
Rollup merge of #86493 - Smittyvb:ctor-typeck-error, r=davidtwco
Say "this enum variant takes"/"this struct takes" instead of "this function takes"

This makes error messages for functions with incorrect argument counts adapt if they refer to a struct or enum variant:
```
error[E0061]: this enum variant takes 1 argument but 0 arguments were supplied
  --> $DIR/struct-enum-wrong-args.rs:7:13
   |
LL |     let _ = Ok();
   |             ^^-- supplied 0 arguments
   |             |
   |             expected 1 argument

error[E0061]: this struct takes 1 argument but 0 arguments were supplied
  --> $DIR/struct-enum-wrong-args.rs:8:13
   |
LL |     let _ = Wrapper();
   |             ^^^^^^^-- supplied 0 arguments
   |             |
   |             expected 1 argument
```

Fixes #86481.
2021-06-22 07:37:56 +09:00
Niko Matsakis
aa3580baa6 introduce helper function 2021-06-21 14:36:25 -04:00
Deadbeef
e66f241b80
Update #83739 with type of the item specified 2021-06-22 01:03:54 +08:00
Deadbeef
200fdaac77
Specify the kind of the item for E0121 2021-06-22 00:40:47 +08:00
Yuki Okushi
1a1909a8a6
Rollup merge of #83739 - JohnTitor:issue-75889, r=estebank
Account for bad placeholder errors on consts/statics with trait objects

Fixes #75889
r? ``@estebank``
2021-06-21 09:42:12 +09:00
bors
e82b65026d Auto merge of #85538 - r00ster91:iterrepeat, r=Mark-Simulacrum
Replace some `std::iter::repeat` with `str::repeat`

I noticed that there were some instances where `std::iter::repeat` would be used to repeat a string or a char to take a specific count of it and then collect it into a `String` when `str::repeat` is actually much faster and better for that.

See also: https://github.com/rust-lang/rust-clippy/issues/7260.
2021-06-20 20:07:13 +00:00
Smitty
4cd2fab8c5 Specify if struct/enum in arg mismatch error 2021-06-20 13:48:37 -04:00
bors
2e940ac5e9 Auto merge of #86250 - RalfJung:intrinsic_operation_unsafety, r=oli-obk
fix intrinsic_operation_unsafety comment
2021-06-20 14:01:26 +00:00
jam1garner
b18704dd58 Fix future_prelude_collision for object calls and use as _ 2021-06-19 18:42:24 -04:00
Niko Matsakis
9bee7f0d0e WIP: identify the case where we need to serialize path 2021-06-18 13:19:08 -04:00
bors
312b894cc1 Auto merge of #85421 - Smittyvb:rm_pushpop_unsafe, r=matthewjasper
Remove some last remants of {push,pop}_unsafe!

These macros have already been removed, but there was still some code handling these macros. That code is now removed.
2021-06-18 14:17:53 +00:00
Yuki Okushi
aff7994740
Rollup merge of #86355 - JohnTitor:issue-82158, r=estebank
Remove invalid suggestions for assoc consts on placeholder type error

Fixes #82158
This also moves some tests to typeck.
r? ``@estebank``
2021-06-17 21:56:45 +09:00
Niko Matsakis
dbc9da7962 WIP: Find the imports that were used to reach a method
And add tests for some corner cases we have to consider.
2021-06-17 06:10:38 -04:00
Yuki Okushi
d828eadd7a
Remove invalid suggestions for assoc consts on placeholder type error 2021-06-16 18:57:53 +09:00
Yuki Okushi
280d19395d
Remove projection_ty_from_predicates 2021-06-16 16:33:03 +09:00
jam1garner
3efa5b4b83 Emit additional arguments in future_prelude_collision lint 2021-06-14 22:43:19 -04:00
LeSeulArtichaut
e3ca81fd5a Use the now available implementation of IntoIterator for arrays 2021-06-14 23:40:09 +02:00
Niko Matsakis
17ab9c0ff9 extract Rust 2021 prelude logic to its own module 2021-06-14 13:59:43 -04:00
Niko Matsakis
8d42f3da63 don't warn for fully qual inherent methods
But do continue to warn for trait methods.
2021-06-14 13:27:25 -04:00
jam1garner
64c61a32f6 Fix future_prelude_collision adding unneeded generic arguments 2021-06-14 13:27:25 -04:00
jam1garner
4a21a0bebc Fix future_prelude_collision not maintaining type aliases 2021-06-14 13:27:25 -04:00
jam1garner
cb4999242d Fix future_prelude_collision lint breaking for pointer mutabilty coercion 2021-06-14 13:27:24 -04:00
jam1garner
93c60f26bf Fix missing generic parameters from future_prelude_collision lint suggestion 2021-06-14 13:27:24 -04:00
jam1garner
327697a540 Fix autoderef and autoref for future_prelude_collision lint 2021-06-14 13:27:24 -04:00
jam1garner
c41a157b90 Fix incorrect argument description on FnCtxt::resolve_ufcs 2021-06-14 13:27:24 -04:00
jam1garner
35af38353e Add UI tests for future_prelude_collision lint 2021-06-14 13:27:24 -04:00
jam1garner
1626e1938a Add support for associated functions to future_prelude_collision lint 2021-06-14 13:27:24 -04:00
jam1garner
a9dc234c43 Add docs for FnCtxt::resolve_ufcs 2021-06-14 13:27:24 -04:00
jam1garner
01bdb8e38a Disable future_prelude_collision for 2021 edition 2021-06-14 13:27:24 -04:00
jam1garner
79388aa067 Add future_prelude_collision lint 2021-06-14 13:27:23 -04:00
Yuki Okushi
ea188e9d21
Permit zero non-zero-field on transparent types 2021-06-14 07:42:14 +09:00
Ralf Jung
7fccdb7b33 fix intrinsic_operation_unsafety comment 2021-06-12 19:01:32 +02:00
Fabian Wolff
79dc9a76a6 Suggest a FnPtr type if a FnDef type is found 2021-06-11 23:05:17 +02:00
Fabian Wolff
f687d5c43a Do not suggest to add type annotations for unnameable types 2021-06-11 16:37:25 +02:00