about summary refs log tree commit diff
path: root/compiler/rustc_mir_build/src
AgeCommit message (Collapse)AuthorLines
2023-06-04Show note for type ascription interpreted as a constant pattern, not a new ↵许杰友 Jieyou Xu (Joe)-1/+6
variable Given the code ```rust pub fn main() { const y: i32 = 4; let y: i32 = 3; } ``` `y` in the let binding is actually interpreted as a constant pattern and is not a new variable, causing confusing diagnostics about refutable patterns in local binding. This commit extends the note for type ascription as a constant pattern to `AscribeUserType` patterns as well.
2023-06-02Separate AnonConst from ConstBlock in HIR.Camille GILLOT-12/+5
2023-05-31Inline from_inline_const into its sole call siteOli Scherer-32/+61
2023-05-31Explain and simplify valtree -> mir-const fallbackOli Scherer-7/+9
2023-05-31`bug!` message nitOli Scherer-1/+1
2023-05-31Simplify an `if let Some` to a `?`Oli Scherer-13/+10
2023-05-31Remove some dead codeOli Scherer-15/+2
2023-05-31Remove `lit_to_mir_constant` queryOli Scherer-12/+11
2023-05-31Remove `deref_mir_constant`Oli Scherer-3/+0
2023-05-31Only rewrite valtree-constants to patterns and keep other constants opaqueOli Scherer-156/+224
2023-05-30Remove a hack that has become obsolete after ↵Oli Scherer-13/+1
https://github.com/rust-lang/rust/pull/108080
2023-05-30Get `lit_to_const` in sync with `const_to_valtree_inner`Oli Scherer-0/+13
Without this, we'd have a discrepancy where float literals are not lowered to valtrees, but float constants are.
2023-05-29Rename `tcx.mk_re_*` => `Region::new_*`Maybe Waffle-1/+1
2023-05-27Rollup merge of #111952 - cjgillot:drop-replace, r=WaffleLapkinGuillaume Gomez-4/+6
Remove DesugaringKind::Replace. A simple boolean flag is enough.
2023-05-26Rollup merge of #111951 - cjgillot:uninh-comment, r=NadrierilMatthias Krüger-2/+2
Correct comment on privately uninhabited pattern. Follow-up to https://github.com/rust-lang/rust/pull/111624#discussion_r1204767933 r? `@Nadrieril`
2023-05-25Rollup merge of #111757 - lowr:fix/lint-attr-on-match-arm, r=eholkMichael Goulet-23/+35
Consider lint check attributes on match arms Currently, lint check attributes on match arms have no effect for some lints. This PR makes some lint passes to take those attributes into account. - `LateContextAndPass` for late lint doesn't update `last_node_with_lint_attrs` when it visits match arms. This leads to lint check attributes on match arms taking no effects on late lints that operate on the arms' pattern: ```rust match value { #[deny(non_snake_case)] PAT => {} // `non_snake_case` only warned due to default lint level } ``` To be honest, I'm not sure whether this is intentional or just an oversight. I've dug the implementation history and searched up issues/PRs but couldn't find any discussion on this. - `MatchVisitor` doesn't update its lint level when it visits match arms. This leads to check lint attributes on match arms taking no effect on some lints handled by this visitor, namely: `bindings_with_variant_name` and `irrefutable_let_patterns`. This seems to be a fallout from #108504. Before 05082f57afbf5d2e8fd7fb67719336d78b58e759, when the visitor operated on HIR rather than THIR, check lint attributes for the said lints were effective. [This playground][play] compiles successfully on current stable (1.69) but fails on current beta and nightly. I wasn't sure where best to place the test for this. Let me know if there's a better place. [play]: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=38432b79e535cb175f8f7d6d236d29c3 [play-match]: https://play.rust-lang.org/?version=beta&mode=debug&edition=2021&gist=629aa71b7c84b269beadeba664e2221d
2023-05-25Remove DesugaringKind::Replace.Camille GILLOT-4/+6
2023-05-25Correct comment on privately uninhabited pattern.Camille GILLOT-2/+2
2023-05-25Rollup merge of #111624 - cjgillot:private-uninhabited-pattern, r=petrochenkovMatthias Krüger-0/+20
Emit diagnostic for privately uninhabited uncovered witnesses. Fixes https://github.com/rust-lang/rust/issues/104034 cc `@Nadrieril`
2023-05-25Auto merge of #111925 - Manishearth:rollup-z6z6l2v, r=Manishearthbors-7/+7
Rollup of 5 pull requests Successful merges: - #111741 (Use `ObligationCtxt` in custom type ops) - #111840 (Expose more information in `get_body_with_borrowck_facts`) - #111876 (Roll compiler_builtins to 0.1.92) - #111912 (Use `Option::is_some_and` and `Result::is_ok_and` in the compiler ) - #111915 (libtest: Improve error when missing `-Zunstable-options`) r? `@ghost` `@rustbot` modify labels: rollup
2023-05-24Rollup merge of #111841 - matthewjasper:validate-match-guards, r=compiler-errorsMatthias Krüger-2/+6
Run AST validation on match guards correctly AST validation was being skipped on match guards other than `if let` guards.
2023-05-24Emit diagnostic for privately uninhabited uncovered witnesses.Camille GILLOT-0/+20
2023-05-24Use `Option::is_some_and` and `Result::is_ok_and` in the compilerMaybe Waffle-7/+7
2023-05-23Rollup merge of #111579 - scottmcm:enum-as-signed, r=oli-obkDylan DPC-43/+58
Also assume wrap-around discriminants in `as` MIR building Resolves this FIXME: https://github.com/rust-lang/rust/blob/8d18c32b61476ed16dd15074e71be3970368d6d7/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs#L231 r? `@oli-obk`
2023-05-23Rollup merge of #111501 - WaffleLapkin:drivebycleanupuwu, r=oli-obkDylan DPC-12/+16
MIR drive-by cleanups Some random drive-by cleanups I did while working with MIR/THIR.
2023-05-22Run AST validation on match guards correctlyMatthew Jasper-2/+6
2023-05-20don't skip inference for type in `offset_of!`Lukas Markeffsky-4/+3
2023-05-19Drive-by-cleanup: Don't emit `thir::ExprKind::NeverToAny` for `! -> !`Maybe Waffle-0/+1
2023-05-19Consider lint check attributes on match arms in match checksRyo Yoshida-23/+35
2023-05-18Also assume wrap-around discriminants in `as` MIR buildingScott McMurray-43/+58
Resolves this FIXME: https://github.com/rust-lang/rust/blob/8d18c32b61476ed16dd15074e71be3970368d6d7/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs#L231
2023-05-17`rustc_mir_build`: drive-by-cleaup: replace nested ifs with a `match`Maybe Waffle-6/+9
2023-05-17`rustc_mir_build`: drive-by-cleanup: remove some local mutable stateMaybe Waffle-6/+6
2023-05-16Erase regions of type in `offset_of!`clubby789-3/+4
2023-05-16Auto merge of #105750 - oli-obk:valtrees, r=lcnrbors-54/+84
Always fall back to PartialEq when a constant in a pattern is not recursively structural-eq Right now we destructure the constant as far as we can, but with this PR we just don't take it apart anymore. This is preparatory work for moving to always using valtrees, as these will just do a single conversion of the constant to a valtree at the start, and if that fails, fall back to `PartialEq`. This removes a few cases where we emitted the `unreachable pattern` lint, because we stop looking into the constant deeply enough to detect that a constant is already covered by another pattern. Previous work: https://github.com/rust-lang/rust/pull/70743 This is groundwork towards fixing https://github.com/rust-lang/rust/issues/83085 and https://github.com/rust-lang/rust/issues/105047
2023-05-16Document how constants as opaque patterns behave differently.Oli Scherer-4/+20
2023-05-15Rollup merge of #111587 - cbeuw:copy-for-deref, r=oli-obkMatthias Krüger-0/+1
Custom MIR: Support `Rvalue::CopyForDeref` r? `@oli-obk` or `@tmiasko` or `@JakobDegen`
2023-05-15Rollup merge of #111578 - Zoxc:query-macro-move, r=cjgillotMatthias Krüger-1/+1
Move expansion of query macros in rustc_middle to rustc_middle::query This moves the expansion of `define_callbacks!` and `define_feedable!` from `rustc_middle::ty::query` to `rustc_middle::query`. This means that types used in queries are both imported and used in `rustc_middle::query` instead of being split between these modules. It also decouples `rustc_middle::ty::query` further from `rustc_middle` which is helpful since we want to move `rustc_middle::ty::query` to the query system crates.
2023-05-15Update some commentsOli Scherer-9/+5
2023-05-15Always fall back to PartialEq when a constant in a pattern is not ↵Oli Scherer-36/+51
recursively structural-eq
2023-05-15Unnest a variable in prep for the next commit which needs access to the placeOli Scherer-5/+8
2023-05-15Add CopyForDeref to custom MIRAndy Wang-0/+1
2023-05-15Move expansion of query macros in rustc_middle to rustc_middle::queryJohn Kåre Alsaker-1/+1
2023-05-15Auto merge of #111570 - compiler-errors:ct-err, r=BoxyUwUbors-1/+1
Rename const error methods for consistency renames `ty::Const`'s methods for creating a `ConstKind::Error` to be in the same naming style as `ty::Ty`'s equivalent methods. r? `@BoxyUwU`
2023-05-14Rename const error methods for consistencyMichael Goulet-1/+1
2023-05-13Implement references VarDebugInfo.Camille GILLOT-0/+4
2023-05-11Rollup merge of #108705 - clubby789:refutable-let-closure-borrow, r=cjgillotMatthias Krüger-12/+17
Prevent ICE with broken borrow in closure r? `@Nilstrieb` Fixes #108683 This solution isn't ideal, I'm hoping to find a way to continue compilation without ICEing.
2023-05-05Rollup merge of #108801 - fee1-dead-contrib:c-str, r=compiler-errorsDylan DPC-0/+6
Implement RFC 3348, `c"foo"` literals RFC: https://github.com/rust-lang/rfcs/pull/3348 Tracking issue: #105723
2023-05-04Auto merge of #110806 - WaffleLapkin:unmkI, r=lcnrbors-1/+1
Replace `tcx.mk_trait_ref` with `TraitRef::new` First step in implementing https://github.com/rust-lang/compiler-team/issues/616 r? `@lcnr`
2023-05-03Restrict `From<S>` for `{D,Subd}iagnosticMessage`.Nicholas Nethercote-7/+7
Currently a `{D,Subd}iagnosticMessage` can be created from any type that impls `Into<String>`. That includes `&str`, `String`, and `Cow<'static, str>`, which are reasonable. It also includes `&String`, which is pretty weird, and results in many places making unnecessary allocations for patterns like this: ``` self.fatal(&format!(...)) ``` This creates a string with `format!`, takes a reference, passes the reference to `fatal`, which does an `into()`, which clones the reference, doing a second allocation. Two allocations for a single string, bleh. This commit changes the `From` impls so that you can only create a `{D,Subd}iagnosticMessage` from `&str`, `String`, or `Cow<'static, str>`. This requires changing all the places that currently create one from a `&String`. Most of these are of the `&format!(...)` form described above; each one removes an unnecessary static `&`, plus an allocation when executed. There are also a few places where the existing use of `&String` was more reasonable; these now just use `clone()` at the call site. As well as making the code nicer and more efficient, this is a step towards possibly using `Cow<'static, str>` in `{D,Subd}iagnosticMessage::{Str,Eager}`. That would require changing the `From<&'a str>` impls to `From<&'static str>`, which is doable, but I'm not yet sure if it's worthwhile.
2023-05-02Auto merge of #111082 - saethlin:box-assertkind, r=saethlinbors-1/+1
Box AssertKind r? `@nnethercote` this feels like your kind of thing I want to add a new variant to `AssertKind` that needs 3 operands, and that ends up breaking a bunch of size assertions. So... what if we go the opposite direction first; shrinking `AssertKind` by boxing it?