Commit graph

8295 commits

Author SHA1 Message Date
Manish Goregaokar
04d3f93a2b
Rollup merge of #89224 - TaKO8Ki:change-the-order-of-suggestions, r=joshtriplett
Change the order of imports suggestions

closes #83564
2021-09-25 18:22:21 -07:00
Manish Goregaokar
653dcaac2b
Rollup merge of #89216 - r00ster91:bigo, r=dtolnay
Consistent big O notation

This makes the big O time complexity notation in places with markdown support more consistent.
Inspired by #89210
2021-09-25 18:22:20 -07:00
bors
63cc2bb3d0 Auto merge of #88243 - nikic:newpm-2, r=nagisa
Enable new pass manager with LLVM 13

The new pass manager is enabled by default in clang since Clang/LLVM 13. Per the recent discussion on llvm-dev (https://lists.llvm.org/pipermail/llvm-dev/2021-August/152305.html) the legacy pass manager will be unmaintained in LLVM 14 and removed entirely in LLVM 15.

This switches us to use the new pass manager if LLVM >= 13 is used. It's possible to still use the old pass manager using `-Z new-llvm-pass-manager=no`.
2021-09-25 13:43:52 +00: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
Nikita Popov
074bbc6b87 Use correct pipeline for LTO at O0
Unlike the pre-link piplines, the LTO pipelines do support O0,
and using them is required to avoid leaving behind undefined
references for the linker.
2021-09-25 11:24:23 +02:00
Nikita Popov
be01f42f73 Enable new pass manager on LLVM 13
The new pass manager is enabled by default in clang since
Clang/LLVM 13. While the discussion about this is still ongoing
(https://lists.llvm.org/pipermail/llvm-dev/2021-August/152305.html)
it's expected that support for the legacy pass manager will be
dropped either in LLVM 14 or 15.

This switches us to use the new pass manager if LLVM >= 13 is used.
2021-09-25 11:24:23 +02:00
bors
218a96cae0 Auto merge of #89237 - BoxyUwU:trackersMcCaller, r=eddyb
make `#[track_caller]` actually do stuff in `Steal::borrow`

makes this ICE message useful:
``thread 'rustc' panicked at 'attempted to read from stolen value', /rustc/ac2d9fc509e36d1b32513744adf58c34bcc4f43c\compiler\rustc_data_structures\src\steal.rs:37:21``
2021-09-25 07:33:25 +00:00
bors
60fe8b3a65 Auto merge of #87220 - petrochenkov:derivecfglimit2, r=Aaron1011
Make `#[derive(A, B, ...)]` cfg-eval its input only for `A, B, ...` and stabilize `feature(macro_attributes_in_derive_output)`

Stabilization report: https://github.com/rust-lang/rust/pull/87220#issuecomment-881923657

Closes #81119
r? `@Aaron1011`
2021-09-25 04:35:59 +00:00
Takayuki Maeda
4c23905515 use drain_filter instead of filter and retain 2021-09-25 11:33:53 +09:00
bors
6867dd2c01 Auto merge of #89230 - workingjubilee:rollup-1swktdq, r=workingjubilee
Rollup of 8 pull requests

Successful merges:

 - #88893 (Add 1.56.0 release notes)
 - #89001 (Be explicit about using Binder::dummy)
 - #89072 (Avoid a couple of Symbol::as_str calls in cg_llvm )
 - #89104 (Simplify scoped_thread)
 - #89208 ([rfc 2229] Drop fully captured upvars in the same order as the regular drop code)
 - #89210 (Add missing time complexities to linked_list.rs)
 - #89217 (Enable "generate-link-to-definition" option on rust tools docs as well)
 - #89221 (Give better error for `macro_rules! name!`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-09-25 00:20:28 +00:00
Gary Guo
19eaee2c32 Report heap allocation instead of non-const fn for exchange_malloc call 2021-09-25 01:08:41 +01:00
Gary Guo
511333fcc4 Use Rvalue::ShallowInitBox for box expression 2021-09-25 01:08:41 +01:00
Gary Guo
c38da2e0a3 Introduce Rvalue::ShallowInitBox 2021-09-25 01:08:41 +01:00
Ellen
f1e71a5b41 arrr caught ya caller
awd
2021-09-25 00:34:02 +01:00
bors
043972f152 Auto merge of #86246 - FabianWolff:issue-83471, r=estebank
Add basic checks for well-formedness of `fn`/`fn_mut` lang items

This pull request fixes #83471. Lang items are never actually checked for well-formedness (#9307). This means that one can get an ICE quite easily, e.g. as follows:
```rust
#![feature(lang_items)]
#[lang = "fn"]
trait MyFn {
    const call: i32 = 42;
}

fn main() {
    (|| 42)();
}
```
or this:
```rust
#![feature(lang_items)]
#[lang = "fn"]
trait MyFn {
    fn call(i: i32, j: i32);
}

fn main() {
    (|| 42)();
}
```
Ideally, there should probably be a more comprehensive strategy for checking lang items for well-formedness, but for the time being, I have added some rudimentary well-formedness checks that prevent #83471 and similar issues.
2021-09-24 21:30:35 +00:00
Vadim Petrochenkov
85f02901a3 Stabilize feature(macro_attributes_in_derive_output) 2021-09-24 21:48:30 +03:00
Vadim Petrochenkov
92804cd490 derive: Do not configure or clone items unless necessary 2021-09-24 21:45:51 +03:00
Vadim Petrochenkov
c993984e4d builtin_macros: Make #[derive(A, B, ...)] cfg-eval its input only for A, B, ... 2021-09-24 21:45:51 +03:00
Jubilee
6f31fa58fd
Rollup merge of #89221 - aDotInTheVoid:macro-error-1, r=estebank
Give better error for `macro_rules! name!`

r? ``@estebank``

``@rustbot`` modify labels: +A-diagnostics +A-parser
2021-09-24 11:40:17 -07:00
Jubilee
7ade6ed48e
Rollup merge of #89208 - wesleywiser:rfc_2229_droporder, r=nikomatsakis
[rfc 2229] Drop fully captured upvars in the same order as the regular drop code

Currently, with the new 2021 edition, if a closure captures all of the
fields of an upvar, we'll drop those fields in the order they are used
within the closure instead of the normal drop order (the definition
order of the fields in the type).

This changes that so we sort the captured fields by the definition order
which causes them to drop in that same order as well.

Fixes rust-lang/project-rfc-2229#42

r? `@nikomatsakis`
2021-09-24 11:40:14 -07:00
Jubilee
80d9886e4c
Rollup merge of #89104 - Mark-Simulacrum:spawn-unchecked, r=nagisa,bjorn3
Simplify scoped_thread

Avoids a bunch of manual pointer manipulation in favor of using the appropriate std API.
2021-09-24 11:40:13 -07:00
Jubilee
8a454f8101
Rollup merge of #89072 - bjorn3:less_symbol_as_str, r=michaelwoerister
Avoid a couple of Symbol::as_str calls in cg_llvm

This should improve performance a tiny bit. Also remove `Symbol::len` and make `SymbolIndex` private.
2021-09-24 11:40:12 -07: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
Fabian Wolff
cb6c13977a Make error message for malformed fn/fn_mut lang item more specific 2021-09-24 20:15:19 +02:00
Fabian Wolff
4337089098 Add basic checks for well-formedness of fn/fn_mut lang items 2021-09-24 18:26:27 +02:00
Vadim Petrochenkov
ab834e5ea9 resolve: Refactor obtaining Module from its DefId
The `Option<Module>` version is supported for the case where we don't know whether the `DefId` refers to a module or not.
Non-local traits and enums are also correctly found now.
2021-09-24 18:57:15 +03:00
Vadim Petrochenkov
a8021888c8 resolve: Use a single common map for local and foreign modules 2021-09-24 18:57:15 +03:00
Vadim Petrochenkov
1a23858983 resolve: Rename some expansion def scope methods 2021-09-24 18:57:15 +03:00
Vadim Petrochenkov
6e9adcbd82 resolve: Cleanup module allocation
Construction of all modules is now centralized and performed by `fn new_module`.
2021-09-24 18:57:15 +03:00
Vadim Petrochenkov
fd58eea4e1 resolve: Do not cache nearest parent mod in ModuleData 2021-09-24 18:57:14 +03:00
Takayuki Maeda
353d6373ff change the order of path suggestions 2021-09-25 00:22:59 +09:00
Nixon Enraght-Moony
ed3b751799 Give better error for macro_rules! name! 2021-09-24 16:21:34 +01:00
bors
a0648eab36 Auto merge of #88835 - FabianWolff:issue-88770, r=petrochenkov
Fix error recovery in format macro parsing

Fixes #88770. Basically, the assumption in the following comment is incorrect:
b69fe57261/compiler/rustc_builtin_macros/src/format.rs (L167-L172)

This is only true in the first iteration of the loop, when [`p.clear_expected_tokens()`](b69fe57261/compiler/rustc_builtin_macros/src/format.rs (L164)) is called. In subsequent iterations, `p.expected_tokens` won't be empty, so `p.expect()` won't actually call `unexpected_try_recover()`:
b69fe57261/compiler/rustc_parse/src/parser/mod.rs (L487-L498)

Instead, it will call `expect_one_of()`, which _can_ recover and return `Ok()`. This PR handles this case to fix the ICE in #88770.
2021-09-24 11:54:29 +00:00
r00ster91
956f87fb04 consistent big O notation 2021-09-24 12:44:28 +02: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
Wesley Wiser
389365631d Fix tidy and respond to some feedback 2021-09-23 22:15:12 -04: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
Jubilee
a071193826
Rollup merge of #89176 - TaKO8Ki:change-singular-to-plural, r=lcnr
Change singular to plural
2021-09-23 17:31:45 -07:00
Jubilee
9e11d1cca4
Rollup merge of #89148 - estebank:used-type-param, r=oli-obk
Suggest `_` in turbofish if param will be inferred from fn argument
2021-09-23 17:31:43 -07:00
Jubilee
5da2f460b3
Rollup merge of #89023 - Wardenfar:issue-85066, r=nagisa
Resolve issue : Somewhat confusing error with extended_key_value_attributes

Fixes #85066
2021-09-23 17:31:42 -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
Wesley Wiser
ab8aef40b1 Drop fully captured upvars in the same order as the regular drop code
Currently, with the new 2021 edition, if a closure captures all of the
fields of an upvar, we'll drop those fields in the order they are used
within the closure instead of the normal drop order (the definition
order of the fields in the type).

This changes that so we sort the captured fields by the definition order
which causes them to drop in that same order as well.

Fixes https://github.com/rust-lang/project-rfc-2229/issues/42
2021-09-23 18:01:32 -04:00
bors
2b862bed98 Auto merge of #89024 - oli-obk:lazy_tait_is_not_limited_to_being_used_in_return_position, r=nikomatsakis
Lazy TAIT preparation cleanups

Check that TAIT generics are fully generic in mir typeck instead of wf-check, as wf-check can by definition only check TAIT in return position and not account for TAITs defined in the body of the function

r? `@spastorino` `@nikomatsakis`
2021-09-23 19:38:30 +00:00
Mark Rousskov
0222556c07 Simplify scoped_thread
Avoids a bunch of manual pointer manipulation.
2021-09-23 12:56:59 -04: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
Esteban Kuber
affea730e9 Suggest _ in turbofish if param will be inferred from fn argument 2021-09-23 14:08:47 +00:00
Oli Scherer
6067eadb65 Check that TAIT generics are fully generic in mir typeck instead of wf-check, as wf-check can by definition only check TAIT in return position and not account for TAITs defined in the body of the function 2021-09-23 13:35:16 +00:00
bors
0132f8258a Auto merge of #87064 - Aaron1011:new-closure-track-caller, r=estebank
Support `#[track_caller]` on closures and generators

## Lang team summary

This PR adds support for placing the `#[track_caller]` attribute on closure and generator expressions. This attribute's addition behaves identically (from a users perspective) to the attribute being placed on the method in impl Fn/FnOnce/FnMut for ... generated by compiler.

The attribute is currently "double" feature gated -- both `stmt_expr_attributes` (preexisting) and `closure_track_caller` (newly added) must be enabled in order to place these attributes on closures.

As the Fn* traits lack a `#[track_caller]` attribute in their definition, caller information does not propagate when invoking closures through dyn Fn*. There is no limitation that this PR adds in supporting this; it can be added in the future.

# Implementation details

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-23 12:26:51 +00:00
Takayuki Maeda
d997a62a3f
Update compiler/rustc_infer/src/infer/error_reporting/mod.rs
Co-authored-by: mbartlett21 <29034492+mbartlett21@users.noreply.github.com>
2021-09-23 20:27:20 +09:00