about summary refs log tree commit diff
path: root/compiler/rustc_resolve/src
AgeCommit message (Collapse)AuthorLines
2022-05-07Permit asm_const and asm_sym to reference outer generic paramsGary Guo-32/+25
2022-05-06Rollup merge of #96557 - nbdd0121:const, r=oli-obkGuillaume Gomez-1/+8
Allow inline consts to reference generic params Tracking issue: #76001 The RFC says that inline consts cannot reference to generic parameters (for now), same as array length expressions. And expresses that it's desirable for it to reference in-scope generics, when array length expressions gain that feature as well. However it is possible to implement this for inline consts before doing this for all anon consts, because inline consts are only used as values and they won't be used in the type system. So we can have: ```rust fn foo<T>() { let x = [4i32; std::mem::size_of::<T>()]; // NOT ALLOWED (for now) let x = const { std::mem::size_of::<T>() }; // ALLOWED with this PR! let x = [4i32; const { std::mem::size_of::<T>() }]; // NOT ALLOWED (for now) } ``` This would make inline consts super useful for compile-time checks and assertions: ```rust fn assert_zst<T>() { const { assert!(std::mem::size_of::<T>() == 0) }; } ``` This would create an error during monomorphization when `assert_zst` is instantiated with non-ZST `T`s. A error during mono might sound scary, but this is exactly what a "desugared" inline const would do: ```rust fn assert_zst<T>() { struct F<T>(T); impl<T> F<T> { const V: () = assert!(std::mem::size_of::<T>() == 0); } let _ = F::<T>::V; } ``` It should also be noted that the current inline const implementation can already reference the type params via type inference, so this resolver-level restriction is not any useful either: ```rust fn foo<T>() -> usize { let (_, size): (PhantomData<T>, usize) = const { const fn my_size_of<T>() -> (PhantomData<T>, usize) { (PhantomData, std::mem::size_of::<T>()) } my_size_of() }; size } ``` ```@rustbot``` label: F-inline_const
2022-05-05Implement the unused_macro_rules lintest31-14/+109
2022-05-05Rollup merge of #96507 - TaKO8Ki:suggest-calling-associated-function, r=lcnrMatthias Krüger-34/+80
Suggest calling `Self::associated_function()` closes #96453
2022-05-05suggest calling `Self::associated_function()`Takayuki Maeda-34/+80
do not suggest when trait_ref is some Update compiler/rustc_resolve/src/late/diagnostics.rs Co-authored-by: lcnr <rust@lcnr.de> use helper struct add a test for functions with some params refactor debug log
2022-05-04Stabilize `bool::then_some`Josh Triplett-1/+0
2022-05-04Auto merge of #96353 - estebank:issue-95413, r=compiler-errorsbors-1/+18
When suggesting to import an item, also suggest changing the path if appropriate When we don't find an item we search all of them for an appropriate import and suggest `use`ing it. This is sometimes done for expressions that have paths with more than one segment. We now also suggest changing that path to work with the `use`. Fix #95413
2022-05-03Auto merge of #95380 - compiler-errors:unit-destructure-assign, r=nikomatsakisbors-7/+4
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-03Allow inline consts to reference generic paramsGary Guo-1/+8
2022-05-03Rollup merge of #96641 - oli-obk:bool_args, r=wesleywiserYuki Okushi-28/+50
Use a yes/no enum instead of a bool. The bool's meaning wasn't obvious to me at some call sites.
2022-05-03Tweak wordingEsteban Kuber-5/+4
2022-05-03When suggesting to import an item, also suggest changing the path if appropriateEsteban Küber-4/+22
When we don't find an item we search all of them for an appropriate import and suggest `use`ing it. This is sometimes done for expressions that have paths with more than one segment. We now also suggest changing that path to work with the `use`. Fix #95413
2022-05-02fix most compiler/ doctestsElliot Roberts-15/+15
2022-05-02Use a yes/no enum instead of a bool.Oli Scherer-28/+50
The bool's meaning wasn't obvious to me at some call sites.
2022-05-02Auto merge of #96431 - petrochenkov:parent, r=cjgillotbors-69/+53
rustc: Panic by default in `DefIdTree::parent` Only crate root def-ids don't have a parent, and in majority of cases the argument of `DefIdTree::parent` cannot be a crate root. So we now panic by default in `parent` and introduce a new non-panicing function `opt_parent` for cases where the argument can be a crate root. Same applies to `local_parent`/`opt_local_parent`.
2022-05-02rustc: Panic by default in `DefIdTree::parent`Vadim Petrochenkov-69/+53
Only crate root def-ids don't have a parent, and in majority of cases the argument of `DefIdTree::parent` cannot be a crate root. So we now panic by default in `parent` and introduce a new non-panicing function `opt_parent` for cases where the argument can be a crate root. Same applies to `local_parent`/`opt_local_parent`.
2022-05-01Auto merge of #96521 - petrochenkov:docrules, r=notriddle,GuillaumeGomezbors-14/+19
rustdoc: Resolve doc links referring to `macro_rules` items cc https://github.com/rust-lang/rust/issues/81633 UPD: the fallback to considering *all* `macro_rules` in the crate for unresolved names is not removed in this PR, it will be removed separately and will be run through crater.
2022-05-01resolve: Rename `unusable_binding` to `ignore_binding`Vadim Petrochenkov-54/+41
2022-05-01resolve: Merge `last_import_segment` into `Finalize`Vadim Petrochenkov-44/+16
2022-05-01resolve: Pass full `Finalize` in nearly all casesVadim Petrochenkov-20/+18
2022-05-01resolve: Turn `enum Finalize` into an optional structVadim Petrochenkov-92/+59
2022-05-01rustdoc: Track `macro_rules` scopes during early doc link resolutionVadim Petrochenkov-3/+13
This way links referring to `macro_rules` items are resolved correctly
2022-04-30rustdoc: Keep full `ParentScope` during early doc link resolutionVadim Petrochenkov-11/+6
2022-04-30Store all generic bounds as where predicates.Camille GILLOT-60/+26
2022-04-30Inline WhereClause into Generics.Camille GILLOT-2/+2
2022-04-30Box HIR Generics and Impl.Camille GILLOT-1/+1
2022-04-30Auto merge of #95776 - cjgillot:ast-lifetimes-static, r=petrochenkovbors-70/+70
Enforce static lifetimes in consts during late resolution This PR moves the handling of implicitly and explicitly static lifetimes in constants from HIR to the AST.
2022-04-30Use newtype `enum`s instead of `bool`Esteban Kuber-21/+43
2022-04-30When encountering a binding that could be a const or unit variant, suggest ↵Esteban Kuber-34/+89
the right path
2022-04-30Ban non-static lifetimes from AnonConst on AST.Camille GILLOT-38/+37
The extra diagnostics come from the compiler no longer aborting before typeck.
2022-04-29Rollup merge of #96559 - cjgillot:elided-path-fn, r=petrochenkovDylan DPC-12/+13
Use the correct lifetime binder for elided lifetimes in path. Fixes https://github.com/rust-lang/rust/issues/96540
2022-04-29Remove `error` variable.Camille GILLOT-5/+3
2022-04-29Use the correct lifetime binder for elided lifetimes in path.Camille GILLOT-11/+14
2022-04-29errors: `span_suggestion` takes `impl ToString`David Wood-1/+1
Change `span_suggestion` (and variants) to take `impl ToString` rather than `String` for the suggested code, as this simplifies the requirements on the diagnostic derive. Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-29Ban non-static in const generics in AST.Camille GILLOT-33/+34
2022-04-28Auto merge of #96495 - Dylan-DPC:rollup-9lm4tpp, r=Dylan-DPCbors-3/+1
Rollup of 7 pull requests Successful merges: - #96377 (make `fn() -> _ { .. }` suggestion MachineApplicable) - #96397 (Make EncodeWide implement FusedIterator) - #96421 (Less `NoDelim`) - #96432 (not need `Option` for `dbg_scope`) - #96466 (Better error messages when collecting into `[T; n]`) - #96471 (replace let else with `?`) - #96483 (Add missing `target_feature` to the list of well known cfg names) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-04-28Rollup merge of #96471 - BoxyUwU:let_else_considered_harmful, r=lcnrDylan DPC-3/+1
replace let else with `?` r? `@oli-obk`
2022-04-27Auto merge of #91557 - cjgillot:ast-lifetimes-named, r=petrochenkovbors-50/+202
Perform lifetime resolution on the AST for lowering Lifetime resolution is currently implemented several times. Once during lowering in order to introduce in-band lifetimes, and once in the resolve_lifetimes query. However, due to the global nature of lifetime resolution and how it interferes with hygiene, it is better suited on the AST. This PR implements a first draft of lifetime resolution on the AST. For now, we specifically target named lifetimes and everything we need to remove lifetime resolution from lowering. Some diagnostics have already been ported, and sometimes made more precise using available hygiene information. Follow-up PRs will address in particular the resolution of anonymous lifetimes on the AST. We reuse the rib design of the current resolution framework. Specific `LifetimeRib` and `LifetimeRibKind` types are introduced. The most important variant is `LifetimeRibKind::Generics`, which happens each time we encounter something which may introduce generic lifetime parameters. It can be an item or a `for<...>` binder. The `LifetimeBinderKind` specifies how this rib behaves with respect to in-band lifetimes. r? `@petrochenkov`
2022-04-27Collect extra lifetime parameters during late resolution.Camille GILLOT-9/+44
2022-04-27Use LifetimeRes during lowering.Camille GILLOT-48/+165
2022-04-27Do not resolve elided lifetimes in path twice.Camille GILLOT-1/+1
2022-04-27tut tut tutEllen-3/+1
2022-04-25Auto merge of #96246 - SparrowLii:bound_contxet, r=compiler-errorsbors-6/+6
Add `BoundKind` in `visit_param_bounds` to check questions in bounds From the FIXME in the impl of `AstValidator`. Better bound checks by adding `BoundCtxt` type parameter to `visit_param_bound` cc `@ecstatic-morse`
2022-04-23Compute has_pub_restricted in the resolver.Camille GILLOT-0/+7
2022-04-23Fix lints.Camille GILLOT-1/+8
2022-04-23Drop vis in Item.Camille GILLOT-0/+2
2022-04-23Stop visiting visibility.Camille GILLOT-2/+2
2022-04-21Remove redundant `format!`sNixon Enraght-Moony-2/+2
2022-04-21rename to `BoundKind` and add commentsSparrowLii-6/+6
2022-04-20Add `BoundCtxt` in `visit_param_bounds` to check questions in boundsSparrowLii-6/+6