summary refs log tree commit diff
path: root/compiler/rustc_mir_build/src
AgeCommit message (Collapse)AuthorLines
2021-11-23Fix stack overflow in `usefulness.rs`Badel2-4/+7
2021-11-21Simplify for loop desugarCameron Steffen-7/+14
2021-11-18Use more let_else in rustc_mir_buildest31-69/+66
Helps avoid rightward drift.
2021-11-16Rollup merge of #90925 - krasimirgg:rustc_mir_build_fix, r=petrochenkovYuki Okushi-1/+1
rustc_mir_build: reorder bindings No functional changes intended. I'm playing around with building compiler components using nightly rust (2021-11-02) in a non-standard way. I encountered the following error while trying to build rustc_mir_build: ``` error[E0597]: `wildcard` does not live long enough --> rust/src/nightly/compiler/rustc_mir_build/src/build/matches/mod.rs:1767:82 | 1767 | let mut otherwise_candidate = Candidate::new(expr_place_builder.clone(), &wildcard, false); | ^^^^^^^^^ borrowed value does not live long enough ... 1799 | } | - | | | `wildcard` dropped here while still borrowed | borrow might be used here, when `guard_candidate` is dropped and runs the destructor for type `Candidate<'_, '_>` | = note: values in a scope are dropped in the opposite order they are defined ``` I believe this flags an issue that may become an error in the future. Swapping the order of `wildcard` and `guard_candidate` resolves it.
2021-11-15rustc_mir_build: reorder bindingsKrasimir Georgiev-1/+1
No functional changes intended. I'm playing around with building compiler components using nightly rust (2021-11-02) in a non-standard way. I encountered the following error while trying to build rustc_mir_build: ``` error[E0597]: `wildcard` does not live long enough --> rust/src/nightly/compiler/rustc_mir_build/src/build/matches/mod.rs:1767:82 | 1767 | let mut otherwise_candidate = Candidate::new(expr_place_builder.clone(), &wildcard, false); | ^^^^^^^^^ borrowed value does not live long enough ... 1799 | } | - | | | `wildcard` dropped here while still borrowed | borrow might be used here, when `guard_candidate` is dropped and runs the destructor for type `Candidate<'_, '_>` | = note: values in a scope are dropped in the opposite order they are defined ``` I believe this flags an issue that may become an error in the future. Swapping the order of `wildcard` and `guard_candidate` resolves it.
2021-11-12Auto merge of #90813 - notriddle:notriddle/vec-extend, r=GuillaumeGomezbors-3/+1
Use Vec extend and collect instead of repeatedly calling push
2021-11-11Use `Vec::extend`, instead of calling `Vec::push` in a loopMichael Howell-3/+1
2021-11-11Auto merge of #90746 - nnethercote:opt-pattern-matching, r=Nadrierilbors-1/+1
Optimize pattern matching These commits speed up the `match-stress-enum` benchmark, which is very artificial, but the changes are simple enough that it's probably worth doing. r? `@Nadrieril`
2021-11-09Change the `assert` in `is_useful` to a `debug_assert`.Nicholas Nethercote-1/+1
It's hot in the `match-stress-enum` benchmark.
2021-11-07Implement type inference for inline constsGary Guo-2/+2
In most cases it is handled in the same way as closures.
2021-10-28Revert "Add rustc lint, warning when iterating over hashmaps"Mark Rousskov-1/+0
2021-10-24Rollup merge of #89558 - lcnr:query-stable-lint, r=estebankMatthias Krüger-0/+1
Add rustc lint, warning when iterating over hashmaps r? rust-lang/wg-incr-comp
2021-10-22Rollup merge of #90028 - tmiasko:structural-match-closure, r=spastorinoYuki Okushi-0/+3
Reject closures in patterns Fixes #90013.
2021-10-21Rollup merge of #90071 - cjgillot:no-blocks, r=oli-obkYuki Okushi-3/+2
Remove hir::map::blocks and use FnKind instead The principal tool is `FnLikeNode`, which is not often used and can be easily implemented using `rustc_hir::intravisit::FnKind`.
2021-10-19Replace FnLikeNode by FnKind.Camille GILLOT-3/+2
2021-10-19Reject closures in patternsTomasz Miąsko-0/+3
2021-10-16Adopt let_else across the compilerest31-9/+4
This performs a substitution of code following the pattern: let <id> = if let <pat> = ... { identity } else { ... : ! }; To simplify it to: let <pat> = ... { identity } else { ... : ! }; By adopting the let_else feature.
2021-10-15allow `potential_query_instability` everywherelcnr-0/+1
2021-10-12Filter unstable and doc hidden variants in usefulness checkingDevin Ragotzy-35/+82
Add test cases for unstable variants Add test cases for doc hidden variants Move is_doc_hidden to method on TyCtxt Add unstable variants test to reachable-patterns ui test Rename reachable-patterns -> omitted-patterns
2021-10-08clippy::complexity fixesMatthias Krüger-5/+3
2021-10-01Rollup merge of #89441 - Nadrieril:fix-89393, r=tmandryManish Goregaokar-3/+4
Normalize after substituting via `field.ty()` Back in https://github.com/rust-lang/rust/issues/72476 I hadn't understood where the problem was coming from, and only worked around the issue. What happens is that calling `field.ty()` on a field of a generic struct substitutes the appropriate generics but doesn't normalize the resulting type. As a consumer of types I'm surprised that one would substitute without normalizing, feels like a footgun, so I added a comment. Fixes https://github.com/rust-lang/rust/issues/89393.
2021-10-01Normalize after substituting via `field.ty()`Nadrieril-3/+4
2021-09-30Rollup merge of #89314 - notriddle:notriddle/lint-fix-enum-variant-match, ↵Manish Goregaokar-19/+36
r=davidtwco fix(lint): don't suggest refutable patterns to "fix" irrefutable bind In function arguments and let bindings, do not suggest changing `C` to `Foo::C` unless `C` is the only variant of `Foo`, because it won't work. The general warning is still kept, because code like this is confusing. Fixes #88730 p.s. `src/test/ui/lint/lint-uppercase-variables.rs` already tests the one-variant case.
2021-09-30Auto merge of #89386 - ehuss:rollup-idf4dmj, r=ehussbors-3/+6
Rollup of 13 pull requests Successful merges: - #87428 (Fix union keyword highlighting in rustdoc HTML sources) - #88412 (Remove ignore-tidy-undocumented-unsafe from core::slice::sort) - #89098 (Fix generics where bounds order) - #89232 (Improve help for recursion limit errors) - #89294 (:arrow_up: rust-analyzer) - #89297 (Remove Never variant from clean::Type enum) - #89311 (Add unit assignment to MIR for `asm!()`) - #89313 (PassWrapper: handle function rename from upstream D36850) - #89315 (Clarify that `CString::from_vec_unchecked` appends 0 byte.) - #89335 (Optimize is_sorted for Range and RangeInclusive) - #89366 (rustdoc: Remove lazy_static dependency) - #89377 (Update cargo) - #89378 (Update books) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2021-09-29Rollup merge of #89311 - FabianWolff:issue-89305, r=oli-obkEric Huss-3/+6
Add unit assignment to MIR for `asm!()` Fixes #89305. `ExprKind::LlvmInlineAsm` gets a `push_assign_unit()` here: https://github.com/rust-lang/rust/blob/2b6ed3b675475abc01ce7e68bb75b457f0c85684/compiler/rustc_mir_build/src/build/expr/into.rs#L475-L479 The same should probably happen for `ExprKind::InlineAsm`, which fixes the "use of possibly-uninitialized variable" error described in #89305.
2021-09-30Auto merge of #89110 - Aaron1011:adjustment-span, r=estebankbors-2/+27
Use larger span for adjustment THIR expressions Currently, we use a relatively 'small' span for THIR expressions generated by an 'adjustment' (e.g. an autoderef, autoborrow, unsizing). As a result, if a borrow generated by an adustment ends up causing a borrowcheck error, for example: ```rust let mut my_var = String::new(); let my_ref = &my_var my_var.push('a'); my_ref; ``` then the span for the mutable borrow may end up referring to only the base expression (e.g. `my_var`), rather than the method call which triggered the mutable borrow (e.g. `my_var.push('a')`) Due to a quirk of the MIR borrowck implementation, this doesn't always get exposed in migration mode, but it does in many cases. This commit makes THIR building consistently use 'larger' spans for adjustment expressions. These spans are recoded when we first create the adjustment during typecheck. For example, an autoref adjustment triggered by a method call will record the span of the entire method call. The intent of this change it make it clearer to users when it's the specific way in which a variable is used (for example, in a method call) that produdes a borrowcheck error. For example, an error message claiming that a 'mutable borrow occurs here' might be confusing if it just points at a usage of a variable (e.g. `my_var`), when no `&mut` is in sight. Pointing at the entire expression should help to emphasize that the method call itself is responsible for the mutable borrow. In several cases, this makes the `#![feature(nll)]` diagnostic output match up exactly with the default (migration mode) output. As a result, several `.nll.stderr` files end up getting removed entirely.
2021-09-29fix(lint): don't suggest refutable patterns to "fix" irrefutable bindMichael Howell-19/+36
In function arguments and let bindings, do not suggest changing `C` to `Foo::C` unless `C` is the only variant of `Foo`, because it won't work. The general warning is still kept, because code like this is confusing. Fixes #88730
2021-09-29Auto merge of #88950 - Nadrieril:deconstruct-pat, r=oli-obkbors-977/+794
Add an intermediate representation to exhaustiveness checking The exhaustiveness checking algorithm keeps deconstructing patterns into a `Constructor` and some `Fields`, but does so a bit all over the place. This PR introduces a new representation for patterns that already has that information, so we only compute it once at the start. I find this makes code easier to follow. In particular `DeconstructedPat::specialize` is a lot simpler than what happened before, and more closely matches the description of the algorithm. I'm also hoping this could help for the project of librarifying exhaustiveness for rust_analyzer since it decouples the algorithm from `rustc_middle::Pat`.
2021-09-28Add unit assignment to MIR for `asm!()`Fabian Wolff-3/+6
2021-09-26Trivialize tracking of unreachable subpatternsNadrieril-297/+95
Phew it had been very had to make it work without a good way to identify patterns. Now it's dead easy.
2021-09-26Avoid double-deref in `Fields`Nadrieril-35/+31
2021-09-26Replace `Pat` with a new intermediate representationNadrieril-489/+615
2021-09-26Remove dependency of `SubPatSet` on `Pat`Nadrieril-27/+23
2021-09-26Move special `&str` handling to `Constructor` and `Fields`Nadrieril-21/+21
2021-09-26Use usize for slice arityNadrieril-15/+15
2021-09-26Rework `Fields` internals.Nadrieril-240/+195
Now `Fields` is just a `Vec` of patterns, with some extra info on the side to reconstruct patterns when needed. This emphasizes that this extra info is not central to the algorithm.
2021-09-26A for loop is a lot faster apparentlyNadrieril-29/+9
2021-09-26Cleanup the reporting of unreachable patternsNadrieril-20/+14
2021-09-26Always report reachability for user-supplied patternsNadrieril-8/+3
2021-09-26Remove some unreachable codeNadrieril-20/+11
2021-09-26Remove premature shortcuttingNadrieril-26/+12
2021-09-25Use larger span for adjustments on method callsAaron Hill-2/+27
Currently, we use a relatively 'small' span for THIR expressions generated by an 'adjustment' (e.g. an autoderef, autoborrow, unsizing). As a result, if a borrow generated by an adustment ends up causing a borrowcheck error, for example: ```rust let mut my_var = String::new(); let my_ref = &my_var my_var.push('a'); my_ref; ``` then the span for the mutable borrow may end up referring to only the base expression (e.g. `my_var`), rather than the method call which triggered the mutable borrow (e.g. `my_var.push('a')`) Due to a quirk of the MIR borrowck implementation, this doesn't always get exposed in migration mode, but it does in many cases. This commit makes THIR building consistently use 'larger' spans for adjustment expressions The intent of this change it make it clearer to users when it's the specific way in which a variable is used (for example, in a method call) that produdes a borrowcheck error. For example, an error message claiming that a 'mutable borrow occurs here' might be confusing if it just points at a usage of a variable (e.g. `my_var`), when no `&mut` is in sight. Pointing at the entire expression should help to emphasize that the method call itself is responsible for the mutable borrow. In several cases, this makes the `#![feature(nll)]` diagnostic output match up exactly with the default (migration mode) output. As a result, several `.nll.stderr` files end up getting removed entirely.
2021-09-25Use Rvalue::ShallowInitBox for box expressionGary Guo-2/+53
2021-09-21Rollup merge of #89126 - FabianWolff:issue-89088, r=petrochenkovthe8472-6/+8
Fix ICE when `indirect_structural_match` is allowed Fixes #89088. The ICE is caused by `delay_good_path_bug()`, which is called (indirectly) from a `format!()` macro invocation. I have moved the macro invocation into the `decorate` closure of `struct_span_lint_hir()`, so that the macro is only invoked if the lint is not allowed (i.e., causes at least a warning, and thus prevents `delay_good_path_bug()` from firing).
2021-09-21Rollup merge of #89113 - BoxyUwU:incr-comp-thir-act, r=lcnrthe8472-3/+6
dont `.ensure()` the `thir_abstract_const` query call in `mir_build` might fix an ICE seen in #89022 (note: this PR does not close that issue) about attempting to read stolen thir. I couldn't repro the ICE but this `.ensure` seems sus anyway. r? `@lcnr`
2021-09-20Fix ICE when `indirect_structural_match` is allowedFabian Wolff-6/+8
2021-09-20no ensureEllen-3/+6
2021-09-16Add `ConstraintCategory::Usage` for handling aggregate constructionAaron Hill-16/+36
In some cases, we emit borrowcheck diagnostics pointing at a particular field expression in a struct expression (e.g. `MyStruct { field: my_expr }`). However, this behavior currently relies on us choosing the `ConstraintCategory::Boring` with the 'correct' span. When adding additional variants to `ConstraintCategory`, (or changing existing usages away from `ConstraintCategory::Boring`), the current behavior can easily get broken, since a non-boring constraint will get chosen over a boring one. To make the diagnostic output less fragile, this commit adds a `ConstraintCategory::Usage` variant. We use this variant for the temporary assignments created for each field of an aggregate we are constructing. Using this new variant, we can emit a message mentioning "this usage", emphasizing the fact that the error message is related to the specific use site (in the struct expression). This is preparation for additional work on improving NLL error messages (see #57374)
2021-09-14Add reachable_patterns lint to rfc-2008-non_exhaustiveDevin Ragotzy-51/+170
Add linting on non_exhaustive structs and enum variants Add ui tests for non_exhaustive reachable lint Rename to non_exhaustive_omitted_patterns and avoid triggering on if let
2021-09-12Rollup merge of #88709 - BoxyUwU:thir-abstract-const, r=lcnrManish Goregaokar-244/+5
generic_const_exprs: use thir for abstract consts instead of mir Changes `AbstractConst` building to use `thir` instead of `mir` so that there's less chance of consts unifying when they shouldn't because lowering to mir dropped information (see `abstract-consts-as-cast-5.rs` test) r? `@lcnr`