Commit graph

8255 commits

Author SHA1 Message Date
Fabian Wolff
3d08ff1c19 Fix incorrect disambiguation suggestion for associated items 2021-09-25 21:47:33 +02: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
bors
197fc8591e Auto merge of #89120 - In-line:remove_unneded_visible_parents_map, r=estebank
Disable visible path calculation for PrettyPrinter in Ok path of compiler
2021-09-24 05:29:49 +00:00
bors
293b8f2c11 Auto merge of #89211 - workingjubilee:rollup-fj4eduk, r=workingjubilee
Rollup of 7 pull requests

Successful merges:

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

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-09-24 01:48:02 +00:00
Jubilee
1875cecfd4
Rollup merge of #89200 - hkmatsumoto:patch, r=workingjubilee
Fix typo
2021-09-23 17:31:47 -07:00
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
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
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
Hirochika Matsumoto
c713ffbe39 Fix typo 2021-09-23 18:57:23 +09:00
bors
67365d64bc Auto merge of #89139 - camsteffen:write-perf, r=Mark-Simulacrum
Use ZST for fmt unsafety

as suggested here - https://github.com/rust-lang/rust/pull/83302#issuecomment-923529151.
2021-09-23 02:10:26 +00:00
Aaron Hill
94b19fac26
Support #[track_caller] on closures and generators
This PR allows applying a `#[track_caller]` attribute to a
closure/generator expression. The attribute as interpreted as applying
to the compiler-generated implementation of the corresponding trait
method (`FnOnce::call_once`, `FnMut::call_mut`, `Fn::call`, or
`Generator::resume`).

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

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

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

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

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

Since `ClosureOnceShim.track_caller` is only used by codegen,
we end up generating two identical MIR shims - one for
`track_caller == true`, and one for `track_caller == false`. However,
these two shims are used by the entire crate (i.e. it's two shims total,
not two shims per unique closure), so this shouldn't a big deal.
2021-09-22 15:19:33 -05:00
the8472
26c7838118
Rollup merge of #89170 - rusticstuff:aarch64_macos_disable_leak_sanitizer, r=petrochenkov
Disable the leak sanitizer on Macos aarch64 for now

It is currently broken, see #88132.
2021-09-22 19:03:27 +02:00
the8472
91af0003e8
Rollup merge of #89162 - petrochenkov:ivmap, r=davidtwco
rustc_index: Add some map-like APIs to `IndexVec`

`IndexVec` is often used as a map, but its map APIs are lacking.
This PR adds a couple of useful methods.
2021-09-22 19:03:25 +02:00
the8472
3bdc894486
Rollup merge of #89133 - FabianWolff:issue-79546, r=michaelwoerister
Fix ICE with `--cap-lints=allow` and `-Zfuel=...=0`

Fixes #79546.
2021-09-22 19:03:24 +02:00
the8472
5948a7b407
Rollup merge of #89046 - oli-obk:fix_oflo, r=estebank
"Fix" an overflow in byte position math

r? `@estebank`

help! I fixed the ICE only to brick the diagnostic.

I mean, it was wrong previously (using an already expanded macro span), but it is really bad now XD
2021-09-22 19:03:22 +02:00
the8472
1deef1f75d
Rollup merge of #89041 - sticnarf:sticnarf/fat-lto-dwarf, r=nagisa
Work around invalid DWARF bugs for fat LTO

This PR applies the same workaround in #46772 to fat LTO.

It seems to fix the bug reported in https://github.com/rust-lang/rust/issues/66118#issuecomment-917434036.
2021-09-22 19:03:21 +02:00
Takayuki Maeda
b69bc8447a change singular to plural 2021-09-23 00:43:51 +09:00
bors
ce45663e14 Auto merge of #88865 - guswynn:must_not_suspend, r=oli-obk
Implement `#[must_not_suspend]`

implements #83310

Some notes on the impl:

1. The code that searches for the attribute on the ADT is basically copied from the `must_use` lint. It's not shared, as the logic did diverge
2. The RFC does specify that the attribute can be placed on fn's (and fn-like objects), like `must_use`. I think this is a direct copy from the `must_use` reference definition. This implementation does NOT support this, as I felt that ADT's (+ `impl Trait` + `dyn Trait`) cover the usecase's people actually want on the RFC, and adding an imp for the fn call case would be significantly harder. The `must_use` impl can do a single check at fn call stmt time, but `must_not_suspend` would need to answer the question: "for some value X with type T, find any fn call that COULD have produced this value". That would require significant changes to `generator_interior.rs`, and I would need mentorship on that. `@eholk` and I are discussing it.
3. `@estebank` do you know a way I can make the user-provided `reason` note pop out? right now it seems quite hidden

Also, I am not sure if we should run perf on this

r? `@nikomatsakis`
2021-09-22 06:43:33 +00:00
Hans Kratz
59e37c829b Disable the leak sanitizer on Macos aarch64 for now.
It is currently broken, see #88132.
2021-09-22 08:05:34 +02:00
bors
77f4143fa2 Auto merge of #88846 - jackh726:issue-88360, r=nikomatsakis
In suggest_missing_return_type, erase late bound regions after normalizing

Fixes #88360

There might be some hardening that could be done to not error or avoid erroring with LUBing `ReErased` with `ReEmpty`, but this was the most simple fix for this particular case.

r? `@nikomatsakis`
2021-09-22 04:02:01 +00:00
bors
5fd6f3b16d Auto merge of #88629 - wesleywiser:fix_debuginfo_for_scalarpair_params, r=oli-obk
Fix debuginfo for parameters passed via the ScalarPair abi on Windows

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 #81898.

Fixes #88625
2021-09-22 01:13:49 +00:00
Vadim Petrochenkov
fbe5e5c0ee rustc_index: Add some map-like APIs to IndexVec 2021-09-22 03:11:29 +03:00
bors
d8d1d1059a Auto merge of #89158 - the8472:rollup-3e4ijth, r=the8472
Rollup of 12 pull requests

Successful merges:

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

Failed merges:

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

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

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

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

cc #89118
2021-09-21 22:54:07 +02:00
the8472
8d95bb2146
Rollup merge of #89126 - FabianWolff:issue-89088, r=petrochenkov
Fix ICE when `indirect_structural_match` is allowed

Fixes #89088. The ICE is caused by `delay_good_path_bug()`, which is called (indirectly) from a `format!()` macro invocation. I have moved the macro invocation into the `decorate` closure of `struct_span_lint_hir()`, so that the macro is only invoked if the lint is not allowed (i.e., causes at least a warning, and thus prevents `delay_good_path_bug()` from firing).
2021-09-21 22:54:06 +02:00
the8472
ecfdadcef9
Rollup merge of #89113 - BoxyUwU:incr-comp-thir-act, r=lcnr
dont `.ensure()` the `thir_abstract_const` query call in `mir_build`

might fix an ICE seen in #89022 (note: this PR does not close that issue) about attempting to read stolen thir. I couldn't repro the ICE but this `.ensure` seems sus anyway.

r? `@lcnr`
2021-09-21 22:54:03 +02:00
the8472
d7de8d2b53
Rollup merge of #89086 - WaffleLapkin:stabilize_iter_map_while, r=kennytm
Stabilize `Iterator::map_while`

Per the FCP: https://github.com/rust-lang/rust/issues/68537#issuecomment-922385035

This PR stabilizes `Iterator::map_while` and `iter::MapWhile` in Rust 1.57.
2021-09-21 22:54:01 +02:00
the8472
9f50c87267
Rollup merge of #89078 - camsteffen:map-ref, r=cjgillot
Cleanup: Remove needless reference in ParentHirIterator

It forces an intermediate binding of `Map` which is a Copy type.
2021-09-21 22:54:00 +02:00
the8472
c2cdba42b9
Rollup merge of #88795 - FabianWolff:issue-88684, r=wesleywiser
Print a note if a character literal contains a variation selector

Fixes #88684.
2021-09-21 22:53:58 +02:00
bors
ac2d9fc509 Auto merge of #89103 - Mark-Simulacrum:migrate-2021, r=estebank
Migrate in-tree crates to 2021

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

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

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

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

It is recommended to skip the mass migration of Cargo.toml's to 2021 for review purposes; you can also use `git diff d6cd2c6c87 -I'^edition = .20...$'` to ignore the edition = 2018/21 lines in the diff.
2021-09-21 19:25:49 +00:00
bors
840acd378a Auto merge of #88981 - durin42:llvm-14-crc32, r=nagisa
rustc_codegen_llvm: make sse4.2 imply crc32 for LLVM 14

This fixes compiling things like the `snap` crate after
https://reviews.llvm.org/D105462. I added a test that verifies the
additional attribute gets specified, and confirmed that I can build
cargo with both LLVM 13 and 14 with this change applied.

r? `@nagisa` cc `@nikic`
2021-09-21 16:13:24 +00:00
Cameron Steffen
09b37d7433 Use ZST for fmt unsafety
This allows the format_args! macro to keep the pre-expansion code out of
the unsafe block without doing gymnastics with nested `match`
expressions. This reduces codegen.
2021-09-21 10:04:44 -05:00
b-naber
999888c086 add case for checking const refs in check_const_value_eq 2021-09-21 15:49:29 +02:00
bors
7743c9fadd Auto merge of #89125 - Aaron1011:remove-intercrate-cache, r=jackh726
Don't use projection cache or candidate cache in intercrate mode

Fixes #88969

It appears that *just* disabling the evaluation cache (in #88994)
leads to other issues involving intercrate mode caching. I suspect
that since we now always end up performing the full evaluation
in intercrate mode, we end up 'polluting' the candidate and projection
caches with results that depend on being in intercrate mode in some way.
Previously, we might have hit a cached evaluation (stored during
non-intercrate mode), and skipped doing this extra work in
intercrate mode.

The whole situation with intercrate mode caching is turning into
a mess. Ideally, we would remove intercrate mode entirely - however,
this might require waiting on Chalk.
2021-09-21 13:25:14 +00:00
bors
dda2a0eca4 Auto merge of #89045 - oli-obk:lazy_normalization_in_opaque_types, r=nikomatsakis
Register normalization obligations instead of immediately normalizing in opaque type instantiation

For lazy TAIT we will need to instantiate opaque types from within `rustc_infer`, which cannot invoke normalization methods (they are in `rustc_trait_resolution`). So before we move the logic over to `rustc_infer`, we need make sure no normalization happens anymore. This PR resolves that by just registering normalization obligations and continuing.

This PR is best reviewed commit by commit

I also included f7ad36e which is just an independent cleanup that touches the same code and reduces diagnostics noise a bit

r? `@nikomatsakis` cc `@spastorino`
2021-09-21 10:33:15 +00:00
Ankit Chandawala
d4ee6982e4 Fix match for placeholder region 2021-09-21 09:31:59 +01:00
bors
49c0861ed0 Auto merge of #87234 - cjgillot:lower-mono, r=petrochenkov
Lower only one HIR owner at a time

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

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

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

(While these items could logically be in different PRs, the dependency between commits and the amount of conflicts force a monolithic PR.)
2021-09-21 07:52:15 +00:00
lcnr
01bcddbdc4 crates is already deterministic 2021-09-21 08:24:23 +02:00
lcnr
5b9cc2068f use indexmap instead of hashmap 2021-09-21 08:24:23 +02:00
lcnr
ca2c55d264 rename 2021-09-21 08:24:23 +02:00
Mark Rousskov
3b89679671 Adjust documentation for compatibility with 2021
This also adjusts the lint docs generation to accept (and ignore) an allow
attribute, rather than expecting the documentation to be immediately followed by
the lint name.
2021-09-20 22:21:43 -04:00
Mark Rousskov
f338900826 Remove Drop-caused migration-added captures
All of these were added due to insignificant Drop types being present.
2021-09-20 22:21:43 -04:00