summary refs log tree commit diff
path: root/compiler/rustc_ast_lowering/src/expr.rs
AgeCommit message (Collapse)AuthorLines
2021-11-25On type mismatch caused by assignment, point at assigneeEsteban Küber-4/+12
* Do not emit unnecessary E0308 after E0070 * Show fewer errors on `while let` missing `let` * Hide redundant E0308 on `while let` missing `let` * Point at binding definition when possible on invalid assignment * do not point at closure twice * do not suggest `if let` for literals in lhs * account for parameter types
2021-11-21Simplify for loop desugarCameron Steffen-99/+38
2021-10-22Rollup merge of #89895 - camsteffen:for-loop-head-span, r=davidtwcoYuki Okushi-21/+18
Don't mark for loop iter expression as desugared We typically don't mark spans of lowered things as desugared. This helps Clippy rightly discern when code is (not) from expansion. This was discovered by ``@flip1995`` at https://github.com/rust-lang/rust-clippy/pull/7789#issuecomment-939289501.
2021-10-15Use more lowered spans in for loopCameron Steffen-12/+14
2021-10-15Don't mark for loop head span with desugaringCameron Steffen-10/+5
2021-10-09Store lowering outputs per owner.Camille GILLOT-2/+3
2021-10-02Add desugaring mark to while loopCameron Steffen-4/+7
2021-09-20Make with_hir_id_owner responsible for registering the item.Camille GILLOT-1/+1
2021-09-20Do not store visibility in *ItemRef.Camille GILLOT-1/+0
2021-09-11Auto merge of #84373 - cjgillot:resolve-span, r=michaelwoerister,petrochenkovbors-1/+3
Encode spans relative to the enclosing item The aim of this PR is to avoid recomputing queries when code is moved without modification. MCP at https://github.com/rust-lang/compiler-team/issues/443 This is achieved by : 1. storing the HIR owner LocalDefId information inside the span; 2. encoding and decoding spans relative to the enclosing item in the incremental on-disk cache; 3. marking a dependency to the `source_span(LocalDefId)` query when we translate a span from the short (`Span`) representation to its explicit (`SpanData`) representation. Since all client code uses `Span`, step 3 ensures that all manipulations of span byte positions actually create the dependency edge between the caller and the `source_span(LocalDefId)`. This query return the actual absolute span of the parent item. As a consequence, any source code motion that changes the absolute byte position of a node will either: - modify the distance to the parent's beginning, so change the relative span's hash; - dirty `source_span`, and trigger the incremental recomputation of all code that depends on the span's absolute byte position. With this scheme, I believe the dependency tracking to be accurate. For the moment, the spans are marked during lowering. I'd rather do this during def-collection, but the AST MutVisitor is not practical enough just yet. The only difference is that we attach macro-expanded spans to their expansion point instead of the macro itself.
2021-09-11Rebase fallout.Camille GILLOT-0/+1
2021-09-11Auto merge of #88214 - notriddle:notriddle/for-loop-span-drop-temps-mut, ↵bors-2/+7
r=nagisa rustc: use more correct span data in for loop desugaring Fixes #82462 Before: help: consider adding semicolon after the expression so its temporaries are dropped sooner, before the local variables declared by the block are dropped | LL | for x in DroppingSlice(&*v).iter(); { | + After: help: consider adding semicolon after the expression so its temporaries are dropped sooner, before the local variables declared by the block are dropped | LL | }; | + This seems like a reasonable fix: since the desugared "expr_drop_temps_mut" contains the entire desugared loop construct, its span should contain the entire loop construct as well.
2021-09-10Give spans their parent item during lowering.Camille GILLOT-1/+2
We only do this operation when incremental compilation is enabled. This avoids pessimizing the span handling for non-incremental compilation.
2021-09-03Replace Vec by Option.Camille GILLOT-26/+6
2021-08-29ast_lowering: Introduce `lower_span` for catching all spans entering HIRVadim Petrochenkov-50/+134
2021-08-28rustc: use more correct span data in for loop desugaringMichael Howell-2/+7
Before: help: consider adding semicolon after the expression so its temporaries are dropped sooner, before the local variables declared by the block are dropped | LL | for x in DroppingSlice(&*v).iter(); { | + After: help: consider adding semicolon after the expression so its temporaries are dropped sooner, before the local variables declared by the block are dropped | LL | }; | + This seems like a reasonable fix: since the desugared "expr_drop_temps_mut" contains the entire desugared loop construct, its span should contain the entire loop construct as well.
2021-08-15Introduce hir::ExprKind::Let - Take 2Caio-207/+56
2021-08-15Use correct drop scopes for if expressionsMatthew Jasper-3/+14
2021-08-01Inline make_if macroCameron Steffen-12/+4
2021-07-15Remove refs from pat slicesCameron Steffen-5/+14
2021-07-09Update the comment on `lower_expr_try`Scott McMurray-7/+8
I'd updated the ones inside the method, but not its doc comment.
2021-06-10Add support for using qualified paths with structs in expression and patternRyan Levick-9/+11
position.
2021-05-18Auto merge of #84767 - scottmcm:try_trait_actual, r=lcnrbors-32/+26
Implement the new desugaring from `try_trait_v2` ~~Currently blocked on https://github.com/rust-lang/rust/issues/84782, which has a PR in https://github.com/rust-lang/rust/pull/84811~~ Rebased atop that fix. `try_trait_v2` tracking issue: https://github.com/rust-lang/rust/issues/84277 Unfortunately this is already touching a ton of things, so if you have suggestions for good ways to split it up, I'd be happy to hear them. (The combination between the use in the library, the compiler changes, the corresponding diagnostic differences, even MIR tests mean that I don't really have a great plan for it other than trying to have decently-readable commits. r? `@ghost` ~~(This probably shouldn't go in during the last week before the fork anyway.)~~ Fork happened.
2021-05-13Add support for const operands and options to global_asm!Amanieu d'Antras-318/+3
On x86, the default syntax is also switched to Intel to match asm!
2021-05-08Make `Diagnostic::span_fatal` unconditionally raise an errorJoshua Nelson-3/+1
It had no callers which didn't immediately call `raise()`, and this unifies the behavior with `Session`.
2021-05-06Actually implement the feature in the compilerScott McMurray-32/+26
Including all the bootstrapping tweaks in the library.
2021-04-29Make current_hir_id_owner a simple tuple.Camille GILLOT-1/+1
2021-04-07Rollup merge of #83916 - Amanieu:asm_anonconst, r=petrochenkovDylan DPC-3/+3
Use AnonConst for asm! constants This replaces the old system which used explicit promotion. See #83169 for more background. The syntax for `const` operands is still the same as before: `const <expr>`. Fixes #83169 Because the implementation is heavily based on inline consts, we suffer from the same issues: - We lose the ability to use expressions derived from generics. See the deleted tests in `src/test/ui/asm/const.rs`. - We are hitting the same ICEs as inline consts, for example #78174. It is unlikely that we will be able to stabilize this before inline consts are stabilized.
2021-04-06Use AnonConst for asm! constantsAmanieu d'Antras-3/+3
2021-04-04Allow clobbering unsupported registers in asm!Amanieu d'Antras-32/+50
Previously registers could only be marked as clobbered if the target feature for that register was enabled. This restriction is now removed.
2021-03-17Auto merge of #83188 - petrochenkov:field, r=lcnrbors-14/+20
ast/hir: Rename field-related structures I always forget what `ast::Field` and `ast::StructField` mean despite working with AST for long time, so this PR changes the naming to less confusing and more consistent. - `StructField` -> `FieldDef` ("field definition") - `Field` -> `ExprField` ("expression field", not "field expression") - `FieldPat` -> `PatField` ("pattern field", not "field pattern") Various visiting and other methods working with the fields are renamed correspondingly too. The second commit reduces the size of `ExprKind` by boxing fields of `ExprKind::Struct` in preparation for https://github.com/rust-lang/rust/pull/80080.
2021-03-16ast: Reduce size of `ExprKind` by boxing fields of `ExprKind::Struct`Vadim Petrochenkov-8/+9
2021-03-16ast/hir: Rename field-related structuresVadim Petrochenkov-7/+12
StructField -> FieldDef ("field definition") Field -> ExprField ("expression field", not "field expression") FieldPat -> PatField ("pattern field", not "field pattern") Also rename visiting and other methods working on them.
2021-03-13Always lower asm! to valid HIRAmanieu d'Antras-45/+44
2021-03-09Use BTreeMap to store attributes.Camille GILLOT-9/+15
2021-03-09Remove hir::Expr::attrs.Camille GILLOT-22/+14
2021-03-09Remove hir::Param::attrs.Camille GILLOT-1/+1
2021-03-09Remove hir::Arm::attrs.Camille GILLOT-16/+3
2021-03-09Take a slice in stmt_let_pat.Camille GILLOT-3/+3
2021-03-09Collect attributes during HIR lowering.Camille GILLOT-9/+11
2021-03-07Remove notes, increase S/N ratioEsteban Küber-18/+11
2021-03-07Account for `if (let pat = expr) {}`Esteban Küber-2/+47
Partially address #82827.
2021-02-25Auto merge of #82447 - Amanieu:legacy_const_generics, r=oli-obkbors-2/+56
Add #[rustc_legacy_const_generics] This is the first step towards removing `#[rustc_args_required_const]`: a new attribute is added which rewrites function calls of the form `func(a, b, c)` to `func::<{b}>(a, c)`. This allows previously stabilized functions in `stdarch` which use `rustc_args_required_const` to use const generics instead. This new attribute is not intended to ever be stabilized, it is only intended for use in `stdarch` as a replacement for `#[rustc_args_required_const]`. ```rust #[rustc_legacy_const_generics(1)] pub fn foo<const Y: usize>(x: usize, z: usize) -> [usize; 3] { [x, Y, z] } fn main() { assert_eq!(foo(0 + 0, 1 + 1, 2 + 2), [0, 2, 4]); assert_eq!(foo::<{1 + 1}>(0 + 0, 2 + 2), [0, 2, 4]); } ``` r? `@oli-obk`
2021-02-25Address review commentsAmanieu d'Antras-40/+8
2021-02-23Add #[rustc_legacy_const_generics]Amanieu d'Antras-2/+88
2021-02-19Lower condition of `if` expression before it's "then" blockEsteban Küber-1/+2
Fix #82290, fix #82250.
2021-02-09Rename HIR UnOp variantsÖmer Sinan Ağacan-3/+3
This renames the variants in HIR UnOp from enum UnOp { UnDeref, UnNot, UnNeg, } to enum UnOp { Deref, Not, Neg, } Motivations: - This is more consistent with the rest of the code base where most enum variants don't have a prefix. - These variants are never used without the `UnOp` prefix so the extra `Un` prefix doesn't help with readability. E.g. we don't have any `UnDeref`s in the code, we only have `UnOp::UnDeref`. - MIR `UnOp` type variants don't have a prefix so this is more consistent with MIR types. - "un" prefix reads like "inverse" or "reverse", so as a beginner in rustc code base when I see "UnDeref" what comes to my mind is something like "&*" instead of just "*".
2021-01-23Rollup merge of #81249 - cjgillot:issue-79537, r=oli-obkJonas Schievink-13/+18
Lower closure prototype after its body. Fixes #79537. r? `@Mark-Simulacrum`
2021-01-21Add loop head span to hirEsteban Küber-4/+15
2021-01-21Lower closure prototype after its body.Camille GILLOT-13/+18