summary refs log tree commit diff
path: root/compiler/rustc_mir_build/src
AgeCommit message (Collapse)AuthorLines
2023-11-30Build pre-coroutine-transform coroutine bodyMichael Goulet-11/+1
(cherry picked from commit 0ba7d19769c068729761eba72e779b53101a19bc)
2023-11-09Auto merge of #117712 - lcnr:expand-coroutine, r=jackh726bors-5/+5
generator layout: ignore fake borrows fixes #117059 We emit fake shallow borrows in case the scrutinee place uses a `Deref` and there is a match guard. This is necessary to prevent the match guard from mutating the scrutinee: https://github.com/rust-lang/rust/blob/fab1054e1742790c22ccc92a625736d658363677/compiler/rustc_mir_build/src/build/matches/mod.rs#L1250-L1265 These fake borrows end up impacting the generator witness computation in `mir_generator_witnesses`, which causes the issue in #117059. This PR now completely ignores fake borrows during this computation. This is sound as thse are always removed after analysis and the actual computation of the generator layout happens afterwards. Only the second commit impacts behavior, and could be backported by itself. r? types
2023-11-08rename `BorrowKind::Shallow` to `Fake`lcnr-5/+5
also adds some comments
2023-11-08Auto merge of #116930 - RalfJung:raw-ptr-match, r=davidtwcobors-30/+31
patterns: reject raw pointers that are not just integers Matching against `0 as *const i32` is fine, matching against `&42 as *const i32` is not. This extends the existing check against function pointers and wide pointers: we now uniformly reject all these pointer types during valtree construction, and then later lint because of that. See [here](https://github.com/rust-lang/rust/pull/116930#issuecomment-1784654073) for some more explanation and context. Also fixes https://github.com/rust-lang/rust/issues/116929. Cc `@oli-obk` `@lcnr`
2023-11-08avoid unnecessary nested conditionalsRalf Jung-11/+9
2023-11-07Auto merge of #117229 - matthewjasper:thir-unsafeck-fixes, r=cjgillotbors-19/+112
Thir unsafeck fixes - Recognise thread local statics in THIR unsafeck - Add suggestion for unsafe_op_in_unsafe_fn - Fix unsafe checking of let expressions
2023-11-06Build a better MIR body when errors are encounteredMichael Goulet-29/+59
2023-11-06Visit patterns in THIR let expressionsMatthew Jasper-8/+0
This fixes some THIR unsafety checking errors not being emitted for let expressions in these situations.
2023-11-06Add suggestion to THIR unsafe_op_in_unsafe_fn lintMatthew Jasper-10/+109
2023-11-06Recognise thread local statics in THIR unsafeckMatthew Jasper-1/+3
2023-11-04Suggest to set lint level on whole matchNadrieril-14/+33
2023-11-04Warn when lint level is set on a match armNadrieril-21/+46
2023-11-04Rollup merge of #117343 - Nadrieril:cleanup_check_match, r=davidtwcoTakayuki Maeda-434/+400
Cleanup `rustc_mir_build/../check_match.rs` The file had become pretty unwieldy, with a fair amount of duplication. As a bonus, I discovered that we weren't running some pattern checks in if-let chains. I recommend looking commit-by-commit. The last commit is a whim, I think it makes more sense that way but I don't hold this opinion strongly.
2023-11-03Tweak spans for "adt defined here" noteNadrieril-6/+1
2023-11-03Accumulate let chains alongside the visitNadrieril-76/+78
2023-11-03clone lessMatthias Krüger-1/+1
2023-11-02Cleanup check_match code pathsNadrieril-110/+104
2023-11-02Factor out pointing at ADT definitionNadrieril-44/+41
2023-11-02Always do all the pattern checksNadrieril-60/+60
2023-11-02Tweak diagnostic for consistencyNadrieril-4/+2
2023-11-02Check pattern error while loweringNadrieril-42/+29
2023-11-02Uncomplicate check_let_chainNadrieril-45/+35
2023-11-02ReorderNadrieril-148/+151
2023-11-01Auto merge of #114208 - GKFX:offset_of_enum, r=wesleywiserbors-1/+1
Support enum variants in offset_of! This MR implements support for navigating through enum variants in `offset_of!`, placing the enum variant name in the second argument to `offset_of!`. The RFC placed it in the first argument, but I think it interacts better with nested field access in the second, as you can then write things like ```rust offset_of!(Type, field.Variant.field) ``` Alternatively, a syntactic distinction could be made between variants and fields (e.g. `field::Variant.field`) but I'm not convinced this would be helpful. [RFC 3308 # Enum Support](https://rust-lang.github.io/rfcs/3308-offset_of.html#enum-support-offset_ofsomeenumstructvariant-field_on_variant) Tracking Issue #106655.
2023-11-01Auto merge of #116692 - Nadrieril:half-open-ranges, r=cjgillotbors-354/+401
Match usize/isize exhaustively with half-open ranges The long-awaited finale to the saga of [exhaustiveness checking for integers](https://github.com/rust-lang/rust/pull/50912)! ```rust match 0usize { 0.. => {} // exhaustive! } match 0usize { 0..usize::MAX => {} // helpful error message! } ``` Features: - Half-open ranges behave as expected for `usize`/`isize`; - Trying to use `0..usize::MAX` will tell you that `usize::MAX..` is missing and explain why. No more unhelpful "`_` is missing"; - Everything else stays the same. This should unblock https://github.com/rust-lang/rust/issues/37854. Review-wise: - I recommend looking commit-by-commit; - This regresses perf because of the added complexity in `IntRange`; hopefully not too much; - I measured each `#[inline]`, they all help a bit with the perf regression (tho I don't get why); - I did not touch MIR building; I expect there's an easy PR there that would skip unnecessary comparisons when the range is half-open.
2023-10-31Support enum variants in offset_of!George Bateman-1/+1
2023-10-30Some more coroutine renamingsMichael Goulet-8/+13
2023-10-30Rollup merge of #117398 - Nadrieril:fix-117378, r=compiler-errorsMatthias Krüger-1/+1
Correctly handle nested or-patterns in exhaustiveness I had assumed nested or-patterns were flattened, and they mostly are but not always. Fixes https://github.com/rust-lang/rust/issues/117378
2023-10-30Correctly handle nested or-patterns in column-wise analysesNadrieril-1/+1
2023-10-30remove some dead codeRalf Jung-10/+0
2023-10-28also lint against fn ptr and raw ptr nested inside the constRalf Jung-13/+9
2023-10-28patterns: reject raw pointers that are not just integersRalf Jung-8/+25
2023-10-27Auto merge of #103208 - cjgillot:match-fake-read, r=oli-obk,RalfJungbors-29/+39
Allow partially moved values in match This PR attempts to unify the behaviour between `let _ = PLACE`, `let _: TY = PLACE;` and `match PLACE { _ => {} }`. The logical conclusion is that the `match` version should not check for uninitialised places nor check that borrows are still live. The `match PLACE {}` case is handled by keeping a `FakeRead` in the unreachable fallback case to verify that `PLACE` has a legal value. Schematically, `match PLACE { arms }` in surface rust becomes in MIR: ```rust PlaceMention(PLACE) match PLACE { // Decision tree for the explicit arms arms, // An extra fallback arm _ => { FakeRead(ForMatchedPlace, PLACE); unreachable } } ``` `match *borrow { _ => {} }` continues to check that `*borrow` is live, but does not read the value. `match *borrow {}` both checks that `*borrow` is live, and fake-reads the value. Continuation of ~https://github.com/rust-lang/rust/pull/102256~ ~https://github.com/rust-lang/rust/pull/104844~ Fixes https://github.com/rust-lang/rust/issues/99180 https://github.com/rust-lang/rust/issues/53114
2023-10-27Make IntRange exclusiveNadrieril-57/+65
2023-10-27s/to_pat/to_diagnostic_pat/Nadrieril-21/+33
2023-10-27Match usize/isize exhaustivelyNadrieril-50/+113
2023-10-27Propagate half-open ranges through exhaustiveness checkingNadrieril-102/+158
2023-10-27Inline `RangeInclusive` into `IntRange`Nadrieril-41/+33
2023-10-27Don't use `IntRange` for booleansNadrieril-14/+56
2023-10-27Propagate half-open ranges through THIRNadrieril-15/+16
2023-10-27Abstract over `PatRange` boundary valueNadrieril-169/+42
2023-10-27Handle `ty::Opaque` correctlyNadrieril-1/+16
2023-10-27Lint overlapping ranges as a separate passNadrieril-89/+91
2023-10-27Abstract over per-column pattern traversalNadrieril-36/+77
2023-10-26Auto merge of #113262 - Nilstrieb:rawr-casting, r=lcnrbors-19/+13
Never consider raw pointer casts to be trival HIR typeck tries to figure out which casts are trivial by doing them as coercions and seeing whether this works. Since HIR typeck is oblivious of lifetimes, this doesn't work for pointer casts that only change the lifetime of the pointee, which are, as borrowck will tell you, not trivial. This change makes it so that raw pointer casts are never considered trivial. This also incidentally fixes the "trivial cast" lint false positive on the same code. Unfortunately, "trivial cast" lints are now never emitted on raw pointer casts, even if they truly are trivial. This could be fixed by also doing the lint in borrowck for raw pointers specifically. fixes #113257
2023-10-25Use let chains instead of let elseNilstrieb-19/+13
This makes it more obvious that we're looking at a special case.
2023-10-25Make THIR unused_unsafe lint consistent with MIRMatthew Jasper-73/+86
Updates THIR behavior to match the changes from #93678
2023-10-25Auto merge of #116482 - matthewjasper:thir-unsafeck-inline-constants, r=b-naberbors-33/+79
Fix inline const pattern unsafety checking in THIR Fix THIR unsafety checking of inline constants. - Steal THIR in THIR unsafety checking (if enabled) instead of MIR lowering. - Represent inline constants in THIR patterns.
2023-10-24Update documentation.Camille GILLOT-3/+3
2023-10-24Use `PlaceMention` for match scrutinees.Camille GILLOT-26/+36