Commit Graph

1841 Commits

Author SHA1 Message Date
Eduard-Mihai Burtescu f14e8dd4e7 ty::pretty: prevent infinite recursion for `extern crate` paths. 2021-10-10 18:58:28 +03:00
Eduard-Mihai Burtescu 152e40377a ty::pretty: document "dummy Span extern crate" special-case in `try_print_visible_def_path_recur`. 2021-10-10 18:18:30 +03:00
bors 9e8356c6ad Auto merge of #88952 - skrap:add-armv7-uclibc, r=nagisa
Add new tier-3 target: armv7-unknown-linux-uclibceabihf

This change adds a new tier-3 target: armv7-unknown-linux-uclibceabihf

This target is primarily used in embedded linux devices where system resources are slim and glibc is deemed too heavyweight.  Cross compilation C toolchains are available [here](https://toolchains.bootlin.com/) or via [buildroot](https://buildroot.org).

The change is based largely on a previous PR #79380 with a few minor modifications.  The author of that PR was unable to push the PR forward, and graciously allowed me to take it over.

Per the [target tier 3 policy](https://github.com/rust-lang/rfcs/blob/master/text/2803-target-tier-policy.md), I volunteer to be the "target maintainer".

This is my first PR to Rust itself, so I apologize if I've missed things!
2021-10-10 08:16:22 +00:00
John Kugelman 169113935f Fix spelling: Cannonical -> Canonical 2021-10-10 00:44:34 -04:00
Camille GILLOT 0431fdb113 Compute full HIR hash during lowering. 2021-10-10 00:05:49 +02:00
Camille GILLOT 41e80b85cf Directly use AttributeMap inside OwnerInfo. 2021-10-10 00:05:35 +02:00
Camille GILLOT 1c7f85f17c Perform indexing during lowering.
Do not access DefId<->HirId maps before they are initialized.
2021-10-09 23:47:59 +02:00
Camille GILLOT c09eaea484 Make index_hir incremental. 2021-10-09 23:14:59 +02:00
Camille GILLOT ed3c8e86cb Hash during lowering. 2021-10-09 19:44:55 +02:00
Camille GILLOT 457de08487 Forbid hashing HIR outside of indexing. 2021-10-09 18:38:28 +02:00
bors 15491d7b6b Auto merge of #89343 - Mark-Simulacrum:no-args-queries, r=cjgillot
Refactor fingerprint reconstruction

This PR replaces can_reconstruct_query_key with fingerprint_style, which returns the style of the fingerprint for that query. This allows us to avoid trying to extract a DefId (or equivalent) from keys which *are* reconstructible because they're () but not as DefIds.

This is done with the goal of fixing -Zdump-dep-graph, which seems to have broken a while ago (I didn't try to bisect). Currently even on a `fn main() {}` file it'll ICE (you need to also pass -Zquery-dep-graph for it to work at all), and this patch indirectly fixes the cause of that ICE. This also adds a test for it continuing to work.
2021-10-09 13:13:07 +00:00
Camille GILLOT cd1ace488f Use an IndexVec for bodies. 2021-10-09 14:01:09 +02:00
Camille GILLOT 48a339ddbb Store lowering outputs per owner. 2021-10-09 11:56:29 +02:00
Guillaume Gomez 836597a881
Rollup merge of #89649 - matthiaskrgr:clippycompl, r=jyn514
clippy::complexity fixes
2021-10-08 22:30:40 +02:00
Matthias Krüger e6f77a1787 clippy::complexity fixes 2021-10-08 20:07:44 +02:00
bors e0aaffd8a4 Auto merge of #89576 - tom7980:issue-89275-fix, r=estebank
Prevent error reporting from outputting a recursion error if it finds an ambiguous trait impl during suggestions

Closes #89275

This fixes the compiler reporting a recursion error during another already in progress error by trying to make a conversion method suggestion and encounters ambiguous trait implementations that can convert a the original type into a type that can then be recursively converted into itself via another method in the trait.

Updated OverflowError struct to be an enum so I could differentiate between passes - it's no longer a ZST but I don't think that should be a problem as they only generate when there's an error in compiling code anyway
2021-10-08 11:44:45 +00:00
bors 44995f7afb Auto merge of #89619 - michaelwoerister:incr-vtables, r=nagisa
Turn vtable_allocation() into a query

This PR removes the untracked vtable-const-allocation cache from the `tcx` and turns the `vtable_allocation()` method into a query.

The change is pretty straightforward and should be backportable without too much effort.

Fixes https://github.com/rust-lang/rust/issues/89598.
2021-10-08 09:04:06 +00:00
Jubilee 6c17601a2e
Rollup merge of #89025 - ricobbe:raw-dylib-link-ordinal, r=michaelwoerister
Implement `#[link_ordinal(n)]`

Allows the use of `#[link_ordinal(n)]` with `#[link(kind = "raw-dylib")]`, allowing Rust to link against DLLs that export symbols by ordinal rather than by name.  As long as the ordinal matches, the name of the function in Rust is not required to match the name of the corresponding function in the exporting DLL.

Part of #58713.
2021-10-07 20:26:11 -07:00
Camille GILLOT 54c3299b3a Remove eval_always for HIR queries.
They depend on `hir_crate` and `index_hir`.
2021-10-07 23:12:28 +02:00
Michael Woerister b7cc99142a Turn tcx.vtable_allocation() into a query. 2021-10-07 20:03:00 +02:00
bors 0157cc977f Auto merge of #89534 - camsteffen:diag-name, r=oli-obk
Introduce `tcx.get_diagnostic_name`

Introduces a "reverse lookup" for diagnostic items. This is mainly intended for `@rust-lang/clippy` which often does a long series of `is_diagnostic_item` calls for the same `DefId`.

r? `@oli-obk`
2021-10-07 14:22:16 +00:00
Michael Woerister a1e2c0f0ad Remove untracked vtable-const-allocation cache from tcx 2021-10-07 11:27:35 +02:00
Mark Rousskov 6f78eed1c7 Query the fingerprint style during key reconstruction
Keys can be reconstructed from fingerprints that are not DefPathHash, but then
we cannot extract a DefId from them.
2021-10-06 22:19:48 -04:00
Manish Goregaokar b87a9a8a7c
Rollup merge of #89329 - tmiasko:print-type-sizes-no-fields, r=jackh726
print-type-sizes: skip field printing for primitives

Fixes #86528.
2021-10-06 12:33:18 -07:00
Yannick Koehler 11381a5a3a Add new target armv7-unknown-linux-uclibceabihf
Co-authored-by: Jonah Petri <jonah@petri.us>
2021-10-06 14:33:13 +00:00
Cameron Steffen 33b9b95305 Introduce get_diagnostic_name 2021-10-06 08:40:28 -05:00
bors d7539a6af0 Auto merge of #89323 - estebank:derive-binop, r=petrochenkov
Consider unfulfilled obligations in binop errors

When encountering a binop where the types would have been accepted, if
all the predicates had been fulfilled, include information about the
predicates and suggest appropriate `#[derive]`s if possible.

Fix #84515.
2021-10-06 06:20:25 +00:00
Esteban Kuber e8fc076f23 Consider unfulfilled obligations in binop errors
When encountering a binop where the types would have been accepted, if
all the predicates had been fulfilled, include information about the
predicates and suggest appropriate `#[derive]`s if possible.

Point at trait(s) that needs to be `impl`emented.
2021-10-05 23:34:13 +00:00
Tom Farmer 0950d5afe2 Issue 89275 fix and test
Issue 89275 fix and test

Fix librustdoc OverflowError usage

rust tidy run

Issue 89275 fix and test
2021-10-05 22:43:06 +01:00
bors 55111d656f Auto merge of #89266 - cjgillot:session-ich, r=michaelwoerister
Move ICH to rustc_query_system

Based on https://github.com/rust-lang/rust/pull/89183

The StableHashingContext does not need to be in rustc_middle.

This PR moves it to rustc_query_system. This will avoid a dependency between rustc_ast_lowering and rustc_middle in https://github.com/rust-lang/rust/pull/89124.
2021-10-05 09:45:11 +00:00
Jubilee 36f173f0a9
Rollup merge of #89466 - Mark-Simulacrum:query-macros, r=oli-obk
Fix bug with query modifier parsing

The previous macro_rules! parsers failed when an additional modifier was added
with ambiguity errors. The error is pretty unclear as to what exactly the cause
here is, but this change simplifies the argument parsing code such that the
error is avoided.

Extracted from other work, and somewhat duplicates 0358edeb5 from #85830, but
this approach seems a little simpler to me. Not technically currently necessary but seems
like a good cleanup.
2021-10-04 21:12:37 -07:00
Jubilee 99e6e3ff07
Rollup merge of #87993 - kornelski:try_reserve_stable, r=joshtriplett
Stabilize try_reserve

Stabilization PR for the [`try_reserve` feature](https://github.com/rust-lang/rust/issues/48043#issuecomment-898040475).
2021-10-04 21:12:33 -07:00
Jubilee 2bc89ce0bf
Rollup merge of #89453 - waywardmonkeys:consistent-supertrait-usage, r=nagisa
Consistently use 'supertrait'.

A subset of places referred to 'super-trait', so this changes them
to all use 'supertrait'. This matches 'supertype' and some other
usages. An exception is 'auto-trait' which is consistently used
in that manner.
2021-10-04 13:58:14 -07:00
Kornel 00152d8977 Stabilize try_reserve 2021-10-04 10:29:46 +01:00
Manish Goregaokar 5215b855b0
Rollup merge of #88481 - bjorn3:remove_feature_gates, r=cjgillot
Remove some feature gates

The first commit removes various feature gates that are unused. The second commit replaces some `Fn` implementations with `Iterator` implementations, which is much cleaner IMO. The third commit replaces an unboxed_closures feature gate with min_specialization. For some reason the unboxed_closures feature gate suppresses the min_specialization feature gate from triggering on an `TrustedStep` impl. The last comment just turns a regular comment into a doc comment as drive by cleanup. I can move it to a separate PR if preferred.
2021-10-03 23:13:20 -07:00
Camille GILLOT fedd7785fe Access StableHashingContext in rustc_query_system. 2021-10-03 16:08:55 +02:00
Camille GILLOT 471cb5c149 Fully remove rustc_middle::ich. 2021-10-03 16:08:55 +02:00
Camille GILLOT 02025d86ac Remove re-export. 2021-10-03 16:08:54 +02:00
Camille GILLOT c355b2e5cd Move ICH to rustc_query_system. 2021-10-03 16:08:53 +02:00
Camille GILLOT 2d38c53767 Remove StableHashProvider. 2021-10-03 16:08:52 +02:00
Camille GILLOT 8961616e60 Move rustc_middle::middle::cstore to rustc_session. 2021-10-03 16:08:51 +02:00
Camille GILLOT b66dfaaa64 Move some HashStable impls. 2021-10-03 16:08:50 +02:00
Cameron Steffen 67ea84d97a Add desugaring mark to while loop 2021-10-02 17:41:14 -05:00
bjorn3 e98f28907e Turn a module non-doc comment into a doc comment 2021-10-02 19:09:29 +02:00
bjorn3 83ddedf170 Remove various unused feature gates 2021-10-02 19:09:18 +02:00
bjorn3 e2d3e09b9c Prevent macro ambiguity errors
The previous macro_rules! parsers failed when an additional modifier was added
with ambiguity errors. The error is pretty unclear as to what exactly the cause
here is, but this change simplifies the argument parsing code such that the
error is avoided.
2021-10-02 13:00:19 -04:00
bors edebf77e00 Auto merge of #89408 - Mark-Simulacrum:fix-query-nondet, r=petrochenkov
Avoid nondeterminism in trimmed_def_paths

Previously this query depended on the global interning order of Symbols, which
meant that irrelevant changes could influence the query and cause
recompilations. This commit ensures that the return set is stable and will not
be affected by the global order by deterministically (in lexicographic order)
choosing a name to use if there are multiple names for a single DefId.

This should fix the cause of the [regressions] in #83343.

[regressions]: https://perf.rust-lang.org/compare.html?start=9620f3a84b079decfdc2e557be007580b097fe43&end=addb4da686a97da46159f0123cb6cdc2ce3d7fdb
2021-10-02 13:36:27 +00:00
Bruce Mitchener 058a21d5cf Consistently use 'supertrait'.
A subset of places referred to 'super-trait', so this changes them
to all use 'supertrait'. This matches 'supertype' and some other
usages. An exception is 'auto-trait' which is consistently used
in that manner.
2021-10-02 08:05:44 +07:00
bors 6e12110812 Auto merge of #89449 - Manishearth:rollup-3alb61f, r=Manishearth
Rollup of 7 pull requests

Successful merges:

 - #85223 (rustdoc: Clarified the attribute which prompts the warning)
 - #88847 (platform-support.md: correct ARMv7+MUSL platform triple notes)
 - #88963 (Coerce const FnDefs to implement const Fn traits )
 - #89376 (Fix use after drop in self-profile with llvm events)
 - #89422 (Replace whitespaces in doctests' name with dashes)
 - #89440 (Clarify a sentence in the documentation of Vec (#84488))
 - #89441 (Normalize after substituting via `field.ty()`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-10-01 22:47:22 +00:00
Manish Goregaokar 5ab1245303
Rollup merge of #89441 - Nadrieril:fix-89393, r=tmandry
Normalize after substituting via `field.ty()`

Back in https://github.com/rust-lang/rust/issues/72476 I hadn't understood where the problem was coming from, and only worked around the issue. What happens is that calling `field.ty()` on a field of a generic struct substitutes the appropriate generics but doesn't normalize the resulting type.
As a consumer of types I'm surprised that one would substitute without normalizing, feels like a footgun, so I added a comment.

Fixes https://github.com/rust-lang/rust/issues/89393.
2021-10-01 14:46:52 -07:00
Manish Goregaokar 743e842afb
Rollup merge of #88963 - fee1-dead:const-iterator, r=oli-obk
Coerce const FnDefs to implement const Fn traits

You can now pass a FnDef to a function expecting `F` where `F: ~const FnTrait`.

r? ``@oli-obk``

``@rustbot`` label T-compiler F-const_trait_impl
2021-10-01 14:46:48 -07:00
bors c02371c442 Auto merge of #88880 - cjgillot:no-krate, r=oli-obk
Rework HIR API to make invocations of the hir_crate query harder.

`hir_crate` forces the recomputation of queries that depend on it.

This PR aims at avoiding useless invocations of `hir_crate` by making dependent code go through `tcx.hir()`.
2021-10-01 20:06:34 +00:00
Nadrieril 68b76a4835 Normalize after substituting via `field.ty()` 2021-10-01 19:45:19 +01:00
David Wood 76b05531ca polymorphize: polymorphize shims
This commit removes the restriction of `InstanceDef::Item` on
polymorphization, so that shims can now be polymorphized.

Signed-off-by: David Wood <david.wood@huawei.com>
2021-10-01 17:08:06 +00:00
David Wood 4528b8e581 collector: limit pme context note to user-defd fns
rustc adds notes to errors which happen post-monomorphization to
provide the user with helpful context (as these errors may rely on the
specific instantiations). To prevent this note being added where it is
not appropriate, the node is checked to originate outwith the current
crate. However, when polymorphization is enabled, this can result in
some errors (produced by `optimized_mir`) to occur earlier in
compilation than they normally would, during the collection of shims.
Some shims have ids that originate in the standard library, but these
should not receive the PME note, so instances for compiler-generated
functions no longer receive this note.

Signed-off-by: David Wood <david.wood@huawei.com>
2021-10-01 16:34:18 +00:00
Manish Goregaokar 37df2753fc
Rollup merge of #87868 - Kixiron:packing-on-the-pounds, r=eddyb
Added -Z randomize-layout flag

An implementation of #77316, it currently randomly shuffles the fields of `repr(rust)` types based on their `DefPathHash`
r? ``@eddyb``
2021-10-01 09:18:16 -07:00
bors 4e4942dfa6 Auto merge of #89395 - In-line:remove_visible_path_from_allowed_deprecated_lint, r=jyn514
Remove visible path calculation from allowed deprecation lint
2021-10-01 06:19:52 +00:00
Chase Wilson 09f1542418
Implemented -Z randomize-layout 2021-09-30 14:50:06 -05:00
Mark Rousskov 56fcf0725a Avoid nondeterminism in trimmed_def_paths
Previously this query depended on the global interning order of Symbols, which
meant that irrelevant changes could influence the query and cause
recompilations. This commit ensures that the return set is stable and will not
be affected by the global order by deterministically (in lexicographic order)
choosing a name to use if there are multiple names for a single DefId.
2021-09-30 14:27:57 -04:00
Camille GILLOT b244b98e7c Move EncodedMetadata to rustc_metadata. 2021-09-30 19:41:32 +02:00
Camille GILLOT df54d3980b Move encode_metadata out of CrateStore. 2021-09-30 19:41:31 +02:00
Camille Gillot 77c300285c Apply suggestions from code review
Co-authored-by: Oli Scherer <github35764891676564198441@oli-obk.de>
2021-09-30 17:40:17 +02:00
Camille GILLOT faa7d4221b Do not pass hir::Crate to lints. 2021-09-30 17:39:54 +02:00
Alik Aslanyan d98ac573a4
Remove visible path calculation from allowed deprecation lint 2021-09-30 15:15:10 +04:00
Camille GILLOT abc57f63ad Move body_owners to tcx.hir(). 2021-09-29 23:16:48 +02:00
Camille GILLOT db9fea508a Avoid more invocations of hir_crate query. 2021-09-29 23:16:47 +02:00
Oli Scherer 9b5aa063d8 More tracing instrumentation 2021-09-28 12:28:22 +00:00
Tomasz Miąsko 25b6f9b68b print-type-sizes: skip field printing for primitives 2021-09-28 00:00:00 +00:00
Aaron Hill 41ad383e11
Remove `DefId` from `ConstraintCategory::Predicate`
This shirnks the size of `ConstraintCategory`, hopefully
fixing a performance regression.
2021-09-27 10:45:34 -05:00
Aaron Hill 93ab12eeab
Improve cause information for NLL higher-ranked errors
This PR has several interconnected pieces:

1. In some of the NLL region error code, we now pass
   around an `ObligationCause`, instead of just a plain `Span`.
   This gets forwarded into `fulfill_cx.register_predicate_obligation`
   during error reporting.
2. The general InferCtxt error reporting code is extended to
   handle `ObligationCauseCode::BindingObligation`
3. A new enum variant `ConstraintCategory::Predicate` is added.
   We try to avoid using this as the 'best blame constraint' - instead,
   we use it to enhance the `ObligationCause` of the `BlameConstraint`
   that we do end up choosing.

As a result, several NLL error messages now contain the same
"the lifetime requirement is introduced here" message as non-NLL
errors.

Having an `ObligationCause` available will likely prove useful
for future improvements to NLL error messages.
2021-09-27 10:23:45 -05:00
bors e9f29a8519 Auto merge of #89030 - nbdd0121:box2, r=jonas-schievink
Introduce `Rvalue::ShallowInitBox`

Polished version of #88700.

Implements MCP rust-lang/compiler-team#460, and should allow #43596 to go forward.

In short, creating an empty box is split from a nullary-op `NullOp::Box` into two steps, first a call to `exchange_malloc`, then a `Rvalue::ShallowInitBox` which transmutes `*mut u8` to a shallow-initialized `Box<T>`. This allows the `exchange_malloc` call to unwind. Details can be found in the MCP.

`NullOp::Box` is not yet removed, purely to make reverting easier in case anything goes wrong as the result of this PR. If revert is needed a reversion of "Use Rvalue::ShallowInitBox for box expression" commit followed by a test bless should be sufficient.

Experiments in #88700 showed a very slight compile-time perf regression due to (supposedly) slightly more time spent in LLVM. We could omit unwind edge generation (in non-`oom=panic` case) in box expression MIR construction to restore perf; but I don't think it's necessary since runtime perf isn't affected and perf difference is rather small.
2021-09-25 11:01:13 +00:00
Gary Guo c38da2e0a3 Introduce `Rvalue::ShallowInitBox` 2021-09-25 01:08:41 +01:00
Jubilee ee2e97c416
Rollup merge of #89001 - jackh726:binder-cleanup, r=nikomatsakis
Be explicit about using Binder::dummy

This is somewhat of a late followup to the binder refactor PR. It removes `ToPredicate` and `ToPolyTraitImpls` that hide the use of `Binder::dummy`. While this does make code a bit more verbose, it allows us be more careful about where we create binders.

Another alternative here might be to add a new trait `ToBinder` or something with a `dummy()` fn. Which could still allow grepping but allows doing something like `trait_ref.dummy()` (but I also wonder if longer-term, it would be better to be even more explicit with a `bind_with_vars(ty::List::empty())` *but* that's not clear yet.

r? ``@nikomatsakis``
2021-09-24 11:40:11 -07:00
bors 197fc8591e Auto merge of #89120 - In-line:remove_unneded_visible_parents_map, r=estebank
Disable visible path calculation for PrettyPrinter in Ok path of compiler
2021-09-24 05:29:49 +00:00
bors 293b8f2c11 Auto merge of #89211 - workingjubilee:rollup-fj4eduk, r=workingjubilee
Rollup of 7 pull requests

Successful merges:

 - #88612 (Add a better error message for #39364)
 - #89023 (Resolve issue : Somewhat confusing error with extended_key_value_attributes)
 - #89148 (Suggest `_` in turbofish if param will be inferred from fn argument)
 - #89171 (Run `no_core` rustdoc tests only on Linux)
 - #89176 (Change singular to plural)
 - #89184 (Temporarily rename int_roundings functions to avoid conflicts)
 - #89200 (Fix typo)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-09-24 01:48:02 +00:00
Jubilee 1875cecfd4
Rollup merge of #89200 - hkmatsumoto:patch, r=workingjubilee
Fix typo
2021-09-23 17:31:47 -07:00
bors 900cf5e890 Auto merge of #88804 - Mark-Simulacrum:never-algo-v2, r=nikomatsakis,jackh726
Revise never type fallback algorithm

This is a rebase of https://github.com/rust-lang/rust/pull/84573, but dropping the stabilization of never type (and the accompanying large test diff).

Each commit builds & has tests updated alongside it, and could be reviewed in a more or less standalone fashion. But it may make more sense to review the PR as a whole, I'm not sure. It should be noted that tests being updated isn't really a good indicator of final behavior -- never_type_fallback is not enabled by default in this PR, so we can't really see the full effects of the commits here.

This combines the work by Niko, which is [documented in this gist](https://gist.github.com/nikomatsakis/7a07b265dc12f5c3b3bd0422018fa660), with some additional rules largely derived to target specific known patterns that regress with the algorithm solely derived by Niko. We build these from an intuition that:

* In general, fallback to `()` is *sound* in all cases
* But, in general, we *prefer* fallback to `!` as it accepts more code, particularly that written to intentionally use `!` (e.g., Result's with a Infallible/! variant).

When evaluating Niko's proposed algorithm, we find that there are certain cases where fallback to `!` leads to compilation failures in real-world code, and fallback to `()` fixes those errors. In order to allow for stabilization, we need to fix a good portion of these patterns.

The final rule set this PR proposes is that, by default, we fallback from `?T` to `!`, with the following exceptions:

1. `?T: Foo` and `Bar::Baz = ?T` and `(): Foo`, then fallback to `()`
2. Per [Niko's algorithm](https://gist.github.com/nikomatsakis/7a07b265dc12f5c3b3bd0422018fa660#proposal-fallback-chooses-between--and--based-on-the-coercion-graph), the "live" `?T` also fallback to `()`.

The first rule is necessary to address a fairly common pattern which boils down to something like the snippet below. Without rule 1, we do not see the closure's return type as needing a () fallback, which leads to compilation failure.

```rust
#![feature(never_type_fallback)]

trait Bar { }
impl Bar for () {  }
impl Bar for u32 {  }

fn foo<R: Bar>(_: impl Fn() -> R) {}

fn main() {
    foo(|| panic!());
}
```

r? `@jackh726`
2021-09-23 22:45:22 +00:00
bors bf642323d6 Auto merge of #89016 - lcnr:non_blanket_impls, r=nikomatsakis,michaelwoerister
fix non_blanket_impls iteration order

We sometimes iterate over all `non_blanket_impls`, not sure if this is observable outside
of error messages (i.e. as incremental bugs). This should fix the underlying issue of #86986.

second attempt of #88718

r? `@nikomatsakis`
2021-09-23 15:44:53 +00:00
Hirochika Matsumoto c713ffbe39 Fix typo 2021-09-23 18:57:23 +09:00
Aaron Hill 94b19fac26
Support `#[track_caller]` on closures and generators
This PR allows applying a `#[track_caller]` attribute to a
closure/generator expression. The attribute as interpreted as applying
to the compiler-generated implementation of the corresponding trait
method (`FnOnce::call_once`, `FnMut::call_mut`, `Fn::call`, or
`Generator::resume`).

This feature does not have its own feature gate - however, it requires
`#![feature(stmt_expr_attributes)]` in order to actually apply
an attribute to a closure or generator.

This is implemented in the same way as for functions - an extra
location argument is appended to the end of the ABI. For closures,
this argument is *not* part of the 'tupled' argument storing the
parameters - the final closure argument for `#[track_caller]` closures
is no longer a tuple.

For direct (monomorphized) calls, the necessary support was already
implemented - we just needeed to adjust some assertions around checking
the ABI and argument count to take closures into account.

For calls through a trait object, more work was needed.
When creating a `ReifyShim`, we need to create a shim
for the trait method (e.g. `FnOnce::call_mut`) - unlike normal
functions, closures are never invoked directly, and always go through a
trait method.

Additional handling was needed for `InstanceDef::ClosureOnceShim`. In
order to pass location information throgh a direct (monomorphized) call
to `FnOnce::call_once` on an `FnMut` closure, we need to make
`ClosureOnceShim` aware of `#[tracked_caller]`. A new field
`track_caller` is added to `ClosureOnceShim` - this is used by
`InstanceDef::requires_caller` location, allowing codegen to
pass through the extra location argument.

Since `ClosureOnceShim.track_caller` is only used by codegen,
we end up generating two identical MIR shims - one for
`track_caller == true`, and one for `track_caller == false`. However,
these two shims are used by the entire crate (i.e. it's two shims total,
not two shims per unique closure), so this shouldn't a big deal.
2021-09-22 15:19:33 -05:00
bors d8d1d1059a Auto merge of #89158 - the8472:rollup-3e4ijth, r=the8472
Rollup of 12 pull requests

Successful merges:

 - #88795 (Print a note if a character literal contains a variation selector)
 - #89015 (core::ascii::escape_default: reduce struct size)
 - #89078 (Cleanup: Remove needless reference in ParentHirIterator)
 - #89086 (Stabilize `Iterator::map_while`)
 - #89096 ([bootstrap] Improve the error message when `ninja` is not found to link to installation instructions)
 - #89113 (dont `.ensure()` the `thir_abstract_const` query call in `mir_build`)
 - #89114 (Fixes a technicality regarding the size of C's `char` type)
 - #89115 (⬆️ rust-analyzer)
 - #89126 (Fix ICE when `indirect_structural_match` is allowed)
 - #89141 (Impl `Error` for `FromSecsError` without foreign type)
 - #89142 (Fix match for placeholder region)
 - #89147 (add case for checking const refs in check_const_value_eq)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-09-21 22:07:32 +00:00
the8472 a3e6c19acf
Rollup merge of #89147 - b-naber:refs_in_check_const_value_eq, r=oli-obk
add case for checking const refs in check_const_value_eq

Previously in `check_const_value_eq` we destructured `ConstValue::ByRef` instances, this didn't account for `ty::Ref`s however, which led to an ICE.

Fixes https://github.com/rust-lang/rust/issues/88876
Fixes https://github.com/rust-lang/rust/issues/88384

r? `@oli-obk`
2021-09-21 22:54:08 +02:00
the8472 aca790b3d6
Rollup merge of #89142 - nerandell:master, r=jackh726
Fix match for placeholder region

cc #89118
2021-09-21 22:54:07 +02:00
the8472 9f50c87267
Rollup merge of #89078 - camsteffen:map-ref, r=cjgillot
Cleanup: Remove needless reference in ParentHirIterator

It forces an intermediate binding of `Map` which is a Copy type.
2021-09-21 22:54:00 +02:00
bors ac2d9fc509 Auto merge of #89103 - Mark-Simulacrum:migrate-2021, r=estebank
Migrate in-tree crates to 2021

This replaces #89075 (cherry picking some of the commits from there), and closes #88637 and fixes #89074.

It excludes a migration of the library crates for now (see tidy diff) because we have some pending bugs around macro spans to fix there.

I instrumented bootstrap during the migration to make sure all crates moved from 2018 to 2021 had the compatibility warnings applied first.

Originally, the intent was to support cargo fix --edition within bootstrap, but this proved fairly difficult to pull off. We'd need to architect the check functionality to support running cargo check and cargo fix within the same x.py invocation, and only resetting sysroots on check. Further, it was found that cargo fix doesn't behave too well with "not quite workspaces", such as Clippy which has several crates. Bootstrap runs with --manifest-path ... for all the tools, and this makes cargo fix only attempt migration for that crate. We can't use e.g. --workspace due to needing to maintain sysroots for different phases of compilation appropriately.

It is recommended to skip the mass migration of Cargo.toml's to 2021 for review purposes; you can also use `git diff d6cd2c6c87 -I'^edition = .20...$'` to ignore the edition = 2018/21 lines in the diff.
2021-09-21 19:25:49 +00:00
b-naber 999888c086 add case for checking const refs in check_const_value_eq 2021-09-21 15:49:29 +02:00
Ankit Chandawala d4ee6982e4 Fix match for placeholder region 2021-09-21 09:31:59 +01:00
bors 49c0861ed0 Auto merge of #87234 - cjgillot:lower-mono, r=petrochenkov
Lower only one HIR owner at a time

Based on https://github.com/rust-lang/rust/pull/83723
Additional diff is here: https://github.com/cjgillot/rust/compare/ownernode...lower-mono

Lowering is very tangled and has a tendency to intertwine the transformation of different items. This PR aims at simplifying the logic by:
- moving global analyses to the resolver (item_generics_num_lifetimes, proc_macros, trait_impls);
- removing a few special cases (non-exported macros and use statements);
- restricting the amount of available information at any one time;
- avoiding back-and-forth between different owners: an item must now be lowered all at once, and its parent cannot refer to its nodes.

I also removed the sorting of bodies by span.  The diagnostic ordering changes marginally, since definitions are pretty much sorted already according to the AST. This uncovered a subtlety in thir-unsafeck.

(While these items could logically be in different PRs, the dependency between commits and the amount of conflicts force a monolithic PR.)
2021-09-21 07:52:15 +00:00
lcnr 5b9cc2068f use indexmap instead of hashmap 2021-09-21 08:24:23 +02:00
lcnr ca2c55d264 rename 2021-09-21 08:24:23 +02:00
Mark Rousskov 3b89679671 Adjust documentation for compatibility with 2021
This also adjusts the lint docs generation to accept (and ignore) an allow
attribute, rather than expecting the documentation to be immediately followed by
the lint name.
2021-09-20 22:21:43 -04:00
Mark Rousskov c746be2219 Migrate to 2021 2021-09-20 22:21:42 -04:00
Richard Cobbe 142f6c0b07 Implement #[link_ordinal] attribute in the context of #[link(kind = "raw-dylib")]. 2021-09-20 14:50:35 -07:00
Alik Aslanyan 9da27f0429
Disable visible path calculation for PrettyPrinter in Ok path of compiler 2021-09-21 00:41:44 +04:00
bors 0c0826c3e2 Auto merge of #88708 - Aaron1011:aggregate-usage, r=oli-obk
Add `ConstraintCategory::Usage` for handling aggregate construction

In some cases, we emit borrowcheck diagnostics pointing
at a particular field expression in a struct expression
(e.g. `MyStruct { field: my_expr }`). However, this
behavior currently relies on us choosing the
`ConstraintCategory::Boring` with the 'correct' span.
When adding additional variants to `ConstraintCategory`,
(or changing existing usages away from `ConstraintCategory::Boring`),
the current behavior can easily get broken, since a non-boring
constraint will get chosen over a boring one.

To make the diagnostic output less fragile, this commit
adds a `ConstraintCategory::Usage` variant. We use this variant
for the temporary assignments created for each field of
an aggregate we are constructing.

Using this new variant, we can emit a message mentioning
"this usage", emphasizing the fact that the error message
is related to the specific use site (in the struct expression).

This is preparation for additional work on improving NLL error messages
(see #57374)
2021-09-20 00:53:13 +00:00
Camille GILLOT d7795d302a Do not store visibility in *ItemRef. 2021-09-20 00:29:53 +02:00
bors 91198820d7 Auto merge of #88575 - eddyb:fn-abi-queries, r=nagisa
Querify `FnAbi::of_{fn_ptr,instance}` as `fn_abi_of_{fn_ptr,instance}`.

*Note: opening this PR as draft because it's based on #88499*

This more or less replicates the `LayoutOf::layout_of` setup from #88499, to replace `FnAbi::of_{fn_ptr,instance}` with `FnAbiOf::fn_abi_of_{fn_ptr,instance}`, and also route them through queries (which `layout_of` has used for a while).

The two changes at the use sites (other than the names) are:
* return type is now wrapped in `&'tcx`
  * the value *is* interned, which may affect performance
* the `extra_args` list is now an interned `&'tcx ty::List<Ty<'tcx>>`
  * should be cheap (it's empty for anything other than C variadics)

Theoretically, a `FnAbiOfHelpers` implementer could choose to keep the `Result<...>` instead of eagerly erroring, but the only existing users of these APIs are codegen backends, so they don't (want to) take advantage of this.
At least miri could make use of this, since it prefers propagating errors (it "just" doesn't use `FnAbi` yet - cc `@RalfJung).`

The way this is done is probably less efficient than what is possible, because the queries handle the correctness-oriented API (i.e. the split into `fn` pointers vs instances), whereas a lower-level query could end up with more reuse between different instances with identical signatures.

r? `@nagisa` cc `@oli-obk` `@bjorn3`
2021-09-19 21:39:47 +00:00
bors 7b5f95270f Auto merge of #88703 - cjgillot:lazymod, r=petrochenkov
Gather module items after lowering.

This avoids having a non-local analysis inside lowering.

By implementing `hir_module_items` using a visitor, we make sure that iterations and visitors are consistent.
2021-09-19 16:13:42 +00:00
bors 697118d23e Auto merge of #88627 - cjgillot:noallocuse, r=petrochenkov
Do not preallocate HirIds

Part of https://github.com/rust-lang/rust/pull/87234

r? `@petrochenkov`
2021-09-19 13:44:18 +00:00
Cameron Steffen 7c8f4f7eab Remove needless hir Map ref 2021-09-18 15:55:34 -05:00