about summary refs log tree commit diff
path: root/compiler/rustc_mir_build/src
AgeCommit message (Collapse)AuthorLines
2022-06-10Revert "More minimal changes"Xavier Denis-14/+27
This reverts commit fe0dedcb06947317d41a8570b7fff7f8690dcbff.
2022-06-10More minimal changesXavier Denis-27/+14
2022-06-10Fix `SourceScope` for `if let` bindings.Xavier Denis-9/+28
2022-06-09thir: wrap hir id of vars into local var idDing Xiang Fei-35/+36
2022-06-07Rollup merge of #97325 - tmiasko:capture-enum-field, r=arora-amanDylan DPC-19/+54
Fix precise field capture of univariant enums When constructing a MIR from a THIR field expression, introduce an additional downcast projection before accessing a field of an enum. When rebasing a place builder on top of a captured place, account for the fact that a single HIR enum field projection corresponds to two MIR projection elements: a downcast element and a field element. Fixes #95271. Fixes #96299. Fixes #96512. Fixes #97378. r? ``@nikomatsakis`` ``@arora-aman``
2022-06-03Replace `&Vec<_>`s with `&[_]`sMaybe Waffle-4/+4
2022-06-02add cast kind of from_exposed_addr (int-to-ptr casts)Ralf Jung-0/+3
2022-06-01rename PointerAddress → PointerExposeAddressRalf Jung-1/+1
2022-05-31Add a pointer to address cast kindTomasz Miąsko-3/+12
A pointer to address cast are often special-cased. Introduce a dedicated cast kind to make them easy distinguishable.
2022-05-28Auto merge of #97383 - dingxiangfei2009:restore-region-scope-tree-query, ↵bors-7/+7
r=dingxiangfei2009 Try to cache region_scope_tree as a query This PR will attempt to restore `region_scope_tree` as a query so that caching works again. It seems that `region_scope_tree` could be re-computed for nested items after all, which could explain the performance regression introduced by #95563. cc `@Mark-Simulacrum` `@pnkfelix` I will try to trigger a perf run here.
2022-05-26clippy::complexity fixesMatthias Krüger-9/+5
clone_on_copy useless_format bind_instead_of_map filter_map_identity useless_conversion map_flatten unnecessary_unwrap
2022-05-25Rollup merge of #97351 - ↵Dylan DPC-9/+9
b-naber:adt-const-params-structural-match-violation, r=michaelwoerister Output correct type responsible for structural match violation Previously we included the outermost type that caused a structural match violation in the error message and stated that that type must be annotated with `#[derive(Eq, PartialEq)]` even if it already had that annotation. This PR outputs the correct type in the error message. Fixes https://github.com/rust-lang/rust/issues/97278
2022-05-25Rollup merge of #95953 - JakobDegen:repeat-leak, r=oli-obkDylan DPC-5/+46
Modify MIR building to drop repeat expressions with length zero Closes #74836 . Previously, when a user wrote `[foo; 0]` we used to simply leak `foo`. The goal is to fix that. This PR changes MIR building to make `[foo; 0]` equivalent to `{ drop(foo); [] }` in all cases. Of course, this is a breaking change (see below). A crater run did not indicate any regressions though, and given that the previous behavior was almost definitely not what any user wanted, it seems unlikely that anyone was relying on this. Note that const generics are in general unaffected by this. Inserting the extra `drop` is only meaningful/necessary when `foo` is of a non-`Copy` type, and array repeat expressions with const generic repetition count must always be `Copy`. Besides the obvious change to behavior associated with the additional drop, there are three categories of examples where this also changes observable behavior. In all of these cases, the new behavior is consistent with what you would get by replacing `[foo; 0]` with `{ drop(foo); [] }`. As such, none of these give the user new powers to express more things. **No longer allowed in const (breaking)**: ```rust const _: [String; 0] = [String::new(); 0]; ``` This compiles on stable today. Because we now introduce the drop of `String`, this no longer compiles as `String` may not be dropped in a const context. **Reduced dataflow (non-breaking)**: ```rust let mut x: i32 = 0; let r = &x; let a = [r; 0]; x = 5; let _b = a; ``` Borrowck rejects this code on stable because it believes there is dataflow between `a` and `r`, and so the lifetime of `r` has to extend to the last statement. This change removes the dataflow and the above code is allowed to compile. **More const promotion (non-breaking)**: ```rust let _v: &'static [String; 0] = &[String::new(); 0]; ``` This does not compile today because `String` having drop glue keeps it from being const promoted (despite that drop glue never being executed). After this change, this is allowed to compile. ### Alternatives A previous attempt at this tried to reduce breakage by various tricks. This is still a possibility, but given that crater showed no regressions it seems unclear why we would want to introduce this complexity. Disallowing `[foo; 0]` completely is also an option, but obviously this is more of a breaking change. I do not know how often this is actually used though. r? `@oli-obk`
2022-05-25try to cache region_scope_tree as a queryDing Xiang Fei-7/+7
2022-05-24Modify MIR building to drop `foo` in `[foo; 0]`Jakob Degen-5/+46
2022-05-24give correct error message on structural match violationb-naber-9/+9
2022-05-23Refactor call terminator to always hold a destination placeJakob Degen-4/+7
2022-05-23Fix precise field capture of univariant enumsTomasz Miąsko-19/+54
When constructing a MIR from a THIR field expression, introduce an additional downcast projection before accessing a field of an enum. When rebasing a place builder on top of a captured place, account for the fact that a single HIR enum field projection corresponds to two MIR projection elements: a downcast element and a field element.
2022-05-22Do leak check after function ptr coercionJack Huey-0/+3
2022-05-22factor out the rvalue lifetime ruleDing Xiang Fei-16/+30
remove region_scope_tree from RegionCtxt Apply suggestions from code review Co-authored-by: Niko Matsakis <niko@alum.mit.edu>
2022-05-21Auto merge of #96515 - lcnr:user-types-in-pat, r=nikomatsakisbors-62/+53
correctly deal with user type ascriptions in pat supersedes #93856 `thir::PatKind::AscribeUserType` previously resulted in `CanonicalUserTypeAnnotations` where the inferred type already had a subtyping relation according to `variance` to the `user_ty`. The bug can pretty much be summarized as follows: - during mir building - `user_ty -> inferred_ty`: considers variance - `StatementKind::AscribeUserType`: `inferred_ty` is the type of the place, so no variance needed - during mir borrowck - `user_ty -> inferred_ty`: does not consider variance - `StatementKind::AscribeUserType`: applies variance This mostly worked fine. The lifetimes in `inferred_ty` were only bound by its relation to `user_ty` and to the `place` of `StatementKind::AscribeUserType`, so it doesn't matter where exactly the subtyping happens. It does however matter when having higher ranked subtying. At this point the place where the subtyping happens is forced, causing this mismatch between building and borrowck to result in unintended errors. cc #96514 which is pretty much the same issue r? `@nikomatsakis`
2022-05-21correctly deal with user type ascriptions in patlcnr-62/+53
2022-05-20Remove `crate` visibility usage in compilerJacob Pratt-129/+140
2022-05-18Auto merge of #97019 - b-naber:transition-to-valtrees-pt1, r=oli-obkbors-130/+173
Transition to valtrees pt1 Compartmentalising https://github.com/rust-lang/rust/pull/96591 as much as possible. r? `@oli-obk`
2022-05-18Auto merge of #96863 - SparrowLii:let, r=michaelwoeristerbors-8/+8
use `hir::Let` in `hir::Guard::IfLet` This PR fixes the FIXME about using `hir::Let` in `hir::Guard::IfLet`
2022-05-16use GlobalId in eval_to_valtree query and introduce query for ↵b-naber-130/+173
valtree_to_const_val
2022-05-14Auto merge of #96883 - jackh726:early-binder-2, r=oli-obkbors-2/+2
Add EarlyBinder Chalk has no concept of `Param` (https://github.com/rust-lang/chalk/blob/e0ade19d139bc784384acc6736cd960c91dd55a1/chalk-ir/src/lib.rs#L579) or `ReEarlyBound` (https://github.com/rust-lang/chalk/blob/e0ade19d139bc784384acc6736cd960c91dd55a1/chalk-ir/src/lib.rs#L1308). Everything is just "bound" - the equivalent of rustc's late-bound. It's not completely clear yet whether to move everything to the same time of binder in rustc or add `Param` and `ReEarlyBound` in Chalk. Either way, tracking when we have or haven't already substituted out these in rustc can be helpful. As a first step, I'm just adding a `EarlyBinder` newtype that is required to call `subst`. I also add a couple "transparent" `bound_*` wrappers around a couple query that are often immediately substituted. r? `@nikomatsakis`
2022-05-13Add bound_type_ofJack Huey-6/+5
2022-05-12Auto merge of #95562 - lcnr:attr-no-encode, r=davidtwcobors-1/+0
don't encode only locally used attrs Part of https://github.com/rust-lang/compiler-team/issues/505. We now filter builtin attributes before encoding them in the crate metadata in case they should only be used in the local crate. To prevent accidental misuse `get_attrs` now requires the caller to state which attribute they are interested in. For places where that isn't trivially possible, I've added a method `fn get_attrs_unchecked` which I intend to remove in a followup PR. After this pull request landed, we can then slowly move all attributes to only be used in the local crate while being certain that we don't accidentally try to access them from extern crates. cc https://github.com/rust-lang/rust/pull/94963#issuecomment-1082924289
2022-05-11Remove `PartialOrd`/`Ord` impl for `PlaceRef`Aaron Hill-2/+4
This is a new attempt at #93315. It removes one usage of the `Ord` impl for `DefId`, which should make it easier to eventually remove that impl.
2022-05-11Auto merge of #96888 - Aaron1011:fake-borrow-no-sort, r=petrochenkovbors-11/+9
Use `FxIndexSet` to avoid sorting fake borrows This fixes #96449, but I haven't yet been able to make the reproducer work using `#[cfg]` attributes, so we can't use the 'revision' infra to write a test The previous implementation relied on sorting by `PlaceRef`. This requires sorting by a `DefId`, which uses untracked state (see #93315)
2022-05-10Introduce EarlyBinderJack Huey-4/+5
2022-05-10only_local: always check for misuselcnr-1/+0
2022-05-09Use `FxIndexSet` to avoid sorting fake borrowsAaron Hill-11/+9
This fixes #96449, but I haven't yet been able to make the reproducer work using `#[cfg]` attributes, so we can't use the 'revision' infra to write a test The previous implementation relied on sorting by `PlaceRef`. This requires sorting by a `DefId`, which uses untracked state (see #93315)
2022-05-09reviewlcnr-8/+3
2022-05-09only compute `codegen_fn_attrs` where neededlcnr-2/+6
2022-05-09use hir::Let in hir::GuardSparrowLii-8/+8
2022-05-07Auto merge of #96094 - Elliot-Roberts:fix_doctests, r=compiler-errorsbors-46/+68
Begin fixing all the broken doctests in `compiler/` Begins to fix #95994. All of them pass now but 24 of them I've marked with `ignore HELP (<explanation>)` (asking for help) as I'm unsure how to get them to work / if we should leave them as they are. There are also a few that I marked `ignore` that could maybe be made to work but seem less important. Each `ignore` has a rough "reason" for ignoring after it parentheses, with - `(pseudo-rust)` meaning "mostly rust-like but contains foreign syntax" - `(illustrative)` a somewhat catchall for either a fragment of rust that doesn't stand on its own (like a lone type), or abbreviated rust with ellipses and undeclared types that would get too cluttered if made compile-worthy. - `(not-rust)` stuff that isn't rust but benefits from the syntax highlighting, like MIR. - `(internal)` uses `rustc_*` code which would be difficult to make work with the testing setup. Those reason notes are a bit inconsistently applied and messy though. If that's important I can go through them again and try a more principled approach. When I run `rg '```ignore \(' .` on the repo, there look to be lots of different conventions other people have used for this sort of thing. I could try unifying them all if that would be helpful. I'm not sure if there was a better existing way to do this but I wrote my own script to help me run all the doctests and wade through the output. If that would be useful to anyone else, I put it here: https://github.com/Elliot-Roberts/rust_doctest_fixing_tool
2022-05-06`mirror_expr` cleanuplcnr-21/+16
2022-05-05Rollup merge of #96628 - joshtriplett:stabilize-then-some, r=m-ou-seYuki Okushi-1/+0
Stabilize `bool::then_some` FCP completed in https://github.com/rust-lang/rust/issues/80967
2022-05-04Stabilize `bool::then_some`Josh Triplett-1/+0
2022-05-04Generate an intermediate temporary for `Drop` constants.Oli Scherer-30/+101
To limit the fallout from this, don't do this for the last (or only) operand in an rvalue.
2022-05-02fix most compiler/ doctestsElliot Roberts-46/+68
2022-05-02rustc: Panic by default in `DefIdTree::parent`Vadim Petrochenkov-2/+2
Only crate root def-ids don't have a parent, and in majority of cases the argument of `DefIdTree::parent` cannot be a crate root. So we now panic by default in `parent` and introduce a new non-panicing function `opt_parent` for cases where the argument can be a crate root. Same applies to `local_parent`/`opt_local_parent`.
2022-04-24only show a simple description in E0133 span labelEmil Gardström-12/+30
2022-04-24add `DefId` to unsafety violations and display function path in E0133Emil Gardström-19/+33
this enables consumers to access the function definition that was reported to be unsafe
2022-04-20Rollup merge of #93313 - tmiasko:uninhabited, r=tmandryDylan DPC-5/+13
Check if call return type is visibly uninhabited when building MIR The main motivation behind the change is to expose information about diverging calls to the generator transform and match the precision of drop range tracking which already understands that call expressions with visibly uninhabited types diverges. This change should also accept strictly more programs than before. That is programs that were previously rejected due to errors raised by control-flow sensitive checks in a code that is no longer considered reachable. Fixes #93161.
2022-04-16Rollup merge of #96023 - matthiaskrgr:clippyper1304, r=lcnrDylan DPC-1/+1
couple of clippy::perf fixes
2022-04-16Auto merge of #94468 - Amanieu:global_asm_sym, r=nagisabors-88/+55
Implement sym operands for global_asm! Tracking issue: #93333 This PR is pretty much a complete rewrite of `sym` operand support for inline assembly so that the same implementation can be shared by `asm!` and `global_asm!`. The main changes are: - At the AST level, `sym` is represented as a special `InlineAsmSym` AST node containing a path instead of an `Expr`. - At the HIR level, `sym` is split into `SymStatic` and `SymFn` depending on whether the path resolves to a static during AST lowering (defaults to `SynFn` if `get_early_res` fails). - `SymFn` is just an `AnonConst`. It runs through typeck and we just collect the resulting type at the end. An error is emitted if the type is not a `FnDef`. - `SymStatic` directly holds a path and the `DefId` of the `static` that it is pointing to. - The representation at the MIR level is mostly unchanged. There is a minor change to THIR where `SymFn` is a constant instead of an expression. - At the codegen level we need to apply the target's symbol mangling to the result of `tcx.symbol_name()` depending on the target. This is done by calling the LLVM name mangler, which handles all of the details. - On Mach-O, all symbols have a leading underscore. - On x86 Windows, different mangling is used for cdecl, stdcall, fastcall and vectorcall. - No mangling is needed on other platforms. r? `@nagisa` cc `@eddyb`
2022-04-15Rollup merge of #96026 - matthiaskrgr:clippy_compl_1304, r=Dylan-DPCDylan DPC-7/+3
couple of clippy::complexity fixes