Commit Graph

554 Commits

Author SHA1 Message Date
Tomasz Miąsko
39d9c1cb1f Move predecessors from Body to BasicBlocks 2022-07-07 08:11:49 +02:00
Takayuki Maeda
83dea35384 replace guess_head_span with def_span 2022-07-06 19:09:47 +09:00
Alan Egerton
4f0a64736b
Update TypeVisitor paths 2022-07-06 06:41:53 +01:00
Alan Egerton
e9e5d0685b
Relax constrained generics to TypeVisitable 2022-07-05 22:25:43 +01:00
Matthias Krüger
cb2d3bb198
Rollup merge of #98878 - lcnr:more-rustc_pass_by_value, r=oli-obk
add more `rustc_pass_by_value`

r? ```@oli-obk``` cc #98766
2022-07-04 23:11:12 +02:00
lcnr
8deadfa271 fully move dropck to mir 2022-07-04 10:26:23 +02:00
lcnr
658b7f3652 more rustc_pass_by_value 2022-07-04 09:40:58 +02:00
bors
ada8c80bed Auto merge of #98673 - pietroalbini:pa-bootstrap-update, r=Mark-Simulacrum
Bump bootstrap compiler

r? `@Mark-Simulacrum`
2022-07-03 06:55:50 +00:00
Dylan DPC
05aebf8f69
Rollup merge of #98766 - lcnr:mir-visit-pass_by_value, r=oli-obk
cleanup mir visitor for `rustc::pass_by_value`

by changing `& $($mutability)?` to `$(& $mutability)?`

I also did some formatting changes because I started doing them for the visit methods I changed and then couldn't get myself to stop xx, I hope that's still fairly easy to review.
2022-07-02 12:23:41 +05:30
Cameron Steffen
ec82bc1996 Factor out hir::Node::Binding 2022-07-01 10:04:19 -05:00
lcnr
cf9c0a5935 cleanup mir visitor for rustc::pass_by_value 2022-07-01 16:21:21 +02:00
Pietro Albini
6b2d3d5f3c
update cfg(bootstrap)s 2022-07-01 15:48:23 +02:00
Niko Matsakis
7fda86249f promote placeholder bounds to 'static obligations
In NLL, when we are promoting a bound out from a closure,
if we have a requirement that `T: 'a` where `'a` is in a
higher universe, we were previously ignoring that, which is
totally wrong. We should be promoting those constraints to `'static`,
since universes are not expressible across closure boundaries.
2022-06-30 10:49:23 -04:00
Dylan DPC
d10497bba2
Rollup merge of #98415 - compiler-errors:rustc-borrowck-session-diagnostic-1, r=davidtwco
Migrate some `rustc_borrowck` diagnostics to `SessionDiagnostic`

Self-explanatory

r? ```@davidtwco```
2022-06-29 17:59:31 +05:30
bors
66c83ffca1 Auto merge of #98558 - nnethercote:smallvec-1.8.1, r=lqd
Update `smallvec` to 1.8.1.

This pulls in https://github.com/servo/rust-smallvec/pull/282, which
gives some small wins for rustc.

r? `@lqd`
2022-06-29 09:11:29 +00:00
Michael Goulet
98af1bfecc Migrate some rustc_borrowck diagnostics to SessionDiagnostic 2022-06-28 22:41:56 +00:00
Michael Goulet
8fd73560b3 Do not use a suggestion to change a binding's name to a type 2022-06-28 22:34:13 +00:00
Michael Goulet
f4fdcc7e24 Remove redundant logic to suggest as_ref 2022-06-28 22:34:13 +00:00
Dylan DPC
400f435c2d
Rollup merge of #98420 - davidtwco:translation-lint-fixes-and-more-migration, r=compiler-errors
translation: lint fix + more migration

- Unfortunately, the diagnostic lints are very broken and trigger much more often than they should. This PR corrects the conditional which checks if the function call being made is to a diagnostic function so that it returns in every intended case.
- The `rustc_lint_diagnostics` attribute is used by the diagnostic translation/struct migration lints to identify calls where non-translatable diagnostics or diagnostics outwith impls are being created. Any function used in creating a diagnostic should be annotated with this attribute so this PR adds the attribute to many more functions.
- Port the diagnostics from the `rustc_privacy` crate and enable the lints for that crate.

r? ``@compiler-errors``
2022-06-28 15:30:04 +05:30
lcnr
70497d9d10 fold_region: remove unused parameter 2022-06-27 15:55:03 +02:00
lcnr
4dbf9ba0ab outside of borrowck, do not provide an implicit_region_bound
see comment added to the field in `VerifyBoundCx`.
2022-06-27 15:48:54 +02:00
David Wood
ae612241dc various: add rustc_lint_diagnostics to diag fns
The `rustc_lint_diagnostics` attribute is used by the diagnostic
translation/struct migration lints to identify calls where
non-translatable diagnostics or diagnostics outwith impls are being
created. Any function used in creating a diagnostic should be annotated
with this attribute so this commit adds the attribute to many more
functions.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-27 08:32:06 +01: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
bors
d017d59ed0 Auto merge of #98109 - nikomatsakis:issue-98095, r=jackh726
fix universes in the NLL type tests

In the NLL code, we were not accommodating universes in the
`type_test` logic.

Fixes #98095.

r? `@compiler-errors`

This breaks some tests, however, so the purpose of this branch is more explanatory and perhaps to do a crater run.
2022-06-24 07:39:28 +00:00
Michael Goulet
49bcc70574
Rollup merge of #98184 - compiler-errors:elided-lifetime-in-impl-nll, r=cjgillot
Give name if anonymous region appears in impl signature

Fixes #98170

We probably should remove the two unwraps in [`report_general_error`](https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_borrowck/diagnostics/region_errors.rs.html#683-685), but I have no idea what to provide if those regions are missing, so I've kept those in. Let me know if I should try harder to remove those.
2022-06-23 14:39:06 -07:00
Niko Matsakis
e93e10516e run x.py fmt 2022-06-23 17:00:46 -04:00
Niko Matsakis
e6b630c5b1
apply suggestions from oli-obk
Co-authored-by: Oli Scherer <github35764891676564198441@oli-obk.de>
2022-06-23 16:40:06 -04:00
Niko Matsakis
27e0f7a886 rename IfEqBound to IfEq 2022-06-23 16:35:47 -04:00
Niko Matsakis
893b919e64 remove VerifyBound::IfEq variant 2022-06-23 16:28:46 -04:00
bors
10f4ce324b Auto merge of #98279 - cjgillot:all-fresh-nofn, r=petrochenkov
Create elided lifetime parameters for function-like types

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

This PR refactor lifetime generic parameters in bare function types and parenthesized traits to introduce the additional required lifetimes as fresh parameters in a `for<>` bound.

This PR does the same to lifetimes appearing in closure signatures, and as-if introducing `for<>` bounds on closures (without the associated change in semantics).

r? `@petrochenkov`
2022-06-22 10:48:58 +00:00
Yuki Okushi
a7f789b502
Rollup merge of #98022 - compiler-errors:erroneous-borrowck-span, r=oli-obk
Fix erroneous span for borrowck error

I am not confident that this is the correct fix, but it does the job. Open to suggestions for a real fix instead.

Fixes #97997

The issue is that we pass a [dummy location](https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_middle/mir/visit.rs.html#302) when type-checking the ["required consts"](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/struct.Body.html#structfield.required_consts) that are needed by the MIR body during borrowck. This means that when we fail to evaluate the constant, we use the span of `bb0[0]`, instead of the actual span of the constant.

There are quite a few other places that use `START_BLOCK.start_location()`, `Location::START`, etc. when calling for a random/unspecified `Location` value. This is because, unlike (for example) `Span`, we don't have a dummy/miscellaneous value to use instead. I would appreciate guidance (either in this PR, or a follow-up) on what needs to be done to clean this up in general.
2022-06-21 20:08:10 +09:00
Michael Goulet
e900a35496 Give name if anonymous region appears in impl signature 2022-06-20 20:56:51 -07:00
Camille GILLOT
4b79b8bfa1 Only use special async fn case for actual async fns in borrowck diagnostics. 2022-06-19 23:30:43 +02:00
Jack Huey
1e9f8df6bb Move RegionKind to rustc_type_ir 2022-06-19 00:20:27 -04:00
Niko Matsakis
12912b9cde fix universes in the NLL type tests
In the NLL code, we were not accommodating universes in the
`type_test` logic. This led to issue 98095.
2022-06-15 17:28:05 -04:00
Niko Matsakis
c5ed318b22 implement (unused) matching solver 2022-06-15 11:47:04 -04:00
Niko Matsakis
d203c13db2 simply the IfEq bound -- we only ever use a region
the excessive generality becomes annoying later because
it wouldn't implement type folding etc
2022-06-15 11:47:04 -04: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
Nicholas Nethercote
93e4b6ef06 Rename the ConstS::val field as kind.
And likewise for the `Const::val` method.

Because its type is called `ConstKind`. Also `val` is a confusing name
because `ConstKind` is an enum with seven variants, one of which is
called `Value`. Also, this gives consistency with `TyS` and `PredicateS`
which have `kind` fields.

The commit also renames a few `Const` variables from `val` to `c`, to
avoid confusion with the `ConstKind::Value` variant.
2022-06-14 13:06:44 +10:00
Takayuki Maeda
77d6176e69 remove unnecessary to_string and String::new 2022-06-13 15:48:40 +09:00
Michael Goulet
ccf6124bd9 Fix erroneous span for borrowck error 2022-06-12 02:40:54 -07:00
Camille GILLOT
3039cfeb6a Make ExprKind::Closure a struct variant. 2022-06-12 00:16:27 +02:00
lcnr
cc013e05b4 bound_vars -> infer: don't return lt map 2022-06-10 10:09:50 +02:00
lcnr
434c7da6ea only expect lb lt for fn calls in mir typeck 2022-06-10 10:09:50 +02:00
bors
b17e9d76f2 Auto merge of #97081 - oli-obk:outlives_query_fast_path, r=jackh726
Re-use the type op instead of calling the implied_outlives_bounds query directly

r? `@ghost`
2022-06-07 21:44:40 +00:00
Dylan DPC
53ab3b2e6e
Rollup merge of #97415 - cjgillot:is-late-bound-solo, r=estebank
Compute `is_late_bound_map` query separately from lifetime resolution

This query is actually very simple, and is only useful for functions and method.  It can be computed directly by fetching the HIR, with no need to embed it within the lifetime resolution visitor.

Based on https://github.com/rust-lang/rust/pull/96296
2022-06-03 17:10:51 +02:00
Camille GILLOT
ba40fe99c3 Compute is_late_bound in a separate query.
The computation is actually much simpler, and can be done by directly
fetching the HIR for the `FnDecl` and its generics.
2022-06-03 12:05:04 +02:00
Camille GILLOT
b1294e86bb Manipulate lifetimes by LocalDefId for region resolution. 2022-06-03 12:03:20 +02:00
Dylan DPC
f116dd76ed
Rollup merge of #97653 - RalfJung:int-to-ptr, r=oli-obk
add cast kind of from_exposed_addr (int-to-ptr casts)

This is basically the dual to https://github.com/rust-lang/rust/pull/97582, for int2ptr casts.

Cc `@tmiasko` https://github.com/rust-lang/rust/issues/97649
2022-06-03 11:18:24 +02:00
Ralf Jung
fafccdced3 add cast kind of from_exposed_addr (int-to-ptr casts) 2022-06-02 10:46:13 -04:00
Dylan DPC
5c041f98fa
Rollup merge of #97023 - cjgillot:uniform-anon, r=estebank
Diagnose anonymous lifetimes errors more uniformly between async and regular fns

Async fns and regular fns are desugared differently.  For the former, we create a generic parameter at HIR level.  For the latter, we just create an anonymous region for typeck.

I plan to migrate regular fns to the async fn desugaring.

Before that, this PR attempts to merge the diagnostics for both cases.

r? ```@estebank```
2022-06-02 11:13:22 +02:00
Ralf Jung
4dc5d457d8 rename PointerAddress → PointerExposeAddress 2022-06-01 14:08:17 -04:00
Tomasz Miąsko
dff602fc18 Add a pointer to address cast kind
A pointer to address cast are often special-cased.
Introduce a dedicated cast kind to make them easy distinguishable.
2022-05-31 00:00:00 +00:00
Camille GILLOT
3162b33ce5 Handle anonymous lifetimes properly in diagnostics. 2022-05-29 12:16:09 +02:00
Michael Goulet
34e05812e0 Fix TyKind lint, make consts no longer fn, etc 2022-05-28 11:38:22 -07:00
Michael Goulet
a056a953f0 Initial fixes on top of type interner commit 2022-05-28 11:38:22 -07:00
bors
ed76b773b5 Auto merge of #97284 - b-naber:constraint-dyn-impl-suggestion, r=estebank
Add suggestion for relaxing static lifetime bounds on dyn trait impls in NLL

This PR introduces suggestions for relaxing static lifetime bounds on impls of dyn trait items for NLL similar to what is already available in lexical region diagnostics.

Fixes https://github.com/rust-lang/rust/issues/95701

r? `@estebank`
2022-05-28 04:04:29 +00:00
Matthias Krüger
5fc8a8e227 clippy::complexity fixes
clone_on_copy
useless_format
bind_instead_of_map
filter_map_identity
useless_conversion
map_flatten
unnecessary_unwrap
2022-05-26 13:14:24 +02:00
b-naber
3c6c8d5a8d rebase, use Ty in CallArgument and re-insert static_assert_size on ConstraintCategory 2022-05-26 10:11:58 +02:00
b-naber
5f65331b3e suggest constraining dyn trait in impl in NLL 2022-05-25 18:13:17 +02:00
b-naber
99fa572ab1 add def_id and substs to ConstraintCategory::CallArgument 2022-05-25 18:13:03 +02:00
Jakob Degen
09b0936db2 Refactor call terminator to always hold a destination place 2022-05-23 17:49:04 -04:00
Michael Goulet
1784634a39 Lifetime variance fixes for rustc 2022-05-22 14:29:32 -07:00
Jacob Pratt
49c82f31a8
Remove crate visibility usage in compiler 2022-05-20 20:04:54 -04:00
SparrowLii
38bf1158bd Change Successors to impl Iterator<Item = BasicBlock> 2022-05-17 08:41:01 +08:00
Oli Scherer
340e708634 Some tracing cleanups 2022-05-16 14:23:15 +00:00
bors
2a8a0fc423 Auto merge of #96883 - jackh726:early-binder-2, r=oli-obk
Add EarlyBinder

Chalk has no concept of `Param` (e0ade19d13/chalk-ir/src/lib.rs (L579)) or `ReEarlyBound` (e0ade19d13/chalk-ir/src/lib.rs (L1308)). Everything  is just "bound" - the equivalent of rustc's late-bound. It's not completely clear yet whether to move everything to the same time of binder in rustc or add `Param` and `ReEarlyBound` in Chalk.

Either way, tracking when we have or haven't already substituted out these in rustc can be helpful.

As a first step, I'm just adding a `EarlyBinder` newtype that is required to call `subst`. I also add a couple "transparent" `bound_*` wrappers around a couple query that are often immediately substituted.

r? `@nikomatsakis`
2022-05-14 23:53:11 +00:00
Jack Huey
c92248ab9f Add bound_type_of 2022-05-13 18:27:18 -04:00
Oli Scherer
7a4ac84a90 For non-defining opaque type usage errors, don't try to also prove all trait bounds 2022-05-13 10:09:11 +00:00
Jack Huey
319575ae8c Introduce EarlyBinder 2022-05-10 22:47:18 -04:00
bors
eead58e75b Auto merge of #96736 - oli-obk:tait_missing_wf_check, r=davidtwco
Check hidden types for well formedness at the definition site instead of only at the opaque type itself

work towards #90409 . We'll need to look into closure and generator bodies of closures and generators nested inside the hidden type in order to fix that. In hindsight this PR is not necessary for that, but it may be a bit easier with it and we'll get better diagnostics from it on its own.
2022-05-10 13:39:43 +00:00
Oli Scherer
f667e952f8 Check hidden types for well formedness at the definition site instead of only at the opaque type itself 2022-05-10 07:20:00 +00: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
Guillaume Gomez
c3ddd59f5b
Rollup merge of #96733 - SparrowLii:place_to_string, r=davidtwco
turn `append_place_to_string` from recursion into iteration

This PR fixes the FIXME in the impl of `append_place_to_string` which turns `append_place_to_string` from recursion into iteration, meanwhile simplifying the code relatively.
2022-05-06 20:05:40 +02:00
bors
9a251644fa Auto merge of #96268 - jackh726:remove-mutable_borrow_reservation_conflict-lint, r=nikomatsakis
Remove mutable_borrow_reservation_conflict lint and allow the code pattern

This was the only breaking issue with the NLL stabilization PR. Lang team decided to go ahead and allow this.

r? `@nikomatsakis`
Closes #59159
Closes #56254
2022-05-06 12:32:44 +00:00
SparrowLii
8ff01894a0 turn append_place_to_string from recursion into iteration 2022-05-06 12:11:42 +08:00
Josh Triplett
0fc5c524f5 Stabilize bool::then_some 2022-05-04 13:22:08 +02:00
Elliot Roberts
7907385999 fix most compiler/ doctests 2022-05-02 17:40:30 -07:00
Vadim Petrochenkov
5b5964f569 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-02 01:56:50 +03:00
bors
a707f40107 Auto merge of #95819 - oli-obk:mir_can't_hold_all_these_lifetimes, r=estebank
Enforce Copy bounds for repeat elements while considering lifetimes

fixes https://github.com/rust-lang/rust/issues/95477

this is a breaking change in order to fix a soundness bug.

Before this PR we only checked whether the repeat element type had an `impl Copy`, but not whether that impl also had the appropriate lifetimes. E.g. if the impl was for `YourType<'static>` and not a general `'a`, then copying any type other than a `'static` one should have been rejected, but wasn't.

r? `@lcnr`
2022-04-29 20:00:47 +00:00
David Wood
73fa217bc1 errors: span_suggestion takes impl ToString
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-29 02:05:20 +01:00
Oli Scherer
4e6e68e27a Check that repeat expression elements are Copy (ignoring lifetimes) in typeck and that they are Copy (with proper lifetime checks) in borrowck 2022-04-28 09:19:42 +00:00
marmeladema
2c94218238 Recover suggestions to introduce named lifetime under NLL 2022-04-27 22:36:40 +02:00
Dylan DPC
dc1f98c655
Rollup merge of #96385 - marmeladema:nll-fix-trait-lifetime-bound-suggestions, r=jackh726
Recover most `impl Trait` and `dyn Trait` lifetime bound suggestions under NLL

This is done by replacing the duplicated (and very partial) implementation from borrowck with one inspsired from `NiceRegionError::try_report_static_impl_trait` and by re-using `suggest_new_region_bound`.

Fixes #96277

r? ```@jackh726```
2022-04-27 02:47:11 +02:00
SparrowLii
74853eedfe simplify describe_field func in borrowck's diagnostics part 2022-04-25 16:09:36 +08:00
marmeladema
e1b074a2a8 Recover most impl Trait and dyn Trait lifetime bound suggestions under NLL 2022-04-25 09:14:44 +02:00
Matthias Krüger
aef9eb50cd
Rollup merge of #96352 - marmeladema:fix-nll-lifetime-bound-suggestions, r=jackh726
Improve span for `consider adding an explicit lifetime bound` suggestions under NLL

Because NLL borrowck is run after typeck, `in_progress_typeck_results` was always `None` which was preventing the retrieval of the span to which the suggestion is suppose to add the lifetime bound.
We now manually pass the `LocalDefId` owner to `construct_generic_bound_failure` so that under NLL, we give the owner id of the current body.

This helps with #96332
2022-04-24 18:00:27 +02:00
SparrowLii
a34e1b58cb make classify_drop_access_kind iterate 2022-04-24 17:27:05 +08:00
marmeladema
53120b59ae Recover missing suggestion part under NLL 2022-04-24 09:36:23 +02:00
marmeladema
7b0db3e7c8 Improve span for consider adding an explicit lifetime bound suggestions under NLL
Because NLL borrowck is run after typeck, `in_progress_typeck_results`
was always `None` which was preventing the retrieval of the span to which
the suggestion is suppose to add the lifetime bound.

We now manually pass the `LocalDefId` owner to `construct_generic_bound_failure`
so that under NLL, we give the owner id of the current body.
2022-04-24 09:34:50 +02:00
Matthias Krüger
eeed267215
Rollup merge of #96315 - SparrowLii:graph_lt, r=petrochenkov
Make the lifetime accurate which is used in the region constraints part

This PR fixes the FIXME about lifetime using in the region constraints part.
We cannot write `<'graph, 'tcx, D>` because the definition of `Successors<'0, '1, D>` requires `'1 : '0`.
We cannot add bound to `'graph` either because `'graph` is required to be an arbitrary value in the definition of `WithSuccessors`
So the most accurate way is to use `<'s, 'tcx, D>`.
cc `@Aaron1011` who added this FIXME in #85343
2022-04-22 18:56:26 +02:00
SparrowLii
343523cbf1 Make the lifetime accurate which is used in the region constraints part 2022-04-22 20:05:39 +08:00
Dylan DPC
18b6ad327f
Rollup merge of #96248 - TaKO8Ki:remove-unnecessary-format-args, r=compiler-errors
Stop using a string literal as a format argument
2022-04-21 20:55:19 +02:00
Jack Huey
2300401fb0 Remove mutable_borrow_reservation_conflict lint 2022-04-20 22:10:46 -04:00
Takayuki Maeda
5078b053b5 remove an unnecessary format arg 2022-04-20 21:16:56 +09:00
Aaron Hill
611a06a375
Add an explicit Span field to OutlivesConstraint
Previously, we would retrieve the span from the `Body` using
the `locations` field. However, we may end up changing the
`locations` field when moving a constraint from a promoted
to a different body.

We now store the original `Span` in a dedication field, so that
changes to the `locations` do not affect the quality of our
diagnostics.
2022-04-19 23:42:20 -04:00
Camille GILLOT
a9e13fa553 Lint elided lifetimes in path on the AST. 2022-04-17 11:03:34 +02:00
Jakob Degen
48b01a0d0e Add new MutatatingUseContexts for deinit and SetDiscriminant 2022-04-11 09:26:26 -04:00
Jakob Degen
9b6b1a625b Add new Deinit statement kind 2022-04-11 08:55:03 -04:00
bors
1f7fb6413d Auto merge of #95889 - Dylan-DPC:rollup-1cmywu4, r=Dylan-DPC
Rollup of 7 pull requests

Successful merges:

 - #95566 (Avoid duplication of doc comments in `std::char` constants and functions)
 - #95784 (Suggest replacing `typeof(...)` with an actual type)
 - #95807 (Suggest adding a local for vector to fix borrowck errors)
 - #95849 (Check for git submodules in non-git source tree.)
 - #95852 (Fix missing space in lossy provenance cast lint)
 - #95857 (Allow multiple derefs to be splitted in deref_separator)
 - #95868 (rustdoc: Reduce allocations in a `html::markdown` function)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-04-10 21:01:13 +00:00
Dylan DPC
c172544848
Rollup merge of #95807 - TaKO8Ki:suggest-local-var-for-vector, r=fee1-dead
Suggest adding a local for vector to fix borrowck errors

closes #95574
2022-04-10 21:03:35 +02:00
Camille GILLOT
69d8183337 Store LocalDefId in is_late_bound_map.
This allows to avoid looking at HIR from borrowck.
2022-04-10 13:36:06 +02:00
Camille GILLOT
db03a2deb0 Avoid accessing HIR from MIR queries. 2022-04-10 13:08:36 +02:00
Takayuki Maeda
470b4fca0e use format-args-capture and remove unnecessary nested blocks 2022-04-09 00:01:40 +09:00
Takayuki Maeda
71fea61bc9 suggest adding a local for vector to fix borrowck errors 2022-04-08 23:17:57 +09:00
Oli Scherer
7d2cad68d2 Deduplicate the error printing code for hidden type mismatches 2022-04-07 13:52:59 +00:00
Oli Scherer
25876b3541 Report opaque type mismatches directly during borrowck of the function instead of within the type_of query.
This allows us to only store a single hidden type per opaque type instead of having to store one per set of substitutions.
2022-04-07 13:39:52 +00:00
Oli Scherer
27dc503556 Check that all hidden types are the same and then deduplicate them. 2022-04-06 15:02:37 +00:00
Dylan DPC
68329648ac
Rollup merge of #95670 - TaKO8Ki:remove-unused-function-parameters, r=davidtwco
Refactor: remove unused function parameters
2022-04-05 15:56:51 +02:00
Takayuki Maeda
975980427b remove unused function parameters 2022-04-05 19:33:22 +09:00
Dylan DPC
2a7e7bd0e0
Rollup merge of #95607 - compiler-errors:issue-95272, r=Aaron1011
Note invariance reason for FnDef types

Fixes #95272. Is it worthwhile even printing a variance explanation here? Or should I try to track down which function parameter is responsible for the invariance?

r? ``@Aaron1011`` since you wrote #89336
2022-04-05 09:33:23 +02:00
David Wood
7f91697b50 errors: implement fallback diagnostic translation
This commit updates the signatures of all diagnostic functions to accept
types that can be converted into a `DiagnosticMessage`. This enables
existing diagnostic calls to continue to work as before and Fluent
identifiers to be provided. The `SessionDiagnostic` derive just
generates normal diagnostic calls, so these APIs had to be modified to
accept Fluent identifiers.

In addition, loading of the "fallback" Fluent bundle, which contains the
built-in English messages, has been implemented.

Each diagnostic now has "arguments" which correspond to variables in the
Fluent messages (necessary to render a Fluent message) but no API for
adding arguments has been added yet. Therefore, diagnostics (that do not
require interpolation) can be converted to use Fluent identifiers and
will be output as before.
2022-04-05 07:01:02 +01:00
David Wood
c45f29595d span: move MultiSpan
`MultiSpan` contains labels, which are more complicated with the
introduction of diagnostic translation and will use types from
`rustc_errors` - however, `rustc_errors` depends on `rustc_span` so
`rustc_span` cannot use types like `DiagnosticMessage` without
dependency cycles. Introduce a new `rustc_error_messages` crate that can
contain `DiagnosticMessage` and `MultiSpan`.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-05 07:01:00 +01:00
Michael Goulet
2a129d4fa5 Format invariance notes with backticks 2022-04-04 20:26:31 -07:00
Michael Goulet
a8877cf738 Handle reporting invariance of fn pointer 2022-04-04 19:37:14 -07:00
lcnr
89c66eb42d update comment 2022-03-31 15:41:52 +02:00
lcnr
d7cada1767 obligation cause: RepeatVec -> RepeatValueCopy 2022-03-31 12:51:46 +02:00
Dylan DPC
1b7d6dbd30
Rollup merge of #95497 - nyurik:compiler-spell-comments, r=compiler-errors
Spellchecking compiler comments

This PR cleans up the rest of the spelling mistakes in the compiler comments. This PR does not change any literal or code spelling issues.
2022-03-31 04:57:28 +02:00
bors
a40c595695 Auto merge of #95436 - cjgillot:static-mut, r=oli-obk
Remember mutability in `DefKind::Static`.

This allows to compute the `BodyOwnerKind` from `DefKind` only, and
removes a direct dependency of some MIR queries onto HIR.

As a side effect, it also simplifies metadata, since we don't need 4
flavours of `EntryKind::*Static` any more.
2022-03-30 22:09:56 +00:00
Yuri Astrakhan
5160f8f843 Spellchecking compiler comments
This PR cleans up the rest of the spelling mistakes in the compiler comments. This PR does not change any literal or code spelling issues.
2022-03-30 15:14:15 -04:00
bors
05142a7e44 Auto merge of #95466 - Dylan-DPC:rollup-g7ddr8y, r=Dylan-DPC
Rollup of 5 pull requests

Successful merges:

 - #95294 (Document Linux kernel handoff in std::io::copy and std::fs::copy)
 - #95443 (Clarify how `src/tools/x` searches for python)
 - #95452 (fix since field version for termination stabilization)
 - #95460 (Spellchecking compiler code)
 - #95461 (Spellchecking some comments)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-03-30 07:45:42 +00:00
Dylan DPC
03b3993ae8
Rollup merge of #95461 - nyurik:spelling, r=lcnr
Spellchecking some comments

This PR attempts to clean up some minor spelling mistakes in comments
2022-03-30 09:10:07 +02:00
Dylan DPC
a629b2ac68
Rollup merge of #95460 - nyurik:spelling-str, r=lcnr
Spellchecking compiler code

Address some spelling mistakes in strings, private function names, and function params.
2022-03-30 09:10:06 +02:00
Yuri Astrakhan
a9cc3f6564 Spellchecking compiler code
Address some spelling mistakes in strings, private function names, and function params.
2022-03-30 01:42:10 -04:00
Yuri Astrakhan
7e8201ae0a Spellchecking some comments
This PR attempts to clean up some minor spelling mistakes in comments
2022-03-30 01:39:38 -04:00
bors
f132bcf3bd Auto merge of #94081 - oli-obk:lazy_tait_take_two, r=nikomatsakis
Lazy type-alias-impl-trait take two

### user visible change 1: RPIT inference from recursive call sites

Lazy TAIT has an insta-stable change. The following snippet now compiles, because opaque types can now have their hidden type set from wherever the opaque type is mentioned.

```rust
fn bar(b: bool) -> impl std::fmt::Debug {
    if b {
        return 42
    }
    let x: u32 = bar(false); // this errors on stable
    99
}
```

The return type of `bar` stays opaque, you can't do `bar(false) + 42`, you need to actually mention the hidden type.

### user visible change 2: divergence between RPIT and TAIT in return statements

Note that `return` statements and the trailing return expression are special with RPIT (but not TAIT). So

```rust
#![feature(type_alias_impl_trait)]
type Foo = impl std::fmt::Debug;

fn foo(b: bool) -> Foo {
    if b {
        return vec![42];
    }
    std::iter::empty().collect() //~ ERROR `Foo` cannot be built from an iterator
}

fn bar(b: bool) -> impl std::fmt::Debug {
    if b {
        return vec![42]
    }
    std::iter::empty().collect() // Works, magic (accidentally stabilized, not intended)
}
```

But when we are working with the return value of a recursive call, the behavior of RPIT and TAIT is the same:

```rust
type Foo = impl std::fmt::Debug;

fn foo(b: bool) -> Foo {
    if b {
        return vec![];
    }
    let mut x = foo(false);
    x = std::iter::empty().collect(); //~ ERROR `Foo` cannot be built from an iterator
    vec![]
}

fn bar(b: bool) -> impl std::fmt::Debug {
    if b {
        return vec![];
    }
    let mut x = bar(false);
    x = std::iter::empty().collect(); //~ ERROR `impl Debug` cannot be built from an iterator
    vec![]
}
```

### user visible change 3: TAIT does not merge types across branches

In contrast to RPIT, TAIT does not merge types across branches, so the following does not compile.

```rust
type Foo = impl std::fmt::Debug;

fn foo(b: bool) -> Foo {
    if b {
        vec![42_i32]
    } else {
        std::iter::empty().collect()
        //~^ ERROR `Foo` cannot be built from an iterator over elements of type `_`
    }
}
```

It is easy to support, but we should make an explicit decision to include the additional complexity in the implementation (it's not much, see a721052457cf513487fb4266e3ade65c29b272d2 which needs to be reverted to enable this).

### PR formalities

previous attempt: #92007

This PR also includes #92306 and #93783, as they were reverted along with #92007 in #93893

fixes #93411
fixes #88236
fixes #89312
fixes #87340
fixes #86800
fixes #86719
fixes #84073
fixes #83919
fixes #82139
fixes #77987
fixes #74282
fixes #67830
fixes #62742
fixes #54895
2022-03-30 05:04:45 +00:00
Camille GILLOT
21a554caf6 Remember mutability in DefKind::Static.
This allows to compute the `BodyOwnerKind` from `DefKind` only, and
removes a direct dependency of some MIR queries onto HIR.

As a side effect, it also simplifies metadata, since we don't need 4
flavours of `EntryKind::*Static` any more.
2022-03-29 18:50:52 +02:00
Dylan DPC
eceb173de9
Rollup merge of #95415 - notriddle:notriddle/issue-82081, r=Dylan-DPC
diagnostics: regression test for HashMap iter_mut suggestion

Closes #82081
2022-03-29 17:11:52 +02:00
Michael Goulet
ac95e80186 Suggest function borrow ignoring needs_note
`needs_note` is false if we've already suggested why the type is Copy...
but that has nothing to do with the diagnostic.
2022-03-28 22:27:07 -07:00
Michael Goulet
a9b02e13a6 drive-by: move Copy bound suggestion to its own function 2022-03-28 22:27:07 -07:00
Michael Goulet
0f3c2933e0 Add suggestion to borrow opaque Fn and FnMut instead of move 2022-03-28 22:27:06 -07:00
Michael Howell
a063b3a4b6 diagnostics: do not suggest map.iter_mut()() 2022-03-28 11:48:14 -07:00
Oli Scherer
1163aa7e72 Remove opaque type obligation and just register opaque types as they are encountered.
This also registers obligations for the hidden type immediately.
2022-03-28 16:57:45 +00:00
Oli Scherer
d5b6510bfb Have the spans of TAIT type conflict errors point to the actual site instead of the owning function 2022-03-28 16:30:59 +00:00
Oli Scherer
264cd05b16 Revert "Auto merge of #93893 - oli-obk:sad_revert, r=oli-obk"
This reverts commit 6499c5e7fc, reversing
changes made to 78450d2d60.
2022-03-28 16:27:14 +00:00
bors
c74925438c Auto merge of #95149 - cjgillot:once-diag, r=estebank
Remove `Session::one_time_diagnostic`

This is untracked mutable state, which modified the behaviour of queries.
It was used for 2 things: some full-blown errors, but mostly for lint declaration notes ("the lint level is defined here" notes).

It is replaced by the diagnostic deduplication infra which already exists in the diagnostic emitter.
A new diagnostic level `OnceNote` is introduced specifically for lint notes, to deduplicate subdiagnostics.

As a drive-by, diagnostic emission takes a `&mut` to allow dropping the `SubDiagnostic`s.
2022-03-26 00:54:54 +00:00
Camille GILLOT
056951d628 Take &mut Diagnostic in emit_diagnostic.
Taking a Diagnostic by move would break the usual pattern
`diag.label(..).emit()`.
2022-03-20 20:36:08 +01:00
Michael Howell
306dcd6efa diagnostics: do not give Option::as_ref suggestion for complex match
Fixes #82528
2022-03-19 15:54:30 -07:00
Dylan DPC
a8956e6618
Rollup merge of #94698 - WaffleLapkin:simplify-copy-suggestions, r=estebank
Remove redundant code from copy-suggestions

Follow up to #94375, just remove some code that is not necessary anymore. This may make the perf of such suggestions a little bit worse, but I don't think this is significant.

r? `@estebank`
2022-03-17 22:55:03 +01:00
mark
bb8d4307eb rustc_error: make ErrorReported impossible to construct
There are a few places were we have to construct it, though, and a few
places that are more invasive to change. To do this, we create a
constructor with a long obvious name.
2022-03-16 10:35:24 -05:00
Nicholas Nethercote
ca5525d564 Improve AdtDef interning.
This commit makes `AdtDef` use `Interned`. Much the commit is tedious
changes to introduce getter functions. The interesting changes are in
`compiler/rustc_middle/src/ty/adt.rs`.
2022-03-11 13:31:24 +11:00
bors
85ce7fdfa2 Auto merge of #94737 - lcnr:pass-stuff-by-value, r=davidtwco
add `#[rustc_pass_by_value]` to more types

the only interesting changes here should be to `TransitiveRelation`, but I believe to be highly unlikely that we will ever use a non `Copy` type with this type.
2022-03-10 00:15:39 +00:00
bors
10dccdc7fc Auto merge of #94515 - estebank:tweak-move-error, r=davidtwco
Tweak move error

Point at method definition that causes type to be consumed.

Fix #94056.
2022-03-09 08:58:47 +00:00
lcnr
b8135fd5c8 add #[rustc_pass_by_value] to more types 2022-03-08 15:39:52 +01:00
Maybe Waffle
74d0866c62 Remove redundant code from copy-suggestions 2022-03-07 23:19:53 +04:00
Michael Goulet
5ddaa2d5e5 Erase regions when checking for missing Copy predicates 2022-03-06 17:21:39 -08:00
pierwill
f684acdd7e Update itertools
Update to 0.10.1
2022-03-04 11:54:28 -06:00
Esteban Kuber
98752776b8 Tweak move error
Point at method definition that causes type to be consumed.

Fix #94056.
2022-03-03 21:21:57 +00:00
Dylan DPC
7537b2036a
Rollup merge of #94375 - WaffleLapkin:copy-suggestion, r=estebank
Adt copy suggestions

Previously we've only suggested adding `Copy` bounds when the type being moved/copied is a type parameter (generic). With this PR we also suggest adding bounds when a type
- Can be copy
- All predicates that need to be satisfied for that are based on type params

i.e. we will suggest `T: Copy` for `Option<T>`, but won't suggest anything for `Option<String>`.

An example:
```rust
fn duplicate<T>(t: Option<T>) -> (Option<T>, Option<T>) {
    (t, t)
}
```
New error (current compiler doesn't provide `help`:):
```text
error[E0382]: use of moved value: `t`
 --> t.rs:2:9
  |
1 | fn duplicate<T>(t: Option<T>) -> (Option<T>, Option<T>) {
  |                 - move occurs because `t` has type `Option<T>`, which does not implement the `Copy` trait
2 |     (t, t)
  |      -  ^ value used here after move
  |      |
  |      value moved here
  |
help: consider restricting type parameter `T`
  |
1 | fn duplicate<T: Copy>(t: Option<T>) -> (Option<T>, Option<T>) {
  |               ++++++
```

Fixes #93623
r? ``````````@estebank``````````
``````````@rustbot`````````` label +A-diagnostics +A-suggestion-diagnostics +C-enhancement

----

I'm not at all sure if this is the right implementation for this kind of suggestion, but it seems to work :')
2022-03-03 01:09:11 +01:00
mark
e489a94dee rename ErrorReported -> ErrorGuaranteed 2022-03-02 09:45:25 -06:00
Maybe Waffle
400d343796 Suggest adding Copy bound when Adt is moved out
Previously we've only suggested adding `Copy` bounds when the type being
moved/copied is a type parameter (generic). With this commit we also
suggest adding bounds when a type
- Can be copy
- All predicates that need to be satisfied for that are based on type
  params

i.e. we will suggest `T: Copy` for `Option<T>`, but won't suggest
anything for `Option<String>`.

Future work: it would be nice to also suggest adding `.clone()` calls
2022-03-01 16:56:00 +03:00
cuishuang
eb2b9441e7 compiler: fix some typos 2022-03-01 20:02:47 +08:00
Caio
0eb8b32de3 3 - Make more use of let_chains
Continuation of #94376.

cc #53667
2022-02-27 11:10:20 -03:00
Matthias Krüger
3b276cbe04
Rollup merge of #93603 - connorff:compute-polonius-liveness-facts-flag, r=ecstatic-morse
Populate liveness facts when calling `get_body_with_borrowck_facts` without `-Z polonius`

For a new feature of [Flowistry](https://github.com/willcrichton/flowistry), a static-analysis tool, we need to obtain a `mir::Body`'s liveness facts using `get_body_with_borrowck_facts` (added in #86977). We'd like to do this without passing `-Z polonius` as a compiler arg to avoid borrow checking the entire crate.

Support for doing this was added in #88983, but the Polonius input facts used for liveness analysis are empty. This happens because the liveness input facts are populated in `liveness::generate` depending only on the value of `AllFacts::enabled` (which is toggled via compiler args).

This PR propagates the [`use_polonius`](8b09ba6a5d/compiler/rustc_borrowck/src/nll.rs (L168)) flag to `liveness::generate` to support populating liveness facts without requiring the `-Z polonius` flag.

This fix is somewhat patchy - if it'd be better to add more widely-accessible state (like `AllFacts::enabled`) I'd be open to ideas!
2022-02-26 00:49:20 +01:00
Mark Rousskov
22c3a71de1 Switch bootstrap cfgs 2022-02-25 08:00:52 -05:00
bors
d4de1f230c Auto merge of #93368 - eddyb:diagbld-guarantee, r=estebank
rustc_errors: let `DiagnosticBuilder::emit` return a "guarantee of emission".

That is, `DiagnosticBuilder` is now generic over the return type of `.emit()`, so we'll now have:
* `DiagnosticBuilder<ErrorReported>` for error (incl. fatal/bug) diagnostics
  * can only be created via a `const L: Level`-generic constructor, that limits allowed variants via a `where` clause, so not even `rustc_errors` can accidentally bypass this limitation
  * asserts `diagnostic.is_error()` on emission, just in case the construction restriction was bypassed (e.g. by replacing the whole `Diagnostic` inside `DiagnosticBuilder`)
  * `.emit()` returns `ErrorReported`, as a "proof" token that `.emit()` was called
    (though note that this isn't a real guarantee until after completing the work on
     #69426)
* `DiagnosticBuilder<()>` for everything else (warnings, notes, etc.)
  * can also be obtained from other `DiagnosticBuilder`s by calling `.forget_guarantee()`

This PR is a companion to other ongoing work, namely:
* #69426
  and it's ongoing implementation:
  #93222
  the API changes in this PR are needed to get statically-checked "only errors produce `ErrorReported` from `.emit()`", but doesn't itself provide any really strong guarantees without those other `ErrorReported` changes
* #93244
  would make the choices of API changes (esp. naming) in this PR fit better overall

In order to be able to let `.emit()` return anything trustable, several changes had to be made:
* `Diagnostic`'s `level` field is now private to `rustc_errors`, to disallow arbitrary "downgrade"s from "some kind of error" to "warning" (or anything else that doesn't cause compilation to fail)
  * it's still possible to replace the whole `Diagnostic` inside the `DiagnosticBuilder`, sadly, that's harder to fix, but it's unlikely enough that we can paper over it with asserts on `.emit()`
* `.cancel()` now consumes `DiagnosticBuilder`, preventing `.emit()` calls on a cancelled diagnostic
  * it's also now done internally, through `DiagnosticBuilder`-private state, instead of having a `Level::Cancelled` variant that can be read (or worse, written) by the user
  * this removes a hazard of calling `.cancel()` on an error then continuing to attach details to it, and even expect to be able to `.emit()` it
  * warnings were switched to *only* `can_emit_warnings` on emission (instead of pre-cancelling early)
  * `struct_dummy` was removed (as it relied on a pre-`Cancelled` `Diagnostic`)
* since `.emit()` doesn't consume the `DiagnosticBuilder` <sub>(I tried and gave up, it's much more work than this PR)</sub>,
  we have to make `.emit()` idempotent wrt the guarantees it returns
  * thankfully, `err.emit(); err.emit();` can return `ErrorReported` both times, as the second `.emit()` call has no side-effects *only* because the first one did do the appropriate emission
* `&mut Diagnostic` is now used in a lot of function signatures, which used to take `&mut DiagnosticBuilder` (in the interest of not having to make those functions generic)
  * the APIs were already mostly identical, allowing for low-effort porting to this new setup
  * only some of the suggestion methods needed some rework, to have the extra `DiagnosticBuilder` functionality on the `Diagnostic` methods themselves (that change is also present in #93259)
  * `.emit()`/`.cancel()` aren't available, but IMO calling them from an "error decorator/annotator" function isn't a good practice, and can lead to strange behavior (from the caller's perspective)
  * `.downgrade_to_delayed_bug()` was added, letting you convert any `.is_error()` diagnostic into a `delay_span_bug` one (which works because in both cases the guarantees available are the same)

This PR should ideally be reviewed commit-by-commit, since there is a lot of fallout in each.

r? `@estebank` cc `@Manishearth` `@nikomatsakis` `@mark-i-m`
2022-02-25 00:46:04 +00:00
bors
4b043faba3 Auto merge of #94131 - Mark-Simulacrum:fmt-string, r=oli-obk
Always format to internal String in FmtPrinter

This avoids monomorphizing for different parameters, decreasing generic code
instantiated downstream from rustc_middle -- locally seeing 7% unoptimized LLVM IR
line wins on rustc_borrowck, for example.

We likely can't/shouldn't get rid of the Result-ness on most functions, though some
further cleanup avoiding fmt::Error where we now know it won't occur may be possible,
though somewhat painful -- fmt::Write is a pretty annoying API to work with in practice
when you're trying to use it infallibly.
2022-02-24 17:18:07 +00:00
Eduard-Mihai Burtescu
b7e95dee65 rustc_errors: let DiagnosticBuilder::emit return a "guarantee of emission". 2022-02-23 06:38:52 +00:00
Eduard-Mihai Burtescu
0b9d70cf6d rustc_errors: take self by value in DiagnosticBuilder::cancel. 2022-02-23 06:08:06 +00:00
Eduard-Mihai Burtescu
02ff9e0aef Replace &mut DiagnosticBuilder, in signatures, with &mut Diagnostic. 2022-02-23 05:38:19 +00:00
bors
bafe8d06e0 Auto merge of #93984 - nnethercote:ChunkedBitSet, r=Mark-Simulacrum
Introduce `ChunkedBitSet` and use it for some dataflow analyses.

This reduces peak memory usage significantly for some programs with very
large functions.

r? `@ghost`
2022-02-23 01:26:07 +00:00
Nicholas Nethercote
36b495f3cf Introduce ChunkedBitSet and use it for some dataflow analyses.
This reduces peak memory usage significantly for some programs with very
large functions, such as:
- `keccak`, `unicode_normalization`, and `match-stress-enum`, from
  the `rustc-perf` benchmark suite;
- `http-0.2.6` from crates.io.

The new type is used in the analyses where the bitsets can get huge
(e.g. 10s of thousands of bits): `MaybeInitializedPlaces`,
`MaybeUninitializedPlaces`, and `EverInitializedPlaces`.

Some refactoring was required in `rustc_mir_dataflow`. All existing
analysis domains are either `BitSet` or a trivial wrapper around
`BitSet`, and access in a few places is done via `Borrow<BitSet>` or
`BorrowMut<BitSet>`. Now that some of these domains are `ClusterBitSet`,
that no longer works. So this commit replaces the `Borrow`/`BorrowMut`
usage with a new trait `BitSetExt` containing the needed bitset
operations. The impls just forward these to the underlying bitset type.
This required fiddling with trait bounds in a few places.

The commit also:
- Moves `static_assert_size` from `rustc_data_structures` to
  `rustc_index` so it can be used in the latter; the former now
  re-exports it so existing users are unaffected.
- Factors out some common "clear excess bits in the final word"
  functionality in `bit_set.rs`.
- Uses `fill` in a few places instead of loops.
2022-02-23 10:18:49 +11:00
lcnr
1245131a11 use List<Ty<'tcx>> for tuples 2022-02-21 07:09:11 +01:00
Mark Rousskov
efb99d780d Always format to internal String in FmtPrinter
This avoids monomorphizing for different parameters, decreasing generic code
instantiated downstream from rustc_middle.
2022-02-20 19:32:18 -05:00
Matthias Krüger
f2d6770f77
Rollup merge of #94146 - est31:let_else, r=cjgillot
Adopt let else in more places

Continuation of #89933, #91018, #91481, #93046, #93590, #94011.

I have extended my clippy lint to also recognize tuple passing and match statements. The diff caused by fixing it is way above 1 thousand lines. Thus, I split it up into multiple pull requests to make reviewing easier. This is the biggest of these PRs and handles the changes outside of rustdoc, rustc_typeck, rustc_const_eval, rustc_trait_selection, which were handled in PRs #94139, #94142, #94143, #94144.
2022-02-20 00:37:34 +01:00
est31
2ef8af6619 Adopt let else in more places 2022-02-19 17:27:43 +01:00
Matthias Krüger
c28940e49d
Rollup merge of #94006 - pierwill:upvar-field, r=nikomatsakis
Use a `Field` in `ConstraintCategory::ClosureUpvar`

As part of #90317, we do not want `HirId` to implement `Ord`, `PartialOrd`. This line of code has made that difficult

1b27144afc/compiler/rustc_borrowck/src/region_infer/mod.rs (L2184)

since it sorts a [`ConstraintCategory::ClosureUpvar(HirId)`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/enum.ConstraintCategory.html#variant.ClosureUpvar).

This PR makes that variant take a [`Field`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/struct.Field.html) instead.

r? `@nikomatsakis`
2022-02-19 06:45:32 +01:00
bors
feac2ecf1c Auto merge of #94088 - oli-obk:revert, r=jackh726
Revert #91403

fixes #94004

r? `@pnkfelix` `@cjgillot`
2022-02-18 07:35:37 +00:00
Matthias Krüger
637d8b89e8
Rollup merge of #94011 - est31:let_else, r=lcnr
Even more let_else adoptions

Continuation of #89933, #91018, #91481, #93046, #93590.
2022-02-17 23:00:59 +01:00
Oli Scherer
86d17b98f2 Revert "Auto merge of #91403 - cjgillot:inherit-async, r=oli-obk"
This reverts commit 3cfa4def7c, reversing
changes made to 5d8767cb22.
2022-02-17 16:00:04 +00:00
pierwill
f41722a2ad Use a Field in ConstraintCategory::ClosureUpvar 2022-02-16 15:57:03 -06:00
est31
60f969a4f2 Adopt let_else in even more places 2022-02-16 22:43:39 +01:00
Nicholas Nethercote
a95fb8b150 Overhaul Const.
Specifically, rename the `Const` struct as `ConstS` and re-introduce `Const` as
this:
```
pub struct Const<'tcx>(&'tcx Interned<ConstS>);
```
This now matches `Ty` and `Predicate` more closely, including using
pointer-based `eq` and `hash`.

Notable changes:
- `mk_const` now takes a `ConstS`.
- `Const` was copy, despite being 48 bytes. Now `ConstS` is not, so need a
  we need separate arena for it, because we can't use the `Dropless` one any
  more.
- Many `&'tcx Const<'tcx>`/`&Const<'tcx>` to `Const<'tcx>` changes
- Many `ct.ty` to `ct.ty()` and `ct.val` to `ct.val()` changes.
- Lots of tedious sigil fiddling.
2022-02-15 16:19:59 +11:00
Nicholas Nethercote
7eb15509ce Remove unnecessary RegionKind:: quals.
The variant names are exported, so we can use them directly (possibly
with a `ty::` qualifier). Lots of places already do this, this commit
just increases consistency.
2022-02-15 16:14:24 +11:00
Nicholas Nethercote
7024dc523a Overhaul RegionKind and Region.
Specifically, change `Region` from this:
```
pub type Region<'tcx> = &'tcx RegionKind;
```
to this:
```
pub struct Region<'tcx>(&'tcx Interned<RegionKind>);
```

This now matches `Ty` and `Predicate` more closely.

Things to note
- Regions have always been interned, but we haven't been using pointer-based
  `Eq` and `Hash`. This is now happening.
- I chose to impl `Deref` for `Region` because it makes pattern matching a lot
  nicer, and `Region` can be viewed as just a smart wrapper for `RegionKind`.
- Various methods are moved from `RegionKind` to `Region`.
- There is a lot of tedious sigil changes.
- A couple of types like `HighlightBuilder`, `RegionHighlightMode` now have a
  `'tcx` lifetime because they hold a `Ty<'tcx>`, so they can call `mk_region`.
- A couple of test outputs change slightly, I'm not sure why, but the new
  outputs are a little better.
2022-02-15 16:08:52 +11:00
Nicholas Nethercote
e9a0c429c5 Overhaul TyS and Ty.
Specifically, change `Ty` from this:
```
pub type Ty<'tcx> = &'tcx TyS<'tcx>;
```
to this
```
pub struct Ty<'tcx>(Interned<'tcx, TyS<'tcx>>);
```
There are two benefits to this.
- It's now a first class type, so we can define methods on it. This
  means we can move a lot of methods away from `TyS`, leaving `TyS` as a
  barely-used type, which is appropriate given that it's not meant to
  be used directly.
- The uniqueness requirement is now explicit, via the `Interned` type.
  E.g. the pointer-based `Eq` and `Hash` comes from `Interned`, rather
  than via `TyS`, which wasn't obvious at all.

Much of this commit is boring churn. The interesting changes are in
these files:
- compiler/rustc_middle/src/arena.rs
- compiler/rustc_middle/src/mir/visit.rs
- compiler/rustc_middle/src/ty/context.rs
- compiler/rustc_middle/src/ty/mod.rs

Specifically:
- Most mentions of `TyS` are removed. It's very much a dumb struct now;
  `Ty` has all the smarts.
- `TyS` now has `crate` visibility instead of `pub`.
- `TyS::make_for_test` is removed in favour of the static `BOOL_TY`,
  which just works better with the new structure.
- The `Eq`/`Ord`/`Hash` impls are removed from `TyS`. `Interned`s impls
  of `Eq`/`Hash` now suffice. `Ord` is now partly on `Interned`
  (pointer-based, for the `Equal` case) and partly on `TyS`
  (contents-based, for the other cases).
- There are many tedious sigil adjustments, i.e. adding or removing `*`
  or `&`. They seem to be unavoidable.
2022-02-15 16:03:24 +11:00
Matthias Krüger
953c4dcc30
Rollup merge of #90532 - fee1-dead:improve-const-fn-err-msg, r=oli-obk
More informative error message for E0015

Helps with #92380
2022-02-13 06:44:13 +01:00
bors
3cfa4def7c Auto merge of #91403 - cjgillot:inherit-async, r=oli-obk
Inherit lifetimes for async fn instead of duplicating them.

The current desugaring of `async fn foo<'a>(&usize) -> &u8` is equivalent to
```rust
fn foo<'a, '0>(&'0 usize) -> foo<'static, 'static>::Opaque<'a, '0, '_>;
type foo<'_a, '_0>::Opaque<'a, '0, '1> = impl Future<Output = &'1 u8>;
```
following the RPIT model.

Duplicating all the inherited lifetime parameters and setting the inherited version to `'static` makes lowering more complex and causes issues like #61949. This PR removes the duplication of inherited lifetimes to directly use
```rust
fn foo<'a, '0>(&'0 usize) -> foo<'a, '0>::Opaque<'_>;
type foo<'a, '0>::Opaque<'1> = impl Future<Output = &'1 u8>;
```
following the TAIT model.

Fixes https://github.com/rust-lang/rust/issues/61949
2022-02-12 21:42:10 +00:00
Deadbeef
d3acb9d00e
Handle Fn family trait call errror 2022-02-12 19:24:43 +11:00
Deadbeef
6d6314f878
Rebased and improved errors 2022-02-12 19:24:42 +11:00
Deadbeef
f7f0f843b7
Improve error messages even more 2022-02-12 19:24:08 +11:00
Camille GILLOT
10cf626d0e Bless nll tests. 2022-02-12 01:26:17 +01:00
Michael Goulet
29c2bb51c0 rework borrowck errors so that it's harder to not set tainted 2022-02-11 12:45:51 -08:00
Michael Goulet
4ad272b282 implement tainted_by_errors in mir borrowck 2022-02-11 12:45:51 -08:00
bors
6499c5e7fc Auto merge of #93893 - oli-obk:sad_revert, r=oli-obk
Revert lazy TAIT PR

Revert https://github.com/rust-lang/rust/pull/92306 (sorry `@Aaron1011,` will include your changes in the fix PR)
Revert https://github.com/rust-lang/rust/pull/93783
Revert https://github.com/rust-lang/rust/pull/92007

fixes https://github.com/rust-lang/rust/issues/93788
fixes https://github.com/rust-lang/rust/issues/93794
fixes https://github.com/rust-lang/rust/issues/93821
fixes https://github.com/rust-lang/rust/issues/93831
fixes https://github.com/rust-lang/rust/issues/93841
2022-02-11 17:39:34 +00:00
Oli Scherer
d54195db22 Revert "Auto merge of #92007 - oli-obk:lazy_tait2, r=nikomatsakis"
This reverts commit e7cc3bddbe, reversing
changes made to 734368a200.
2022-02-11 07:18:06 +00:00
Oli Scherer
2d8b8f3593 Revert "Auto merge of #92306 - Aaron1011:opaque-type-op, r=oli-obk"
This reverts commit 1f0a96862a, reversing
changes made to bf242bb119.
2022-02-11 07:17:16 +00:00
Frank Steffahn
7eff2feb62 Remove further usage of &hir::Map 2022-02-10 13:04:59 +01:00
Aaron Hill
48a48fd1b8
Improve opaque type higher-ranked region error message under NLL
Currently, any higher-ranked region errors involving opaque types
fall back to a generic "higher-ranked subtype error" message when
run under NLL. This PR adds better error message handling for this
case, giving us the same kinds of error messages that we currently
get without NLL:

```
error: implementation of `MyTrait` is not general enough
  --> $DIR/opaque-hrtb.rs:12:13
   |
LL | fn foo() -> impl for<'a> MyTrait<&'a str> {
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `MyTrait` is not general enough
   |
   = note: `impl MyTrait<&'2 str>` must implement `MyTrait<&'1 str>`, for any lifetime `'1`...
   = note: ...but it actually implements `MyTrait<&'2 str>`, for some specific lifetime `'2`

error: aborting due to previous error
```

To accomplish this, several different refactoring needed to be made:

* We now have a dedicated `InstantiateOpaqueType` struct which
implements `TypeOp`. This is used to invoke `instantiate_opaque_types`
during MIR type checking.
* `TypeOp` is refactored to pass around a `MirBorrowckCtxt`, which is
needed to report opaque type region errors.
* We no longer assume that all `TypeOp`s correspond to canonicalized
queries. This allows us to properly handle opaque type instantiation
(which does not occur in a query) as a `TypeOp`.
A new `ErrorInfo` associated type is used to determine what
additional information is used during higher-ranked region error
handling.
* The body of `try_extract_error_from_fulfill_cx`
has been moved out to a new function `try_extract_error_from_region_constraints`.
This allows us to re-use the same error reporting code between
canonicalized queries (which can extract region constraints directly
from a fresh `InferCtxt`) and opaque type handling (which needs to take
region constraints from the pre-existing `InferCtxt` that we use
throughout MIR borrow checking).
2022-02-08 12:35:42 -05:00
bors
e7cc3bddbe Auto merge of #92007 - oli-obk:lazy_tait2, r=nikomatsakis
Lazy type-alias-impl-trait

Previously opaque types were processed by

1. replacing all mentions of them with inference variables
2. memorizing these inference variables in a side-table
3. at the end of typeck, resolve the inference variables in the side table and use the resolved type as the hidden type of the opaque type

This worked okayish for `impl Trait` in return position, but required lots of roundabout type inference hacks and processing.

This PR instead stops this process of replacing opaque types with inference variables, and just keeps the opaque types around.
Whenever an opaque type `O` is compared with another type `T`, we make the comparison succeed and record `T` as the hidden type. If `O` is compared to `U` while there is a recorded hidden type for it, we grab the recorded type (`T`) and compare that against `U`. This makes implementing

* https://github.com/rust-lang/rfcs/pull/2515

much simpler (previous attempts on the inference based scheme were very prone to ICEs and general misbehaviour that was not explainable except by random implementation defined oddities).

r? `@nikomatsakis`

fixes #93411
fixes #88236
2022-02-07 23:40:26 +00:00
Connor Fogarty
42371a502f Propagate use_polonius flag to liveness module 2022-02-02 18:50:27 -06:00
Matthias Krüger
3388e6d9fd
Rollup merge of #93590 - est31:let_else, r=lcnr
More let_else adoptions

Continuation of #89933, #91018, #91481, #93046.
2022-02-02 19:34:07 +01:00
Matthias Krüger
b622552e10
Rollup merge of #93221 - alyssaverkade:fix-93093, r=wesleywiser
[borrowck] Fix help on mutating &self in async fns

Previously, when rustc was provided an async function that tried to
mutate through a shared reference to an implicit self (as shown in the
ui test), rustc would suggest modifying the parameter signature
to `&mut` + the fully qualified name of the ty (in the case of the repro
`S`). If a user modified their code to match the suggestion, the
compiler would not accept it.

This commit modifies the suggestion so that when rustc is provided the
ui test that is also attached in this commit, it suggests (correctly)
`&mut self`. We try to be careful about distinguishing between implicit
and explicit self annotations, since the latter seem to be handled
correctly already.

This is my first PR here so I'm pretty sure I probably missed something/could use better terminology. I also didn't try to make the match exhaustive since implicit self is the only real special case that I need to handle (that I'm aware of), and I'm pretty sure there's a cleaner way to do this so any advice would be greatly appreciated! (I'm also not terribly confident about how I wrote the ui tests)

here is your cc as requested `@compiler-errors`

This is an attempt to fix #93093
2022-02-02 19:34:02 +01:00
est31
670f5c6ef3 More let_else adoptions 2022-02-02 17:11:01 +01:00
Oli Scherer
7a1ccf9a03 Avoid an ICE in the presence of HKL 2022-02-02 15:40:12 +00:00
Oli Scherer
59d0bff0e6 Reduce follow-up errors that are not helpful 2022-02-02 15:40:12 +00:00
Oli Scherer
22477784a7 Fixup changes that aren't neccessary anymore 2022-02-02 15:40:11 +00:00
Oli Scherer
94d6a9acc9 This can't happen anymore. An opaque type can't end up with itself as its hidden type 2022-02-02 15:40:11 +00:00
Oli Scherer
3146c961fe We're equating hidden types eagerly now 2022-02-02 15:40:11 +00:00
Oli Scherer
edaf9625fb Clean up leftovers from eager hidden type merging 2022-02-02 15:40:11 +00:00
Oli Scherer
7bce50c01a Register member constraints on the final merged hidden type
Previously we did this per hidden type candiate, which didn't always have all the information available.
2022-02-02 15:40:11 +00:00
Oli Scherer
0f6e06b7c0 Lazily resolve type-alias-impl-trait defining uses
by using an opaque type obligation to bubble up comparisons between opaque types and other types

Also uses proper obligation causes so that the body id works, because out of some reason nll uses body ids for logic instead of just diagnostics.
2022-02-02 15:40:11 +00:00
Oli Scherer
f7abc1b6f8 Expose current span to type equality checking in nll 2022-02-02 15:40:10 +00:00
Oli Scherer
4e1a5968f1 Found suspicious comparison of constants 2022-02-02 15:40:10 +00:00
Oli Scherer
d49b0746f6 Add roll back infrastructure for opaque type caches 2022-02-02 15:40:10 +00:00
lcnr
a1a30f7548 add a rustc::query_stability lint 2022-02-01 10:15:59 +01:00
bors
8cdb3cd94e Auto merge of #93095 - Aaron1011:remove-assoc-ident, r=cjgillot
Store a `Symbol` instead of an `Ident` in `AssocItem`

This is the same idea as #92533, but for `AssocItem` instead
of `VariantDef`/`FieldDef`.

With this change, we no longer have any uses of
`#[stable_hasher(project(...))]`
2022-01-25 18:53:45 +00:00
bors
17dfae79bb Auto merge of #93089 - pierwill:rm-outlivesconstraint-ord, r=michaelwoerister
Remove ordering traits from `OutlivesConstraint`

In two cases where this ordering was used, I've replaced the sorting to use a key that does not rely on `DefId` being `Ord`. This is part of #90317. If I understand correctly, whether this is correct depends on whether the `RegionVid`s are tracked during incremental compilation. But I might be mistaken in this approach. cc `@cjgillot`
2022-01-25 08:18:25 +00:00
Michael Goulet
4ff7e6e3e3 Normalize field access types during borrowck 2022-01-22 20:05:05 -08:00
Alyssa Verkade
b885700c7b [borrowck] Fix help on mutating &self in async fns
Previously, when rustc was provided an async function that tried to
mutate through a shared reference to an implicit self (as shown in the
ui test), rustc would suggest modifying the parameter signature
to `&mut` + the fully qualified name of the ty (in the case of the repro
`S`). If a user modified their code to match the suggestion, the
compiler would not accept it.

This commit modifies the suggestion so that when rustc is provided the
ui test that is also attached in this commit, it suggests (correctly)
`&mut self`. We try to be careful about distinguishing between implicit
and explicit self annotations, since the latter seem to be handled
correctly already.

Fixes rust-lang/rust#93093
2022-01-22 16:21:16 -08:00
Matthias Krüger
10c9ec399e
Rollup merge of #92467 - Aaron1011:extern-local-region, r=oli-obk
Ensure that early-bound function lifetimes are always 'local'

During borrowchecking, we treat any free (early-bound) regions on
the 'defining type' as `RegionClassification::External`. According
to the doc comments, we should only have 'external' regions when
checking a closure/generator.

However, a plain function can also have some if its regions
be considered 'early bound' - this occurs when the region is
constrained by an argument, appears in a `where` clause, or
in an opaque type. This was causing us to incorrectly mark these
regions as 'external', which caused some diagnostic code
to act as if we were referring to a 'parent' region from inside
a closure.

This PR marks all instantiated region variables as 'local'
when we're borrow-checking something other than a
closure/generator/inline-const.
2022-01-21 22:03:12 +01:00
bors
84e918971d Auto merge of #92896 - lqd:update-deps, r=Mark-Simulacrum
Update some rustc dependencies to deduplicate them

This PR updates `rand` and `itertools` in rustc (not the whole workspace) in order to deduplicate them (and hopefully slightly improve compile times).

~~Currently, `object` is still duplicated, but https://github.com/rust-lang/thorin/pull/15 and updating `thorin` in the future will remove the use of version 0.27.~~  Update: Thorin 0.2 has now been released, and this PR updates `rustc_codegen_ssa` to use it and deduplicate the `object` crate.

There's a final tiny rustc dependency, `cfg-if`, which will be left: as both versions 0.1.x and 1.0 looked to be heavily depended on, they will require a few cascading updates to be removed.
2022-01-21 10:38:30 +00:00
Aaron Hill
c8941d3e48
Store a Symbol instead of an Ident in AssocItem
This is the same idea as #92533, but for `AssocItem` instead
of `VariantDef`/`FieldDef`.

With this change, we no longer have any uses of
`#[stable_hasher(project(...))]`
2022-01-19 17:13:21 -05:00
pierwill
7f16d0ed54 Remove ordering traits from rustc_borrowck::constraints::OutlivesConstraint
In two cases where this ordering was used, I've replaced the sorting
to use a key that does not include DefId. I'm not sure this is correct
in terms of our goals from #90317, or otherwise.
2022-01-19 13:12:26 -06:00
kadmin
67f56671d0 Use Term in ProjectionPredicate
ProjectionPredicate should be able to handle both associated types and consts so this adds the
first step of that. It mainly just pipes types all the way down, not entirely sure how to handle
consts, but hopefully that'll come with time.
2022-01-17 17:44:56 +00:00
bors
a34c079752 Auto merge of #92816 - tmiasko:rm-llvm-asm, r=Amanieu
Remove deprecated LLVM-style inline assembly

The `llvm_asm!` was deprecated back in #87590 1.56.0, with intention to remove
it once `asm!` was stabilized, which already happened in #91728 1.59.0. Now it
is time to remove `llvm_asm!` to avoid continued maintenance cost.

Closes #70173.
Closes #92794.
Closes #87612.
Closes #82065.

cc `@rust-lang/wg-inline-asm`

r? `@Amanieu`
2022-01-17 09:40:29 +00:00
bors
7be8693984 Auto merge of #92805 - BoxyUwU:revert-lazy-anon-const-substs, r=lcnr
partially revertish `lazily "compute" anon const default substs`

reverts #87280 except for some of the changes around `ty::Unevaluated` having a visitor and a generic for promoted
why revert: <https://github.com/rust-lang/rust/pull/92805#issuecomment-1010736049>

r? `@lcnr`
2022-01-16 11:19:21 +00:00
Camille GILLOT
67727aa7c3 Reduce use of local_def_id_to_hir_id. 2022-01-15 21:26:25 +01:00
Camille GILLOT
60064726ae Return a LocalDefId in get_parent_item. 2022-01-15 21:26:20 +01:00
Matthias Krüger
8df08e8bce
Rollup merge of #92625 - inquisitivecrystal:mirbug-caller, r=michaelwoerister
Add `#[track_caller]` to `mirbug`

When a "'no errors encountered even though `delay_span_bug` issued" error results from the `mirbug` function, the file location information points to the `mirbug` function itself, rather than its caller. This doesn't make sense, since the caller is the real source of the bug. Adding `#[track_caller]` will produce diagnostics that are more useful to anyone fixing the ICE.
2022-01-15 02:25:15 +01:00
Ellen
71bbb603f4 initial revert 2022-01-15 01:16:55 +00:00
Rémy Rakic
5928056af2 Update itertools to deduplicate it 2022-01-14 12:33:54 +01:00
bors
22e491ac7e Auto merge of #89861 - nbdd0121:closure, r=wesleywiser
Closure capture cleanup & refactor

Follow up of #89648

Each commit is self-contained and the rationale/changes are documented in the commit message, so it's advisable to review commit by commit.

The code is significantly cleaner (at least IMO), but that could have some perf implication, so I'd suggest a perf run.

r? `@wesleywiser`
cc `@arora-aman`
2022-01-13 18:51:07 +00:00
Tomasz Miąsko
279c9d3d9f Remove no longer used MutateMode enum 2022-01-12 18:51:31 +01:00
Tomasz Miąsko
000b36c505 Remove deprecated LLVM-style inline assembly 2022-01-12 18:51:31 +01:00
Aaron Hill
450ef8613c
Store a Symbol instead of an Ident in VariantDef/FieldDef
The field is also renamed from `ident` to `name. In most cases,
we don't actually need the `Span`. A new `ident` method is added
to `VariantDef` and `FieldDef`, which constructs the full `Ident`
using `tcx.def_ident_span()`. This method is used in the cases
where we actually need an `Ident`.

This makes incremental compilation properly track changes
to the `Span`, without all of the invalidations caused by storing
a `Span` directly via an `Ident`.
2022-01-11 10:16:22 -05:00
Gary Guo
48258ffe5a Remove region from UpvarCapture and move it to CapturedPlace
Region info is completely unnecessary for upvar capture kind computation
and is only needed to create the final upvar tuple ty. Doing so makes
creation of UpvarCapture very cheap and expose further cleanup opportunity.
2022-01-07 22:55:34 +00:00
Gary Guo
3698e03fb6 Remove span from UpvarCapture::ByValue
This span is unused and is superseded by capture_kind_expr_id in CaptureInfo
2022-01-07 22:54:28 +00:00
inquisitivecrystal
f6f8149577 Add #[track_caller] to mirbug 2022-01-06 13:31:28 -08:00
Matthias Krüger
57a4f4a634
Rollup merge of #90102 - nbdd0121:box3, r=jonas-schievink
Remove `NullOp::Box`

Follow up of #89030 and MCP rust-lang/compiler-team#460.

~1 month later nothing seems to be broken, apart from a small regression that #89332 (1aac85bb716c09304b313d69d30d74fe7e8e1a8e) shows could be regained by remvoing the diverging path, so it shall be safe to continue and remove `NullOp::Box` completely.

r? `@jonas-schievink`
`@rustbot` label T-compiler
2022-01-03 14:44:15 +01:00
Aaron Hill
e3a048c3c9
Ensure that early-bound function lifetimes are always 'local'
During borrowchecking, we treat any free (early-bound) regions on
the 'defining type' as `RegionClassification::External`. According
to the doc comments, we should only have 'external' regions when
checking a closure/generator.

However, a plain function can also have some if its regions
be considered 'early bound' - this occurs when the region is
constrained by an argument, appears in a `where` clause, or
in an opaque type. This was causing us to incorrectly mark these
regions as 'external', which caused some diagnostic code
to act as if we were referring to a 'parent' region from inside
a closure.

This PR marks all instantiated region variables as 'local'
when we're borrow-checking something other than a
closure/generator/inline-const.
2021-12-31 18:42:54 -05:00
Mark Rousskov
4abb3283f3 Use SparseIntervalMatrix instead of SparseBitMatrix
Region inference contains several bitsets which are filled with large intervals
representing liveness. These can cause excessive memory usage, and are
relatively slow when growing to large sizes compared to the IntervalSet.
2021-12-30 22:33:52 -05:00
Aaron Hill
b15cb29a4a
Refactor variance diagnostics to work with more types
Instead of special-casing mutable pointers/references, we
now support general generic types (currently, we handle
`ty::Ref`, `ty::RawPtr`, and `ty::Adt`)

When a `ty::Adt` is involved, we show an additional note
explaining which of the type's generic parameters is
invariant (e.g. the `T` in `Cell<T>`). Currently, we don't
explain *why* a particular generic parameter ends up becoming
invariant. In the general case, this could require printing
a long 'backtrace' of types, so doing this would be
more suitable for a follow-up PR.

We still only handle the case where our variance switches
to `ty::Invariant`.
2021-12-29 18:53:40 -05:00
Aaron Hill
cac431ba75
Store a DefId instead of an AdtDef in AggregateKind::Adt
The `AggregateKind` enum ends up in the final mir `Body`. Currently,
any changes to `AdtDef` (regardless of how significant they are)
will legitimately cause the overall result of `optimized_mir` to change,
invalidating any codegen re-use involving that mir.

This will get worse once we start hashing the `Span` inside `FieldDef`
(which is itself contained in `AdtDef`).

To try to reduce these kinds of invalidations, this commit changes
`AggregateKind::Adt` to store just the `DefId`, instead of the full
`AdtDef`. This allows the result of `optimized_mir` to be unchanged
if the `AdtDef` changes in a way that doesn't actually affect any
of the MIR we build.
2021-12-22 14:36:34 -05:00
bors
a41a6925ba Auto merge of #91957 - nnethercote:rm-SymbolStr, r=oli-obk
Remove `SymbolStr`

This was originally proposed in https://github.com/rust-lang/rust/pull/74554#discussion_r466203544. As well as removing the icky `SymbolStr` type, it allows the removal of a lot of `&` and `*` occurrences.

Best reviewed one commit at a time.

r? `@oli-obk`
2021-12-19 09:31:37 +00:00
Lucas Kent
e57307560e get_mut_span_in_struct_field uses span.between 2021-12-18 13:00:08 +11:00
Lucas Kent
97bf7b934e Improve suggestion to change struct field to &mut 2021-12-17 13:20:40 +11:00
Dániel Buga
e837101890 Remove in_band_lifetimes from borrowck 2021-12-15 08:39:21 +01:00
Nicholas Nethercote
056d48a2c9 Remove unnecessary sigils around Symbol::as_str() calls. 2021-12-15 17:32:14 +11:00
PFPoitras
304ede6bcc Stabilize iter::zip. 2021-12-14 18:50:31 -04:00
Deadbeef
84b1d859c8
Revert "Auto merge of #91491 - spastorino:revert-91354, r=oli-obk"
This reverts commit ff2439b7b9, reversing
changes made to 2a9e0831d6.
2021-12-12 12:34:46 +08:00
bors
928783de66 Auto merge of #91799 - matthiaskrgr:rollup-b38xx6i, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #83174 (Suggest using a temporary variable to fix borrowck errors)
 - #89734 (Point at capture points for non-`'static` reference crossing a `yield` point)
 - #90270 (Make `Borrow` and `BorrowMut` impls `const`)
 - #90741 (Const `Option::cloned`)
 - #91548 (Add spin_loop hint for RISC-V architecture)
 - #91721 (Minor improvements to `future::join!`'s implementation)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-12-11 18:56:59 +00:00
Matthias Krüger
7bba5c163c
Rollup merge of #89734 - estebank:issue-72312, r=nikomatsakis
Point at capture points for non-`'static` reference crossing a `yield` point

```
error[E0759]: `self` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement
  --> $DIR/issue-72312.rs:10:24
   |
LL |     pub async fn start(&self) {
   |                        ^^^^^ this data with an anonymous lifetime `'_`...
...
LL |         require_static(async move {
   |         -------------- ...is required to live as long as `'static` here...
LL |             &self;
   |             ----- ...and is captured here
   |
note: `'static` lifetime requirement introduced by this trait bound
  --> $DIR/issue-72312.rs:2:22
   |
LL | fn require_static<T: 'static>(val: T) -> T {
   |                      ^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0759`.
```

Fix #72312.
2021-12-11 17:35:23 +01:00
Noah Lev
e27315268b Suggest using a temporary variable to fix borrowck errors
In Rust, nesting method calls with both require `&mut` access to `self`
produces a borrow-check error:

    error[E0499]: cannot borrow `*self` as mutable more than once at a time
     --> src/lib.rs:7:14
      |
    7 |     self.foo(self.bar());
      |     ---------^^^^^^^^^^-
      |     |    |   |
      |     |    |   second mutable borrow occurs here
      |     |    first borrow later used by call
      |     first mutable borrow occurs here

That's because Rust has a left-to-right evaluation order, and the method
receiver is passed first. Thus, the argument to the method cannot then
mutate `self`.

There's an easy solution to this error: just extract a local variable
for the inner argument:

    let tmp = self.bar();
    self.foo(tmp);

However, the error doesn't give any suggestion of how to solve the
problem. As a result, new users may assume that it's impossible to
express their code correctly and get stuck.

This commit adds a (non-structured) suggestion to extract a local
variable for the inner argument to solve the error. The suggestion uses
heuristics that eliminate most false positives, though there are a few
false negatives (cases where the suggestion should be emitted but is
not). Those other cases can be implemented in a future change.
2021-12-10 14:34:00 -08:00
Esteban Kuber
d10fe26f39 Point at capture points for non-'static reference crossing a yield point
```
error[E0759]: `self` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement
  --> $DIR/issue-72312.rs:10:24
   |
LL |     pub async fn start(&self) {
   |                        ^^^^^ this data with an anonymous lifetime `'_`...
...
LL |         require_static(async move {
   |         -------------- ...is required to live as long as `'static` here...
LL |             &self;
   |             ----- ...and is captured here
   |
note: `'static` lifetime requirement introduced by this trait bound
  --> $DIR/issue-72312.rs:2:22
   |
LL | fn require_static<T: 'static>(val: T) -> T {
   |                      ^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0759`.
```

Fix #72312.
2021-12-10 03:08:22 +00:00
Camille GILLOT
8576ab45e4 Store impl_trait_fn inside OpaqueTyOrigin. 2021-12-07 21:30:45 +01:00
bors
887999d163 Auto merge of #88439 - cynecx:unwind_asm, r=Amanieu
Unwinding support for inline assembly

r? `@Amanieu`
2021-12-04 05:59:16 +00:00
Matthias Krüger
df51bffe6b
Rollup merge of #91488 - compiler-errors:issue-91477, r=estebank
Fix ICE when `yield`ing in function returning `impl Trait`

Change an assert to a `delay_span_bug` and remove an unwrap, that should fix it.

Fixes #91477
2021-12-04 02:26:26 +01:00
Amanieu d'Antras
940b2eabad Add initial AST and MIR support for unwinding from inline assembly 2021-12-03 23:51:46 +01:00
Santiago Pastorino
85b723c4e6
Revert "Auto merge of #91354 - fee1-dead:const_env, r=spastorino"
This reverts commit 18bb8c61a9, reversing
changes made to d9baa36190.
2021-12-03 10:11:21 -03:00