Commit Graph

18150 Commits

Author SHA1 Message Date
Dylan DPC
ada50112ba
Rollup merge of #103224 - compiler-errors:semi-after-closure-in-macro, r=fee1-dead
Allow semicolon after closure within parentheses in macros

#88546 added some parsing logic that if we're parsing a closure, and we're within parentheses, and a semicolon follows, then we must be parsing something erroneous like: `f(|| a; b)`, so it replaces the closure body with an error expression. However, it's valid to parse those tokens if we're within a macro, as in #103222.

This is a bit unsatisfying fix. Is there a more robust way of checking that we're within a macro?

I would also be open to removing this "_It is likely that the closure body is a block but where the braces have been removed_" check altogether at the expense of more verbose errors, since it seems very suspicious in the first place...

Fixes #103222.
2022-10-22 16:28:08 +05:30
Dylan DPC
16c3b64794
Rollup merge of #102602 - WaffleLapkin:linty_action, r=estebank
Slightly tweak comments wrt `lint_overflowing_range_endpoint`

From the review: https://github.com/rust-lang/rust/pull/101986#discussion_r975610611

It _seemed_ that the lint was not emitted when the `if` check failed, but _actually_ this happens already in a special case and the lint is emitted outside of this function, if this function doesn't. I've cleared up the code/comments a bit, so it's more obvious :)

r? ```@estebank```
2022-10-22 16:28:07 +05:30
bors
26c96e3416 Auto merge of #103227 - lcnr:bye-bye-unevaluated-const, r=oli-obk
stop using `ty::UnevaluatedConst` directly

best reviewed commit by commit.

simplifies #99798 because we now don't have to expand `ty::UnevaluatedConst` to `ty::Const`.
I also remember some other places where using `ty::UnevaluatedConst` directly was annoying and caused issues, though I don't quite remember what they were rn '^^

r? `@oli-obk` cc `@JulianKnodt`
2022-10-22 07:49:33 +00:00
Michael Goulet
3d7b1f0d18 Don't erroneously deny semicolons after closure expr within parentheses in a macro 2022-10-22 06:59:49 +00:00
bors
3022afe3d1 Auto merge of #103196 - Nilstrieb:no-meta-query, r=cjgillot
Get rid of native_library projection queries

They don't seem particularly useful as I don't expect native libraries to change frequently.

Maybe they do provide significant value of keeping incremental compilation green though, I'm not sure.
2022-10-22 05:08:51 +00:00
bors
eecde5850c Auto merge of #103172 - pcwalton:deduced-param-attrs, r=oli-obk
Introduce deduced parameter attributes, and use them for deducing `readonly` on indirect immutable freeze by-value function parameters.

Introduce deduced parameter attributes, and use them for deducing `readonly` on
indirect immutable freeze by-value function parameters.

Right now, `rustc` only examines function signatures and the platform ABI when
determining the LLVM attributes to apply to parameters. This results in missed
optimizations, because there are some attributes that can be determined via
analysis of the MIR making up the function body. In particular, `readonly`
could be applied to most indirectly-passed by-value function arguments
(specifically, those that are freeze and are observed not to be mutated), but
it currently is not.

This patch introduces the machinery that allows `rustc` to determine those
attributes. It consists of a query, `deduced_param_attrs`, that, when
evaluated, analyzes the MIR of the function to determine supplementary
attributes. The results of this query for each function are written into the
crate metadata so that the deduced parameter attributes can be applied to
cross-crate functions. In this patch, we simply check the parameter for
mutations to determine whether the `readonly` attribute should be applied to
parameters that are indirect immutable freeze by-value.  More attributes could
conceivably be deduced in the future: `nocapture` and `noalias` come to mind.

Adding `readonly` to indirect function parameters where applicable enables some
potential optimizations in LLVM that are discussed in [issue 103103] and [PR
103070] around avoiding stack-to-stack memory copies that appear in functions
like `core::fmt::Write::write_fmt` and `core::panicking::assert_failed`. These
functions pass a large structure unchanged by value to a subfunction that also
doesn't mutate it. Since the structure in this case is passed as an indirect
parameter, it's a pointer from LLVM's perspective. As a result, the
intermediate copy of the structure that our codegen emits could be optimized
away by LLVM's MemCpyOptimizer if it knew that the pointer is `readonly
nocapture noalias` in both the caller and callee. We already pass `nocapture
noalias`, but we're missing `readonly`, as we can't determine whether a
by-value parameter is mutated by examining the signature in Rust. I didn't have
much success with having LLVM infer the `readonly` attribute, even with fat
LTO; it seems that deducing it at the MIR level is necessary.

No large benefits should be expected from this optimization *now*; LLVM needs
some changes (discussed in [PR 103070]) to more aggressively use the `noalias
nocapture readonly` combination in its alias analysis. I have some LLVM patches
for these optimizations and have had them looked over. With all the patches
applied locally, I enabled LLVM to remove all the `memcpy`s from the following
code:

```rust
fn main() {
    println!("Hello {}", 3);
}
```

which is a significant codegen improvement over the status quo. I expect that if this optimization kicks in in multiple places even for such a simple program, then it will apply to Rust code all over the place.

[issue 103103]: https://github.com/rust-lang/rust/issues/103103

[PR 103070]: https://github.com/rust-lang/rust/pull/103070
2022-10-22 02:28:05 +00:00
Matthias Krüger
ed430ca5fe
Rollup merge of #103351 - oli-obk:tilde_const_impls, r=fee1-dead
Require Drop impls to have the same constness on its bounds as the bounds on the struct have

r? ``@fee1-dead``
2022-10-22 00:14:02 +02:00
Matthias Krüger
7ee0aeacaf
Rollup merge of #103339 - Rageking8:fix-some-typos, r=fee1-dead
Fix some typos
2022-10-22 00:14:00 +02:00
Matthias Krüger
ebfdf735ac
Rollup merge of #102635 - lcnr:incoherent_auto_trait_objects, r=jackh726
make `order_dependent_trait_objects` show up in future-breakage reports

tried to change it to a hard error in #102474 but breaking the more than 1000 dependents of `traitobject` doesn't feel great 😅

This lint has existed since more than 3 years now and the way this is currently implemented is buggy and will break with #102472. imo we should upgrade it to also report for dependencies and maybe also backport this to beta. Then after maybe 2-3 stable versions I would like to finally convert this lint to a hard error.
2022-10-22 00:13:59 +02:00
bors
57e2c06a8d Auto merge of #101077 - sunshowers:signal-mask-inherit, r=sunshowers
Change process spawning to inherit the parent's signal mask by default

Previously, the signal mask was always reset when a child process is
started. This breaks tools like `nohup` which expect `SIGHUP` to be
blocked for all transitive processes.

With this change, the default behavior changes to inherit the signal mask.

This also changes the signal disposition for `SIGPIPE` to only be changed if the `#[unix_sigpipe]` attribute isn't set.
2022-10-21 18:09:03 +00:00
bors
ba9d01be67 Auto merge of #98450 - lqd:doc-metadata, r=lqd,GuillaumeGomez
Remove more attributes from metadata

A lot of the attributes that are currently stored in the metadata aren't used at all. The biggest metadata usage comes from the doc attributes currently but they are needed by rustdoc so we only removed the ones that cannot be used in downstream crates (doc comments on private items).

r? `@ghost`
2022-10-21 15:27:56 +00:00
Oli Scherer
d6cf8934db Require Drop impls to have the same constness on its bounds as the bounds on the struct have 2022-10-21 14:22:13 +00:00
Oli Scherer
349ba6bb51 Remove needless special cases and dead code 2022-10-21 14:21:44 +00:00
bors
657f246812 Auto merge of #103344 - Dylan-DPC:rollup-d1rpfvx, r=Dylan-DPC
Rollup of 6 pull requests

Successful merges:

 - #102287 (Elaborate supertrait bounds when triggering `unused_must_use` on `impl Trait`)
 - #102922 (Filtering spans when emitting json)
 - #103051 (translation: doc comments with derives, subdiagnostic-less enum variants, more derive use)
 - #103111 (Account for hygiene in typo suggestions, and use them to point to shadowed names)
 - #103260 (Fixup a few tests needing asm support)
 - #103321 (rustdoc: improve appearance of source page navigation bar)

Failed merges:

 - #103209 (Diagnostic derives: allow specifying multiple alternative suggestions)

r? `@ghost`
`@rustbot` modify labels: rollup
2022-10-21 12:41:09 +00:00
Dylan DPC
3055eb9b26
Rollup merge of #103260 - cuviper:needs-asm-support, r=fee1-dead
Fixup a few tests needing asm support
2022-10-21 17:29:59 +05:30
Dylan DPC
41a1cfdbaf
Rollup merge of #103111 - cjgillot:shadow-label, r=estebank
Account for hygiene in typo suggestions, and use them to point to shadowed names

Fixes https://github.com/rust-lang/rust/issues/97459

r? `@estebank`
2022-10-21 17:29:59 +05:30
Dylan DPC
e11511dfa6
Rollup merge of #103051 - davidtwco:translation-tidying-up, r=compiler-errors
translation: doc comments with derives, subdiagnostic-less enum variants, more derive use

- Adds support for `doc` attributes in the diagnostic derives so that documentation comments don't result in the derive failing.
- Adds support for enum variants in the subdiagnostic derive to not actually correspond to an addition to a diagnostic.
- Made use of the derive in more places in the `rustc_ast_lowering`, `rustc_ast_passes`, `rustc_lint`, `rustc_session`, `rustc_infer` - taking advantage of recent additions like eager subdiagnostics, multispan suggestions, etc.

cc #100717
2022-10-21 17:29:58 +05:30
Dylan DPC
0a0e9f73af
Rollup merge of #102922 - kper:bugfix/102902-filtering-json, r=oli-obk
Filtering spans when emitting json

According to the issue #102902, we shouldn't emit spans which have an empty span and no suggested replacement.
2022-10-21 17:29:58 +05:30
Dylan DPC
66d91d8276
Rollup merge of #102287 - compiler-errors:unused-must-use-also-supertrait, r=fee1-dead
Elaborate supertrait bounds when triggering `unused_must_use` on `impl Trait`

Given `impl Trait`, if one of its supertraits has a `#[must_use]`, then trigger the lint. This means that, for example, `-> impl ExactSizeIterator` also triggers the `must_use` on `trait Iterator`, which fixes #102183.

This might need `@rust-lang/lang` sign-off, since it changes the behavior of the lint, so cc'ing them.
2022-10-21 17:29:57 +05:30
Rageking8
62a2a1d257 fix some typos 2022-10-21 18:04:00 +08:00
bors
0940040c04 Auto merge of #103310 - lcnr:rustc_hir_typeck, r=compiler-errors
move hir typeck into separate crate

second part https://github.com/rust-lang/compiler-team/issues/529

I avoided pretty much anything that wasn't just a simple move + path adjustment. Left fixmes for methods which are at an odd place

r? `@compiler-errors`
2022-10-21 09:52:18 +00:00
Patrick Walton
da630ac79d Introduce deduced parameter attributes, and use them for deducing readonly on
indirect immutable freeze by-value function parameters.

Right now, `rustc` only examines function signatures and the platform ABI when
determining the LLVM attributes to apply to parameters. This results in missed
optimizations, because there are some attributes that can be determined via
analysis of the MIR making up the function body. In particular, `readonly`
could be applied to most indirectly-passed by-value function arguments
(specifically, those that are freeze and are observed not to be mutated), but
it currently is not.

This patch introduces the machinery that allows `rustc` to determine those
attributes. It consists of a query, `deduced_param_attrs`, that, when
evaluated, analyzes the MIR of the function to determine supplementary
attributes. The results of this query for each function are written into the
crate metadata so that the deduced parameter attributes can be applied to
cross-crate functions. In this patch, we simply check the parameter for
mutations to determine whether the `readonly` attribute should be applied to
parameters that are indirect immutable freeze by-value.  More attributes could
conceivably be deduced in the future: `nocapture` and `noalias` come to mind.

Adding `readonly` to indirect function parameters where applicable enables some
potential optimizations in LLVM that are discussed in [issue 103103] and [PR
103070] around avoiding stack-to-stack memory copies that appear in functions
like `core::fmt::Write::write_fmt` and `core::panicking::assert_failed`. These
functions pass a large structure unchanged by value to a subfunction that also
doesn't mutate it. Since the structure in this case is passed as an indirect
parameter, it's a pointer from LLVM's perspective. As a result, the
intermediate copy of the structure that our codegen emits could be optimized
away by LLVM's MemCpyOptimizer if it knew that the pointer is `readonly
nocapture noalias` in both the caller and callee. We already pass `nocapture
noalias`, but we're missing `readonly`, as we can't determine whether a
by-value parameter is mutated by examining the signature in Rust. I didn't have
much success with having LLVM infer the `readonly` attribute, even with fat
LTO; it seems that deducing it at the MIR level is necessary.

No large benefits should be expected from this optimization *now*; LLVM needs
some changes (discussed in [PR 103070]) to more aggressively use the `noalias
nocapture readonly` combination in its alias analysis. I have some LLVM patches
for these optimizations and have had them looked over. With all the patches
applied locally, I enabled LLVM to remove all the `memcpy`s from the following
code:

```rust
fn main() {
    println!("Hello {}", 3);
}
```

which is a significant codegen improvement over the status quo. I expect that
if this optimization kicks in in multiple places even for such a simple
program, then it will apply to Rust code all over the place.

[issue 103103]: https://github.com/rust-lang/rust/issues/103103

[PR 103070]: https://github.com/rust-lang/rust/pull/103070
2022-10-21 02:33:15 -07:00
Guillaume Gomez
ae5108a1ed Add code comments and documentation 2022-10-20 22:44:10 +00:00
Guillaume Gomez
72d6fde130 Remove doc comments only for private items or some specific doc comments 2022-10-20 22:44:10 +00:00
Guillaume Gomez
b12b65c1b7 Add missing @local_only on attributes 2022-10-20 22:44:10 +00:00
Rain
a52c79e859 Change process spawning to inherit the parent's signal mask by default
Previously, the signal mask is always reset when a child process is
started. This breaks tools like `nohup` which expect `SIGHUP` to be
blocked.

With this change, the default behavior changes to inherit the signal mask.

This also changes the signal disposition for `SIGPIPE` to only be
changed if the `#[unix_sigpipe]` attribute isn't set.
2022-10-20 14:53:38 -07:00
lcnr
adc700b089 update doc links 2022-10-20 23:47:49 +02:00
Matthias Krüger
f9944a9d2c
Rollup merge of #103319 - fee1-dead-contrib:improve_tilde_const_msg, r=oli-obk
Improve "`~const` is not allowed here" message

r? `@oli-obk`
2022-10-20 22:42:42 +02:00
Matthias Krüger
801e32647e
Rollup merge of #103315 - RalfJung:interpret-switchint-ice, r=bjorn3
interpret: remove an incorrect assertion

This fixes an ICE in Miri, [reported](https://rust-lang.zulipchat.com/#narrow/stream/269128-miri/topic/SwitchInt.20with.20no.20targets.3F) by `@saethlin.` The faulty assertion was introduced by 432535da2b, when a previously correct assertion checking that the `otherwise` target exists got replaced by this assertion checking that at least one more target beyond `otherwise` exists.

Sadly we don't have a small reproducer so I don't think we can easily add a testcase.
2022-10-20 22:42:41 +02:00
Matthias Krüger
be4816fbf0
Rollup merge of #103230 - nnethercote:clarify-startup, r=jyn514
Clarify startup

A small follow-up to #102769.

r? `@jyn514`
2022-10-20 22:42:38 +02:00
Matthias Krüger
7ee4b218a8
Rollup merge of #103221 - TaKO8Ki:fix-103202, r=oli-obk
Fix `SelfVisitor::is_self_ty` ICE

Fixes #103202
2022-10-20 22:42:38 +02:00
Deadbeef
ebf5028574 Improve "~const is not allowed here" message 2022-10-20 19:32:16 +00:00
Michael Goulet
8509819aef Elaborate supertrait bounds when triggering unused_must_use on impl Trait 2022-10-20 17:31:01 +00:00
Ralf Jung
bf14e3196b interpret: remove an incorrect assertion 2022-10-20 19:06:34 +02:00
bors
5ffa67d730 Auto merge of #103092 - petrochenkov:weaklto, r=wesleywiser
linker: Fix weak lang item linking with combination windows-gnu + LLD + LTO

In https://github.com/rust-lang/rust/pull/100404 this logic was originally disabled for MSVC due to issues with LTO, but the same issues appear on windows-gnu with LLD because that LLD uses the same underlying logic as MSVC LLD, just with re-syntaxed command line options.

So this PR just disables it for LTO builds in general.
2022-10-20 16:20:50 +00:00
lcnr
8eb2b75a11 add increased recursion limit 2022-10-20 18:03:28 +02:00
lcnr
fb3ab13a1c rustc_hir_typeck: fix paths and partially mv files 2022-10-20 17:53:14 +02:00
lcnr
f468a90bad rustc_hir_typeck: move whole files 2022-10-20 17:53:14 +02:00
bors
542febd2d3 Auto merge of #103290 - matthiaskrgr:rollup-ngozai3, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #103197 (Stabilize proc_macro::Span::source_text)
 - #103251 (Fix item declaration highlighting)
 - #103262 (Adjusting test to needs-unwind, with linking issue)
 - #103268 (rustdoc: remove no-op CSS `nav.sub { font-size: 1rem }`)
 - #103272 (Remove extra spaces in docs)
 - #103276 (Erase regions before checking for `Default` in uninitialized binding error)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-10-20 13:33:50 +00:00
bors
53728ff751 Auto merge of #103185 - chenyukang:yukang/fix-span-next-point, r=davidtwco
Fix the bug of next_point in source_map

There is a bug in `next_point`, the new span won't move to next position when be called in the first time.

For this reason, our current code is working like this:
1. When we really want to move to the next position, we called two times of `next_point`
2. Some code which use `next_point` actually done the same thing with `shrink_to_hi`

This fix make sure when `next_point` is called, span will move with the width at least 1, and also work correctly in the scenario of multiple bytes.

Ref: https://github.com/rust-lang/rust/pull/103140#discussion_r997710998

r? `@davidtwco`
2022-10-20 10:40:09 +00:00
Kevin Per
28d0312b7d Implement assertions and fixes to not emit empty spans without suggestions 2022-10-20 08:25:31 +00:00
Matthias Krüger
e29ecb70af
Rollup merge of #103276 - compiler-errors:default-on-uninit-ice, r=TaKO8Ki
Erase regions before checking for `Default` in uninitialized binding error

Fixes #103250
2022-10-20 07:58:58 +02:00
bors
4b3b731b55 Auto merge of #103220 - compiler-errors:deny-infers, r=lcnr
Deny hashing ty/re/ct inference variables

cc `@cjgillot` and https://github.com/rust-lang/rust/pull/102695#issuecomment-1275706528
r? `@lcnr`

best reviewed one commit at a time, mostly because the second commit that fixes `ClosureOutlivesRequirement` is mostly noise because of losing its `<'tcx>` lifetime parameter.
2022-10-20 05:56:56 +00:00
Takayuki Maeda
9a9e2fe15f check if impl_self is Some 2022-10-20 14:10:52 +09:00
bors
ebdde35dce Auto merge of #103205 - spastorino:fix-rpits-lifetime-remapping, r=cjgillot
Do anonymous lifetimes remapping correctly for nested rpits

Closes #103141

r? `@cjgillot` `@nikomatsakis`

This fixes a stable to stable regression that in my opinion is `P-critical` so, we probably want to backport it all the way up to stable.
2022-10-20 03:07:17 +00:00
bors
cb9467515b Auto merge of #102417 - oli-obk:opaque_lifetimes2, r=jackh726
Require lifetime bounds for opaque types in order to allow hidden types to capture said lifetimes

fixes #96996

cc `@aliemjay`
2022-10-20 00:22:17 +00:00
Michael Goulet
c5c9f74829 Erase regions before checking for default in uninitialized binding error 2022-10-19 23:36:28 +00:00
Santiago Pastorino
49ce8a22b0
Do anonymous lifetimes remapping correctly for nested rpits 2022-10-19 16:49:39 -03:00
Santiago Pastorino
fb5475887f
Extract orig_opt_local_def_id as a function 2022-10-19 16:49:39 -03:00
Matthias Krüger
12775ce16a
Rollup merge of #103239 - m-ou-se:unstable-abi-fn-impl-check, r=lcnr
Allow #[unstable] impls for fn() with unstable abi.

This allows `#[unstable]` trait impls for `extern "unwind-C" fn()`, based on the fact that that abi and therefore that type is unstable.

See https://github.com/rust-lang/rust/pull/101263#issuecomment-1283099947
2022-10-19 21:38:41 +02:00