summary refs log tree commit diff
path: root/compiler/rustc_mir_build/src
AgeCommit message (Collapse)AuthorLines
2022-06-20Rollup merge of #98267 - compiler-errors:suggest-wildcard-arm, r=oli-obkMatthias Krüger-11/+23
Don't omit comma when suggesting wildcard arm after macro expr * Also adds `Span::eq_ctxt` to consolidate the various usages of `span.ctxt() == other.ctxt()` * Also fixes an unhygenic usage of spans which caused the suggestion to render weirdly when we had one arm match in a macro * Also always suggests a comma (i.e. even after a block) if we're rendering a wildcard arm in a single-line match (looks prettier :rose:) Fixes #94866
2022-06-20Auto merge of #97931 - xldenis:fix-if-let-source-scopes, r=nagisabors-12/+51
Fix `SourceScope` for `if let` bindings. Fixes #97799. I'm not sure how to test this properly, is there any way to observe the difference in behavior apart from `ui` tests? I'm worried that they would be overlooked in the case of a regression.
2022-06-19Be more hygenic with spansMichael Goulet-6/+7
2022-06-19Use `Span::eq_ctxt` method instead of `.ctxt() == .ctxt()`Michael Goulet-4/+4
2022-06-19Only omit trailing comma if block doesn't come from macro expansionMichael Goulet-3/+14
2022-06-16compare_const_vals: add a special case for certain ranges.Nicholas Nethercote-4/+19
This commit removes the `a == b` early return, which isn't useful in practice, and replaces it with one that helps matches with many ranges, including char ranges.
2022-06-16compare_const_vals: Use infallible evaluation.Nicholas Nethercote-27/+23
Because these evaluations can never fail.
2022-06-16Remove `ty` arg from `compare_const_vals`.Nicholas Nethercote-21/+8
It's now only used in no-longer-interesting assertion.
2022-06-16Remove `from_bool` closure.Nicholas Nethercote-4/+2
The code is clearer and simpler without it. Note that the `a == b` early return at the top of the function means the `a == b` test at the end of the function could never succeed.
2022-06-16Inline and remove `fallback` closure.Nicholas Nethercote-3/+1
2022-06-16Remove one use of `compare_const_vals`.Nicholas Nethercote-15/+2
A direct comparison has the same effect. This also avoids the need for a type test within `compare_const_vals`.
2022-06-16Assert type equality of `a` and `b` in `compare_const_vals`.Nicholas Nethercote-1/+3
Because they're always equal.
2022-06-16Remove dead code from `compare_const_vals`.Nicholas Nethercote-11/+0
It's never executed when running the entire test suite. I think it's because of the early return at the top of the function if `a.ty() != ty` succeeds.
2022-06-16simplify_match_pair: avoid the second comparison if possible.Nicholas Nethercote-9/+12
Also, the `try_to_bits` always succeeds, so use `unwrap`.
2022-06-16sort_candidates: avoid the second comparison if possible.Nicholas Nethercote-25/+19
This is a performance win for `unicode-normalization`. The commit also removes the closure, which isn't necessary. And reformulates the comparison into a form I find easier to read.
2022-06-16const_range_contains: avoid the second comparison if possible.Nicholas Nethercote-8/+11
This is a performance win for `unicode-normalization`. Also, I find the new formulation easier to read.
2022-06-15Rollup merge of #98110 - cjgillot:closure-brace, r=Aaron1011Yuki Okushi-3/+3
Make `ExprKind::Closure` a struct variant. Simple refactor since we both need it to introduce additional fields in `ExprKind::Closure`. r? ``@Aaron1011``
2022-06-14Only create scopes for if letXavier Denis-4/+20
2022-06-14rebaseb-naber-1/+2
2022-06-14address reviewb-naber-72/+59
2022-06-14address reviewb-naber-57/+3
2022-06-14fix clippy test failuresb-naber-1/+1
2022-06-14implement valtrees as the type-system representation for constant valuesb-naber-93/+169
2022-06-14Rename the `ConstS::val` field as `kind`.Nicholas Nethercote-4/+4
And likewise for the `Const::val` method. Because its type is called `ConstKind`. Also `val` is a confusing name because `ConstKind` is an enum with seven variants, one of which is called `Value`. Also, this gives consistency with `TyS` and `PredicateS` which have `kind` fields. The commit also renames a few `Const` variables from `val` to `c`, to avoid confusion with the `ConstKind::Value` variant.
2022-06-12Make `ExprKind::Closure` a struct variant.Camille GILLOT-3/+3
2022-06-10Actually fixXavier Denis-19/+23
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`