Commit graph

471 commits

Author SHA1 Message Date
Aman Arora
d3e85014a7 Process mentioned upvars for analysis first pass after ExprUseVisitor
- This allows us add fake information after handling migrations if
  needed.
- Capture analysis also priortizes what we see earlier, which means
  fake information should go in last.
2021-02-01 18:32:50 -05:00
Jonas Schievink
991b31377c
Rollup merge of #81480 - b-naber:nested_fields_suggestion, r=estebank
Add suggestion for nested fields

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

r? ```@estebank```
2021-01-31 16:36:46 +01:00
Jonas Schievink
7e3a8ec688
Rollup merge of #80092 - sexxi-goose:restrict_precision, r=nikomatsakis
2229: Fix issues with move closures and mutability

This PR fixes two issues when feature `capture_disjoint_fields` is used.

1. Can't mutate using a mutable reference
2. Move closures try to move value out through a reference.

To do so, we
1. Compute the mutability of the capture and store it as part of the `CapturedPlace`  that is written in TypeckResults
2. Restrict capture precision. Note this is temporary for now, to allow the feature to be used with move closures and ByValue captures and might change depending on discussions with the lang team.
    - No Derefs are captured for ByValue captures, since that will result in value behind a reference getting moved.
    - No projections are applied to raw pointers since these require unsafe blocks. We capture
    them completely.

r? `````@nikomatsakis`````
2021-01-31 16:36:41 +01:00
Jonas Schievink
33cd862733
Rollup merge of #81547 - pierwill:edit-typeck-mod-docs, r=davidtwco
Edit rustc_typeck top-level docs

Edit punctuation and wording in note on type variables vs. type parameters.

Also add missing punctuation and two inter-doc links.
2021-01-31 01:47:41 +01:00
Jonas Schievink
84b6f46d6e
Rollup merge of #81422 - estebank:dotdot_sugg, r=davidtwco
Account for existing `_` field pattern when suggesting `..`

Follow up to #80017.
2021-01-31 01:47:33 +01:00
Jonas Schievink
1e99f26894
Rollup merge of #80470 - SimonSapin:array-intoiter-type, r=m-ou-se
Stabilize by-value `[T; N]` iterator `core::array::IntoIter`

Tracking issue: https://github.com/rust-lang/rust/issues/65798

This is unblocked now that `min_const_generics` has been stabilized in https://github.com/rust-lang/rust/pull/79135.

This PR does *not* include the corresponding `IntoIterator` impl, which is https://github.com/rust-lang/rust/pull/65819. Instead, an iterator can be constructed through the `new` method.

`new` would become unnecessary when `IntoIterator` is implemented and might be deprecated then, although it will stay stable.
2021-01-31 01:47:25 +01:00
b-naber
9946b54823 add suggestion for nested fields 2021-01-30 23:19:41 +01:00
pierwill
adfb04fc4e Edit rustc_typeck top-level docs
Edit punctuation and wording in note on type variables
vs. type parameters.

Also add missing punctuation and two inter-doc links.
2021-01-30 10:04:19 -08:00
Aman Arora
0f4bab246b Fixme for closure origin when reborrow is implemented 2021-01-29 16:25:01 -05:00
Aman Arora
3488082582 Compute mutability of closure captures
When `capture_disjoint_fields` is not enabled, checking if the root variable
binding is mutable would suffice.

However with the feature enabled, the captured place might be mutable
because it dereferences a mutable reference.

This PR computes the mutability of each capture after capture analysis
in rustc_typeck. We store this in `ty::CapturedPlace` and then use
`ty::CapturedPlace::mutability` in mir_build and borrow_check.
2021-01-29 15:37:40 -05:00
Aman Arora
b421cd56d9 Restrict precision of captures with capture_disjoint_fields set
- No Derefs in move closure, this will result in value behind a reference getting moved.
- No projections are applied to raw pointers, since these require unsafe blocks. We capture
  them completely.

Motivations for these are recorded here: https://hackmd.io/71qq-IOpTNqzMkPpAI1dVg?view
2021-01-29 15:37:05 -05:00
bors
643a79af3d Auto merge of #81149 - Aaron1011:feature/better-no-method-found-err, r=estebank
Avoid describing a method as 'not found' when bounds are unsatisfied

Fixes #76267

When there is a single applicable method candidate, but its trait bounds
are not satisfied, we avoid saying that the method is "not found".
Insted, we update the error message to directly mention which bounds are
not satisfied, rather than mentioning them in a note.
2021-01-28 12:09:50 +00:00
Yuki Okushi
d98fcbd561
Rollup merge of #81433 - lcnr:stop-looking-into-ty-alias, r=oli-obk
const_evaluatable: stop looking into type aliases

see https://rust-lang.zulipchat.com/#narrow/stream/260443-project-const-generics/topic/const_evaluatable.3A.20type.20alias

r? ````@oli-obk````
2021-01-28 15:09:20 +09:00
Yuki Okushi
b8eac50ff5
Rollup merge of #81416 - estebank:suggestion-span-tweak, r=petrochenkov
Tweak suggestion for missing field in patterns

Account for parser recovered struct and tuple patterns to avoid invalid
suggestion.

Follow up to #81103.
2021-01-28 15:09:13 +09:00
Yuki Okushi
84ad95be70
Rollup merge of #81062 - sexxi-goose:precise_capture_diagnostics, r=nikomatsakis
Improve diagnostics for Precise Capture

This is just the capture analysis part and borrow checker logging will updated as part of rust-lang/project-rfc-2229#8

Closes rust-lang/project-rfc-2229#22
2021-01-28 15:09:06 +09:00
Yuki Okushi
446edd1e1a
Rollup merge of #79951 - LeSeulArtichaut:ty-ir, r=nikomatsakis
Refractor a few more types to `rustc_type_ir`

In the continuation of #79169, ~~blocked on that PR~~.

This PR:
 - moves `IntVarValue`, `FloatVarValue`, `InferTy` (and friends) and `Variance`
 - creates the `IntTy`, `UintTy` and `FloatTy` enums in `rustc_type_ir`, based on their `ast` and `chalk_ir` equilavents, and uses them for types in the rest of the compiler.

~~I will split up that commit to make this easier to review and to have a better commit history.~~
EDIT: done, I split the PR in commits of 200-ish lines each

r? `````@nikomatsakis````` cc `````@jackh726`````
2021-01-28 15:09:02 +09:00
Bastian Kauschke
b519deb224 const_evaluatable: stop looking into type aliases 2021-01-27 13:34:45 +01:00
Aaron Hill
dea8a16af5
Avoid describing a method as 'not found' when bounds are unsatisfied
Fixes #76267

When there is a single applicable method candidate, but its trait bounds
are not satisfied, we avoid saying that the method is "not found".
Insted, we update the error message to directly mention which bounds are
not satisfied, rather than mentioning them in a note.
2021-01-26 23:59:50 -05:00
Esteban Küber
a398994cb2 Account for existing _ field pattern when suggesting ..
Follow up to #80017.
2021-01-26 16:53:56 -08:00
Esteban Küber
0959f0f912 Tweak suggestion for missing field in patterns
Account for parser recovered struct and tuple patterns to avoid invalid
suggestion.

Follow up to #81103.
2021-01-26 11:27:53 -08:00
Ömer Sinan Ağacan
d035be8e6f typeck: Don't suggest converting LHS exprs
Converting LHS of an assignment does not work, so avoid suggesting that.

Fixes #81293
2021-01-26 09:09:15 +03:00
Jonas Schievink
70be327f2a
Rollup merge of #81279 - bugadani:iter, r=davidtwco
Small refactor in typeck

 - `check_impl_items_against_trait` only queries and walks through associated items once
 - extracted function that reports errors
 - don't check specialization validity when trait item does not match
 - small additional cleanups
2021-01-24 22:10:01 +01:00
Bastian Kauschke
688cf6406a replace RefCell with Cell in FnCtxt 2021-01-23 11:47:38 +01:00
Dániel Buga
f29b32983d Fix formatting 2021-01-22 18:55:37 +01:00
Dániel Buga
aa4f5833e1 Only query associated_items once 2021-01-22 18:36:33 +01:00
Dániel Buga
ee639de007 Only guess span if absolutely necessary 2021-01-22 18:36:33 +01:00
Dániel Buga
d63b278c2f Only scan through assoc items once in check_impl_items_against_trait 2021-01-22 18:36:30 +01:00
Mara Bos
3682a06dcf
Rollup merge of #81236 - estebank:everybody-loop-now, r=oli-obk
Gracefully handle loop labels missing leading `'` in different positions

Fix #81192.

* Account for labels when suggesting `loop` instead of `while true`
* Suggest `'a` when given `a` only when appropriate
* Add loop head span to hir
* Tweak error for invalid `break expr`
* Add more misspelled label tests
* Avoid emitting redundant "unused label" lint
* Parse loop labels missing a leading `'`

Each commit can be reviewed in isolation.
2021-01-22 14:30:19 +00:00
Dániel Buga
9988821a04 Move missing_item check inside condition 2021-01-22 08:22:15 +01:00
Dániel Buga
58a90de9ad No peeking 2021-01-22 08:14:25 +01:00
Dániel Buga
3e9f27dadf Remove unnecessary closure 2021-01-22 08:06:01 +01:00
Esteban Küber
060dba67b7 Add loop head span to hir 2021-01-21 21:41:46 -08:00
Bastian Kauschke
f32a6acdab require gat substs to be invariant 2021-01-21 17:35:44 +01:00
Guillaume Gomez
348997a05f
Rollup merge of #81147 - estebank:drop-suggestion, r=varkor
Fix structured suggestion for explicit `drop` call
2021-01-19 10:27:56 +01:00
bors
94e6ea9fc9 Auto merge of #81103 - zackmdavis:comma_trail, r=davidtwco
don't suggest erroneous trailing comma after `..`

In #76612, suggestions were added for missing fields in patterns. However, the suggestions are being inserted just at the end
of the last field in the pattern—before any trailing comma after the last field. This resulted in the "if you don't care about missing fields" suggestion to recommend code with a trailing comma after the field ellipsis (`..,`), which is actually not legal ("`..` must be at the end and cannot have a trailing comma")!

Incidentally, the doc-comment on `error_unmentioned_fields` was using `you_cant_use_this_field` as an example field name (presumably copy-paste inherited from the description of Issue #76077), but the present author found this confusing, because unmentioned fields aren't necessarily unusable.

The suggested code in the diff this commit introduces to `destructuring-assignment/struct_destructure_fail.stderr` doesn't work, but it didn't work beforehand, either (because of the "found reserved identifier `_`" thing), so you can't really call it a regression; it could be fixed in a separate PR.

Resolves #78511.

r? `@davidtwco` or `@estebank`
2021-01-19 02:54:58 +00:00
LeSeulArtichaut
50e1ae15e9 Use ty::{IntTy,UintTy,FloatTy} in rustc 2021-01-18 21:09:30 +01:00
Daiki Ihara
db95b5ca9b Add suggestion for impl_candidates with E0283
Update compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

Co-authored-by: Esteban Kuber <estebank@users.noreply.github.com>
2021-01-18 21:57:15 +09:00
bors
86e0ff47a0 Auto merge of #80995 - tmandry:instrument-method-checker, r=lcnr
Add tracing instrumentation to method typeck

I was recently digging into how this code works, and this instrumentation was helpful.
2021-01-18 08:39:31 +00:00
Esteban Küber
70a43e07f6 Fix structured suggestion for explicit drop call 2021-01-17 16:48:52 -08:00
bors
4253153db2 Auto merge of #80679 - jackh726:predicate-kind-take2, r=lcnr
Remove PredicateKind and instead only use Binder<PredicateAtom>

Originally brought up in https://github.com/rust-lang/rust/pull/76814#discussion_r546858171

r? `@lcnr`
2021-01-17 20:49:11 +00:00
Mara Bos
34e073f44b
Rollup merge of #81084 - LingMan:map, r=oli-obk
Use Option::map instead of open-coding it

r? ```@oli-obk```
```@rustbot``` modify labels +C-cleanup +T-compiler
2021-01-17 12:24:58 +00:00
Mara Bos
19f97802ca
Rollup merge of #80635 - sexxi-goose:use-place-instead-of-symbol, r=nikomatsakis`
Improve diagnostics when closure doesn't meet trait bound

Improves the diagnostics when closure doesn't meet trait bound by modifying `TypeckResuts::closure_kind_origins` such that `hir::Place` is used instead of `Symbol`. Using `hir::Place` to describe which capture influenced the decision of selecting a trait a closure satisfies to (Fn/FnMut/FnOnce, Copy) allows us to show precise path in the diagnostics when `capture_disjoint_field` feature is enabled.

Closes rust-lang/project-rfc-2229/issues/21

r? ```@nikomatsakis```
2021-01-17 12:24:44 +00:00
Zack M. Davis
14eb94fe7a don't suggest erroneous trailing comma after ..
In #76612, suggestions were added for missing fields in
patterns. However, the suggestions are being inserted just at the end
of the last field in the pattern—before any trailing comma after the
last field. This resulted in the "if you don't care about missing
fields" suggestion to recommend code with a trailing comma after the
field ellipsis (`..,`), which is actually not legal ("`..` must be at
the end and cannot have a trailing comma")!

Incidentally, the doc-comment on `error_unmentioned_fields` was using
`you_cant_use_this_field` as an example field name (presumably
copy-paste inherited from the description of Issue #76077), but
the present author found this confusing, because unmentioned fields
aren't necessarily unusable.

The suggested code in the diff this commit introduces to
`destructuring-assignment/struct_destructure_fail.stderr` doesn't
work, but it didn't work beforehand, either (because of the "found
reserved identifier `_`" thing), so you can't really call it a
regression; it could be fixed in a separate PR.

Resolves #78511.
2021-01-16 16:01:36 -08:00
Jack Huey
3dea68de1d Review changes 2021-01-16 18:56:37 -05:00
Jack Huey
476bd53058 Cleanup 2021-01-16 18:50:34 -05:00
Jack Huey
e76476afe4 Cleanup 2021-01-16 18:40:47 -05:00
Jack Huey
4cd6f85a07 Remove PredicateKind 2021-01-16 18:40:47 -05:00
Jack Huey
4cb3d6f983 Intermediate formatting and such 2021-01-16 18:40:47 -05:00
Jack Huey
8278314a8b Remove PredicateKind::Atom 2021-01-16 18:40:47 -05:00
LingMan
76003f31f1 Use Option::map instead of open-coding it 2021-01-16 20:05:02 +01:00