Commit Graph

788 Commits

Author SHA1 Message Date
Camille GILLOT
1f370d9437 Use tcx.hir() utils for spans in MIR building.
This corrects the `span_with_body` in the case of closures, which was
incorrectly shortened to the `def_span`.
2022-09-13 19:18:23 +02:00
Camille GILLOT
ffe20d61d6 Only keep one version of ImplicitSelfKind. 2022-09-13 19:18:23 +02:00
bors
2e44c17c12 Auto merge of #100968 - cjgillot:mir-upvar-vec, r=wesleywiser
Only compute captures once when building MIR.
2022-09-10 12:07:29 +00:00
Camille Gillot
bcbd183ca3
Remove unused temp.
Co-authored-by: Wesley Wiser <wwiser@gmail.com>
2022-09-10 12:10:04 +02:00
bors
24d6992020 Auto merge of #101467 - nnethercote:shrink-hir-Ty-Pat, r=spastorino
Shrink `hir::Ty` and `hir::Pat`

r? `@ghost`
2022-09-08 13:11:57 +00:00
Dylan DPC
0d61a507f5
Rollup merge of #101399 - cjgillot:borrowck-binding-span, r=estebank
Shrink span for bindings with subpatterns.

Bindings with nested patterns (`binding @ pat` syntax) currently point to the full pattern.  This PR proposes to shrink the span to stop before the ````@`.```  This makes the diagnostics for move/mutability conflicts clearer, as they not point to the `binding` only, instead of the full pat.

r? ```@estebank```
2022-09-08 11:55:06 +05:30
Nicholas Nethercote
e67f39f8bc Introduce DotDotPos.
This shrinks `hir::Pat` from 88 to 72 bytes.
2022-09-08 15:25:50 +10:00
Camille GILLOT
5d94d42485 Shrink span for bindings with subpatterns. 2022-09-06 20:57:44 +02:00
Guillaume Gomez
d13aefdc65
Rollup merge of #101357 - compiler-errors:variant-sugg-tweak, r=oli-obk
Include enum path in variant suggestion

(except for `Result` and `Option`, which we should have via the prelude)

Fixes #101356
2022-09-06 17:00:25 +02:00
Takayuki Maeda
fea1c5f5c8 refactor: remove unnecessary variables 2022-09-05 22:31:02 +09:00
Takayuki Maeda
87c6da363f separate the receiver from arguments in HIR 2022-09-05 22:25:49 +09:00
Michael Goulet
be53bd8380 Include enum path in variant suggestion 2022-09-03 08:11:17 +00:00
Nicholas Nethercote
43a0268f3a Use boxed slices in PatKind.
To shrink it a little more.
2022-09-02 07:26:22 +10:00
Nicholas Nethercote
a40124e01c Box CanonicalUserTypeAnnotation::CanonicalUserType.
This shrinks `Ascription`, which shrinks `PatKind::AscribeUserType`,
which shrinks `Pat`.
2022-09-02 07:26:22 +10:00
Nicholas Nethercote
2c4c8eb1a3 Box PatKind::Range.
Because it's the biggest variant. Also, make `PatRange` non-`Copy`,
because it's 104 bytes, which is pretty big.
2022-09-02 07:26:22 +10:00
Nicholas Nethercote
bd1e6836a0 Avoid some clones.
`Builder::expr_into_pattern` has a single call site. Currently the
`pattern` argument at the call site is always cloned.

This commit changes things so that we instead do a clone within
`expr_into_pattern`, but only if the pattern has the
`PatKind::AscribeUserType` kind, and we only clone the annotation within
the pattern instead of the entire pattern.
2022-09-02 07:26:22 +10:00
Nicholas Nethercote
053874eecc Clean up THIR patterns.
`thir::Pat::kind` is a `Box<PatKind>`, which doesn't follow the usual
pattern in AST/HIR/THIR which is that the "kind" enum for a node is
stored inline within the parent struct.

This commit makes the `PatKind` directly inline within the `Pat`. This
requires using `Box<Pat>` in all the types that hold a `Pat.

Ideally, `Pat` would be stored in `Thir` like `Expr` and `Stmt` and
referred to with a `PatId` rather than `Box<Pat>`. But this is hard to
do because lots of `Pat`s get created after the destruction of the `Cx`
that does normal THIR building. But this does get us a step closer to
`PatId`, because all the `Box<Pat>` occurrences would be replaced with
`PatId` if `PatId` ever happened.

At 128 bytes, `Pat` is large. Subsequent commits will shrink it.
2022-09-02 07:26:17 +10:00
Oli Scherer
1fc9ef1edd tracing::instrument cleanup 2022-09-01 14:54:27 +00:00
Oli Scherer
ee3c835018 Always import all tracing macros for the entire crate instead of piecemeal by module 2022-09-01 14:54:27 +00:00
Oli Scherer
d3b22c7267 Directly use the instrument macro instead of its full path 2022-09-01 14:53:46 +00:00
Dezhi Wu
b1430fb7ca Fix a bunch of typo
This PR will fix some typos detected by [typos].

I only picked the ones I was sure were spelling errors to fix, mostly in
the comments.

[typos]: https://github.com/crate-ci/typos
2022-08-31 18:24:55 +08:00
Nilstrieb
d1ef8180f9 Revert let_chains stabilization
This reverts commit 3266460749.

This is the revert against master, the beta revert was already done in #100538.
2022-08-29 19:34:11 +02:00
Matthias Krüger
d182081de1
Rollup merge of #99027 - tmiasko:basic-blocks, r=oli-obk
Replace `Body::basic_blocks()` with field access

Since the refactoring in #98930, it is possible to borrow the basic blocks
independently from other parts of MIR by accessing the `basic_blocks` field
directly.

Replace unnecessary `Body::basic_blocks()` method with a direct field access,
which has an additional benefit of borrowing the basic blocks only.
2022-08-29 06:34:43 +02:00
Tomasz Miąsko
b48870b451 Replace Body::basic_blocks() with field access 2022-08-26 14:27:08 +02:00
bors
8a13871b69 Auto merge of #100944 - nnethercote:shrink-thir-Expr, r=cjgillot
Shrink `thir::Expr`

r? `@cjgillot`
2022-08-26 10:00:27 +00:00
Yuki Okushi
b3f178350a
Rollup merge of #99954 - dingxiangfei2009:break-out-let-else-higher-up, r=oli-obk
let-else: break out to one scope higher for let-else

```@est31``` This PR follows up with #99518 which is to break out to the last remainder scope. It breaks to the out-most `region_scope` of the block if the first statement is a `let-else`.
2022-08-25 08:50:55 +09:00
Nicholas Nethercote
e3755c1d54 Rename thir::Adt as thir::AdtExpr.
This matches the naming scheme used elsewhere, e.g. in the AST, and
avoids name clashes with the `ExprKind::Closure` variant.
2022-08-24 15:06:50 +10:00
Nicholas Nethercote
e57ac764b8 Box thir::ExprKind::InlineAsm.
This shrinks `thir::Expr`.
2022-08-24 15:06:50 +10:00
Nicholas Nethercote
b3245a8dff Box thir::ExprKind::Closure.
This shrinks `thir::Expr`.
2022-08-24 15:06:50 +10:00
Nicholas Nethercote
2df805fc7a Store blocks in Thir.
Like expressions, statements, and match arms. This shrinks `thir::Stmt`
and is a precursor to further shrinking `thir::Expr`.
2022-08-24 15:06:44 +10:00
Nicholas Nethercote
e7c25c3a97 Box user_ty fields in thir::ExprKind.
This shrinks several large variants of `ExprKind`.
2022-08-24 14:16:09 +10:00
Camille GILLOT
389c6041a4 Only compute captures once when building MIR. 2022-08-23 22:24:43 +02:00
Nicholas Nethercote
6087dc2054 Remove the symbol from ast::LitKind::Err.
Because it's never used meaningfully.
2022-08-23 16:56:24 +10:00
bors
a785176741 Auto merge of #100881 - Dylan-DPC:rollup-q9rr658, r=Dylan-DPC
Rollup of 8 pull requests

Successful merges:

 - #98200 (Expand potential inner `Or` pattern for THIR)
 - #99770 (Make some const prop mir-opt tests `unit-test`s)
 - #99957 (Rework Ipv6Addr::is_global to check for global reachability rather than global scope - rebase)
 - #100331 (Guarantee `try_reserve` preserves the contents on error)
 - #100336 (Fix two const_trait_impl issues)
 - #100713 (Convert diagnostics in parser/expr to SessionDiagnostic)
 - #100820 (Use pointer `is_aligned*` methods)
 - #100872 (Add guarantee that Vec::default() does not alloc)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-08-22 17:46:57 +00:00
Dylan DPC
56ba13ac7f
Rollup merge of #98200 - ouz-a:issue-98177, r=oli-obk
Expand potential inner `Or` pattern for THIR

Code assumed there wouldn't be a deeper `Or` pattern inside expanded `PatStack` this fixes it by looking for the `Or` pattern inside expanded `PatStack`.

A more ideal solution would be recursively doing this but I haven't found a good way to do that.
_fixes #97898_
2022-08-22 20:34:08 +05:30
Nilstrieb
135c24102c Fix span for consts in mir builder 2022-08-22 14:06:55 +02:00
Dylan DPC
2fe2975391
Rollup merge of #100081 - RalfJung:unused-unsafe-in-unsafe-fn, r=jackh726
never consider unsafe blocks unused if they would be required with deny(unsafe_op_in_unsafe_fn)

Judging from https://github.com/rust-lang/rust/issues/71668#issuecomment-1200317370 the consensus nowadays seems to be that we should never consider an unsafe block unused if it was required with `deny(unsafe_op_in_unsafe_fn)`, no matter whether that lint is actually enabled or not. So let's adjust rustc accordingly.

The first commit does the change, the 2nd does some cleanup.
2022-08-19 12:26:40 +05:30
Mark Rousskov
154a09dd91 Adjust cfgs 2022-08-12 16:28:15 -04:00
Dylan DPC
561ea0a746
Rollup merge of #99110 - audunhalland:match_has_guard_from_candidate, r=pnkfelix
Determine match_has_guard from candidates instead of looking up thir table again

Currently looking through mir build of matches because of interest in deref patterns. Finding some micro-optimizable things.
2022-08-11 22:46:57 +05:30
Matthias Krüger
b11b8d6939
Rollup merge of #100240 - cjgillot:noice-structural-match, r=davidtwco
Fail gracefully when const pattern is not structural match.

Fixes https://github.com/rust-lang/rust/issues/82909
2022-08-10 00:00:30 +02:00
Takayuki Maeda
56ec5bec1e suggest adding an appropriate missing pattern excluding comments 2022-08-09 14:27:26 +09:00
Camille GILLOT
aa031f9fbf Fail gracefully when const pattern is not structural match. 2022-08-07 19:12:33 +02:00
Matthias Krüger
eabf1a2e8e
Rollup merge of #100132 - compiler-errors:issue-100103, r=tmiasko
Use (actually) dummy place for let-else divergence

Fixes #100103
2022-08-06 16:15:56 +02:00
Matthias Krüger
6b938c8491
Rollup merge of #100093 - wcampbell0x2a:unused-parens-for-match-arms, r=petrochenkov
Enable unused_parens for match arms

Fixes: https://github.com/rust-lang/rust/issues/92751

Currently I can't get the `stderr` to work with `./x.py test`, but this should fix the issue. Help would be appreciated!
2022-08-04 22:25:02 +02:00
wcampbell
8dd44f1af4 Enable unused_parens for match arms 2022-08-04 07:16:39 -04:00
bors
2f2243c9b6 Auto merge of #99843 - oli-obk:is_useful_perf, r=compiler-errors
Some `is_useful` cleanups

#98582 was reverted because it was a perf regression.

https://github.com/rust-lang/rust/pull/99806 reintroduces the changes, but this PR picks individual ones that have no regressions.
2022-08-04 07:35:33 +00:00
Michael Goulet
47a7a91c96 Use (actually) dummy place for let-else divergence 2022-08-04 05:08:09 +00:00
Ralf Jung
86e2ca3088
add link to discussion 2022-08-02 18:57:22 -04:00
Ralf Jung
ee3fc9dff8 never consider unsafe blocks unused if they would be required with unsafe_op_in_unsafe_fn 2022-08-02 17:09:41 -04:00
Camille GILLOT
957548183d Remove trait_of_item query. 2022-08-01 21:39:26 +02:00