Commit graph

479 commits

Author SHA1 Message Date
Yuki Okushi 87e373e82f
Rollup merge of #98110 - cjgillot:closure-brace, r=Aaron1011
Make `ExprKind::Closure` a struct variant.

Simple refactor since we both need it to introduce additional fields in `ExprKind::Closure`.

r? ``@Aaron1011``
2022-06-15 19:37:14 +09:00
EdwinRy c8b411ebf1 rename function and remove return type 2022-06-15 01:06:40 +01:00
Takayuki Maeda 77d6176e69 remove unnecessary to_string and String::new 2022-06-13 15:48:40 +09:00
Michael Goulet 5f7474e6dc Address comments 2022-06-11 16:38:48 -07:00
Michael Goulet 9c47afe9fa Handle empty where-clause better 2022-06-11 16:27:01 -07:00
Camille GILLOT 3039cfeb6a Make ExprKind::Closure a struct variant. 2022-06-12 00:16:27 +02:00
Santiago Pastorino 4ae69f8617
Extract lower_generic_and_bounds function 2022-06-07 18:29:07 -03:00
Santiago Pastorino 1e6ed67d37
Extract lower_generic_param_kind 2022-06-07 18:29:07 -03:00
Santiago Pastorino a22aad32eb
Instrument important fns in AST lowering 2022-06-07 18:29:06 -03:00
Camille GILLOT a07290047e Compute lifetimes in scope at diagnostic time. 2022-06-04 15:28:15 +02:00
bors c3384ea35c Auto merge of #97717 - matthiaskrgr:rollup-lalaii2, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #97446 (Make hir().get_generics and generics_of consistent.)
 - #97656 (Add a suggestion to replace parentheses with angle brackets on associated trait constraint)
 - #97692 (Add `#T-types/nominated` zulip notification)
 - #97696 (Do not ICE when failing to normalize during inlining.)
 - #97702 (Remove useless LocalDefId in ImplTraitContext::Universal.)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-06-04 02:10:35 +00:00
bors f15370b4e4 Auto merge of #97670 - spastorino:simplify-universal-impl-trait-lowering2, r=Dylan-DPC
Make params be SmallVec as originally was

r? `@cjgillot`
It was originally a [`SmallVec`](https://github.com/rust-lang/rust/pull/97598/files#diff-0a61b538a3cec072c76fecae4635af6a12ec3256860029ac70549c2aa53ab394L1497), I've mistakenly changed it [here](https://github.com/rust-lang/rust/pull/97598/files#diff-0a61b538a3cec072c76fecae4635af6a12ec3256860029ac70549c2aa53ab394R1377) to a `Vec`
2022-06-03 23:29:30 +00:00
Matthias Krüger a88d94b072
Rollup merge of #97702 - cjgillot:no-universal-did, r=spastorino
Remove useless LocalDefId in ImplTraitContext::Universal.
2022-06-04 00:42:52 +02:00
Matthias Krüger 401be78f2c
Rollup merge of #97656 - EdwinRy:error_ast_low_type_contraint_parentheses, r=cjgillot
Add a suggestion to replace parentheses with angle brackets on associated trait constraint

This implements a requested suggestion FIXME in [`compiler/rustc_ast_lowering/src/lib.rs` ](9598b4b594/compiler/rustc_ast_lowering/src/lib.rs (L921))

The suggestion asks for the parentheses to either be replaced with angle brackets or removed completely depending on whether there are arguments provided within.

![image](https://user-images.githubusercontent.com/20026256/171770414-ab60bfe2-ae27-44b0-964d-9ffcc32a7475.png)

![image](https://user-images.githubusercontent.com/20026256/171770383-ca8a2766-b3aa-43e3-8ba4-ae18874886ce.png)

r? `@oli-obk`
2022-06-04 00:42:50 +02:00
Camille GILLOT 4120080d66 Remove useless LocalDefId in ImplTraitContext::Universal. 2022-06-03 20:17:12 +02:00
EdwinRy cd03fe18d8 Suggest replace parentheses with angle brackets 2022-06-03 16:48:59 +01:00
Camille GILLOT b1294e86bb Manipulate lifetimes by LocalDefId for region resolution. 2022-06-03 12:03:20 +02:00
bors 3a90bedb33 Auto merge of #96296 - cjgillot:remove-label-lt-shadow, r=petrochenkov
Remove label/lifetime shadowing warnings

This PR removes some pre-1.0 shadowing warnings for labels and lifetimes.

The current behaviour of the compiler is to warn
* labels that shadow unrelated labels in the same function --> removed
```rust
'a: loop {}
'a: loop {} // STOP WARNING
```

* labels that shadow enclosing labels --> kept, but only if shadowing is hygienic
```rust
'a: loop {
  'a: loop {} // KEEP WARNING
}
```

* labels that shadow lifetime --> removed
```rust
fn foo<'a>() {
  'a: loop {} // STOP WARNING
}
```

* lifetimes that shadow labels --> removed
```rust
'a: loop {
  let b = Box::new(|x: &i8| *x) as Box<dyn for <'a> Fn(&'a i8) -> i8>; // STOP WARNING
}
```

* lifetimes that shadow lifetimes --> kept
```rust
fn foo<'a>() {
  let b = Box::new(|x: &i8| *x) as Box<dyn for <'a> Fn(&'a i8) -> i8>; // KEEP WARNING
}
```

Closes https://github.com/rust-lang/rust/issues/31745.

-----

From `@petrochenkov` in https://github.com/rust-lang/rust/pull/95781#issuecomment-1105199014
> I think we should remove these silly checks entirely.
> They were introduced long time ago in case some new language features appear and require this space.
> Now we have another mechanism for such language changes - editions, and if "lifetimes in expressions" or something like that needs to be introduced it could be introduced as an edition change.
> However, there was no plans to introduce anything like for years, so it's unlikely that even the edition mechanism will be necessary.

r? rust-lang/lang
2022-06-03 07:27:09 +00:00
Camille GILLOT c75409d5e4 Do not lower generic lifetime params when AST resolution emitted an error. 2022-06-03 08:26:10 +02:00
Santiago Pastorino b051fcaefe
Make params be SmallVec as originally was 2022-06-02 23:42:49 -03:00
bors 42bcd41d4d Auto merge of #97598 - spastorino:simplify-universal-impl-trait-lowering, r=cjgillot
Simplify universal impl trait lowering

Closes #96644

r? `@cjgillot`
2022-06-02 21:37:38 +00:00
Santiago Pastorino 15a82d6917
Always assert that impl_trait_def|bounds are empty at start 2022-06-01 15:38:37 -03:00
Santiago Pastorino 67deaf9fea
instrument lower_fn_decl 2022-06-01 15:02:15 -03:00
Santiago Pastorino 2de2520e94
Split extend + inner chain into to extend calls 2022-06-01 14:48:14 -03:00
Santiago Pastorino b3bc438f56
Add debug_assert comment
Co-authored-by: Camille Gillot <gillot.camille@gmail.com>
2022-06-01 14:43:16 -03:00
est31 0a24b9493b Remove #[rustc_box] attr during lowering 2022-06-01 02:44:12 +02:00
est31 cfc21deebd Add #[rustc_box]
This commit adds an alternative content boxing syntax,
and uses it inside alloc.

The usage inside the very performance relevant code in
liballoc is the only remaining relevant usage of box syntax
in the compiler (outside of tests, which are comparatively
easy to port).

box syntax was originally designed to be used by all Rust
developers. This introduces a replacement syntax more tailored
to only being used inside the Rust compiler, and with it,
lays the groundwork for eventually removing box syntax.
2022-06-01 02:28:34 +02:00
Santiago Pastorino 15f2b119b1
Fix lower_generics rustdocs 2022-05-31 17:40:50 -03:00
Santiago Pastorino 2ade55d908
Inline lower_generics_mut and remove GenericsCtor 2022-05-31 16:57:16 -03:00
Santiago Pastorino d327db9319
Remove ImplTraitContext::reborrow 2022-05-31 16:49:27 -03:00
Santiago Pastorino 208ffbbe86
derive Copy, Clone, PartialEq, Eq for ImplTraitContext 2022-05-31 16:47:53 -03:00
Santiago Pastorino bd3a097d64
Move lower_generics definition to item.rs 2022-05-31 15:33:51 -03:00
Santiago Pastorino d5ab8b2f5b
Rename add_implicit_generics to lower_generics 2022-05-31 15:32:05 -03:00
Santiago Pastorino e080298e35
Replace calls to lower_generics with calls to add_implicit_generics 2022-05-31 15:30:14 -03:00
Santiago Pastorino 190b4a7152
Add itctx: ImplTraitContext arg to add_implicit_generics 2022-05-31 14:55:49 -03:00
Santiago Pastorino 1a71103c93
Take and restore fields in with_hir_id_owner calls 2022-05-31 14:53:32 -03:00
Santiago Pastorino 3d6eae8cd2
Move defs and bounds from Universal to LoweringContext 2022-05-31 12:40:34 -03:00
Vadim Petrochenkov 8e8fb4f49e rustc_parse: Move AST -> TokenStream conversion logic to rustc_ast 2022-05-22 12:01:07 +03:00
Yuki Okushi 6ef4911b99
Rollup merge of #97236 - cjgillot:recover-lifetime-res, r=jackh726
Recover when resolution did not resolve lifetimes.

This can happen for items inside a foreign fn's body, which are not visited at all.

Fixes https://github.com/rust-lang/rust/issues/97193
Fixes https://github.com/rust-lang/rust/issues/97194
2022-05-22 11:53:07 +09:00
Camille GILLOT 075429f76b Recover when resolution did not resolve lifetimes. 2022-05-21 09:39:41 +02:00
Jacob Pratt 49c82f31a8
Remove crate visibility usage in compiler 2022-05-20 20:04:54 -04:00
bors 07ae142d77 Auto merge of #96863 - SparrowLii:let, r=michaelwoerister
use `hir::Let` in `hir::Guard::IfLet`

This PR fixes the FIXME about using `hir::Let` in `hir::Guard::IfLet`
2022-05-18 17:48:46 +00:00
SparrowLii 5251a80c0a use hir::Let in hir::Guard 2022-05-09 20:35:58 +08:00
bors ed3164baf0 Auto merge of #96770 - flip1995:fix-trait-type-in-bounds, r=cjgillot
Track if a where bound comes from a impl Trait desugar

With https://github.com/rust-lang/rust/pull/93803 `impl Trait` function arguments get desugared to hidden where bounds. However, Clippy needs to know if a bound was originally a `impl Trait` or an actual bound. This adds a field to the `WhereBoundPredicate` struct to keep track of this information during AST->HIR lowering.

r? `@cjgillot`

cc `@estebank` (as the reviewer of #93803)
2022-05-08 14:10:12 +00:00
flip1995 dd1ff405e3
Track if a where bound comes from a impl Trait desugar
With #93803 `impl Trait` function arguments get desugared to hidden
where bounds. However, Clippy needs to know if a bound was originally a
impl Trait or an actual bound. This adds a field to the
`WhereBoundPredicate` struct to keep track of this information during
HIR lowering.
2022-05-07 17:10:30 +02:00
bors 574830f573 Auto merge of #96094 - Elliot-Roberts:fix_doctests, r=compiler-errors
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-07 06:30:29 +00:00
bors 4c60a0ea5b Auto merge of #96546 - nnethercote:overhaul-MacArgs, r=petrochenkov
Overhaul `MacArgs`

Motivation:
- Clarify some code that I found hard to understand.
- Eliminate one use of three places where `TokenKind::Interpolated` values are created.

r? `@petrochenkov`
2022-05-04 21:16:28 +00:00
Nicholas Nethercote 99f5945f85 Overhaul MacArgs::Eq.
The value in `MacArgs::Eq` is currently represented as a `Token`.
Because of `TokenKind::Interpolated`, `Token` can be either a token or
an arbitrary AST fragment. In practice, a `MacArgs::Eq` starts out as a
literal or macro call AST fragment, and then is later lowered to a
literal token. But this is very non-obvious. `Token` is a much more
general type than what is needed.

This commit restricts things, by introducing a new type `MacArgsEqKind`
that is either an AST expression (pre-lowering) or an AST literal
(post-lowering). The downside is that the code is a bit more verbose in
a few places. The benefit is that makes it much clearer what the
possibilities are (though also shorter in some other places). Also, it
removes one use of `TokenKind::Interpolated`, taking us a step closer to
removing that variant, which will let us make `Token` impl `Copy` and
remove many "handle Interpolated" code paths in the parser.

Things to note:
- Error messages have improved. Messages like this:
  ```
  unexpected token: `"bug" + "found"`
  ```
  now say "unexpected expression", which makes more sense. Although
  arbitrary expressions can exist within tokens thanks to
  `TokenKind::Interpolated`, that's not obvious to anyone who doesn't
  know compiler internals.
- In `parse_mac_args_common`, we no longer need to collect tokens for
  the value expression.
2022-05-05 07:06:12 +10:00
bors 1b2e0b60cc Auto merge of #95380 - compiler-errors:unit-destructure-assign, r=nikomatsakis
Fix unit struct/enum variant in destructuring assignment

See https://github.com/rust-lang/rfcs/blob/master/text/2909-destructuring-assignment.md#guide-level-explanation, "including **unit** and tuple structs"

Fixes #94319
2022-05-03 22:29:58 +00:00
Elliot Roberts 7907385999 fix most compiler/ doctests 2022-05-02 17:40:30 -07:00