Commit graph

8160 commits

Author SHA1 Message Date
Aman Arora
d2cbe21756 Handle type params in insig dtors 2021-09-21 05:06:19 -04:00
Aman Arora
95cfbe43d2 2229: Early exit when we see an insigificant drop 2021-09-21 04:06:00 -04:00
bors
e7958d35ca Auto merge of #87830 - hkmatsumoto:suggest-brackets-for-array-esque-block-expr, r=estebank
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-21 00:34:10 +00:00
bors
60e70cc909 Auto merge of #89117 - michaelwoerister:update-to-odht-0.3, r=wesleywiser
Update odht crate to 0.3.0

This version of odht contains a potential fix for #89085.

r? `@wesleywiser`
2021-09-20 17:38:07 +00:00
bors
3bb9eecf07 Auto merge of #89069 - bjorn3:optimize_sharded_new, r=Mark-Simulacrum
Use <[T; N]>::map in Sharded instead of SmallVec and unsafe code

This results in a lot less assembly
2021-09-20 14:33:00 +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
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
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
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
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
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
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
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
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
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
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