about summary refs log tree commit diff
path: root/compiler/rustc_mir_build
AgeCommit message (Collapse)AuthorLines
2023-11-07Auto merge of #117229 - matthewjasper:thir-unsafeck-fixes, r=cjgillotbors-19/+115
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/+112
2023-11-06Recognise thread local statics in THIR unsafeckMatthew Jasper-1/+3
2023-11-04Suggest to set lint level on whole matchNadrieril-16/+37
2023-11-04Warn when lint level is set on a match armNadrieril-21/+49
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-30Auto merge of #117415 - matthiaskrgr:rollup-jr2p1t2, r=matthiaskrgrbors-1/+1
Rollup of 7 pull requests Successful merges: - #116862 (Detect when trait is implemented for type and suggest importing it) - #117389 (Some diagnostics improvements of `gen` blocks) - #117396 (Don't treat closures/coroutine types as part of the public API) - #117398 (Correctly handle nested or-patterns in exhaustiveness) - #117403 (Poison check_well_formed if method receivers are invalid to prevent typeck from running on it) - #117411 (Improve some diagnostics around `?Trait` bounds) - #117414 (Don't normalize to an un-revealed opaque when we hit the recursion limit) r? `@ghost` `@rustbot` modify labels: rollup
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-30Clean up `rustc_*/Cargo.toml`.Nicholas Nethercote-7/+7
- Sort dependencies and features sections. - Add `tidy` markers to the sorted sections so they stay sorted. - Remove empty `[lib`] sections. - Remove "See more keys..." comments. Excluded files: - rustc_codegen_{cranelift,gcc}, because they're external. - rustc_lexer, because it has external use. - stable_mir, because it has external use.
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-74/+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
2023-10-21Fix #117033Nadrieril-0/+3
2023-10-21Auto merge of #116734 - Nadrieril:lint-per-column, r=cjgillotbors-243/+326
Lint `non_exhaustive_omitted_patterns` by columns This is a rework of the `non_exhaustive_omitted_patterns` lint to make it more consistent. The intent of the lint is to help consumers of `non_exhaustive` enums ensure they stay up-to-date with all upstream variants. This rewrite fixes two cases we didn't handle well before: First, because of details of exhaustiveness checking, the following wouldn't lint `Enum::C` as missing: ```rust match Some(x) { Some(Enum::A) => {} Some(Enum::B) => {} _ => {} } ``` Second, because of the fundamental workings of exhaustiveness checking, the following would treat the `true` and `false` cases separately and thus lint about missing variants: ```rust match (true, x) { (true, Enum::A) => {} (true, Enum::B) => {} (false, Enum::C) => {} _ => {} } ``` Moreover, it would correctly not lint in the case where the pair is flipped, because of asymmetry in how exhaustiveness checking proceeds. A drawback is that it no longer makes sense to set the lint level per-arm. This will silently break the lint for current users of it (but it's behind a feature gate so that's ok). The new approach is now independent of the exhaustiveness algorithm; it's a separate pass that looks at patterns column by column. This is another of the motivations for this: I'm glad to move it out of the algorithm, it was akward there. This PR is almost identical to https://github.com/rust-lang/rust/pull/111651. cc `@eholk` who reviewed it at the time. Compared to then, I'm more confident this is the right approach.
2023-10-20s/generator/coroutine/Oli Scherer-56/+56
2023-10-20s/Generator/Coroutine/Oli Scherer-20/+20
2023-10-18coverage: Attach an optional `FunctionCoverageInfo` to `mir::Body`Zalathar-0/+1
This allows coverage information to be attached to the function as a whole when appropriate, instead of being smuggled through coverage statements in the function's basic blocks. As an example, this patch moves the `function_source_hash` value out of individual `CoverageKind::Counter` statements and into the per-function info. When synthesizing unused functions for coverage purposes, the absence of this info is taken to indicate that a function was not eligible for coverage and should not be synthesized.
2023-10-16Address review commentsMatthew Jasper-59/+42
Clean up code and add comments. Use InlineConstant to wrap range patterns.