Commit Graph

1227 Commits

Author SHA1 Message Date
Camille GILLOT 74fb87e3a0 Stop sorting bodies by span.
The definition order is already close to the span order, and only differs
in corner cases.
2021-09-01 20:13:16 +02:00
bors c2a408840a Auto merge of #87688 - camsteffen:let-else, r=cjgillot
Introduce `let...else`

Tracking issue: #87335

The trickiest part for me was enforcing the diverging else block with clear diagnostics. Perhaps the obvious solution is to expand to `let _: ! = ..`, but I decided against this because, when a "mismatched type" error is found in typeck, there is no way to trace where in the HIR the expected type originated, AFAICT. In order to pass down this information, I believe we should introduce `Expectation::LetElseNever(HirId)` or maybe add `HirId` to `Expectation::HasType`, but I left that as a future enhancement. For now, I simply assert that the block is `!` with a custom `ObligationCauseCode`, and I think this is clear enough, at least to start. The downside here is that the error points at the entire block rather than the specific expression with the wrong type. I left a todo to this effect.

Overall, I believe this PR is feature-complete with regard to the RFC.
2021-09-01 01:02:42 +00:00
Camille GILLOT 8d7d488d3b Lint Abi in ast validation. 2021-08-31 20:30:17 +02:00
Mara Bos 41249cad91 Rollup merge of #88445 - inquisitivecrystal:ast-lowering, r=cjgillot
Clean up the lowering of AST items

This PR simplifies and improves `rustc_ast_lowering::item` in various minor ways. The reasons for the changes should mostly be self evident, though I'm happy to specifically explain anything if needed.

These changes used to be part of #88019, but I removed them after it was pointed out that some of my other changes to `rustc_ast_lowering` were unnecessary. It felt like a bad idea to clean up code which I didn't even need to touch anymore.

r? `@cjgillot`
2021-08-31 17:54:57 +02:00
Cameron Steffen 960ea093ab Add let_else feature gate 2021-08-30 20:18:39 -05:00
Cameron Steffen ae32e88909 Lower let-else to HIR 2021-08-30 20:17:46 -05:00
Cameron Steffen 120d46e255 Refactor lower_stmts 2021-08-30 20:17:45 -05:00
Cameron Steffen 581abbfc6d Move some methods to block module 2021-08-30 20:17:45 -05:00
Cameron Steffen 89d2600d01 Add let-else to AST 2021-08-30 20:17:45 -05:00
bjorn3 1a2fe87b09 Remove unused arena macro args 2021-08-30 13:09:38 +02:00
inquisitivecrystal 147f74a3c3 Clean up the lowering of AST items 2021-08-29 20:05:34 -07:00
Vadim Petrochenkov 59013cdebe ast_lowering: Introduce lower_span for catching all spans entering HIR 2021-08-29 10:49:40 +03:00
Michael Howell fe1a7f71fb rustc: use more correct span data in for loop desugaring
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-28 12:18:46 -07:00
inquisitivecrystal 8c62fa0575 Treat macros as HIR items 2021-08-28 00:16:34 -07:00
Deadbeef 8660832086 Introduce ~const
- [x] Removed `?const` and change uses of `?const`
 - [x] Added `~const` to the AST. It is gated behind const_trait_impl.
 - [x] Validate `~const` in ast_validation.
 - [ ] Add enum `BoundConstness` to the HIR. (With variants `NotConst` and
 `ConstIfConst` allowing future extensions)
 - [ ] Adjust trait selection and pre-existing code to use `BoundConstness`.
 - [ ] Optional steps (*for this PR, obviously*)
      - [ ] Fix #88155
      - [ ] Do something with constness bounds in chalk
2021-08-27 05:07:37 +00:00
asquared31415 0b81c2eb82 Move named_asm_labels to a HIR lint 2021-08-24 08:23:58 -04:00
bors f66e825f73 Auto merge of #87739 - Aaron1011:remove-used-attrs, r=wesleywiser
Remove `Session.used_attrs` and move logic to `CheckAttrVisitor`

Instead of updating global state to mark attributes as used,
we now explicitly emit a warning when an attribute is used in
an unsupported position. As a side effect, we are to emit more
detailed warning messages (instead of just a generic "unused" message).

`Session.check_name` is removed, since its only purpose was to mark
the attribute as used. All of the callers are modified to use
`Attribute.has_name`

Additionally, `AttributeType::AssumedUsed` is removed - an 'assumed
used' attribute is implemented by simply not performing any checks
in `CheckAttrVisitor` for a particular attribute.

We no longer emit unused attribute warnings for the `#[rustc_dummy]`
attribute - it's an internal attribute used for tests, so it doesn't
mark sense to treat it as 'unused'.

With this commit, a large source of global untracked state is removed.
2021-08-24 03:58:22 +00:00
Frank Steffahn bf88b113ea Fix typos “a”→“an” 2021-08-22 15:35:11 +02:00
Aaron Hill af46699f81 Remove Session.used_attrs and move logic to CheckAttrVisitor
Instead of updating global state to mark attributes as used,
we now explicitly emit a warning when an attribute is used in
an unsupported position. As a side effect, we are to emit more
detailed warning messages (instead of just a generic "unused" message).

`Session.check_name` is removed, since its only purpose was to mark
the attribute as used. All of the callers are modified to use
`Attribute.has_name`

Additionally, `AttributeType::AssumedUsed` is removed - an 'assumed
used' attribute is implemented by simply not performing any checks
in `CheckAttrVisitor` for a particular attribute.

We no longer emit unused attribute warnings for the `#[rustc_dummy]`
attribute - it's an internal attribute used for tests, so it doesn't
mark sense to treat it as 'unused'.

With this commit, a large source of global untracked state is removed.
2021-08-21 13:27:27 -05:00
Caio 6aa9937a76 Introduce hir::ExprKind::Let - Take 2 2021-08-15 16:18:26 -03:00
Matthew Jasper 2d9f2eae84 Use correct drop scopes for if expressions 2021-08-15 16:05:25 -03:00
Amanieu d'Antras 3fd463a5ca Add support for clobber_abi to asm! 2021-08-12 12:43:11 +01:00
Cameron Steffen 02cd72e34b Inline make_if macro 2021-08-01 17:46:28 -05:00
Esteban Küber 15a40c7ee8 Do not discard ?Sized type params and suggest their removal 2021-07-30 08:44:31 -07:00
bors fd853c00e2 Auto merge of #83484 - JulianKnodt:infer, r=oli-obk,lcnr
Add hir::GenericArg::Infer

In order to extend inference to consts, make an Infer type on hir::GenericArg.
2021-07-27 16:24:45 +00:00
kadmin 8759f00c73 Actually infer args in visitors 2021-07-26 21:15:18 +00:00
bors 6489ee1041 Auto merge of #83723 - cjgillot:ownernode, r=petrochenkov
Store all HIR owners in the same container

This replaces the previous storage in a BTreeMap for each of Item/ImplItem/TraitItem/ForeignItem.
This should allow for a more compact storage.

Based on https://github.com/rust-lang/rust/pull/83114
2021-07-25 11:11:02 +00:00
Camille GILLOT fee421685d Introduce OwnerNode::Crate. 2021-07-25 12:22:47 +02:00
Camille GILLOT 36a28060f1 Merge the BTreeMap in hir::Crate. 2021-07-25 12:18:56 +02:00
kadmin 417b098cfc Add generic arg infer 2021-07-25 07:28:51 +00:00
surechen 0f5bfc2242 Correct fmt 2021-07-21 12:01:03 +08:00
surechen 7af840f62e Simplify the collecting of ? Trait bounds in where clause 2021-07-21 11:35:06 +08:00
bors da7d405357 Auto merge of #87244 - jackh726:issue-71883, r=estebank
Better diagnostics with mismatched types due to implicit static lifetime

Fixes #78113

I think this is my first diagnostics PR...definitely happy to hear thoughts on the direction/implementation here.

I was originally just trying to solve the error above, where the lifetime on a GAT was causing a cryptic "mismatched types" error. But as I was writing this, I realized that this (unintentionally) also applied to a different case: `wf-in-foreign-fn-decls-issue-80468.rs`. I'm not sure if this diagnostic should get a new error code, or even reuse an existing one. And, there might be some ways to make this even more generalized. Also, the error is a bit more lengthy and verbose than probably needed. So thoughts there are welcome too.

This PR essentially ended up adding a new nice region error pass that triggers if a type doesn't match the self type of an impl which is selected because of a predicate because of an implicit static bound on that self type.

r? `@estebank`
2021-07-20 10:56:08 +00:00
jackh726 ae02491984 Better errors when we don't have implicit statics in trait objects 2021-07-19 23:46:11 -04:00
Santiago Pastorino 3e857f5743 Improve impl trait disallowed context error text 2021-07-19 10:19:58 -03:00
Santiago Pastorino e8c04b4386 Remove impl_trait_in_bindings feature flag 2021-07-18 09:30:11 -03:00
Santiago Pastorino c34fb5167e Remove origin field from TypeAliasesOpaqueTy 2021-07-18 09:30:10 -03:00
Santiago Pastorino 000b945cea Remove OpaqueTyOrigin::Misc, use TyAlias instead 2021-07-18 09:30:10 -03:00
Santiago Pastorino 4d2d90307d Remove impl trait bindings handling on const AST lowering 2021-07-18 09:30:07 -03:00
Santiago Pastorino bc106ebb5a Remove impl traits bindings error message handling on AST lowering 2021-07-17 23:14:23 -03:00
Santiago Pastorino ac3a43b316 Fix TypeAliasesOpaqueTy origin docs 2021-07-17 23:14:23 -03:00
Santiago Pastorino 13287d8dd2 Rename OtherOpaqueTy to TypeAliasesOpaqueTy 2021-07-17 23:14:22 -03:00
Santiago Pastorino 66c9cd9e66 Remove OpaqueTyOrigin::Binding 2021-07-17 23:14:22 -03:00
Cameron Steffen 1537cd4fb1 Remove refs from pat slices 2021-07-15 16:09:57 -05:00
Camille GILLOT 616ce3c5c0 Cache expansion hash. 2021-07-13 23:10:56 +02:00
bors 99f8efec46 Auto merge of #86416 - Amanieu:asm_clobber_only, r=nagisa
Add clobber-only register classes for asm!

These are needed to properly express a function call ABI using a clobber
list, even though we don't support passing actual values into/out of
these registers.
2021-07-11 01:06:58 +00:00
Amanieu d'Antras e1c3f5e017 Add clobber-only register classes for asm!
These are needed to properly express a function call ABI using a clobber
list, even though we don't support passing actual values into/out of
these registers.
2021-07-10 17:29:00 +02:00
Scott McMurray 099a357e5c Update the comment on lower_expr_try
I'd updated the ones inside the method, but not its doc comment.
2021-07-09 00:13:44 -07:00
Camille GILLOT c520cf2253 Arena-allocate Crate during lowering. 2021-06-30 20:31:56 +02:00
bors 607d6b00d4 Auto merge of #86321 - JohnTitor:rollup-q61c8q4, r=JohnTitor
Rollup of 10 pull requests

Successful merges:

 - #80269 (Explain non-dropped sender recv in docs)
 - #82179 (Add functions `Duration::try_from_secs_{f32, f64}`)
 - #85608 (Stabilize `ops::ControlFlow` (just the type))
 - #85792 (Refactor windows sockets impl methods)
 - #86220 (Improve maybe_uninit_extra docs)
 - #86277 (Remove must_use from ALLOWED_ATTRIBUTES)
 - #86285 (⬆️ rust-analyzer)
 - #86294 (Stabilize {std, core}::prelude::rust_*.)
 - #86306 (Add mailmap entries for myself)
 - #86314 (Remove trailing triple backticks in `mut_keyword` docs)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-06-15 20:15:23 +00:00