Commit graph

464 commits

Author SHA1 Message Date
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
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
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
bors
492b83c697 Auto merge of #80290 - RalfJung:less-intrinsic-write, r=lcnr
implement ptr::write without dedicated intrinsic

This makes `ptr::write` more consistent with `ptr::write_unaligned`, `ptr::read`, `ptr::read_unaligned`, all of which are implemented in terms of `copy_nonoverlapping`.

This means we can also remove `move_val_init` implementations in codegen and Miri, and its special handling in the borrow checker.

Also see [this Zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/ptr.3A.3Aread.20vs.20ptr.3A.3Awrite).
2021-01-16 17:28:32 +00:00
Chris Pardy
2624b3e443 Improve diagnostics for Precise Capture 2021-01-15 19:39:24 -05:00
LingMan
ba1f036c7a Drop a few unneeded borrows 2021-01-15 21:29:28 +01:00
Yuki Okushi
a584d87417
Rollup merge of #80944 - LingMan:map_or, r=nagisa
Use Option::map_or instead of `.map(..).unwrap_or(..)`

``@rustbot`` modify labels +C-cleanup +T-compiler
2021-01-15 18:26:14 +09:00
LingMan
a56bffb4f9 Use Option::map_or instead of .map(..).unwrap_or(..) 2021-01-14 19:23:59 +01:00
Mara Bos
d3b31065e3
Rollup merge of #80017 - camelid:sugg-rest-pattern, r=estebank
Suggest `_` and `..` if a pattern has too few fields

Fixes #80010.
2021-01-14 17:59:55 +00:00
bors
d03fe84169 Auto merge of #79328 - c410-f3r:hir-if, r=matthewjasper
Reintroduce hir::ExprKind::If

Basically copied and paste #59288/https://github.com/rust-lang/rust-clippy/pull/4080 with some modifications.

The vast majority of tests were fixed and now there are only a few remaining. Since I am still unable to figure out the missing pieces, any help with the following list is welcome.

- [ ] **Unnecessary `typeck` exception**: [Cheated on this one to make CI green.](https://github.com/rust-lang/rust/pull/79328/files#diff-3faee9ba23fc54a12b7c43364ba81f8c5660045c7e1d7989a02a0cee1c5b2051)
- [x] **Incorrect span**: [Span should reference `then` and `else` separately.](https://github.com/rust-lang/rust/pull/79328/files#diff-cf2c46e82222ee4b1037a68fff8a1af3c4f1de7a6b3fd798aacbf3c0475abe3d)
- [x] **New note regarding `assert!`**: [Modified but not "wrong". Maybe can be a good thing?](https://github.com/rust-lang/rust/pull/79328/files#diff-9e0d7c89ed0224e2b62060c957177c27db43c30dfe3c2974cb6b5091cda9cfb5)
- [x] **Inverted report location**: [Modified but not "wrong". Locations were inverted.](https://github.com/rust-lang/rust/pull/79328/files#diff-f637ce7c1f68d523a165aa9651765df05e36c4d7d279194b1a6b28b48a323691)
- [x] **`src/test/ui/point-to-type-err-cause-on-impl-trait-return.rs` has weird errors**: [Not sure why this is happening.](https://github.com/rust-lang/rust/pull/79328/files#diff-c823c09660f5b112f95e97e8ff71f1797b6c7f37dbb3d16f8e98bbaea8072e95)
- [x] **Missing diagnostic**: [???](https://github.com/rust-lang/rust/pull/79328/files#diff-6b8ab09360d725ba4513933827f9796b42ff9522b0690f80b76de067143af2fc)
2021-01-14 14:41:58 +00:00