about summary refs log tree commit diff
path: root/compiler/rustc_mir_build
AgeCommit message (Collapse)AuthorLines
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-21Auto merge of #89158 - the8472:rollup-3e4ijth, r=the8472bors-9/+14
Rollup of 12 pull requests Successful merges: - #88795 (Print a note if a character literal contains a variation selector) - #89015 (core::ascii::escape_default: reduce struct size) - #89078 (Cleanup: Remove needless reference in ParentHirIterator) - #89086 (Stabilize `Iterator::map_while`) - #89096 ([bootstrap] Improve the error message when `ninja` is not found to link to installation instructions) - #89113 (dont `.ensure()` the `thir_abstract_const` query call in `mir_build`) - #89114 (Fixes a technicality regarding the size of C's `char` type) - #89115 (:arrow_up: rust-analyzer) - #89126 (Fix ICE when `indirect_structural_match` is allowed) - #89141 (Impl `Error` for `FromSecsError` without foreign type) - #89142 (Fix match for placeholder region) - #89147 (add case for checking const refs in check_const_value_eq) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
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-20Remove Drop-caused migration-added capturesMark Rousskov-1/+0
All of these were added due to insignificant Drop types being present.
2021-09-20Migrate to 2021Mark Rousskov-1/+1
2021-09-20Fix ICE when `indirect_structural_match` is allowedFabian Wolff-6/+8
2021-09-20Enable 2021 compatibility lints for all in-tree codeMark Rousskov-0/+1
This just applies the suggested fixes from the compatibility warnings, leaving any that are in practice spurious in. This is primarily intended to provide a starting point to identify possible fixes to the migrations (e.g., by avoiding spurious warnings). A secondary commit cleans these up where they are false positives (as is true in many of the cases).
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`
2021-09-11Rollup merge of #88849 - matthiaskrgr:clony_on_copy, r=petrochenkovJubilee-1/+1
don't clone types that are Copy (clippy::clone_on_copy)
2021-09-11Auto merge of #88327 - bonega:scalar_refactor, r=eddybbors-3/+2
`WrappingRange` (#88242) follow-up (`is_full_for`, `Scalar: Copy`, etc.) Some changes related to feedback during #88242 r? `@RalfJung`
2021-09-11don't clone types that are Copy (clippy::clone_on_copy)Matthias Krüger-1/+1
2021-09-09Ignore automatically derived impls of `Clone` and `Debug` in dead code analysisFabian Wolff-11/+9
2021-09-09Rename `(un)signed` to `(un)signed_int`Andreas Liljeqvist-1/+1
2021-09-09Move `unsigned_max` etc into `Size` againAndreas Liljeqvist-3/+2
2021-09-09rename mir -> thir around abstract constsEllen-2/+2
2021-09-09remove debug stmtsEllen-6/+0
2021-09-09move thir visitor to rustc_middleEllen-242/+1
2021-09-09WIP stateEllen-2/+10
2021-09-05Change scope of temporaries in match guardsMatthew Jasper-5/+5
Each pattern in a match arm has its own copy of the match guard in MIR, with its own temporary, so it has to be dropped before the the guards are joined to the single copy of the arm.
2021-09-02Bless 32bit MIR opt testsMatthew Jasper-4/+4
2021-09-02Remove TODOMatthew Jasper-1/+0
2021-09-01Fix drop handling for `if let` expressionsMatthew Jasper-110/+183
MIR lowering for `if let` expressions is now more complicated now that `if let` exists in HIR. This PR adds a scope for the variables bound in an `if let` expression and then uses an approach similar to how we handle loops to ensure that we reliably drop the correct variables.
2021-08-30Handle irrufutable or unreachable let-elseCameron Steffen-1/+20