Commit graph

503 commits

Author SHA1 Message Date
bors 38b72154de Auto merge of #98637 - cjgillot:bare-trait-anon-lt, r=petrochenkov
Create fresh lifetime parameters for bare fn trait too

The current code fails to account for the equivalence between `dyn FnMut(&mut u8)` and bare `FnMut(&mut u8)`, and treated them differently.

This PR introduces a special case for `Fn` traits, which are always fully resolved.

Fixes #98616
Fixes #98726
This will require a beta-backport, as beta contains that bug.

r? `@petrochenkov`
2022-07-11 17:09:37 +00:00
bors 0f573a0c54 Auto merge of #95573 - cjgillot:lower-query, r=michaelwoerister
Make lowering a query

Split from https://github.com/rust-lang/rust/pull/88186.

This PR refactors the relationship between lowering and the resolver outputs in order to make lowering itself a query.
In a first part, lowering is changed to avoid modifying resolver outputs, by maintaining its own data structures for creating new `NodeId`s and so.

Then, the `TyCtxt` is modified to allow creating new `LocalDefId`s from inside it. This is done by:
- enclosing `Definitions` in a lock, so as to allow modification;
- creating a query `register_def` whose purpose is to declare a `LocalDefId` to the query system.

See `TyCtxt::create_def` and `TyCtxt::iter_local_def_id` for more detailed explanations of the design.
2022-07-07 18:14:44 +00:00
bors e78e747f53 Auto merge of #98827 - aDotInTheVoid:suggest-extern-block, r=nagisa
Suggest using block for `extern "abi" fn` with no body

`@rustbot` modify labels: +A-diagnostics
2022-07-07 04:18:47 +00:00
Camille GILLOT 32a30cad03 Use DefIdTree instead of re-implementing it. 2022-07-06 23:30:00 +02:00
Camille GILLOT 8fc3deb1b4 Remove sess field from LoweringContext. 2022-07-06 23:15:57 +02:00
Camille GILLOT 74be945820 Expand comment in with_hir_id_owner. 2022-07-06 23:15:11 +02:00
Camille GILLOT 682f57656e Do not create a new NodeId when not used. 2022-07-06 23:10:36 +02:00
Camille GILLOT fb060fb774 Remove useless branch. 2022-07-06 23:09:29 +02:00
Camille GILLOT 250c71b85d Make AST lowering a query. 2022-07-06 23:04:55 +02:00
Nixon Enraght-Moony 18ca2946e0 ast: Add span to Extern 2022-07-02 23:30:03 +01:00
Camille GILLOT 21a12e8ab7 Handle fresh lifetimes on bare trait objects. 2022-07-02 09:21:55 +02:00
Cameron Steffen ec82bc1996 Factor out hir::Node::Binding 2022-07-01 10:04:19 -05:00
Nicholas Nethercote 7c40661ddb Update smallvec to 1.8.1.
This pulls in https://github.com/servo/rust-smallvec/pull/282, which
gives some small wins for rustc.
2022-06-27 08:48:55 +10:00
Camille GILLOT 7437136f0e Use CreateParameter mode for closures too. 2022-06-21 21:13:43 +02:00
Camille GILLOT 32af719b07 Always create parameters for functions-like types. 2022-06-21 21:13:41 +02:00
Camille GILLOT bc6a2c11ee Leave the responsibility to create Fresh lifetimes to lowering. 2022-06-19 22:32:43 +02:00
bors 3a8b0144c8 Auto merge of #98106 - cjgillot:split-definitions, r=michaelwoerister
Split up `Definitions` and `ResolverAstLowering`.

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

r? `@michaelwoerister`
2022-06-17 10:00:11 +00:00
Yuki Okushi bfc6c90115
Rollup merge of #98119 - EdwinRy:path-parenthesized-type-error, r=estebank
Refactor path segment parameter error

This PR attempts to rewrite the error handling for an unexpected parenthesised type parameters to:
- Use provided data instead of re-parsing the whole span
- Add a multipart suggestion to reflect on the changes with an underline
- Remove the unnecessary "if" nesting
2022-06-16 07:24:43 +09:00
Camille GILLOT ae5959f4ba Consume resolutions for lowering separately. 2022-06-15 19:42:43 +02:00
Camille GILLOT 8ffbd814af Update next_node_id. 2022-06-15 19:41:41 +02:00
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 71a98e1a4e Refactor path segment parameter error 2022-06-15 02:50:34 +01:00
EdwinRy c8b411ebf1 rename function and remove return type 2022-06-15 01:06:40 +01:00
Camille GILLOT 34e4d72929 Separate source_span and expn_that_defined from Definitions. 2022-06-14 22:45:51 +02:00
Camille GILLOT b676edd641 Do not modify the resolver outputs. 2022-06-14 22:44:27 +02:00
Camille GILLOT 603746a35e Make ResolverAstLowering a struct. 2022-06-14 22:44:27 +02: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