Commit Graph

197 Commits

Author SHA1 Message Date
Mara Bos
9e8edc8c22
Rollup merge of #80495 - jyn514:rename-empty, r=petrochenkov
Rename kw::Invalid -> kw::Empty

See https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/Is.20there.20a.20symbol.20for.20the.20empty.20string.3F/near/220054471
for context.

r? `@petrochenkov`
2020-12-30 20:56:58 +00:00
Joshua Nelson
edeac1778c Rename kw::Invalid -> kw::Empty
See https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/Is.20there.20a.20symbol.20for.20the.20empty.20string.3F/near/220054471
for context.
2020-12-30 09:50:02 -05:00
Yuki Okushi
41fa0dba27
Rollup merge of #80509 - matthiaskrgr:ptr_arg, r=varkor
where possible, pass slices instead of &Vec or &String (clippy::ptr_arg)
2020-12-30 22:49:26 +09:00
Matthias Krüger
bdc9291ed9 where possible, pass slices instead of &Vec or &String (clippy::ptr_arg) 2020-12-30 13:11:52 +01:00
Yuki Okushi
a309468a8c
Rollup merge of #80348 - matthiaskrgr:less_clones, r=Dylan-DPC
remove redundant clones (clippy::redundant_clone)
2020-12-30 18:15:04 +09:00
Matthias Krüger
d12a358673 use matches!() macro in more places 2020-12-24 13:35:12 +01:00
Matthias Krüger
6e852cc4ce remove redundant clones (clippy::redundant_clone) 2020-12-24 12:59:22 +01:00
Nadrieril
be23694622 Fix a comment 2020-12-22 15:20:24 +00:00
Nadrieril
85fdb34d3a Apply suggestions from code review
Co-authored-by: varkor <github@varkor.com>
2020-12-22 15:20:24 +00:00
Nadrieril
1c176d1150 Simplify field filtering 2020-12-22 15:20:23 +00:00
Nadrieril
53e03fb7c1 Make the special "missing patterns" constructor real 2020-12-22 15:20:23 +00:00
Nadrieril
2a541cea35 Completely rework the explanation of the algorithm 2020-12-22 15:20:23 +00:00
Nadrieril
43d445c8d1 Pass Matrix explicitly instead of via PatCtxt 2020-12-22 15:20:23 +00:00
Nadrieril
8b38b6859a Inline the constructor-specific split functions 2020-12-22 15:20:23 +00:00
Nadrieril
3141f2d78c Inline all_constructors 2020-12-22 15:20:23 +00:00
Nadrieril
bbb4ac0651 Rebrand MissingConstructors as SplitWildcard 2020-12-22 15:20:23 +00:00
Nadrieril
9d0c2ed913 Factor out SplitVarLenSlice used for slice splitting 2020-12-22 15:20:23 +00:00
Nadrieril
7948f91910 Run the annoying lint separately 2020-12-22 15:20:23 +00:00
Nadrieril
5a24b2c2c7 Factor out SplitIntRange used for integer range splitting 2020-12-22 15:20:23 +00:00
bors
75e1acb63a Auto merge of #78242 - Nadrieril:rename-overlapping_endpoints-lint, r=varkor
Rename `overlapping_patterns` lint

As discussed in https://github.com/rust-lang/rust/issues/65477. I also tweaked a few things along the way.

r? `@varkor`
`@rustbot` modify labels: +A-exhaustiveness-checking
2020-12-22 10:32:03 +00:00
bors
1f5bc176b0 Auto merge of #80104 - Nadrieril:usefulness-merging, r=varkor
Improve and fix diagnostics of exhaustiveness checking

Primarily, this fixes https://github.com/rust-lang/rust/issues/56379. This also fixes incorrect interactions between or-patterns and slice patterns that I discovered while working on #56379. Those two examples show the incorrect diagnostics:

```rust
match &[][..] {
    [true] => {}
    [true // detected as unreachable but that's not true
        | false, ..] => {}
    _ => {}
}
match (true, None) {
    (true, Some(_)) => {}
    (false, Some(true)) => {}
    (true | false, None | Some(true // should be detected as unreachable
                               | false)) => {}
}
```

I did not measure any perf impact. However, I suspect that [`616ba9f`](616ba9f9f7) should have a negative impact on large or-patterns. I'll see what the perf run says; I have optimization ideas up my sleeve if needed.

EDIT: I initially had a noticeable perf impact that I thought unavoidable. I then proceeded to avoid it x)

r? `@varkor`
`@rustbot` label +A-exhaustiveness-checking
2020-12-19 19:14:04 +00:00
Nadrieril
5b6c175566 Tweak diagnostics 2020-12-19 17:48:31 +00:00
Nadrieril
cefcadbe92 Unify the two kinds of usefulness merging
This is elegant but a bit of a perf gamble. That said, or-patterns
rarely have many branches and it's easy to optimize or revert if we ever
need to. In the meantime simpler code is worth it.
2020-12-18 16:21:39 +00:00
Nadrieril
6319d737e0 Merge unreachable subpatterns correctly 2020-12-18 16:21:39 +00:00
Nadrieril
2d71a0b9b9 Keep all witnesses of non-exhaustiveness 2020-12-18 16:21:38 +00:00
Nadrieril
d7a6365b77 Rewrite usefulness merging using SpanSet
`SpanSet` is heavily inspired from `DefIdForest`.
2020-12-18 16:21:38 +00:00
Nadrieril
170fae2c18 Log the output of is_useful in the or-pattern case too 2020-12-18 16:21:38 +00:00
Nadrieril
7009d20290 Factor out or-pattern usefulness merging 2020-12-18 16:21:38 +00:00
Yuki Okushi
1e1ba7c936
Rollup merge of #79051 - LeSeulArtichaut:if-let-guard, r=matthewjasper
Implement if-let match guards

Implements rust-lang/rfcs#2294 (tracking issue: #51114).

I probably should do a few more things before this can be merged:
- [x] Add tests (added basic tests, more advanced tests could be done in the future?)
- [x] Add lint for exhaustive if-let guard (comparable to normal if-let statements)
- [x] Fix clippy

However since this is a nightly feature maybe it's fine to land this and do those steps in follow-up PRs.

Thanks a lot `@matthewjasper` ❤️ for helping me with lowering to MIR! Would you be interested in reviewing this?
r? `@ghost` for now
2020-12-17 11:43:55 +09:00
bors
e99a89c7c0 Auto merge of #73210 - wesleywiser:consts_in_debuginfo, r=oli-obk
[mir-opt] Allow debuginfo to be generated for a constant or a Place

Prior to this commit, debuginfo was always generated by mapping a name
to a Place. This has the side-effect that `SimplifyLocals` cannot remove
locals that are only used for debuginfo because their other uses have
been const-propagated.

To allow these locals to be removed, we now allow debuginfo to point to
a constant value. The `ConstProp` pass detects when debuginfo points to
a local with a known constant value and replaces it with the value. This
allows the later `SimplifyLocals` pass to remove the local.
2020-12-15 08:46:00 +00:00
Yuki Okushi
1b81f08d4c
Rollup merge of #79940 - matthiaskrgr:cl15ppy, r=Dylan-DPC
fix more clippy::complexity findings

fix clippy::unnecessary_filter_map
use if let Some(x) = ..  instead of ...map(|x|) to conditionally run fns that return () (clippy::option_map_unit_fn)
fix clippy::{needless_bool, manual_unwrap_or}
don't clone types that are copy (clippy::clone_on_copy)
don't convert types into identical types with .into() (clippy::useless_conversion)
use strip_prefix over slicing (clippy::manual_strip)

r? ``@Dylan-DPC``
2020-12-13 11:05:36 +09:00
bors
5bd9b60333 Auto merge of #79553 - sexxi-goose:mir_min_cap_writeback, r=nikomatsakis
Capture precise paths in THIR and MIR

This PR allows THIR and MIR to use the result of the new capture analysis to actually capture precise paths

To achieve we:
- Writeback min capture results to TypeckResults
- Move handling upvars to PlaceBuilder in mir_build
- Lower precise paths in THIR build by reading min_captures
- Search for ancestors in min_capture when trying to build a MIR place which starts off of an upvar

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

Partly implements: rust-lang/project-rfc-2229#18

Work that remains (not in this PR):
- [ ] [Known bugs when feature gate is enabled](https://github.com/rust-lang/project-rfc-2229/projects/1?card_filter_query=label%3Abug)
- [ ] Use min_capure_map for
  - [ ] Liveness analysis
  - [ ] rustc_mir/interpret/validity.rs
  - [ ] regionck
- [ ] rust-lang/project-rfc-2229#8
- [ ] remove closure_captures and upvar_capture_map

r? `@ghost`
2020-12-12 00:23:29 +00:00
Matthias Krüger
5833f74a9c use if let Some(x) = .. instead of ...map(|x|) to conditionally run fns that return () (clippy::option_map_unit_fn) 2020-12-11 23:02:19 +01:00
Aman Arora
e2efdd156b Use precise places when lowering Closures in THIR
- Closures now use closure_min_captures to figure out captured paths
- Build upvar_mutbls using closure_min_captures
- Change logic in limit_capture_mutability to differentiate b/w
  capturing parent's local variable or capturing a variable that is
  captured by the parent (in case of nested closure) using PlaceBase.

Co-authored-by: Roxane Fruytier <roxane.fruytier@hotmail.com>
2020-12-09 22:34:15 -05:00
Aman Arora
6a1d0699a4 Use Places for captures in MIR
- Use closure_min_capture maps to capture precise paths
- PlaceBuilder now searches for ancestors in min_capture list
- Add API to `Ty` to allow access to the n-th element in a
  tuple in O(1) time.

Co-authored-by: Roxane Fruytier <roxane.fruytier@hotmail.com>
2020-12-09 22:33:33 -05:00
oli
84fe7cf24e Also generate StorageDead in constants 2020-12-09 10:59:10 +00:00
Wesley Wiser
01aec8d185 [mir-opt] Allow debuginfo to be generated for a constant or a Place
Prior to this commit, debuginfo was always generated by mapping a name
to a Place. This has the side-effect that `SimplifyLocals` cannot remove
locals that are only used for debuginfo because their other uses have
been const-propagated.

To allow these locals to be removed, we now allow debuginfo to point to
a constant value. The `ConstProp` pass detects when debuginfo points to
a local with a known constant value and replaces it with the value. This
allows the later `SimplifyLocals` pass to remove the local.
2020-12-06 20:48:25 -05:00
Aman Arora
d9523622ff Move handling UpvarRef to PlaceBuilder
- This allows us to delay figuring out the index of a capture
  in the closure structure when all projections to atleast form
  a capture have been applied to the builder

Co-authored-by: Roxane Fruytier <roxane.fruytier@hotmail.com>
2020-12-06 18:30:23 -05:00
Tomasz Miąsko
91fe548825 Retain assembly operands span when lowering AST to HIR 2020-12-06 20:48:08 +01:00
LeSeulArtichaut
f3d4aa6afb Implement lowering of if-let guards to MIR 2020-12-06 13:42:24 +01:00
LeSeulArtichaut
bab20800f0 Introduce if-let guards in the THIR 2020-12-06 11:48:08 +01:00
Matthew Jasper
4fef39113a Avoid leaking block expression values 2020-12-04 23:07:46 +00:00
Matthew Jasper
7f3e8551dd Use record_operands_moved more aggresively 2020-12-04 22:22:52 +00:00
Matthew Jasper
b766abc88f Simplify unscheduling of drops after moves 2020-12-04 22:19:28 +00:00
Nadrieril
793c40e0bd Inline is_covered_by 2020-12-04 01:45:34 +00:00
Nadrieril
94ad5e1672 Improve error message 2020-11-29 21:29:19 +00:00
Nadrieril
c89d439bb5 Be consistent about linting singletons 2020-11-29 21:29:19 +00:00
Nadrieril
d1a50ffb7c Rename the overlapping_patterns lint to overlapping_range_endpoints 2020-11-29 21:29:19 +00:00
Nadrieril
bdd2bdb53b Don't store ty and span in IntRange
We prefer to grab `ty` and `span` from `pcx`. This makes it consistent
with other constructors.
2020-11-28 22:07:15 +00:00
Nadrieril
d8983655c1 Correctly detect usize/isize range overlaps 2020-11-28 21:23:38 +00:00