about summary refs log tree commit diff
path: root/compiler/rustc_mir_build
AgeCommit message (Collapse)AuthorLines
2024-01-19Pack the u128 in LitKind::IntJosh Stone-2/+2
2024-01-19Rollup merge of #120009 - Nadrieril:never_patterns_tyck, r=compiler-errorsMatthias Krüger-0/+31
never_patterns: typecheck never patterns This checks that a `!` pattern is only used on an uninhabited type (modulo match ergonomics, i.e. `!` is allowed on `&Void`). r? `@compiler-errors`
2024-01-19Rollup merge of #119835 - Nadrieril:simplify-empty-logic, r=compiler-errorsMatthias Krüger-1/+2
Exhaustiveness: simplify empty pattern logic The logic that handles empty patterns had gotten quite convoluted. This PR simplifies it a lot. I tried to make the logic as easy as possible to follow; this only does logically equivalent changes. The first commit is a drive-by comment clarification that was requested after another PR a while back. r? `@compiler-errors`
2024-01-18Typecheck never patternsNadrieril-0/+31
2024-01-18Consistently warn unreachable subpatternsNadrieril-31/+37
2024-01-18Consistently set `MatchVisitor.error` on errorNadrieril-12/+16
2024-01-17Add `PatKind::Err`Lieselotte-0/+2
2024-01-16Auto merge of #116520 - Enselic:large-copy-into-fn, r=oli-obkbors-10/+26
large_assignments: Lint on specific large args passed to functions Requires lowering function call arg spans down to MIR, which is done in the second commit. Part of #83518 Also see * https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/arg.20Spans.20for.20TerminatorKind.3A.3ACall.3F * https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/move_size_limit.20lint r? `@oli-obk` (E-mentor)
2024-01-16Rollup merge of #119969 - compiler-errors:simplify-closure-env-ty, r=oli-obkMatthias Krüger-37/+19
Simplify `closure_env_ty` and `closure_env_param` Random cleanup that I found when working on async closures. This makes it easier to separate the latter into a new tykind.
2024-01-15make unsafe_op_in_unsafe_fn MachineApplicable and add it to 2024 compatibilityasquared31415-1/+1
2024-01-15compiler: Lower fn call arg spans down to MIRMartin Nordholts-10/+26
To enable improved accuracy of diagnostics in upcoming commits.
2024-01-15Clarify that the status of `&!` is undecidedNadrieril-1/+2
2024-01-15Rollup merge of #119971 - compiler-errors:zip-eq, r=nnethercoteMatthias Krüger-3/+6
Use `zip_eq` to enforce that things being zipped have equal sizes Some `zip`s are best enforced to be equal, since size mismatches suggest deeper bugs in the compiler.
2024-01-14Use zip_eq to enforce that things being zipped have equal sizesMichael Goulet-2/+4
2024-01-14Closure body was being built incorrectly on error...Michael Goulet-1/+2
2024-01-14Simplify closure_env_ty and closure_env_paramMichael Goulet-37/+19
2024-01-11Rollup merge of #119715 - Nadrieril:graceful-type-error, r=compiler-errorsMatthias Krüger-2/+8
Exhaustiveness: abort on type error This adds an error path to exhaustiveness checking so that we abort instead of ICEing when encountering a stray `ty::Error`. Fixes https://github.com/rust-lang/rust/issues/119493 Fixes https://github.com/rust-lang/rust/issues/119778 r? `@compiler-errors`
2024-01-10Add `DiagCtxt::delayed_bug`.Nicholas Nethercote-34/+33
We have `span_delayed_bug` and often pass it a `DUMMY_SP`. This commit adds `delayed_bug`, which matches pairs like `err`/`span_err` and `warn`/`span_warn`.
2024-01-10Rename `struct_span_err!` as `struct_span_code_err!`.Nicholas Nethercote-2/+4
Because it takes an error code after the span. This avoids the confusing overlap with the `DiagCtxt::struct_span_err` method, which doesn't take an error code.
2024-01-09Don't mix combinators and `let else`Nadrieril-3/+6
Co-authored-by: Michael Goulet <michael@errs.io>
2024-01-07Add an error path to the algorithmNadrieril-2/+5
2024-01-06Don't populate yield and resume types after the factMichael Goulet-65/+65
2024-01-06Auto merge of #119329 - Nadrieril:reveal-opaques-early, r=compiler-errorsbors-4/+4
Exhaustiveness: Statically enforce revealing of opaques In https://github.com/rust-lang/rust/pull/116821 it was decided that exhaustiveness should operate on the hidden type of an opaque type when relevant. This PR makes sure we consistently reveal opaques within exhaustiveness. This makes it possible to remove `reveal_opaque_ty` from the `TypeCx` trait which was an unfortunate implementation detail. r? `@compiler-errors`
2024-01-05Rollup merge of #119563 - compiler-errors:coroutine-resume, r=oli-obkMatthias Krüger-10/+17
Check yield terminator's resume type in borrowck In borrowck, we didn't check that the lifetimes of the `TerminatorKind::Yield`'s `resume_place` were actually compatible with the coroutine's signature. That means that the lifetimes were totally going unchecked. Whoops! This PR implements this checking. Fixes #119564 r? types
2024-01-05Rollup merge of #119554 - matthewjasper:remove-guard-distinction, ↵Matthias Krüger-67/+69
r=compiler-errors Fix scoping for let chains in match guards If let guards were previously represented as a different type of guard in HIR and THIR. This meant that let chains in match guards were not handled correctly because they were treated exactly like normal guards. - Remove `hir::Guard` and `thir::Guard`. - Make the scoping different between normal guards and if let guards also check for let chains. closes #118593
2024-01-05Rollup merge of #119538 - nnethercote:cleanup-errors-5, r=compiler-errorsMichael Goulet-4/+4
Cleanup error handlers: round 5 More rustc_errors cleanups. A sequel to https://github.com/rust-lang/rust/pull/119171. r? ````@compiler-errors````
2024-01-05Restore if let guard temporary scoping differenceMatthew Jasper-0/+6
Match guards with an if let guard or an if let chain guard should have a temporary scope of the whole arm. This is to allow ref bindings to temporaries to borrow check.
2024-01-05Remove `thir::Guard`Matthew Jasper-58/+21
Use Expr instead. Use `ExprKind::Let` to represent if let guards.
2024-01-05Remove `hir::Guard`Matthew Jasper-12/+45
Use Expr instead. Use `ExprKind::Let` to represent if let guards.
2024-01-05Handle context for const patterns correctlyMatthew Jasper-1/+7
2024-01-05Stabilize THIR unsafeckMatthew Jasper-5/+6
2024-01-04Rollup merge of #119325 - RalfJung:custom-mir, r=compiler-errorsMatthias Krüger-2/+10
custom mir: make it clear what the return block is Custom MIR recently got support for specifying the "unwind action", so now there's two things coming after the actual call part of `Call` terminators. That's not very self-explaining so I propose we change the syntax to imitate keyword arguments: ``` Call(popped = Vec::pop(v), ReturnTo(drop), UnwindContinue()) ``` Also fix some outdated docs and add some docs to `Call` and `Drop`.
2024-01-04Check yield terminator's resume type in borrowckMichael Goulet-10/+17
2024-01-03Rename some `Diagnostic` setters.Nicholas Nethercote-4/+4
`Diagnostic` has 40 methods that return `&mut Self` and could be considered setters. Four of them have a `set_` prefix. This doesn't seem necessary for a type that implements the builder pattern. This commit removes the `set_` prefixes on those four methods.
2024-01-01Statically enforce revealing of opaquesNadrieril-4/+4
2023-12-28Movability doesn't need to be a query anymoreMichael Goulet-1/+1
2023-12-28Remove movability from TyKind::CoroutineMichael Goulet-9/+6
2023-12-26Keep reference to the original `Pat` in `DeconstructedPat`Nadrieril-4/+4
2023-12-26custom mir: make it clear what the return block isRalf Jung-2/+10
2023-12-26Rollup merge of #119307 - compiler-errors:pat-lifetimes, r=NadrierilMichael Goulet-21/+21
Clean up some lifetimes in `rustc_pattern_analysis` This PR removes some redundant lifetimes. I figured out that we were shortening the lifetime of an arena-allocated `&'p DeconstructedPat<'p>` to `'a DeconstructedPat<'p>`, which forced us to carry both lifetimes when we could otherwise carry just one. This PR also removes and elides some unnecessary lifetimes. I also cherry-picked 0292eb9bb9b897f5c0926c6a8530877f67e7cc9b, and then simplified more lifetimes in `MatchVisitor`, which should make #119233 a very simple PR! r? Nadrieril
2023-12-26Merge 'thir and 'pMichael Goulet-17/+17
2023-12-26`thir::Visitor` only needs to visit `&'thir` dataNadrieril-14/+14
2023-12-26Auto merge of #119146 - nnethercote:rm-DiagCtxt-api-duplication, ↵bors-75/+67
r=compiler-errors Remove `DiagCtxt` API duplication `DiagCtxt` defines the internal API for creating and emitting diagnostics: methods like `struct_err`, `struct_span_warn`, `note`, `create_fatal`, `emit_bug`. There are over 50 methods. Some of these methods are then duplicated across several other types: `Session`, `ParseSess`, `Parser`, `ExtCtxt`, and `MirBorrowckCtxt`. `Session` duplicates the most, though half the ones it does are unused. Each duplicated method just calls forward to the corresponding method in `DiagCtxt`. So this duplication exists to (in the best case) shorten chains like `ecx.tcx.sess.parse_sess.dcx.emit_err()` to `ecx.emit_err()`. This API duplication is ugly and has been bugging me for a while. And it's inconsistent: there's no real logic about which methods are duplicated, and the use of `#[rustc_lint_diagnostic]` and `#[track_caller]` attributes vary across the duplicates. This PR removes the duplicated API methods and makes all diagnostic creation and emission go through `DiagCtxt`. It also adds `dcx` getter methods to several types to shorten chains. This approach scales *much* better than API duplication; indeed, the PR adds `dcx()` to numerous types that didn't have API duplication: `TyCtxt`, `LoweringCtxt`, `ConstCx`, `FnCtxt`, `TypeErrCtxt`, `InferCtxt`, `CrateLoader`, `CheckAttrVisitor`, and `Resolver`. These result in a lot of changes from `foo.tcx.sess.emit_err()` to `foo.dcx().emit_err()`. (You could do this with more types, but it gets into diminishing returns territory for types that don't emit many diagnostics.) After all these changes, some call sites are more verbose, some are less verbose, and many are the same. The total number of lines is reduced, mostly because of the removed API duplication. And consistency is increased, because calls to `emit_err` and friends are always preceded with `.dcx()` or `.dcx`. r? `@compiler-errors`
2023-12-25Auto merge of #119122 - matthewjasper:if-let-guard-scoping, r=TaKO8Kibors-236/+230
Give temporaries in if let guards correct scopes Temporaries in if-let guards have scopes that escape the match arm, this causes problems because the drops might be for temporaries that are not storage live. This PR changes the scope of temporaries in if-let guards to be limited to the arm: ```rust _ if let Some(s) = std::convert::identity(&Some(String::new())) => {} // Temporary for Some(String::new()) is dropped here ^ ``` We also now deduplicate temporaries between copies of the guard created for or-patterns: ```rust // Only create a single Some(String::new()) temporary variable _ | _ if let Some(s) = std::convert::identity(&Some(String::new())) => {} ``` This changes MIR building to pass around `ExprId`s rather than `Expr`s so that we have a way to index different expressions. cc #51114 Closes #116079
2023-12-24Remove `Session` methods that duplicate `DiagCtxt` methods.Nicholas Nethercote-75/+67
Also add some `dcx` methods to types that wrap `TyCtxt`, for easier access.
2023-12-22Rollup merge of #119230 - Nadrieril:librarify-even-further, r=compiler-errorsMichael Goulet-3/+3
Exhaustiveness: clean up after librarification This cleans up some things that weren't done nicely by https://github.com/rust-lang/rust/pull/118842. r? `@compiler-errors`
2023-12-23Give `DiagnosticBuilder` a default type.Nicholas Nethercote-11/+3
`IntoDiagnostic` defaults to `ErrorGuaranteed`, because errors are the most common diagnostic level. It makes sense to do likewise for the closely-related (and much more widely used) `DiagnosticBuilder` type, letting us write `DiagnosticBuilder<'a, ErrorGuaranteed>` as just `DiagnosticBuilder<'a>`. This cuts over 200 lines of code due to many multi-line things becoming single line things.
2023-12-23Clarify the situation with dummy patterns and `PatData`Nadrieril-3/+3
Use an explicit `Option` instead of requiring a `Default` bound
2023-12-22Auto merge of #116821 - Nadrieril:fix-opaque-ice, r=compiler-errorsbors-0/+4
Exhaustiveness: reveal opaque types properly Previously, exhaustiveness had no clear policy around opaque types. In this PR I propose the following policy: within the body of an item that defines the hidden type of some opaque type, exhaustiveness checking on a value of that opaque type is performed using the concrete hidden type inferred in this body. I'm not sure how consistent this is with other operations allowed on opaque types; I believe this will require FCP. From what I can tell, this doesn't change anything for non-empty types. The observable changes are: - when the real type is uninhabited, matches within the defining scopes can now rely on that for exhaustiveness, e.g.: ```rust #[derive(Copy, Clone)] enum Void {} fn return_never_rpit(x: Void) -> impl Copy { if false { match return_never_rpit(x) {} } x } ``` - this properly fixes ICEs like https://github.com/rust-lang/rust/issues/117100 that occurred because a same match could have some patterns where the type is revealed and some where it is not. Bonus subtle point: if `x` is opaque, a match like `match x { ("", "") => {} ... }` will constrain its type ([playground](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=901d715330eac40339b4016ac566d6c3)). This is not the case for `match x {}`: this will not constain the type, and will only compile if something else constrains the type to be empty. Fixes https://github.com/rust-lang/rust/issues/117100 r? `@oli-obk` Edited for precision of the wording [Included](https://github.com/rust-lang/rust/pull/116821#issuecomment-1813171764) in the FCP on this PR is this rule: > Within the body of an item that defines the hidden type of some opaque type, exhaustiveness checking on a value of that opaque type is performed using the concrete hidden type inferred in this body.
2023-12-22Auto merge of #119097 - nnethercote:fix-EmissionGuarantee, r=compiler-errorsbors-6/+11
Fix `EmissionGuarantee` There are some problems with the `DiagCtxt` API related to `EmissionGuarantee`. This PR fixes them. r? `@compiler-errors`