Commit graph

218 commits

Author SHA1 Message Date
bors
b4e8596e3e Auto merge of #88598 - estebank:type-ascription-can-die-in-a-fire, r=wesleywiser
Detect bare blocks with type ascription that were meant to be a `struct` literal

Address part of #34255.

Potential improvement: silence the other knock down errors in `issue-34255-1.rs`.
2021-09-04 01:40:36 +00:00
bors
577a76f003 Auto merge of #88597 - cjgillot:lower-global, r=petrochenkov
Move global analyses from lowering to resolution

Split off https://github.com/rust-lang/rust/pull/87234

r? `@petrochenkov`
2021-09-03 14:47:13 +00:00
Esteban Kuber
12ce6e9c60 Detect bare blocks with type ascription that were meant to be a struct literal
Address part of #34255.

Potential improvement: silence the other knock down errors in
`issue-34255-1.rs`.
2021-09-03 14:43:04 +00:00
Vadim Petrochenkov
9940758416 expand: Treat more macro calls as statement macro calls 2021-09-02 14:14:38 +03:00
Camille GILLOT
f8efe5d822 Compute proc_macros in resolutions. 2021-09-01 20:13:16 +02:00
Cameron Steffen
29bc94ff0d Handle let-else initializer edge case errors 2021-08-30 20:18:42 -05:00
Cameron Steffen
89d2600d01 Add let-else to AST 2021-08-30 20:17:45 -05:00
lcnr
4747cbb3bb allow unordered const/ty params if any cg feature is active 2021-08-30 11:00:21 +02:00
lcnr
0c28e028b6 feature(const_generics) -> feature(const_param_types) 2021-08-30 11:00:21 +02: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
bors
76e755cf4a Auto merge of #88066 - LeSeulArtichaut:patterns-cleanups, r=nagisa
Use if-let guards in the codebase and various other pattern cleanups

Dogfooding if-let guards as experimentation for the feature.

Tracking issue #51114. Conflicts with #87937.
2021-08-26 05:23:35 +00:00
Léo Lanteri Thauvin
2b0c8fff8a Various pattern cleanups 2021-08-25 20:24:39 +02:00
Léo Lanteri Thauvin
fde1b76b4b Use if-let guards in the codebase 2021-08-25 20:24:35 +02:00
asquared31415
0b81c2eb82 Move named_asm_labels to a HIR lint 2021-08-24 08:23:58 -04:00
Frank Steffahn
bf88b113ea Fix typos “a”→“an” 2021-08-22 15:35:11 +02:00
est31
1cd1cd034b Remove box syntax from rustc_ast 2021-08-18 09:25:26 +02:00
Caio
6aa9937a76 Introduce hir::ExprKind::Let - Take 2 2021-08-15 16:18:26 -03:00
Amanieu d'Antras
3fd463a5ca Add support for clobber_abi to asm! 2021-08-12 12:43:11 +01:00
bors
b53a93db2d Auto merge of #87535 - lf-:authors, r=Mark-Simulacrum
rfc3052 followup: Remove authors field from Cargo manifests

Since RFC 3052 soft deprecated the authors field, hiding it from
crates.io, docs.rs, and making Cargo not add it by default, and it is
not generally up to date/useful information for contributors, we may as well
remove it from crates in this repo.
2021-08-02 05:49:17 +00:00
Anton Golov
5d59b4412e Add warning when whitespace is not skipped after an escaped newline. 2021-07-30 16:26:39 +02:00
Jade
3cf820e17d rfc3052: Remove authors field from Cargo manifests
Since RFC 3052 soft deprecated the authors field anyway, hiding it from
crates.io, docs.rs, and making Cargo not add it by default, and it is
not generally up to date/useful information, we should remove it from
crates in this repo.
2021-07-29 14:56:05 -07:00
Jacob Pratt
36f02f3523
Stabilize const_fn_transmute 2021-07-27 16:03:09 -04:00
kadmin
8759f00c73 Actually infer args in visitors 2021-07-26 21:15:18 +00:00
kadmin
417b098cfc Add generic arg infer 2021-07-25 07:28:51 +00:00
Aaron Hill
f9f238e6b8
Remove special case for ExprKind::Paren in MutVisitor
The special case breaks several useful invariants (`ExpnId`s are
globally unique, and never change). This special case
was added back in 2016 in https://github.com/rust-lang/rust/pull/34355
2021-07-19 17:23:10 -05:00
Camille GILLOT
078dd37f88 Use LocalExpnId where possible. 2021-07-17 19:41:02 +02:00
Camille GILLOT
6e78d6c9d6 Make the CrateNum part of the ExpnId. 2021-07-17 19:35:33 +02:00
bors
0d76b73745 Auto merge of #83918 - workingjubilee:stable-rangefrom-pat, r=joshtriplett
Stabilize "RangeFrom" patterns in 1.55

Implements a partial stabilization of #67264 and #37854.
Reference PR: https://github.com/rust-lang/reference/pull/900

# Stabilization Report

This stabilizes the `X..` pattern, shown as such, offering an exhaustive match for unsigned integers:
```rust
match x as u32 {
      0 => println!("zero!"),
      1.. => println!("positive number!"),
}
```

Currently if a Rust author wants to write such a match on an integer, they must use `1..={integer}::MAX` . By allowing a "RangeFrom" style pattern, this simplifies the match to not require the MAX path and thus not require specifically repeating the type inside the match, allowing for easier refactoring. This is particularly useful for instances like the above case, where different behavior on "0" vs. "1 or any positive number" is desired, and the actual MAX is unimportant.

Notably, this excepts slice patterns which include half-open ranges from stabilization, as the wisdom of those is still subject to some debate.

## Practical Applications

Instances of this specific usage have appeared in the compiler:
16143d1067/compiler/rustc_middle/src/ty/inhabitedness/mod.rs (L219)
673d0db5e3/compiler/rustc_ty_utils/src/ty.rs (L524)

And I have noticed there are also a handful of "in the wild" users who have deployed it to similar effect, especially in the case of rejecting any value of a certain number or greater. It simply makes it much more ergonomic to write an irrefutable match, as done in Katholieke Universiteit Leuven's [SCALE and MAMBA project](05e5db00d5/WebAssembly/scale_std/src/fixed_point.rs (L685-L695)).

## Tests
There were already many tests in [src/test/ui/half-open-range/patterns](90a2e5e3fe/src/test/ui/half-open-range-patterns), as well as [generic pattern tests that test the `exclusive_range_pattern` feature](673d0db5e3/src/test/ui/pattern/usefulness/integer-ranges/reachability.rs), many dating back to the feature's introduction and remaining standing to this day. However, this stabilization comes with some additional tests to explore the... sometimes interesting behavior of interactions with other patterns. e.g. There is, at least, a mild diagnostic improvement in some edge cases, because before now, the pattern `0..=(5+1)` encounters the `half_open_range_patterns` feature gate and can thus emit the request to enable the feature flag, while also emitting the "inclusive range with no end" diagnostic. There is no intent to allow an `X..=` pattern that I am aware of, so removing the flag request is a strict improvement. The arrival of the `J | K` "or" pattern also enables some odd formations.

Some of the behavior tested for here is derived from experiments in this [Playground](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=58777b3c715c85165ac4a70d93efeefc) example, linked at https://github.com/rust-lang/rust/issues/67264#issuecomment-812770692, which may be useful to reference to observe the current behavior more closely.

In addition tests constituting an explanation of the "slicing range patterns" syntax issue are included in this PR.

## Desiderata

The exclusive range patterns and half-open range patterns are fairly strongly requested by many authors, as they make some patterns much more natural to write, but there is disagreement regarding the "closed" exclusive range pattern or the "RangeTo" pattern, especially where it creates "off by one" gaps in the presence of a "catch-all" wildcard case. Also, there are obviously no range analyses in place that will force diagnostics for e.g. highly overlapping matches. I believe these should be warned on, ideally, and I think it would be reasonable to consider such a blocker to stabilizing this feature, but there is no technical issue with the feature as-is from the purely syntactic perspective as such overlapping or missed matches can already be generated today with such a catch-all case. And part of the "point" of the feature, at least from my view, is to make it easier to omit wildcard matches: a pattern with such an "open" match produces an irrefutable match and does not need the wild card case, making it easier to benefit from exhaustiveness checking.

## History

- Implemented:
  - Partially via exclusive ranges: https://github.com/rust-lang/rust/pull/35712
  - Fully with half-open ranges: https://github.com/rust-lang/rust/pull/67258
- Unresolved Questions:
  - The precedence concerns of https://github.com/rust-lang/rust/pull/48501 were considered as likely requiring adjustment but probably wanting a uniform consistent change across all pattern styles, given https://github.com/rust-lang/rust/issues/67264#issuecomment-720711656, but it is still unknown what changes might be desired
  - How we want to handle slice patterns in ranges seems to be an open question still, as witnessed in the discussion of this PR!

I checked but I couldn't actually find an RFC for this, and given "approved provisionally by lang team without an RFC", I believe this might require an RFC before it can land? Unsure of procedure here, on account of this being stabilizing a subset of a feature of syntax.

r? `@scottmcm`
2021-07-11 06:31:42 +00:00
Guillaume Gomez
a2654fb64c Rework SESSION_GLOBALS API to prevent overwriting it 2021-07-08 16:16:28 +02:00
bors
f8ac8fdacf Auto merge of #86190 - asquared31415:extern-main-86110-fix, r=varkor
Fix ICE when `main` is declared in an `extern` block

Changes in #84401 to implement `imported_main` changed how the crate entry point is found, and a declared `main` in an `extern` block was detected erroneously.  This was causing the ICE described in #86110.

This PR adds a check for this case and emits an error instead.  Previously a `main` declaration in an `extern` block was not detected as an entry point at all, so emitting an error shouldn't break anything that worked previously.  In 1.52.1 stable this is demonstrated, with a `` `main` function not found`` error.

Fixes #86110
2021-07-01 06:39:37 +00:00
Mark Rousskov
06661ba759 Update to new bootstrap compiler 2021-06-28 11:30:49 -04:00
bors
345530412f Auto merge of #85909 - cjgillot:alloc-kind-query, r=Aaron1011
Make allocator_kind a query.

Part of #85153

r? `@Aaron1011`
2021-06-28 01:20:01 +00:00
bors
e6b4c252ea Auto merge of #86599 - Amanieu:asm_raw, r=nagisa
Add a "raw" option for asm! which ignores format string specifiers

This is useful when including raw assembly snippets using `include_str!`.
2021-06-25 20:44:28 +00:00
Amanieu d'Antras
d0443bb7c2 Add a "raw" option for asm! which ignores format string specifiers 2021-06-24 23:42:15 +01:00
Camille GILLOT
6a371d2c89 Make allocator_kind a query. 2021-06-20 11:52:51 +02:00
Yuki Okushi
4f8e0ebcc5
Use AttrVec for Arm, FieldDef, and Variant 2021-06-17 08:04:54 +09:00
Ryan Levick
6936349233 Add support for using qualified paths with structs in expression and pattern
position.
2021-06-10 13:18:41 +02:00
asquared31415
9b2ba6d1a1 Fix ICE when main is declared in an extern block 2021-06-09 23:14:02 -04:00
bors
86b0bafbf1 Auto merge of #84995 - petrochenkov:tcollect, r=Aaron1011
parser: Ensure that all nonterminals have tokens after parsing

`parse_nonterminal` should always result in something with tokens.

This requirement wasn't satisfied in two cases:
- `stmt` nonterminal with expression statements (e.g. `0`, or `{}`, or `path + 1`) because `fn parse_stmt_without_recovery` forgot to propagate `force_collect` in some cases.
- `expr` nonterminal with expressions with built-in attributes (e.g. `#[allow(warnings)] 0`) due to an incorrect optimization in `fn parse_expr_force_collect`, it assumed that all expressions starting with `#` have their tokens collected during parsing, but that's not true if all the attributes on that expression are built-in and inert.

(Discovered when trying to implement eager `cfg` expansion for all attributes https://github.com/rust-lang/rust/pull/83824#issuecomment-817317170.)

r? `@Aaron1011`
2021-06-06 14:00:43 +00:00
Vadim Petrochenkov
cbdfa1edca parser: Ensure that all nonterminals have tokens after parsing 2021-06-06 14:21:12 +03:00
Yuki Okushi
2f0a8556a9
Rollup merge of #86043 - klensy:attr-clone, r=jyn514
don't clone attrs
2021-06-06 19:11:23 +09:00
Camille Gillot
0f0f3138cb
Revert "Reduce the amount of untracked state in TyCtxt" 2021-06-01 09:05:22 +02:00
bjorn3
312f964478 Remove unused feature gates 2021-05-31 13:55:43 +02:00
klensy
56a2a2ae1f don't clone attrs 2021-05-30 22:44:40 +03:00
Camille GILLOT
ee94fbb607 Make allocator_kind a query. 2021-05-30 19:58:01 +02:00
Jacob Pratt
bc2f0fb5a9
Specialize implementations
Implementations in stdlib are now optimized as they were before.
2021-05-26 18:07:09 -04:00
Pietro Albini
9e22b844dd remove cfg(bootstrap) 2021-05-24 11:07:48 -04:00
Ralf Jung
65cd051b4a stabilize const_fn_unsize 2021-05-22 10:35:49 +02:00
jedel1043
059b68dd67 Implement Anonymous{Struct, Union} in the AST
Add unnamed_fields feature gate and gate unnamed fields on parsing
2021-05-16 09:49:16 -05:00
Amanieu d'Antras
5918ee4317 Add support for const operands and options to global_asm!
On x86, the default syntax is also switched to Intel to match asm!
2021-05-13 22:31:57 +01:00