Commit graph

8348 commits

Author SHA1 Message Date
Oli Scherer
5fb1a65215 Inline a function that is only called once 2021-09-20 14:15:36 +00:00
Oli Scherer
5afeed05e8 Use tracing debugging in fold_opaque_ty 2021-09-20 14:15:36 +00:00
Oli Scherer
dfb11a8a26 Add helper function to InferCtxt that generates inference vars for unresolved associated types 2021-09-20 13:57:56 +00:00
Michael Woerister
543a73d678 Update odht crate to 0.3.0
This version of odht contains a potential fix for #89085.
2021-09-20 15:57:45 +02:00
Mark Rousskov
45b989a033 Enable 2021 compatibility lints for all in-tree code
This just applies the suggested fixes from the compatibility warnings,
leaving any that are in practice spurious in. This is primarily intended to
provide a starting point to identify possible fixes to the migrations (e.g., by
avoiding spurious warnings).

A secondary commit cleans these up where they are false positives (as is true in
many of the cases).
2021-09-20 08:45:39 -04:00
Mark Rousskov
5e1a614b53 Adjust to SourceType::InTree in several places
These were left over in migrations to subtrees, which should generally be treated
as-if it was local.

Also fixes a warning caused by this change.
2021-09-20 08:45:39 -04:00
Mark Rousskov
440d9372a2 Workaround ICE with if-let and RFC 2229 2021-09-20 08:45:39 -04:00
Ellen
5fdb9e4cf4 no ensure 2021-09-20 09:30:28 +01:00
bors
db1fb85cff Auto merge of #88321 - glaubitz:m68k-linux, r=wesleywiser
Add initial support for m68k

This patch series adds initial support for m68k making use of the new M68k
backend introduced with LLVM-13. Additional changes will be needed to be
able to actually use the backend for this target.
2021-09-20 07:21:05 +00:00
Camille GILLOT
a1a35576eb Make with_hir_id_owner responsible for registering the item. 2021-09-20 08:31:16 +02: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
c1bac9229a Remove lower_node_id_with_owner. 2021-09-20 00:50:47 +02: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
5ecc8ad846 Auto merge of #89049 - Aaron1011:caching-sourcemap-assert, r=Mark-Simulacrum
Convert `debug_assert` to `assert` in `CachingSourceMapView`

I suspect that there's a bug somewhere in this code, which is
leading to the `predicates_of` ICE being seen in #89035
2021-09-19 18:54:31 +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
bjorn3
86f9bcfb8e Merge commit '61667dedf55e3e5aa584f7ae2bd0471336b92ce9' into sync_cg_clif-2021-09-19 2021-09-19 13:56:58 +02:00
Hirochika Matsumoto
21eff8f050 Suggest replacing braces for brackets on array-esque invalid block expr
Newcomers may write `{1, 2, 3}` for making arrays, and the current error
message is not informative enough to quickly convince them what is
needed to fix the error.
This PR implements a diagnostic for this case, and its output looks like
this:
```text
error: this code is interpreted as a block expression, not an array
 --> src/lib.rs:1:22
  |
1 |   const FOO: [u8; 3] = {
  |  ______________________^
2 | |     1, 2, 3
3 | | };
  | |_^
  |
  = note: to define an array, one would use square brackets instead of curly braces
help: try using [] instead of {}
  |
1 | const FOO: [u8; 3] = [
2 |     1, 2, 3
3 | ];
  |
```

Fix #87672
2021-09-19 20:01:23 +09:00
Theo
250a3e482f Resolve issue 85066
Fix : use struct_dummy

Fix different os messages
2021-09-19 10:53:49 +02:00
Yuki Okushi
441046af97
Rollup merge of #89055 - Kobzol:wrapped-method-expr-call-parens, r=wesleywiser
Suggest better place to add call parentheses for method expressions wrapped in parentheses

I wanted to improve the suggestion a bit to both remove the wrapping parentheses **and** add call parentheses by both calling `suggest_method_call` and using `multipart_suggestion`. But I very quickly ran into a problem where multiple overlapping machine applicable suggestions cannot be properly applied together. So I applied the suggestion from the issue and only added the call parentheses directly after the expression.

Fixes: https://github.com/rust-lang/rust/issues/89044
2021-09-19 17:31:35 +09:00
Yuki Okushi
61bfe3653b
Rollup merge of #89021 - WaffleLapkin:separate_error_for_dyn_trait_in_const_fn, r=estebank
Add a separate error for `dyn Trait` in `const fn`

Previously "trait bounds other than `Sized` on const fn parameters are unstable" error was used for both trait bounds (`<T: Trait>`) and trait objects (`dyn Trait`). This was pretty confusing.

This PR adds a separate error for trait objects: "trait objects in const fn are unstable". The error for trait bounds is otherwise intact.

This is follow up to #88907

r? ``@estebank``

``@rustbot`` label: +A-diagnostics
2021-09-19 17:31:33 +09:00
Yuki Okushi
1c3fce01df
Rollup merge of #88996 - Aaron1011:trailing-macro-semi, r=petrochenkov
Fix linting when trailing macro expands to a trailing semi

When a macro is used in the trailing expression position of a block
(e.g. `fn foo() { my_macro!() }`), we currently parse it as an
expression, rather than a statement. As a result, we ended up
using the `NodeId` of the containing statement as our `lint_node_id`,
even though we don't normally do this for macro calls.

If such a macro expands to an expression with a `#[cfg]` attribute,
then the trailing statement can get removed entirely. This lead to
an ICE, since we were usng the `NodeId` of the expression to emit
a lint.

Ths commit makes us skip updating `lint_node_id` when handling
a macro in trailing expression position. This will cause us to
lint at the closest parent of the macro call.
2021-09-19 17:31:31 +09:00
Yuki Okushi
ba1a90a417
Rollup merge of #88966 - tmiasko:block-label-shadowing, r=petrochenkov
Check for shadowing issues involving block labels
2021-09-19 17:31:30 +09:00
Yuki Okushi
e675073e73
Rollup merge of #88855 - calebzulawski:feature/simd_shuffle, r=nagisa
Allow simd_shuffle to accept vectors of any length

cc ``@rust-lang/project-portable-simd`` ``@workingjubilee``
2021-09-19 17:31:29 +09:00
Yuki Okushi
ebd31f5f1a
Rollup merge of #87960 - hkmatsumoto:suggest-inexisting-field-for-unmentioned-field, r=estebank
Suggest replacing an inexisting field for an unmentioned field

Fix #87938

This PR adds a suggestion to replace an inexisting field for an
unmentioned field. Given the following code:
```rust
enum Foo {
    Bar { alpha: u8, bravo: u8, charlie: u8 },
}

fn foo(foo: Foo) {
    match foo {
        Foo::Bar {
            alpha,
            beta, // `bravo` miswritten as `beta` here.
            charlie,
        } => todo!(),
    }
}
```
the compiler now emits the error messages below.
```text
error[E0026]: variant `Foo::Bar` does not have a field named `beta`
 --> src/lib.rs:9:13
  |
9 |             beta, // `bravo` miswritten as `beta` here.
  |             ^^^^
  |             |
  |             variant `Foo::Bar` does not have this field
  |             help: `Foo::Bar` has a field named `bravo`: `bravo`
```

Note that this suggestion is available iff the number of inexisting
fields and unmentioned fields are both 1.
2021-09-19 17:31:29 +09:00
bors
3bca7230ff Auto merge of #89028 - Aaron1011:coercion-cause, r=nagisa
Propagate coercion cause into `try_coerce`

Currently, `coerce_inner` discards its `ObligationCause`
when calling `try_coerce`. This interfers with other
diagnostc improvements I'm working on, since we will lose
the original span by the time the actual coercion occurs.

Additionally, we now use the span of the trailing expression
(rather than the span of the entire function) when performing
a coercion in `check_return_expr`. This currently has no visible
effect on any of the unit tests, but will unblock future
diagnostic improvements.
2021-09-19 04:34:16 +00:00
bors
10967a1dcc Auto merge of #88968 - tmiasko:start-block-no-predecessors, r=davidtwco
Start block is not allowed to have basic block predecessors

* The MIR validator is extended to detect potential violations.
* The start block has no predecessors after building MIR, so no changes are required there.
* The SimplifyCfg could previously violate this requirement when collapsing goto chains, so transformation is disabled for the start block, which also substantially simplifies the implementation.
* The LLVM function entry block also must not have basic block predecessors. Previously, to ensure that code generation had to perform necessary adjustments. This now became unnecessary.

The motivation behind the change is to align with analogous requirement in LLVM, and to avoid potential latent bugs like the one reported in #88043.
2021-09-19 01:38:17 +00:00
Cameron Steffen
7c8f4f7eab Remove needless hir Map ref 2021-09-18 15:55:34 -05:00
bors
aa8f2d432b Auto merge of #89000 - Mark-Simulacrum:no-new-lrc, r=petrochenkov
Reuse existing shared Lrc for MatchImpl parent

This is a small performance win for the hot path, which helps to address this regression: https://github.com/rust-lang/rust/pull/87244#issuecomment-883635813.
2021-09-18 20:13:21 +00:00
Gus Wynn
08e026675e deduplication 2021-09-18 13:00:36 -07:00
Gus Wynn
f1021bf054 generic test 2021-09-18 12:23:16 -07:00
bors
35c8f2612f Auto merge of #88994 - Aaron1011:intercrate-caching, r=jackh726
Disable the evaluation cache when in intercrate mode

It's possible to use the same `InferCtxt` with both
an intercrate and non-intercrate `SelectionContext`. However,
the local (inferctxt) evaluation cache is not aware of this
distinction, so this kind of `InferCtxt` re-use will pollute
the cache wth bad results.

This commit avoids the issue by disabling the evaluation cache
entirely during intercrate mode.
2021-09-18 17:18:28 +00:00
bors
d6cd2c6c87 Auto merge of #82183 - michaelwoerister:lazier-defpathhash-loading2, r=wesleywiser
Simplify lazy DefPathHash decoding by using an on-disk hash table.

This PR simplifies the logic around mapping `DefPathHash` values encountered during incremental compilation to valid `DefId`s in the current session. It is able to do so by using an on-disk hash table encoding that allows for looking up values directly, i.e. without deserializing the entire table.

The main simplification comes from not having to keep track of `DefPathHashes` being used during the compilation session.
2021-09-18 14:37:39 +00:00
bjorn3
7b50fd5450 Use <[T; N]>::map in Sharded instead of SmallVec and unsafe code
This results in a lot less assembly
2021-09-18 15:07:24 +02:00
Camille GILLOT
d60bbde7e2 Do not preallocate UseTree HirIds. 2021-09-18 14:41:50 +02:00
bors
23afad6e7f Auto merge of #88650 - sapessi:issue-77175-fix, r=estebank
Skip single use lifetime lint for generated opaque types

Fix: #77175

The opaque type generated by the desugaring process of an async function uses the lifetimes defined by the originating function. The DefId for the lifetimes in the opaque type are different from the ones in the originating async function - as they should be, as far as I understand, and could therefore be considered a single use lifetimes, this causes the single_use_lifetimes lint to fail compilation if explicitly denied. This fix skips the lint for lifetimes used only once in generated opaque types for an async function that are declared in the parent async function definition.

More info in the comments on the original issue: 1 and 2
2021-09-18 11:56:23 +00:00
Jakub Beránek
68147ebd60
Suggest better place to add call parentheses for method expressions wrapped in parentheses 2021-09-18 13:55:40 +02:00
Camille GILLOT
59f43bdd29 Do not preallocate item HirIds. 2021-09-18 13:14:29 +02:00
bors
5438ee424c Auto merge of #88980 - tmiasko:instrument-debug, r=oli-obk
Use explicit log level in tracing instrument macro

Specify a log level in tracing instrument macro explicitly.

Additionally reduce the used log level from a default info level to a
debug level (all of those appear to be developer oriented logs, so there
should be no need to include them in release builds).
2021-09-18 06:11:02 +00:00
bors
6c33a0a2ec Auto merge of #88978 - bjorn3:move_symbol_interner_lock, r=Mark-Simulacrum
Move the Lock into symbol::Interner

This makes it easier to make the symbol interner (near) lock free in case of concurrent accesses in the future.

With https://github.com/rust-lang/rust/pull/87867 landed this shouldn't affect performance anymore.
2021-09-18 03:30:13 +00:00
Eduard-Mihai Burtescu
8c918d7e2d [HACK(eddyb)] arena-allocate but don't intern FnAbis. 2021-09-18 04:41:33 +03:00
Eduard-Mihai Burtescu
c1837ef1c5 Querify fn_abi_of_{fn_ptr,instance}. 2021-09-18 04:41:33 +03:00
Eduard-Mihai Burtescu
e9b68304ef ty::layout: replicate layout_of setup for fn_abi_of_{fn_ptr,instance}. 2021-09-18 04:41:29 +03:00
bors
8e398f5ba7 Auto merge of #88965 - fee1-dead:const-drop-1, r=oli-obk
Fast reject for NeedsNonConstDrop

Hopefully fixes the regression in #88558.

I've always wanted to help with the performance of rustc, but it doesn't feel the same when you are fixing a regression caused by your own PR...

r? `@oli-obk`
2021-09-18 00:18:28 +00:00
Tomasz Miąsko
3489ba3bbb Remove support for reentrant start blocks from codegen
The start block is guaranteed not to have any basic block predecessors.
2021-09-18 07:28:56 +02:00
Tomasz Miąsko
4d614e1d1f Do not collapse goto chains beginning with the start block
If any block on a goto chain has more than one predecessor, then the new
start block would have basic block predecessors.

Skip the transformation for the start block altogether, to avoid
violating the new invariant that the start block does not have any basic
block predecessors.
2021-09-18 07:28:55 +02:00
Tomasz Miąsko
5118dd5a2f Start block is not allowed to have basic block predecessors 2021-09-18 07:28:55 +02:00
Eduard-Mihai Burtescu
319dec89e7 rustc_codegen_llvm: move misplaced HasParamEnv impl. 2021-09-18 01:42:45 +03:00
Eduard-Mihai Burtescu
344df76fed ty::layout: intern FnAbis as &'tcx. 2021-09-18 01:42:45 +03:00
Eduard-Mihai Burtescu
0c02e3f550 ty::context: move interning Allocations and Layouts to direct_interners!. 2021-09-18 01:42:44 +03:00
Eduard-Mihai Burtescu
7f2f927eb8 ty::layout: propagate errors up to (but not out of) FnAbi::of_*. 2021-09-18 01:42:44 +03:00
Eduard-Mihai Burtescu
4d36faf9ef rustc_target: adjust_for_cabi -> adjust_for_foreign_abi. 2021-09-18 01:42:43 +03:00
Eduard-Mihai Burtescu
feca7d0a03 ty::layout: split out a private trait from FnAbiExt. 2021-09-18 01:42:43 +03:00
Eduard-Mihai Burtescu
a1d7c51d27 ty::layout: move trait FnAbiExt to just before its impl. 2021-09-18 01:42:43 +03:00
Antoni Boucher
df487317d0 Merge commit '48d60ab7c505c6c1ebb042eacaafd8dc9f7a9267' into libgccjit-codegen 2021-09-17 17:52:40 -04:00
bors
a58db2e4dd Auto merge of #88962 - fee1-dead:const-drop, r=oli-obk
inline(always) on check_recursion_limit

r? `@oli-obk`

#88558 caused a regression, this PR adds `#[inline(always)]` to `check_recursion_limit`, a possible suspect of that regression.
2021-09-17 21:37:01 +00:00
Mark Rousskov
078e3fd4ba Add another case of fallback to () avoid breakage
This adds src/test/ui/never_type/fallback-closure-ret.rs as a test case which
showcases the failure mode fixed by this commit.
2021-09-17 15:34:47 -04:00
Aaron Hill
95bea1594c
Convert debug_assert to assert in CachingSourceMapView
I suspect that there's a bug somewhere in this code, which is
leading to the `predicates_of` ICE being seen in #89035
2021-09-17 12:01:29 -05:00
Niko Matsakis
59dc2013e2 optimization: use a single DepthFirstSearch instead of hashsets
Extend the `DepthFirstSearch` iterator so that it can be re-used and
extended with add'l start nodes. Then replace the FxHashSets of nodes
we were using in the fallback analysis with a single iterator. This
way we won't re-walk portions of the graph that are reached more than
once, and we also do less allocation etc.
2021-09-17 12:47:48 -04:00
Niko Matsakis
bc2ece2a8d stop categorizing inference variables as diverging when created
Instead, we now rely on the code that looks for a NeverToAny adjustment.
2021-09-17 12:47:48 -04:00
Niko Matsakis
1c004f2d43 remove reliance on "diverging" type variables
Instead, we now record those type variables that are the target of a
`NeverToAny` adjustment and consider those to be the "diverging" type
variables. This allows us to remove the special case logic that
creates a type variable for `!` in coercion.
2021-09-17 12:47:48 -04:00
Niko Matsakis
ebb8ff9edf remove diverging type variables from fn check
The comment seems incorrect. Testing revealed that the examples in
question still work (as well as some variants) even without the
special casing here.
2021-09-17 12:47:48 -04:00
Niko Matsakis
2ee89144e2 introduce new fallback algorithm
We now fallback type variables using the following rules:

* Construct a coercion graph `A -> B` where `A` and `B` are unresolved
  type variables or the `!` type.
* Let D be those variables that are reachable from `!`.
* Let N be those variables that are reachable from a variable not in
D.
* All variables in (D \ N) fallback to `!`.
* All variables in (D & N) fallback to `()`.
2021-09-17 12:47:48 -04:00
Maybe Waffle
71e2eacc7b Stabilize Iterator::map_while 2021-09-17 19:42:46 +03:00
Guillaume Gomez
101a88f950
Rollup merge of #89012 - vishadGoyal:issue-88802-fix, r=jyn514
Suggest removing `#![feature]` for library features that have been stabilized

Issue: https://github.com/rust-lang/rust/issues/88802
Delayed the check if #![feature] has been used to enable lib features in a non-nightly build to occur after TyCtxt has been constructed.
2021-09-17 17:41:21 +02:00
Guillaume Gomez
eb62779f2d
Rollup merge of #88954 - nbdd0121:panic3, r=oli-obk
Allow `panic!("{}", computed_str)` in const fn.

Special-case `panic!("{}", arg)` and translate it to `panic_display(&arg)`. `panic_display` will behave like `panic_any` in cosnt eval and behave like `panic!(format_args!("{}", arg))` in runtime.

This should bring Rust 2015 and 2021 to feature parity in terms of `const_panic`; and hopefully would unblock the stabilisation of #51999.

`@rustbot` modify labels: +T-compiler +T-libs +A-const-eval +A-const-fn

r? `@oli-obk`
2021-09-17 17:41:19 +02:00
Guillaume Gomez
6f5c09849e
Rollup merge of #88949 - FabianWolff:issue-87563, r=estebank
Fix handling of `hir::GenericArg::Infer` in `wrong_number_of_generic_args.rs`

Fixes #87563. More precisely, I have fixed the "index out of bounds" error, which is what #87563 is about. The example given there still ICEs due to running into this `todo!()`, but I'd say that this is a separate issue:
c3c0f80d60/compiler/rustc_typeck/src/astconv/mod.rs (L460-L463)
2021-09-17 17:41:17 +02:00
Guillaume Gomez
307f2ddfa4
Rollup merge of #88899 - FabianWolff:issue-88844, r=matthewjasper
Do not issue E0071 if a type error has already been reported

Fixes #88844. A suggested fix is already included in the error message for E0412, so with my changes, E0071 is simply not emitted anymore if the type in question is a "type error". This makes sense, I think, because we cannot confidently state that something is "not a struct" if we couldn't resolve it properly; and it's unnecessary to pollute the output with this additional error message, as it is a direct consequence of the former error.

I have also addressed the issue mentioned in https://github.com/rust-lang/rust/issues/88844#issuecomment-917324856 by changing the fixed example in the documentation to more closely match the erroneous code example.
2021-09-17 17:41:16 +02:00
Guillaume Gomez
1b7896716e
Rollup merge of #87566 - JohnTitor:find-eqeq-on-assoc-type-bounds, r=estebank
Recover invalid assoc type bounds using `==`

Fix #87493
r? `@estebank`
2021-09-17 17:41:14 +02:00
Guillaume Gomez
aed7f00097
Rollup merge of #87460 - FabianWolff:issue-87456, r=Aaron1011
Point to closure when emitting 'cannot move out' for captured variable

Attempts to fix #87456. The error message now points to the capturing closure, but I was not able to explain _why_ the closure implements `Fn` or `FnMut` (`TypeckResults::closure_kind_origins` did not contain anything for the closure in question).

cc `@Aaron1011`
2021-09-17 17:41:13 +02:00
Guillaume Gomez
b6d0ccab72
Rollup merge of #86422 - JohnTitor:clearer-parens-err-for-loop, r=estebank
Emit clearer diagnostics for parens around `for` loop heads

Fixes #63113
r? `@estebank`
2021-09-17 17:41:12 +02:00
Yilin Chen
d5de680e20 Work around invalid DWARF bugs for fat LTO
Signed-off-by: Yilin Chen <sticnarf@gmail.com>
2021-09-17 23:19:38 +08:00
John Paul Adrian Glaubitz
fa27d50caa compiler/rustc_llvm: Enable M68k LLVM target 2021-09-17 15:07:14 +00:00
John Paul Adrian Glaubitz
580559129b compiler/rustc_target: Add support for m68k-linux-gnu 2021-09-17 15:07:12 +00:00
Michael Woerister
4d151d92de Update odht to 0.2.1 2021-09-17 15:57:57 +02:00
bors
e0c38af27c Auto merge of #88945 - Aaron1011:no-projection-completion, r=wesleywiser,jackh726
Remove concept of 'completion' from the projection cache

Fixes #88910

When we initially store a `NormalizedTy` in the projection cache,
we discard all obligations that we can (while ensuring that we
don't cause any issues with incremental compilation).

Marking a projection cache entry as 'completed' discards all
obligations associated with it. This can only cause problems,
since any obligations stored in the cache are there for a reason
(e.g. they evaluate to `EvaluatedToOkModuloRegions`).

This commit removes `complete` and `complete_normalized` entirely.
2021-09-17 09:44:28 +00:00
bors
1c03f0d0ba Auto merge of #89037 - JohnTitor:rollup-rd9btbs, r=JohnTitor
Rollup of 10 pull requests

Successful merges:

 - #86382 (Make diagnostics clearer for `?` operators)
 - #87529 (Fix ICE in `improper_ctypes_definitions` lint with all-ZST transparent types)
 - #88339 (Add TcpListener::into_incoming and IntoIncoming)
 - #88735 (Don't lint about missing code examples in derived traits)
 - #88751 (Couple of changes to FileSearch and SearchPath)
 - #88883 (Move some tests to more reasonable directories - 7)
 - #88887 (Const Deref)
 - #88911 (Improve error message for type mismatch in generator arguments)
 - #89014 (PassWrapper: handle separate Module*SanitizerPass)
 - #89033 (Set the library path in sysroot-crates-are-unstable)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-09-17 06:47:35 +00:00
Yuki Okushi
ee99bb3939
Apply review comments 2021-09-17 14:10:41 +09:00
Yuki Okushi
3cff47b608
Rollup merge of #89014 - durin42:llvm-14-module-pass-manager, r=nikic
PassWrapper: handle separate Module*SanitizerPass

Change ab41eef9aca3 in LLVM split MemorySanitizerPass into
MemorySanitizerPass for functions and ModuleMemorySanitizerPass for
modules. There's a related change for ThreadSanitizerPass, and in here
since we're using a ModulePassManager I only add the module flavor of
the pass on LLVM 14.

r? `@nikic` cc `@nagisa`
2021-09-17 14:09:50 +09:00
Yuki Okushi
c97ff098f1
Rollup merge of #88911 - FabianWolff:issue-88653, r=petrochenkov
Improve error message for type mismatch in generator arguments

Fixes #88653. The code example given there is invalid because the `Generator` trait (unlike the `Fn` traits) does not take the generator arguments in tupled-up form (because there can only be one argument, from my understanding). Hence, the type error in the example in #88653 is correct, because the given generator takes a `bool` argument, whereas the function's return type talks about a generator with a `(bool,)` argument.

The error message is both confusing and wrong, though: It is wrong because it displays the wrong "expected signature", and it is confusing because both the "expected" and "found" notes point at the same span. With my changes, I get the following, more helpful output:
```
error[E0631]: type mismatch in generator arguments
 --> test.rs:5:22
  |
5 | fn foo(bar: bool) -> impl Generator<(bool,)> {
  |                      ^^^^^^^^^^^^^^^^^^^^^^^ expected signature of `fn((bool,)) -> _`
6 |     |bar| {
  |     ----- found signature of `fn(bool) -> _`
```
2021-09-17 14:09:49 +09:00
Yuki Okushi
a84d39c7d4
Rollup merge of #88751 - bjorn3:move_filesearch, r=oli-obk
Couple of changes to FileSearch and SearchPath

* Turn a couple of regular comments into doc comments
* Move `get_tools_search_paths` from `FileSearch` to `Session`
* Use Lrc instead of Option to avoid duplication of a `SearchPath`
2021-09-17 14:09:47 +09:00
Yuki Okushi
81dc21699e
Rollup merge of #87529 - FabianWolff:issue-87496, r=nikomatsakis
Fix ICE in `improper_ctypes_definitions` lint with all-ZST transparent types

Fixes #87496. There is also another function in the same file that looks fishy, but I haven't been able to produce an ICE there, and in any case, it's not related to #87496:
fd853c00e2/compiler/rustc_lint/src/types.rs (L720-L734)

r? ```@JohnTitor```
2021-09-17 14:09:44 +09:00
Yuki Okushi
9342be5538
Recover invalid assoc type bounds using == 2021-09-17 14:02:00 +09:00
Yuki Okushi
e9bf73cb2b
Use multipart_suggestion 2021-09-17 13:39:26 +09:00
Yuki Okushi
58765d61ee
Emit clearer diagnostics for parens around for loop heads 2021-09-17 13:14:23 +09:00
Yuki Okushi
378300a63d
Make diagnostics clearer for ? operators 2021-09-17 13:13:28 +09:00
bors
38e576423d Auto merge of #88934 - tmiasko:trace-log, r=davidtwco
Avoid unnecessary formatting when trace log level is disabled
2021-09-17 03:47:23 +00:00
bors
78a46efff0 Auto merge of #88832 - pcwalton:debug-unit-variant-fast-path, r=oli-obk
Introduce a fast path that avoids the `debug_tuple` abstraction when deriving Debug for unit-like enum variants.

The intent here is to allow LLVM to remove the switch entirely in favor of an
indexed load from a table of constant strings, which is likely what the
programmer would write in C. Unfortunately, LLVM currently doesn't perform this
optimization due to a bug, but there is [a
patch](https://reviews.llvm.org/D109565) that fixes this issue. I've verified
that, with that patch applied on top of this commit, Debug for unit-like tuple
variants becomes a load, reducing the O(n) code bloat to O(1).

Note that inlining `DebugTuple::finish()` wasn't enough to allow LLVM to
optimize the code properly; I had to avoid the abstraction entirely. Not using
the abstraction is likely better for compile time anyway.

Part of #88793.

r? `@oli-obk`
2021-09-17 01:00:11 +00:00
bors
e36621057d Auto merge of #88719 - estebank:point-at-arg-for-obligation, r=nagisa
Point at argument instead of call for their obligations

When an obligation is introduced by a specific `fn` argument, point at
the argument instead of the `fn` call if the obligation fails to be
fulfilled.

Move the information about pointing at the call argument expression in
an unmet obligation span from the `FulfillmentError` to a new
`ObligationCauseCode`.

When giving an error about an obligation introduced by a function call
that an argument doesn't fulfill, and that argument is a block, add a
span_label pointing at the innermost tail expression.

Current output:

```
error[E0425]: cannot find value `x` in this scope
 --> f10.rs:4:14
  |
4 |         Some(x * 2)
  |              ^ not found in this scope

error[E0277]: expected a `FnOnce<({integer},)>` closure, found `Option<_>`
 --> f10.rs:2:31
  |
2 |       let p = Some(45).and_then({
  |  ______________________--------_^
  | |                      |
  | |                      required by a bound introduced by this call
3 | |         |x| println!("doubling {}", x);
4 | |         Some(x * 2)
  | |         -----------
5 | |     });
  | |_____^ expected an `FnOnce<({integer},)>` closure, found `Option<_>`
  |
  = help: the trait `FnOnce<({integer},)>` is not implemented for `Option<_>`
```

Previous output:

```
error[E0425]: cannot find value `x` in this scope
 --> f10.rs:4:14
  |
4 |         Some(x * 2)
  |              ^ not found in this scope

error[E0277]: expected a `FnOnce<({integer},)>` closure, found `Option<_>`
 --> f10.rs:2:22
  |
2 |     let p = Some(45).and_then({
  |                      ^^^^^^^^ expected an `FnOnce<({integer},)>` closure, found `Option<_>`
  |
  = help: the trait `FnOnce<({integer},)>` is not implemented for `Option<_>`
```

Partially address #27300. Will require rebasing on top of #88546.
2021-09-16 22:17:33 +00:00
Aaron Hill
31cdd8cdd2
Propagate coercion cause into try_coerce
Currently, `coerce_inner` discards its `ObligationCause`
when calling `try_coerce`. This interfers with other
diagnostc improvements I'm working on, since we will lose
the original span by the time the actual coercion occurs.

Additionally, we now use the span of the trailing expression
(rather than the span of the entire function) when performing
a coercion in `check_return_expr`. This currently has no visible
effect on any of the unit tests, but will unblock future
diagnostic improvements.
2021-09-16 16:53:40 -05:00
bors
e4828d5b7f Auto merge of #89019 - Manishearth:rollup-5qp8a5s, r=Manishearth
Rollup of 10 pull requests

Successful merges:

 - #88292 (Enable --generate-link-to-definition for rustc's docs)
 - #88729 (Recover from `Foo(a: 1, b: 2)`)
 - #88875 (cleanup(rustc_trait_selection): remove vestigial code from rustc_on_unimplemented)
 - #88892 (Move object safety suggestions to the end of the error)
 - #88928 (Document the closure arguments for `reduce`.)
 - #88976 (Clean up and add doc comments for CStr)
 - #88983 (Allow calling `get_body_with_borrowck_facts` without `-Z polonius`)
 - #88985 (Update clobber_abi list to include k[1-7] regs)
 - #88986 (Update the backtrace crate)
 - #89009 (Fix typo in `break` docs)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-09-16 19:33:39 +00:00
Augie Fackler
bc4d8af123 PassWrapper: these two lines shouldn't have been ifdef'd 2021-09-16 15:04:18 -04:00
Waffle
f84000d9bc Add a separate error for dyn Trait in const fn
Previously "trait bounds other than `Sized` on const fn parameters are unstable"
error was used for both trait bounds (<T: Trait>) and trait objects (dyn Trait).
This was pretty confusing.

This patch adds a separeta error for trait objects: "trait objects in const fn
are unstable". The error for trait bounds is otherwise intact.
2021-09-16 21:32:05 +03:00
Vishad Goyal
9f7e281d47 delay error for enabling unstable lib features
If #![feature] is used outside the nightly channel for only lib
features, the check will be delayed to the stability pass after
parsing. This is done so that appropriate help messages can be shown if
the #![feature] has been used needlessly
2021-09-16 14:22:32 -04:00
Manish Goregaokar
4601a71a4b
Rollup merge of #88983 - willcrichton:allow-single-polonius-call, r=ecstatic-morse
Allow calling `get_body_with_borrowck_facts` without `-Z polonius`

For my [static analysis tool](https://github.com/willcrichton/flowistry), I need to access the set of outlives-constraints. Recently, #86977 merged a way to access these facts via Polonius. However, the merged implementation requires `-Z polonius` to be provided to use this feature. This uses Polonius for borrow checking on the entire crate, which as described [here](https://rust-lang.zulipchat.com/#narrow/stream/186049-t-compiler.2Fwg-polonius/topic/Polonius.20performance.20in.20a.20rustc.20plugin/near/251301631), is very slow.

This PR allows `get_body_with_borrowck_facts` to be called without `-Z polonius`. This is essential for my tool to run in a sensible length of time. This is a temporary patch as the Polonius-related APIs develop -- I can update my code as future changes happen.

Additionally, this PR also makes public two APIs that were previously public but then became private after `rustc_mir` got broken up: `rustc_mir_dataflow::framework::graphviz` and `rustc_mir_transform::MirPass`. I need both of these for my analysis tool. (I can break this change into a separate PR if necessary.)
2021-09-16 10:57:22 -07:00
Manish Goregaokar
06dbc284a8
Rollup merge of #88976 - notriddle:notriddle/cow-from-cstr-docs, r=Mark-Simulacrum
Clean up and add doc comments for CStr

CC #51430
2021-09-16 10:57:21 -07:00
Manish Goregaokar
14eb87dd26
Rollup merge of #88892 - estebank:trait-objects, r=petrochenkov
Move object safety suggestions to the end of the error
2021-09-16 10:57:20 -07:00
Manish Goregaokar
b66c9c3ac1
Rollup merge of #88875 - notriddle:notriddle/cleanup-unused-trait-selection, r=Mark-Simulacrum
cleanup(rustc_trait_selection): remove vestigial code from rustc_on_unimplemented

This isn't allowed by the validator, and seems to be unused.
When it was added in ed10a3faae,
it was used on `Sized`, and that usage is gone.
2021-09-16 10:57:19 -07:00
Manish Goregaokar
2c7d48b900
Rollup merge of #88729 - estebank:struct-literal-using-parens, r=oli-obk
Recover from `Foo(a: 1, b: 2)`

Detect likely `struct` literal using parentheses as delimiters and emit
targeted suggestion instead of type ascription parse error.

Fix #61326.
2021-09-16 10:57:18 -07:00
Aaron Hill
a41a13f775
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-16 12:36:19 -05:00
bors
237bb5e008 Auto merge of #88979 - tmiasko:no-remove-zsts-in-generators, r=oli-obk
Disable RemoveZsts in generators to avoid query cycles

Querying layout of a generator requires its optimized MIR. Thus
computing layout during MIR optimization of a generator might create a
query cycle. Disable RemoveZsts in generators to avoid the issue
(similar approach is used in ConstProp transform already).

Fixes #88972.
2021-09-16 16:46:02 +00:00
Augie Fackler
a97f89aeb4 PassWrapper: handle separate Module*SanitizerPass
Change ab41eef9aca3 in LLVM split MemorySanitizerPass into
MemorySanitizerPass for functions and ModuleMemorySanitizerPass for
modules. There's a related change for ThreadSanitizerPass, and in here
since we're using a ModulePassManager I only add the module flavor of
the pass on LLVM 14.

r? @nikic cc @nagisa
2021-09-16 11:49:02 -04:00
Esteban Kuber
4951e3ad9e Point at argument when evaluating Path's bounds
When evaluating an `ExprKind::Call`, we first have to `check_expr` on it's
callee. When this one is a `ExprKind::Path`, we had to evaluate the bounds
introduced for its arguments, but by the time we evaluated them we no
longer had access to the argument spans. Now we special case this so
that we can point at the right place on unsatisfied bounds. This also
allows the E0277 deduplication to kick in correctly, so we now emit
fewer errors.
2021-09-16 12:12:28 +00:00
Esteban Kuber
1d82905685 Fix rebase 2021-09-16 12:12:28 +00:00
Esteban Kuber
88a5321060 Remove unnecessary label 2021-09-16 12:12:28 +00:00
Esteban Kuber
f7c4a50f8a fix clone call 2021-09-16 12:12:28 +00:00
Esteban Kuber
22318f1a31 Account for blocks in arguments
When giving an error about an obligation introduced by a function call
that an argument doesn't fulfill, and that argument is a block, add a
span_label pointing at the innermost tail expression.
2021-09-16 12:12:28 +00:00
Esteban Kuber
569a842730 Point at call span that introduced obligation for the arg 2021-09-16 12:12:27 +00:00
Esteban Kuber
8a3f712518 Refactor FulfillmentError to track less data
Move the information about pointing at the call argument expression in
an unmet obligation span from the `FulfillmentError` to a new
`ObligationCauseCode`.
2021-09-16 12:12:27 +00:00
Esteban Kuber
284a8a9ce7 Point at argument instead of call for their obligations
When an obligation is introduced by a specific `fn` argument, point at
the argument instead of the `fn` call if the obligation fails to be
fulfilled.
2021-09-16 12:12:27 +00:00
bors
2b5ddf36fd Auto merge of #86809 - DevinR528:reachable-pat, r=Nadrieril
Add non_exhaustive_omitted_patterns lint related to rfc-2008-non_exhaustive

Fixes: #84332

This PR adds `non_exhaustive_omitted_patterns`, an allow by default lint that is triggered when a `non_exhaustive` type is missing explicit patterns. The warning or deny attribute can be put above the wildcard `_` pattern on enums or on the expression for enums or structs. The lint is capable of warning about multiple types within the same pattern. This lint will not be triggered for `if let ..` patterns.

```rust
// crate A
#[non_exhaustive]
pub struct Foo {
    a: u8,
    b: usize,
}
#[non_exhaustive]
pub enum Bar {
    A(Foo),
    B,
}

// crate B
#[deny(non_exhaustive_omitted_patterns)] // here
match Bar::B {
    Bar::B => {}
    #[deny(non_exhaustive_omitted_patterns)] // or here
    _ => {}
}

#[warn(non_exhaustive_omitted_patterns)] // only here
let Foo { a, .. } = Foo::default();

#[deny(non_exhaustive_omitted_patterns)]
match Bar::B {
    // triggers for Bar::B, and Foo.b
    Bar::A(Foo { a, .. }) => {}
    // if the attribute was here only Bar::B would cause a warning
    _ => {}
}
```
2021-09-16 05:29:22 +00:00
Caleb Zulawski
4a4ca94151 Fix shuffle index constant not being monomorphized. 2021-09-16 02:59:49 +00:00
Mark Rousskov
905beab38e Reuse existing shared Lrc for MatchImpl parent
This is hopefully a small performance win for the hot path.
2021-09-15 22:58:40 -04:00
jackh726
c065f57111 Remove ToPolyTraitRef impl for TraitRef 2021-09-15 22:55:10 -04:00
jackh726
be76bdf905 Remove ToPredicate impls that use Binder::dummy 2021-09-15 20:54:50 -04:00
Aaron Hill
bd4c9676c7
Fix linting when trailing macro expands to a trailing semi
When a macro is used in the trailing expression position of a block
(e.g. `fn foo() { my_macro!() }`), we currently parse it as an
expression, rather than a statement. As a result, we ended up
using the `NodeId` of the containing statement as our `lint_node_id`,
even though we don't normally do this for macro calls.

If such a macro expands to an expression with a `#[cfg]` attribute,
then the trailing statement can get removed entirely. This lead to
an ICE, since we were usng the `NodeId` of the expression to emit
a lint.

Ths commit makes us skip updating `lint_node_id` when handling
a macro in trailing expression position. This will cause us to
lint at the closest parent of the macro call.
2021-09-15 19:36:28 -05:00
Aaron Hill
6d1f4d2fed
Disable the evaluation cache when in intercrate mode
It's possible to use the same `InferCtxt` with both
an intercrate and non-intercrate `SelectionContext`. However,
the local (inferctxt) evaluation cache is not aware of this
distinction, so this kind of `InferCtxt` re-use will pollute
the cache wth bad results.

This commit avoids the issue by disabling the evaluation cache
entirely during intercrate mode.
2021-09-15 18:17:38 -05:00
Manish Goregaokar
d11ee806a4
Rollup merge of #88933 - tmiasko:remove-min-align-of, r=oli-obk
Remove implementation of `min_align_of` intrinsic

Since #88839 `min_align_of` is lowered to AlignOf operator.
2021-09-15 14:57:03 -07:00
Manish Goregaokar
e1acdf51bf
Rollup merge of #88907 - WaffleLapkin:targeted_const_fn_with_a_bound_in_impl_block_error, r=estebank
Highlight the `const fn` if error happened because of a bound on the impl block

Currently, for the following code, the compiler produces the errors like the
following:
```rust
struct Type<T>(T);

impl<T: Clone> Type<T> {
    const fn f() {}
}
```
```text
error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
 --> ./test.rs:3:6
  |
3 | impl<T: Clone> Type<T> {
  |      ^
  |
  = note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
  = help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable
```

This can be confusing (especially to newcomers) since the error mentions "const fn parameters", but highlights only the impl.

This PR adds function highlighting, changing the error to the following:

```text
error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
 --> ./test.rs:3:6
  |
3 | impl<T: Clone> Type<T> {
  |      ^
4 |     pub const fn f() {}
  |     ---------------- function declared as const here
  |
  = note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
  = help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable
```

---

I've originally wanted to point directly to `const` token, but couldn't find a way to get it's span. It seems like this span is lost during the AST -> HIR lowering.

Also, since the errors for object casts in `const fn`s (`&T` -> `&dyn Trait`) seem to trigger the same error, this PR accidentally changes these errors too. Not sure if it's desired or how to fix this.

P.S. it's my first time contributing to diagnostics, so feedback is very appreciated!

---

r? ```@estebank```

```@rustbot``` label: +A-diagnostics
2021-09-15 14:57:01 -07:00
Manish Goregaokar
1bf94a156a
Rollup merge of #88841 - notriddle:notriddle/method-parens, r=estebank
feat(rustc_typeck): suggest removing bad parens in `(recv.method)()`

Fixes #88803
2021-09-15 14:56:59 -07:00
Manish Goregaokar
fb2d7dff80
Rollup merge of #88775 - pnkfelix:revert-anon-union-parsing, r=davidtwco
Revert anon union parsing

Revert PR #84571 and #85515, which implemented anonymous union parsing in a manner that broke the context-sensitivity for the `union` keyword and thus broke stable Rust code.

Fix #88583.
2021-09-15 14:56:58 -07:00
Manish Goregaokar
4b568409ad
Rollup merge of #88690 - m-ou-se:macro-braces-dot-question-expr-parse, r=nagisa
Accept `m!{ .. }.method()` and `m!{ .. }?` statements.

This PR fixes something that I keep running into when using `quote!{}.into()` in a proc macro to convert the `proc_macro2::TokenStream` to a `proc_macro::TokenStream`:

Before:

```
error: expected expression, found `.`
 --> src/lib.rs:6:6
  |
4 |     quote! {
5 |         ...
6 |     }.into()
  |      ^ expected expression
```

After:
```
```
(No output, compiles fine.)

---

Context:

For expressions like `{ 1 }` and `if true { 1 } else { 2 }`, we accept them as full statements without a trailing `;`, which means the following is not accepted:

```rust
{ 1 } - 1 // error
```

since that is parsed as two statements: `{ 1 }` and `-1`. Syntactically correct, but the type of `{ 1 }` should be `()` as there is no `;`.

However, for specifically `.` and `?` after the `}`, we do [continue parsing it as an expression](13db8440bb/compiler/rustc_parse/src/parser/expr.rs (L864-L876)):

```rust
{ "abc" }.len(); // ok
```

For braced macro invocations, we do not do this:

```rust
vec![1, 2, 3].len(); // ok
vec!{1, 2, 3}.len(); // error
```

(It parses `vec!{1, 2, 3}` as a full statement, and then complains about `.len()` not being a valid expression.)

This PR changes this to also look for a `.` and `?` after a braced macro invocation. We can be sure the macro is an expression and not a full statement in those cases, since no statement can start with a `.` or `?`.
2021-09-15 14:56:57 -07:00
Manish Goregaokar
84646e9d67
Rollup merge of #87320 - danakj:debug-compilation-dir, r=michaelwoerister
Introduce -Z remap-cwd-prefix switch

This switch remaps any absolute paths rooted under the current
working directory to a new value. This includes remapping the
debug info in `DW_AT_comp_dir` and `DW_AT_decl_file`.

Importantly, this flag does not require passing the current working
directory to the compiler, such that the command line can be
run on any machine (with the same input files) and produce the
same results. This is critical property for debugging compiler
issues that crop up on remote machines.

This is based on adetaylor's dbc4ae7cba

Major Change Proposal: https://github.com/rust-lang/compiler-team/issues/450
Discussed on #38322. Would resolve issue #87325.
2021-09-15 14:56:56 -07:00
Gary Guo
11c0e58c74 Allow panic!("{}", computed_str) in const fn. 2021-09-15 21:56:43 +01:00
Gus Wynn
110aecd23e factor into struct, and comments 2021-09-15 11:48:34 -07:00
Will Crichton
47104a34a6 Allow call to get_body_with_borrowck_facts without -Z polonius 2021-09-15 11:45:31 -07:00
Will Crichton
4fd39dd8a6 Make rustc_mir_dataflow::framework::graphviz and rustc_mir_transform::MirPass public 2021-09-15 11:41:37 -07:00
Tomasz Miąsko
b6b19f3b6c Use explicit log level in tracing instrument macro
Specify a log level in tracing instrument macro explicitly.

Additionally reduce the used log level from a default info level to a
debug level (all of those appear to be developer oriented logs, so there
should be no need to include them in release builds).
2021-09-15 19:02:10 +02:00
Tomasz Miąsko
c39d7599a3 Disable RemoveZsts in generators to avoid query cycles
Querying layout of a generator requires its optimized MIR. Thus
computing layout during MIR optimization of a generator might create a
query cycle. Disable RemoveZsts in generators to avoid the issue
(similar approach is used in ConstProp transform already).
2021-09-15 18:48:29 +02:00
bjorn3
ccba8cb4bb Make two functions private 2021-09-15 18:46:53 +02:00
bjorn3
0ad8981945 Inline with_interner 2021-09-15 18:46:53 +02:00
bjorn3
05c09cb62d Move the Lock into symbol::Interner
This makes it easier to make the symbol interner (near) lock free in
case of concurrent accesses in the future.
2021-09-15 18:46:45 +02:00
Michael Howell
ef44452a83 chore(rustc_expand): fix typo in comment 2021-09-15 09:13:18 -07:00
Esteban Kuber
9762116299 Move object safety suggestions to the end of the error 2021-09-15 14:48:53 +00:00
Tomasz Miąsko
ffdabc8be8 Check for shadowing issues involving block labels 2021-09-15 15:42:15 +02:00
Deadbeef
aade63aeee
Fast reject for NeedsNonConstDrop 2021-09-15 13:26:12 +00:00
bors
2c7bc5e33c Auto merge of #87867 - bjorn3:unique_type_id_interner, r=wesleywiser
Use a separate interner type for UniqueTypeId

Using symbol::Interner makes it very easy to mixup UniqueTypeId symbols
with the global interner. In fact the Debug implementation of
UniqueTypeId did exactly this.

Using a separate interner type also avoids prefilling the interner with
unused symbols and allow for optimizing the symbol interner for parallel
access without negatively affecting the single threaded module codegen.
2021-09-15 12:34:31 +00:00
Deadbeef
b76b2c263d
inline(always) on check_recursion_limit 2021-09-15 09:17:35 +00:00
bors
cdeba02ff7 Auto merge of #88558 - fee1-dead:const-drop, r=oli-obk
Const drop

The changes are pretty primitive at this point. But at least it works. ^-^

Problems with the current change that I can think of now:
 - [x] `~const Drop` shouldn't change anything in the non-const world.
 - [x] types that do not have drop glues shouldn't fail to satisfy `~const Drop` in const contexts. `struct S { a: u8, b: u16 }` This might not fail for `needs_non_const_drop`, but it will fail in `rustc_trait_selection`.
 - [x] The current change accepts types that have `const Drop` impls but have non-const `Drop` glue.

Fixes #88424.

Significant Changes:

- `~const Drop` is no longer treated as a normal trait bound. In non-const contexts, this bound has no effect, but in const contexts, this restricts the input type and all of its transitive fields to either a) have a `const Drop` impl or b) can be trivially dropped (i.e. no drop glue)
- `T: ~const Drop` will not be linted like `T: Drop`.
- Instead of recursing and iterating through the type in `rustc_mir::transform::check_consts`, we use the trait system to special case `~const Drop`. See [`rustc_trait_selection::...::candidate_assembly#assemble_const_drop_candidates`](https://github.com/fee1-dead/rust/blob/const-drop/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs#L817) and others.

Changes not related to `const Drop`ping and/or changes that are insignificant:

 - `Node.constness_for_typeck` no longer returns `hir::Constness::Const` for type aliases in traits. This was previously used to hack how we determine default bound constness for items. But because we now use an explicit opt-in, it is no longer needed.
 - Removed `is_const_impl_raw` query. We have `impl_constness`, and the only existing use of that query uses `HirId`, which means we can just operate it with hir.
 - `ty::Destructor` now has a field `constness`, which represents the constness of the destructor.

r? `@oli-obk`
2021-09-15 03:51:03 +00:00
Fabian Wolff
21b7052eb8 Point to closure when emitting 'cannot move out' for captured variable 2021-09-15 01:47:22 +02:00
Fabian Wolff
2a2bfd1e59 Fix handling of hir::GenericArg::Infer in wrong_number_of_generic_args.rs 2021-09-15 01:25:51 +02:00
Aaron Hill
055651d1af
Remove concept of 'completion' from the projection cache
Fixes #88910

When we initially store a `NormalizedTy` in the projection cache,
we discard all obligations that we can (while ensuring that we
don't cause any issues with incremental compilation).

Marking a projection cache entry as 'completed' discards all
obligations associated with it. This can only cause problems,
since any obligations stored in the cache are there for a reason
(e.g. they evaluate to `EvaluatedToOkModuloRegions`).

This commit removes `complete` and `complete_normalized` entirely.
2021-09-14 15:42:50 -05:00
Devin Ragotzy
33a06b73d9 Add reachable_patterns lint to rfc-2008-non_exhaustive
Add linting on non_exhaustive structs and enum variants

Add ui tests for non_exhaustive reachable lint

Rename to non_exhaustive_omitted_patterns and avoid triggering on if let
2021-09-14 15:45:13 -04:00
Esteban Kuber
ffc623ab93 review comment: move recovery code to its own function 2021-09-14 18:16:33 +00:00
Tomasz Miąsko
f9b8191282 Remove implementation of min_align_of intrinsic
Since 88839 `min_align_of` is lowered to AlignOf operator.
2021-09-14 13:58:35 +02:00
Michael Woerister
66cf8ea1af Replace cnum_map with tcx.stable_crate_id_to_crate_num() in OnDiskCache. 2021-09-14 13:56:33 +02:00
Michael Woerister
919497cc30 rustc_metadata: Remove Metadata::raw_bytes() and use Metadata::blob() directly instead. 2021-09-14 13:56:33 +02:00
Michael Woerister
5f73085f92 Rename DefPathHashMap in rustc_metadata so its name does not clash with DefPathHashMap in rustc_hir. 2021-09-14 13:56:33 +02:00
Michael Woerister
021c0520e3 Fix up comment about OnDiskCache::foreign_expn_data. 2021-09-14 13:56:33 +02:00
Michael Woerister
2b60338ee9 Make DefPathHash->DefId panic for if the mapping fails.
We only use this mapping for cases where we know that it must succeed.
Letting it panic otherwise makes it harder to use the API in unsupported
ways.
2021-09-14 13:56:33 +02:00
Michael Woerister
5445715c20 Remove RawDefId tracking infrastructure from incr. comp. framework.
This infrastructure is obsolete now with the new encoding scheme for
the DefPathHash->DefIndex maps in crate metadata.
2021-09-14 13:56:33 +02:00
Michael Woerister
960893c50a Store DefPathHash->DefIndex map in on-disk-hash-table format in crate metadata.
This encoding allows for random access without an expensive upfront decoding
state which in turn allows simplifying the DefPathIndex lookup logic without
regressing performance.
2021-09-14 13:56:33 +02:00
Michael Woerister
d0be27c8ec Use on-disk-hash-table format for DefPathHashMap in hir::definitions. 2021-09-14 13:54:41 +02:00
Michael Woerister
0debea1377 Allow taking an OwningRef of the crate metadata blob. 2021-09-14 13:53:55 +02:00
Tomasz Miąsko
e84996bd7f Avoid unnecessary formatting when trace log level is disabled 2021-09-14 13:51:22 +02:00
bors
ec9a1bdc45 Auto merge of #88914 - GuillaumeGomez:rollup-h5svc6w, r=GuillaumeGomez
Rollup of 7 pull requests

Successful merges:

 - #88033 (Add links for primitives in "jump to definition" feature)
 - #88722 (Make `UnsafeCell::get_mut` const)
 - #88851 (Fix duplicate bounds for const_trait_impl)
 - #88859 (interpreter PointerArithmetic: use new Size helper methods)
 - #88885 (Fix jump def background)
 - #88894 (Improve error message for missing trait in trait impl)
 - #88896 (Reduce possibility of flaky tests)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-09-14 08:46:22 +00:00
bors
9f85cd6f2a Auto merge of #87794 - bonega:enum_niche_prefer_zero, r=nagisa
Enum should prefer discriminant zero for niche

Given an enum with unassigned zero-discriminant, rust should prefer it for niche selection.
Zero as discriminant for `Option<Enum>` makes it possible for LLVM to optimize resulting asm.

- Eliminate branch when expected value coincides.
- Use smaller instruction `test eax, eax` instead of `cmp eax, ?`
- Possible interaction with zeroed memory?

Example:
```rust

pub enum Size {
    One = 1,
    Two = 2,
    Three = 3,
}

pub fn handle(x: Option<Size>) -> u8 {
    match x {
        None => {0}
        Some(size) => {size as u8}
    }
}
```
In this case discriminant zero is available as a niche.

Above example on nightly:
```asm
 mov     eax, edi
 cmp     al, 4
 jne     .LBB0_2
 xor     eax, eax
.LBB0_2:
 ret
```

PR:
```asm
 mov     eax, edi
 ret
```

I created this PR because I had a performance regression when I tried to use an enum to represent legal grapheme byte-length for utf8.

Using an enum instead of `NonZeroU8` [here](d683304f5d/src/internal/decoder_incomplete.rs (L90))
resulted in a performance regression of about 5%.
I consider this to be a somewhat realistic benchmark.

Thanks to `@ogoffart` for pointing me in the right direction!

Edit: Updated description
2021-09-13 22:14:57 +00:00
Andreas Liljeqvist
4d66fbc4b9 enum niche allocation grows toward zero if possible 2021-09-13 21:55:14 +02:00
Guillaume Gomez
84d65fee0e
Rollup merge of #88894 - FabianWolff:issue-88818, r=estebank
Improve error message for missing trait in trait impl

Fixes #88818. For the following example:
```rust
struct S { }
impl for S { }
```
the current output is:
```
error: missing trait in a trait impl
 --> t1.rs:2:5
  |
2 | impl for S { }
  |     ^
```
With my changes, I get:
```
error: missing trait in a trait impl
 --> t1.rs:2:5
  |
2 | impl for S { }
  |     ^
  |
help: add a trait here
  |
2 | impl Trait for S { }
  |      +++++
help: for an inherent impl, drop this `for`
  |
2 - impl for S { }
2 + impl S { }
  |
```
2021-09-13 21:20:42 +02:00
Guillaume Gomez
c0e7f7edea
Rollup merge of #88859 - RalfJung:size-helpers, r=oli-obk
interpreter PointerArithmetic: use new Size helper methods
2021-09-13 21:20:40 +02:00
Guillaume Gomez
a9bc2ef894
Rollup merge of #88851 - fee1-dead:dup-bound, r=oli-obk
Fix duplicate bounds for const_trait_impl

Fixes #88383.

Compare the constness of the candidates before winnowing and removing a `~const` `BoundCandidate`.
2021-09-13 21:20:39 +02:00
Fabian Wolff
cbd79836a5 Improve error message for type mismatch in generator arguments 2021-09-13 19:39:30 +02:00
bors
9bb77da74d Auto merge of #87915 - estebank:fancy-spans, r=oli-obk
Use smaller spans for some structured suggestions

Use more accurate suggestion spans for

* argument parse error
* fully qualified path
* missing code block type
* numeric casts
2021-09-13 16:31:12 +00:00
Gus Wynn
2af1ebfbdf error formatting and fix build 2021-09-13 08:19:40 -07:00
Oli Scherer
a6c642a9f8 Update compiler/rustc_codegen_ssa/src/mir/mod.rs 2021-09-13 10:51:48 -04:00
Wesley Wiser
4e8701e620 Fix debuginfo for ScalarPair abi parameters
Mark all of these as locals so the debugger does not try to interpret
them as being a pointer to the value. This extends the approach used in
PR #81898.
2021-09-13 10:51:47 -04:00
Wesley Wiser
3d69b5bc17 Add tracing level for codegen_mir 2021-09-13 10:51:46 -04:00
Waffle
6ec7255d7b Highlight the const function if error happened because of a bound on the impl block
Currently, for the following code, the compiler produces the errors like the
following error:
```rust
struct Type<T>

impl<T: Clone> Type<T> {
	fn const f() {}
}
```
```text
error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
 --> ./test.rs:3:6
  |
3 | impl<T: Clone> Type<T> {
  |      ^
  |
  = note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
  = help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable
```

This can be confusing (especially to newcomers) since the error mentions
"const fn parameters", but highlights only the impl.

This commits adds function highlighting, changing the error to the following:

```text
error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
 --> ./test.rs:3:6
  |
3 | impl<T: Clone> Type<T> {
  |      ^
4 |     pub const fn f() {}
  |     ---------------- function declared as const here
  |
  = note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
  = help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable
```
2021-09-13 16:36:14 +03:00
bjorn3
8c7840e8cb Use a separate interner type for UniqueTypeId
Using symbol::Interner makes it very easy to mixup UniqueTypeId symbols
with the global interner. In fact the Debug implementation of
UniqueTypeId did exactly this.

Using a separate interner type also avoids prefilling the interner with
unused symbols and allow for optimizing the symbol interner for parallel
access without negatively affecting the single threaded module codegen.
2021-09-13 14:42:06 +02:00
Hirochika Matsumoto
37196e3691 Suggest replacing an inexisting field for an unmentioned field
This PR adds a suggestion to replace an inexisting field for an
unmentioned field. Given the following code:
```rust
enum Foo {
    Bar { alpha: u8, bravo: u8, charlie: u8 },
}

fn foo(foo: Foo) {
    match foo {
        Foo::Bar {
            alpha,
            beta, // `bravo` miswritten as `beta` here.
            charlie,
        } => todo!(),
    }
}
```
the compiler now emits the error messages below.
```text
error[E0026]: variant `Foo::Bar` does not have a field named `beta`
 --> src/lib.rs:9:13
  |
9 |             beta, // `bravo` miswritten as `beta` here.
  |             ^^^^
  |             |
  |             variant `Foo::Bar` does not have this field
  |             help: `Foo::Bar` has a field named `bravo`: `bravo`
```

Note that this suggestion is available iff the number of inexisting
fields and unmentioned fields are both 1.
2021-09-13 21:16:05 +09:00
bors
61a1029143 Auto merge of #88529 - Meziu:master, r=nagisa
ARMv6K Nintendo 3DS Tier 3 target added

Addition of the target specifications to build .elf files for Nintendo 3DS (ARMv6K, Horizon). Requires devkitARM 3DS toolkit for system libraries and arm-none-eabi-gcc linker.
2021-09-13 05:48:03 +00:00
Michael Howell
8be729cdd6 chore: convert to a multi-part suggestion 2021-09-12 19:51:09 -07:00
bors
96dee2825e Auto merge of #88839 - nbdd0121:alignof, r=nagisa
Introduce NullOp::AlignOf

This PR introduces `Rvalue::NullaryOp(NullOp::AlignOf, ty)`, which will be lowered from `align_of`, similar to `size_of` lowering to `Rvalue::NullaryOp(NullOp::SizeOf, ty)`.

The changes are originally part of #88700 but since it's not dependent on other changes and could have performance impact on its own, it's separated into its own PR.
2021-09-12 23:49:24 +00:00
Gary Guo
1c3409f333 Introduce NullOp::AlignOf 2021-09-13 00:08:35 +01:00
Fabian Wolff
ab83d501a4 Do not issue E0071 if a type error has already been reported 2021-09-12 23:07:23 +02:00
bors
51e514c0fb Auto merge of #88759 - Amanieu:panic_in_drop, r=nagisa,eddyb
Add -Z panic-in-drop={unwind,abort} command-line option

This PR changes `Drop` to abort if an unwinding panic attempts to escape it, making the process abort instead. This has several benefits:
- The current behavior when unwinding out of `Drop` is very unintuitive and easy to miss: unwinding continues, but the remaining drops in scope are simply leaked.
- A lot of unsafe code doesn't expect drops to unwind, which can lead to unsoundness:
  - https://github.com/servo/rust-smallvec/issues/14
  - https://github.com/bluss/arrayvec/issues/3
- There is a code size and compilation time cost to this: LLVM needs to generate extra landing pads out of all calls in a drop implementation. This can compound when functions are inlined since unwinding will then continue on to process drops in the callee, which can itself unwind, etc.
  - Initial measurements show a 3% size reduction and up to 10% compilation time reduction on some crates (`syn`).

One thing to note about `-Z panic-in-drop=abort` is that *all* crates must be built with this option for it to be sound since it makes the compiler assume that dropping `Box<dyn Any>` will never unwind.

cc https://github.com/rust-lang/lang-team/issues/97
2021-09-12 20:48:09 +00:00
Fabian Wolff
3f0e695919 Improve error message for missing trait in trait impl 2021-09-12 22:05:52 +02:00
bors
d2dfb0eb8e Auto merge of #88811 - jackh726:issue-88446, r=nikomatsakis
Use a HashMap for UniverseInfo in mir borrowck

Fixes #88446

r? `@nikomatsakis`
2021-09-12 17:04:10 +00:00
Camille GILLOT
91575f89cc Use non-recursive algorithm in non-parallel compiler. 2021-09-12 16:33:18 +02:00
Camille GILLOT
6bbb0792ea Use boxed slice instead of BTreeSet. 2021-09-12 16:33:17 +02:00
Camille GILLOT
fa6f5adf73 Gather module items after lowering. 2021-09-12 16:33:16 +02:00
bors
c7dbe7a830 Auto merge of #88881 - Manishearth:rollup-alohfwx, r=Manishearth
Rollup of 7 pull requests

Successful merges:

 - #88336 ( Detect stricter constraints on gats where clauses in impls vs trait)
 - #88677 (rustc: Remove local variable IDs from `Export`s)
 - #88699 (Remove extra unshallow from cherry-pick checker)
 - #88709 (generic_const_exprs: use thir for abstract consts instead of mir)
 - #88711 (Rework DepthFirstSearch API)
 - #88810 (rustdoc: Cleanup `clean` part 1)
 - #88813 (explicitly link to external `ena` docs)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-09-12 13:29:56 +00:00
Manish Goregaokar
b87d0d0d94
Rollup merge of #88711 - Mark-Simulacrum:fix-dfs-bug, r=jackh726
Rework DepthFirstSearch API

This expands the API to be more flexible, allowing for more visitation patterns
on graphs. This will be useful to avoid extra datasets (and allocations) in
cases where the expanded DFS API is sufficient.

This also fixes a bug with the previous DFS constructor, which left the start
node not marked as visited (even though it was immediately returned).

Commit written by ```@nikomatsakis``` originally, cherry picked from several commits in work on never type stabilization, but stands alone.
2021-09-12 03:44:57 -07:00
Manish Goregaokar
f5ac5cadd3
Rollup merge of #88709 - BoxyUwU:thir-abstract-const, r=lcnr
generic_const_exprs: use thir for abstract consts instead of mir

Changes `AbstractConst` building to use `thir` instead of `mir` so that there's less chance of consts unifying when they shouldn't because lowering to mir dropped information (see `abstract-consts-as-cast-5.rs` test)

r? `@lcnr`
2021-09-12 03:44:56 -07:00
Manish Goregaokar
bb5ca58d29
Rollup merge of #88677 - petrochenkov:exportid, r=davidtwco
rustc: Remove local variable IDs from `Export`s

Local variables can never be exported.
2021-09-12 03:44:53 -07:00
Manish Goregaokar
6d4f27ebc7
Rollup merge of #88336 - jackh726:gats-where-constraints, r=estebank
Detect stricter constraints on gats where clauses in impls vs trait

I might try to see if I can do a bit more to improve these diagnostics, but any initial feedback is appreciated. I can also do any additional work in a followup PR.

r? `@estebank`
2021-09-12 03:44:53 -07:00
bors
9ef27bf7dc Auto merge of #88771 - jackh726:wf_tys_set, r=nikomatsakis
Use FxHashSet instead of Vec for well formed tys

Trying to recover perf from #88312

r? `@ghost`
2021-09-12 10:32:55 +00:00
Michael Howell
e1873ba007 cleanup(rustc_trait_selection): remove vestigial code from rustc_on_unimplemented
This isn't allowed by the validator, and seems to be unused.
When it was added in ed10a3faae,
it was used on `Sized`, and that usage is gone.
2021-09-11 16:42:42 -07:00
bors
547d9374d2 Auto merge of #84373 - cjgillot:resolve-span, r=michaelwoerister,petrochenkov
Encode spans relative to the enclosing item

The aim of this PR is to avoid recomputing queries when code is moved without modification.

MCP at https://github.com/rust-lang/compiler-team/issues/443

This is achieved by :
1. storing the HIR owner LocalDefId information inside the span;
2. encoding and decoding spans relative to the enclosing item in the incremental on-disk cache;
3. marking a dependency to the `source_span(LocalDefId)` query when we translate a span from the short (`Span`) representation to its explicit (`SpanData`) representation.

Since all client code uses `Span`, step 3 ensures that all manipulations
of span byte positions actually create the dependency edge between
the caller and the `source_span(LocalDefId)`.
This query return the actual absolute span of the parent item.
As a consequence, any source code motion that changes the absolute byte position of a node will either:
- modify the distance to the parent's beginning, so change the relative span's hash;
- dirty `source_span`, and trigger the incremental recomputation of all code that
  depends on the span's absolute byte position.

With this scheme, I believe the dependency tracking to be accurate.

For the moment, the spans are marked during lowering.
I'd rather do this during def-collection,
but the AST MutVisitor is not practical enough just yet.
The only difference is that we attach macro-expanded spans
to their expansion point instead of the macro itself.
2021-09-11 23:35:28 +00:00
bors
8c2b6ea37d Auto merge of #78780 - cjgillot:req, r=Mark-Simulacrum
Refactor query forcing

The control flow in those functions was very complex, with several layers of continuations.

I tried to simplify the implementation, while keeping essentially the same logic.
Now, all code paths go through `try_execute_query` for the actual query execution.
Communication with the `dep_graph` and the live caches are the only difference between query getting/ensuring/forcing.
2021-09-11 20:39:47 +00:00
Gus Wynn
ee1d2ea3b7 fix doctests 2021-09-11 12:39:33 -07:00
Gus Wynn
461a0f3da4 array comment + test for references 2021-09-11 12:24:40 -07:00
Gus Wynn
74ea16301e skip the uninhabitated check and comments 2021-09-11 12:10:06 -07:00
Gus Wynn
67ee91e77e remove attempt at fn call 2021-09-11 10:50:09 -07:00
Gus Wynn
2271376fb2 must_not_suspend impl 2021-09-11 10:45:17 -07:00
Ralf Jung
07b64bfd3a interpreter PointerArithmetic: use new Size helper methods 2021-09-11 12:21:10 -04:00
Camille GILLOT
7842b80478 Rebase fallout. 2021-09-11 17:52:39 +02:00
Jubilee
2a8ad06689
Rollup merge of #88850 - matthiaskrgr:identical_conv, r=jackh726
don't convert types into identical types

example: let x: String = String::new().into();
2021-09-11 08:23:46 -07:00
Jubilee
c2e1097f44
Rollup merge of #88849 - matthiaskrgr:clony_on_copy, r=petrochenkov
don't clone types that are Copy (clippy::clone_on_copy)
2021-09-11 08:23:45 -07:00