]> git.lizzy.rs Git - rust.git/log
rust.git
20 months agoAllow specifying multiple alternative suggestions
Xiretza [Mon, 17 Oct 2022 17:41:49 +0000 (19:41 +0200)]
Allow specifying multiple alternative suggestions

This allows porting uses of span_suggestions() to diagnostic structs.

Doesn't work for multipart_suggestions() because the rank would be
reversed - the struct would specify multiple spans, each of which has
multiple possible replacements, while multipart_suggestions() creates
multiple possible replacements, each with multiple spans.

20 months agoAuto merge of #103431 - Dylan-DPC:rollup-oozfo89, r=Dylan-DPC
bors [Sun, 23 Oct 2022 11:33:18 +0000 (11:33 +0000)]
Auto merge of #103431 - Dylan-DPC:rollup-oozfo89, r=Dylan-DPC

Rollup of 6 pull requests

Successful merges:

 - #101293 (Recover when unclosed char literal is parsed as a lifetime in some positions)
 - #101908 (Suggest let for assignment, and some code refactor)
 - #103192 (rustdoc: Eliminate uses of `EarlyDocLinkResolver::all_traits`)
 - #103226 (Check `needs_infer` before `needs_drop` during HIR generator analysis)
 - #103249 (resolve: Revert "Set effective visibilities for imports more precisely")
 - #103305 (Move some tests to more reasonable places)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup

20 months agoRollup merge of #103305 - c410-f3r:moar-errors, r=petrochenkov
Dylan DPC [Sun, 23 Oct 2022 09:50:20 +0000 (15:20 +0530)]
Rollup merge of #103305 - c410-f3r:moar-errors, r=petrochenkov

Move some tests to more reasonable places

r? `@petrochenkov`

20 months agoRollup merge of #103249 - petrochenkov:revaddids, r=oli-obk
Dylan DPC [Sun, 23 Oct 2022 09:50:18 +0000 (15:20 +0530)]
Rollup merge of #103249 - petrochenkov:revaddids, r=oli-obk

resolve: Revert "Set effective visibilities for imports more precisely"

In theory the change was correct, but in practice the use of import items in HIR is limited and hacky, and it expects that (effective) visibilities for all (up to) 3 IDs of the import are set to the value reflecting (effective) visibility of the whole syntactic `use` item rather than its individual components.

Fixes https://github.com/rust-lang/rust/issues/102352
r? `@oli-obk`

20 months agoRollup merge of #103226 - compiler-errors:delay-if-need-infer, r=lcnr
Dylan DPC [Sun, 23 Oct 2022 09:50:17 +0000 (15:20 +0530)]
Rollup merge of #103226 - compiler-errors:delay-if-need-infer, r=lcnr

Check `needs_infer` before `needs_drop` during HIR generator analysis

This is kinda a revival of #103036, but with the understanding that after fallback, a generator-interior type will only have `needs_infer` true if there's an error that prevented int or float variable fallback to occur (modulo region variables, which are erased).

Therefore the best choice here is to delay a bug and skip the `needs_drop` call altogether.

r? `@lcnr` feel free to reassign though

20 months agoRollup merge of #103192 - petrochenkov:noalltraits, r=jyn514
Dylan DPC [Sun, 23 Oct 2022 09:50:17 +0000 (15:20 +0530)]
Rollup merge of #103192 - petrochenkov:noalltraits, r=jyn514

rustdoc: Eliminate uses of `EarlyDocLinkResolver::all_traits`

Another step to https://github.com/rust-lang/rust/pull/94857.

20 months agoRollup merge of #101908 - chenyukang:fix-101880, r=estebank
Dylan DPC [Sun, 23 Oct 2022 09:50:16 +0000 (15:20 +0530)]
Rollup merge of #101908 - chenyukang:fix-101880, r=estebank

Suggest let for assignment, and some code refactor

Fixes #101880

20 months agoRollup merge of #101293 - compiler-errors:lt-is-actually-char, r=estebank
Dylan DPC [Sun, 23 Oct 2022 09:50:16 +0000 (15:20 +0530)]
Rollup merge of #101293 - compiler-errors:lt-is-actually-char, r=estebank

Recover when unclosed char literal is parsed as a lifetime in some positions

Fixes #101278

20 months agoAuto merge of #103345 - Nilstrieb:diag-flat, r=compiler-errors
bors [Sun, 23 Oct 2022 09:06:39 +0000 (09:06 +0000)]
Auto merge of #103345 - Nilstrieb:diag-flat, r=compiler-errors

Flatten diagnostic slug modules

This makes it easier to grep for the slugs in the code.

See https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Localization.20infra.20interferes.20with.20grepping.20for.20error for more discussion about it.

This was mostly done with a few regexes and a bunch of manual work. This also exposes a pretty annoying inconsistency for the extra labels. Some of the extra labels are defined as additional properties in the fluent message (which makes them not prefixed with the crate name) and some of them are new fluent messages themselves (which makes them prefixed with the crate name). I don't know whether we want to clean this up at some point but it's useful to know.

r? `@davidtwco`

20 months agoUpdate translation tests
Nilstrieb [Sat, 22 Oct 2022 09:08:09 +0000 (11:08 +0200)]
Update translation tests

20 months agoMigrate all diagnostics
Nilstrieb [Sat, 22 Oct 2022 09:07:54 +0000 (11:07 +0200)]
Migrate all diagnostics

20 months agoGenerate fluent message constant in a flat module for all crates
Nilstrieb [Fri, 21 Oct 2022 10:25:25 +0000 (12:25 +0200)]
Generate fluent message constant in a flat module for all crates

This will make it easier to grep for fluent message names.

20 months agoAuto merge of #103426 - matthiaskrgr:rollup-n6dqdy8, r=matthiaskrgr
bors [Sun, 23 Oct 2022 06:20:24 +0000 (06:20 +0000)]
Auto merge of #103426 - matthiaskrgr:rollup-n6dqdy8, r=matthiaskrgr

Rollup of 9 pull requests

Successful merges:

 - #103123 (Introduce `subst_iter` and `subst_iter_copied` on `EarlyBinder` )
 - #103328 (Do not suggest trivially false const predicates)
 - #103354 (Escape string literals when fixing overlong char literal)
 - #103355 (Handle return-position `impl Trait` in traits properly in `register_hidden_type`)
 - #103368 (Delay ambiguity span bug in normalize query iff not rustdoc)
 - #103388 (rustdoc: remove unused CSS class `.result-description`)
 - #103399 (Change `unknown_lint` applicability to `MaybeIncorrect`)
 - #103401 (Use functions for headings rustdoc GUI test)
 - #103412 (Fix typo in docs of `String::leak`.)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup

20 months agoRollup merge of #103412 - finnbear:fix_docs_typo_string_leak, r=thomcc
Matthias Krüger [Sun, 23 Oct 2022 06:14:34 +0000 (08:14 +0200)]
Rollup merge of #103412 - finnbear:fix_docs_typo_string_leak, r=thomcc

Fix typo in docs of `String::leak`.

I introduced a typo in #103280, this PR fixes it.

See https://github.com/rust-lang/rust/pull/103280#discussion_r1002538265

20 months agoRollup merge of #103401 - GuillaumeGomez:gui-test-headings-cleanup, r=notriddle
Matthias Krüger [Sun, 23 Oct 2022 06:14:33 +0000 (08:14 +0200)]
Rollup merge of #103401 - GuillaumeGomez:gui-test-headings-cleanup, r=notriddle

Use functions for headings rustdoc GUI test

r? ````@notriddle````

20 months agoRollup merge of #103399 - smoelius:unknown-lint-maybe-incorrect, r=fee1-dead
Matthias Krüger [Sun, 23 Oct 2022 06:14:33 +0000 (08:14 +0200)]
Rollup merge of #103399 - smoelius:unknown-lint-maybe-incorrect, r=fee1-dead

Change `unknown_lint` applicability to `MaybeIncorrect`

This small PR changes the applicability of `unknown_lint` to `MaybeIncorrect`, because the suggested lint might not be the correct one.

Here is one example where the current applicability causes a problem. Clippy has a set of internal lints guarded by a feature called `internal`. If the feature is not enabled, then the internal lints are "unknown." In that case, running `cargo clippy --fix ...` on `clippy_utils` causes lines such as the followig
https://github.com/rust-lang/rust/blob/26c96e341639102afacbbcad0dc18ad0ac71ab18/src/tools/clippy/clippy_utils/src/paths.rs#L51-L52
to be changed to
```rust
 #[expect(clippy::invalid_regex)] // internal lints do not know about all external crates
 pub const FUTURES_IO_ASYNCREADEXT: [&str; 3] = ["futures_util", "io", "AsyncReadExt"];
```
which is not correct.

20 months agoRollup merge of #103388 - notriddle:notriddle/result-description, r=GuillaumeGomez
Matthias Krüger [Sun, 23 Oct 2022 06:14:32 +0000 (08:14 +0200)]
Rollup merge of #103388 - notriddle:notriddle/result-description, r=GuillaumeGomez

rustdoc: remove unused CSS class `.result-description`

It was added to the CSS in d8de2b4c338471aacaf0e8a096f9a7148b146ab4, but was never actually used in that PR.

20 months agoRollup merge of #103368 - compiler-errors:normalization-ambiguity-bug, r=oli-obk
Matthias Krüger [Sun, 23 Oct 2022 06:14:32 +0000 (08:14 +0200)]
Rollup merge of #103368 - compiler-errors:normalization-ambiguity-bug, r=oli-obk

Delay ambiguity span bug in normalize query iff not rustdoc

Oli and I decided that the compiler debt of adding another usage of `tcx.sess.opts.actually_rustdoc` is fine, because we don't really want to add more complexity to the normalize query, and moving rustdoc to use fulfill normalization (`fully_normalize`, i.e. not use the normalize query) is unnecessary overhead given that it's skipping binders and stuff.

r? oli-obk

Fixes #102827
Fixes #103181

20 months agoRollup merge of #103355 - compiler-errors:rpitit-default-check, r=oli-obk
Matthias Krüger [Sun, 23 Oct 2022 06:14:31 +0000 (08:14 +0200)]
Rollup merge of #103355 - compiler-errors:rpitit-default-check, r=oli-obk

Handle return-position `impl Trait` in traits properly in `register_hidden_type`

The bounds that we get by calling `bound_explicit_item_bounds` from an RPITIT have projections, not opaques, but when we're *registering* an opaque, we want to treat it like an opaque.

Coincidentally fixes #102688 as well, which makes sense, since that was failing because we were inferring an opaque type to be equal to itself (opaque cycle error => "cannot resolve opaque type").

Fixes #103352

r? ```@oli-obk```

20 months agoRollup merge of #103354 - clubby789:escape-string-literals, r=compiler-errors
Matthias Krüger [Sun, 23 Oct 2022 06:14:31 +0000 (08:14 +0200)]
Rollup merge of #103354 - clubby789:escape-string-literals, r=compiler-errors

Escape string literals when fixing overlong char literal

Fixes #103323

````@rustbot```` label +A-diagnostics +A-suggestion-diagnostics

20 months agoRollup merge of #103328 - compiler-errors:trivial-false-const-sugg, r=jackh726
Matthias Krüger [Sun, 23 Oct 2022 06:14:30 +0000 (08:14 +0200)]
Rollup merge of #103328 - compiler-errors:trivial-false-const-sugg, r=jackh726

Do not suggest trivially false const predicates

Pass through constness to `predicate_can_apply` and don't suggest other impls if it's satisfied but not const.

Fixes #103267

20 months agoRollup merge of #103123 - compiler-errors:early-binder-iter, r=cjgillot
Matthias Krüger [Sun, 23 Oct 2022 06:14:30 +0000 (08:14 +0200)]
Rollup merge of #103123 - compiler-errors:early-binder-iter, r=cjgillot

Introduce `subst_iter` and `subst_iter_copied` on `EarlyBinder`

Makes working with bounds lists a bit easier, which I seem to do a lot.

Specifically, means that we don't need to do `.transpose_iter().map(|(pred, _)| *pred)` every time we want to iterate through an `EarlyBinder<&'tcx [(Predicate, Span)]>` (and even then, still have to call `subst` later), which was a very awkward idiom imo.

20 months agoAuto merge of #102660 - camsteffen:uninhabited-perf, r=oli-obk
bors [Sun, 23 Oct 2022 03:39:43 +0000 (03:39 +0000)]
Auto merge of #102660 - camsteffen:uninhabited-perf, r=oli-obk

Remove ParamEnv from uninhabited query

20 months agoFix typo in docs of `String::leak`.
Finn Bear [Sat, 22 Oct 2022 19:26:47 +0000 (12:26 -0700)]
Fix typo in docs of `String::leak`.

20 months agoAuto merge of #103240 - BelovDV:issue-102290, r=petrochenkov
bors [Sat, 22 Oct 2022 19:14:34 +0000 (19:14 +0000)]
Auto merge of #103240 - BelovDV:issue-102290, r=petrochenkov

Add architectures to fn create_object_file

Fixes #102290

r? `@petrochenkov`

20 months agoIntroduce InhabitedPredicate
Cameron Steffen [Tue, 4 Oct 2022 14:22:39 +0000 (09:22 -0500)]
Introduce InhabitedPredicate

20 months agoAuto merge of #103400 - weihanglo:update-cargo, r=weihanglo
bors [Sat, 22 Oct 2022 16:26:31 +0000 (16:26 +0000)]
Auto merge of #103400 - weihanglo:update-cargo, r=weihanglo

Update cargo

5 commits in 3ff044334f0567ce1481c78603aeee7211b91623..071eeaf210708219a5a1b2c4728ca2f97df7f2ae 2022-10-17 20:25:00 +0000 to 2022-10-22 01:17:55 +0000

- fix: Remove leading newline in vendor output (rust-lang/cargo#11273)
- Fix publishing with a dependency on a sparse registry (rust-lang/cargo#11268)
- Add missing edition (rust-lang/cargo#11265)
- fix(publish): Check remote git registry more than once post-publish (rust-lang/cargo#11255)
- Fix typo (rust-lang/cargo#11258)

r? `@ghost`

20 months agoAuto merge of #103398 - Dylan-DPC:rollup-cj6w00o, r=Dylan-DPC
bors [Sat, 22 Oct 2022 13:40:59 +0000 (13:40 +0000)]
Auto merge of #103398 - Dylan-DPC:rollup-cj6w00o, r=Dylan-DPC

Rollup of 7 pull requests

Successful merges:

 - #102602 (Slightly tweak comments wrt `lint_overflowing_range_endpoint`)
 - #103190 (rustdoc: render bounds of cross-crate GAT params)
 - #103224 (Allow semicolon after closure within parentheses in macros)
 - #103280 ((#102929) Implement `String::leak` (attempt 2))
 - #103329 (Add a forgotten check for NonNull::new_unchecked's precondition)
 - #103346 (Adjust argument type for mutable with_metadata_of (#75091))
 - #103360 (Reduce false positives in msys2 detection)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup

20 months agoUse functions for headings rustodoc GUI test
Guillaume Gomez [Sat, 22 Oct 2022 12:12:01 +0000 (14:12 +0200)]
Use functions for headings rustodoc GUI test

20 months agoUpdate cargo
Weihang Lo [Sat, 22 Oct 2022 12:05:48 +0000 (20:05 +0800)]
Update cargo

5 commits in 3ff044334f0567ce1481c78603aeee7211b91623..071eeaf210708219a5a1b2c4728ca2f97df7f2ae
2022-10-17 20:25:00 +0000 to 2022-10-22 01:17:55 +0000

- fix: Remove leading newline in vendor output (rust-lang/cargo#11273)
- Fix publishing with a dependency on a sparse registry (rust-lang/cargo#11268)
- Add missing edition (rust-lang/cargo#11265)
- fix(publish): Check remote git registry more than once post-publish (rust-lang/cargo#11255)
- Fix typo (rust-lang/cargo#11258)

20 months agoChange `unknown_lint` applicability to `MaybeIncorrect`
Samuel Moelius [Sat, 22 Oct 2022 11:08:45 +0000 (07:08 -0400)]
Change `unknown_lint` applicability to `MaybeIncorrect`

20 months agoRollup merge of #103360 - ChrisDenton:isterm-filetype, r=thomcc
Dylan DPC [Sat, 22 Oct 2022 10:58:09 +0000 (16:28 +0530)]
Rollup merge of #103360 - ChrisDenton:isterm-filetype, r=thomcc

Reduce false positives in msys2 detection

Currently msys2 will be detected by getting the file path and looking to see if it contains the substrings "msys-" and "-ptr" (or "cygwin-" and "-pty"). This risks false positives, especially with filesystem files and if `GetFileInformationByHandleEx` returns a [full path](https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/ntifs/nf-ntifs-ntqueryinformationfile#remarks).

This PR adds a check to see if the handle is a pipe before doing the substring search. Additionally, for "msys2-" or "cygwin-" it only checks if the file name starts with the substring rather than looking at the whole path.

20 months agoRollup merge of #103346 - HeroicKatora:metadata_of_const_pointer_argument, r=dtolnay
Dylan DPC [Sat, 22 Oct 2022 10:58:09 +0000 (16:28 +0530)]
Rollup merge of #103346 - HeroicKatora:metadata_of_const_pointer_argument, r=dtolnay

Adjust argument type for mutable with_metadata_of (#75091)

The method takes two pointer arguments: one `self` supplying the pointer value, and a second pointer supplying the metadata.

The new parameter type more clearly reflects the actual requirements. The provenance of the metadata parameter is disregarded completely. Using a mutable pointer in the call site can be coerced to a const pointer while the reverse is not true.

In some cases, the current parameter type can thus lead to a very slightly confusing additional cast. [Example](https://github.com/HeroicKatora/static-alloc/commit/cad93775eb9adc62f744651e3abf19513e69e7d0).

```rust
// Manually taking an unsized object from a `ManuallyDrop` into another allocation.
let val: &core::mem::ManuallyDrop<T> = …;

let ptr = val as *const _ as *mut T;
let ptr = uninit.as_ptr().with_metadata_of(ptr);
```

This could then instead be simplified to:

```rust
// Manually taking an unsized object from a `ManuallyDrop` into another allocation.
let val: &core::mem::ManuallyDrop<T> = …;

let ptr = uninit.as_ptr().with_metadata_of(&**val);
```

Tracking issue: https://github.com/rust-lang/rust/issues/75091

``@dtolnay`` you're reviewed #95249, would you mind chiming in?

20 months agoRollup merge of #103329 - saethlin:nonnull-precondition, r=thomcc
Dylan DPC [Sat, 22 Oct 2022 10:58:08 +0000 (16:28 +0530)]
Rollup merge of #103329 - saethlin:nonnull-precondition, r=thomcc

Add a forgotten check for NonNull::new_unchecked's precondition

Looks like I forgot this function a while ago in https://github.com/rust-lang/rust/pull/92686

r? ```@thomcc```

20 months agoRollup merge of #103280 - finnbear:impl_string_leak_2, r=joshtriplett
Dylan DPC [Sat, 22 Oct 2022 10:58:08 +0000 (16:28 +0530)]
Rollup merge of #103280 - finnbear:impl_string_leak_2, r=joshtriplett

(#102929) Implement `String::leak` (attempt 2)

Implementation of `String::leak` (#102929)

ACP: https://github.com/rust-lang/libs-team/issues/109

Supersedes #102941 (see previous reviews there)

```@rustbot``` label +T-libs-api -T-libs

20 months agoRollup merge of #103224 - compiler-errors:semi-after-closure-in-macro, r=fee1-dead
Dylan DPC [Sat, 22 Oct 2022 10:58:08 +0000 (16:28 +0530)]
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.

20 months agoRollup merge of #103190 - fmease:rustdoc-render-bounds-of-cross-crate-gat-params...
Dylan DPC [Sat, 22 Oct 2022 10:58:07 +0000 (16:28 +0530)]
Rollup merge of #103190 - fmease:rustdoc-render-bounds-of-cross-crate-gat-params, r=GuillaumeGomez

rustdoc: render bounds of cross-crate GAT params

Follow-up to #102439.
Render the trait bounds of type parameters of cross-crate (generic) associated types.

`````@rustbot````` label T-rustdoc A-cross-crate-reexports
r? `````@GuillaumeGomez`````

20 months agoRollup merge of #102602 - WaffleLapkin:linty_action, r=estebank
Dylan DPC [Sat, 22 Oct 2022 10:58:07 +0000 (16:28 +0530)]
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```

20 months agoAuto merge of #103231 - ecnelises:le_fix, r=lcnr
bors [Sat, 22 Oct 2022 10:53:17 +0000 (10:53 +0000)]
Auto merge of #103231 - ecnelises:le_fix, r=lcnr

Remove byte swap of valtree hash on big endian

This addresses problem reported in #103183. The code was originally introduced in https://github.com/rust-lang/rust/commit/e14b34c386ad2809e937e0e6e0379c5cc5474954. (see https://github.com/rust-lang/rust/pull/96591)

On big-endian environment, this operation sequence actually put the other half from 128-bit result, thus we got different hash result on LE and BE.

20 months agoAuto merge of #103227 - lcnr:bye-bye-unevaluated-const, r=oli-obk
bors [Sat, 22 Oct 2022 07:49:33 +0000 (07:49 +0000)]
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`

20 months agoDon't erroneously deny semicolons after closure expr within parentheses in a macro
Michael Goulet [Wed, 19 Oct 2022 04:55:31 +0000 (04:55 +0000)]
Don't erroneously deny semicolons after closure expr within parentheses in a macro

20 months agoRecover unclosed char literal being parsed as lifetime
Michael Goulet [Thu, 1 Sep 2022 18:48:09 +0000 (18:48 +0000)]
Recover unclosed char literal being parsed as lifetime

20 months agoIntroduce subst_iter and subst_iter_copied on EarlyBinder
Michael Goulet [Sun, 16 Oct 2022 18:48:28 +0000 (18:48 +0000)]
Introduce subst_iter and subst_iter_copied on EarlyBinder

20 months agonit: Inline may_need_drop
Michael Goulet [Wed, 19 Oct 2022 05:33:02 +0000 (05:33 +0000)]
nit: Inline may_need_drop

20 months agoCheck needs_infer before needs_drop in HIR generator analysis
Michael Goulet [Wed, 19 Oct 2022 05:28:40 +0000 (05:28 +0000)]
Check needs_infer before needs_drop in HIR generator analysis

20 months agorustdoc: remove unused CSS class `.result-description`
Michael Howell [Sat, 22 Oct 2022 05:06:16 +0000 (22:06 -0700)]
rustdoc: remove unused CSS class `.result-description`

It was added to the CSS in d8de2b4c338471aacaf0e8a096f9a7148b146ab4, but
was never actually used in that PR.

20 months agoAuto merge of #103196 - Nilstrieb:no-meta-query, r=cjgillot
bors [Sat, 22 Oct 2022 05:08:51 +0000 (05:08 +0000)]
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.

20 months agoAuto merge of #103172 - pcwalton:deduced-param-attrs, r=oli-obk
bors [Sat, 22 Oct 2022 02:28:05 +0000 (02:28 +0000)]
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

20 months agoUpdate UI tests
clubby789 [Sat, 22 Oct 2022 01:37:20 +0000 (02:37 +0100)]
Update UI tests

20 months agoProperly escape quotes when suggesting switching between char/string literals
clubby789 [Sat, 22 Oct 2022 01:37:15 +0000 (02:37 +0100)]
Properly escape quotes when suggesting switching between char/string literals

20 months agoAuto merge of #103375 - matthiaskrgr:rollup-4xrs7f2, r=matthiaskrgr
bors [Fri, 21 Oct 2022 23:42:01 +0000 (23:42 +0000)]
Auto merge of #103375 - matthiaskrgr:rollup-4xrs7f2, r=matthiaskrgr

Rollup of 9 pull requests

Successful merges:

 - #102635 (make `order_dependent_trait_objects` show up in future-breakage reports)
 - #103335 (Replaced wrong test with the correct mcve)
 - #103339 (Fix some typos)
 - #103340 (WinConsole::new is not actually fallible)
 - #103341 (Add test for issue 97607)
 - #103351 (Require Drop impls to have the same constness on its bounds as the bounds on the struct have)
 - #103359 (Remove incorrect comment in `Vec::drain`)
 - #103364 (rustdoc: clean up rustdoc-toggle CSS)
 - #103370 (rustdoc: remove unused CSS `.out-of-band { font-weight: normal }`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup

20 months agoRollup merge of #103370 - notriddle:notriddle/out-of-band, r=GuillaumeGomez
Matthias Krüger [Fri, 21 Oct 2022 22:14:04 +0000 (00:14 +0200)]
Rollup merge of #103370 - notriddle:notriddle/out-of-band, r=GuillaumeGomez

rustdoc: remove unused CSS `.out-of-band { font-weight: normal }`

This CSS was added in 083c3952e0d5473cd5c41a9eb7b4ffca18cc8e5f to normalize the appearance of out-of-band elements that were nested directly below headers.

Now, the only use of `out-of-band` is in the main page header, and it is nested below a wrapper, not the `<h1>` itself.

20 months agoRollup merge of #103364 - notriddle:notriddle/toggles, r=jsha
Matthias Krüger [Fri, 21 Oct 2022 22:14:03 +0000 (00:14 +0200)]
Rollup merge of #103364 - notriddle:notriddle/toggles, r=jsha

rustdoc: clean up rustdoc-toggle CSS

20 months agoRollup merge of #103359 - WaffleLapkin:drain_no_mut_qqq, r=scottmcm
Matthias Krüger [Fri, 21 Oct 2022 22:14:03 +0000 (00:14 +0200)]
Rollup merge of #103359 - WaffleLapkin:drain_no_mut_qqq, r=scottmcm

Remove incorrect comment in `Vec::drain`

r? ``@scottmcm``

Turns out this comment wasn't correct for 6 years, since #34951, which switched from using `slice::IterMut` into using `slice::Iter`.

20 months agoRollup merge of #103351 - oli-obk:tilde_const_impls, r=fee1-dead
Matthias Krüger [Fri, 21 Oct 2022 22:14:02 +0000 (00:14 +0200)]
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``

20 months agoRollup merge of #103341 - Rageking8:add-test-for-issue-97607, r=compiler-errors
Matthias Krüger [Fri, 21 Oct 2022 22:14:01 +0000 (00:14 +0200)]
Rollup merge of #103341 - Rageking8:add-test-for-issue-97607, r=compiler-errors

Add test for issue 97607

Fixes #97607

r? ``@compiler-errors``

Not sure which UI test dir to put this under, kindly let me know of a better dir if necessary and I will change it. Thanks.

20 months agoRollup merge of #103340 - RalfJung:winconsole, r=thomcc
Matthias Krüger [Fri, 21 Oct 2022 22:14:01 +0000 (00:14 +0200)]
Rollup merge of #103340 - RalfJung:winconsole, r=thomcc

WinConsole::new is not actually fallible

I just noticed this while reading the code for other reasons.
r? ``@thomcc``

20 months agoRollup merge of #103339 - Rageking8:fix-some-typos, r=fee1-dead
Matthias Krüger [Fri, 21 Oct 2022 22:14:00 +0000 (00:14 +0200)]
Rollup merge of #103339 - Rageking8:fix-some-typos, r=fee1-dead

Fix some typos

20 months agoRollup merge of #103335 - SarthakSingh31:issue-89008, r=jackh726
Matthias Krüger [Fri, 21 Oct 2022 22:14:00 +0000 (00:14 +0200)]
Rollup merge of #103335 - SarthakSingh31:issue-89008, r=jackh726

Replaced wrong test with the correct mcve

Closes #89008.

The old test was wrong and the compiler was [correctly raising an error](https://github.com/rust-lang/rust/issues/89008#issuecomment-1285128060). The bug in the issue was resolved at some point but due to the wrong test the issue was never closed.

This pr replaces that test with the correct MCVE (made by ``@jackh726).``

The error raised by the bug changed between when the bug was posted (2021-09-08) and when the MCVE [was posted](https://github.com/rust-lang/rust/issues/89008#issuecomment-950110735) (2021-10-23).
I ran them both through `nightly-2021-09-08` and they produce identical error messages. They also produce identical but different from before error messages when ran through `nightly-2021-10-23`.

<details>
  <summary>Error message with <code>nightly-2021-09-08</code></summary>

The code with the original bug report:
  ```
error[E0277]: the size for values of type `Repr` cannot be known at compilation time
  --> src/main.rs:23:43
   |
23 |     fn line_stream<'a, Repr>(&'a self) -> Self::LineStreamFut<'a, Repr> {
   |                        ----               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
   |                        |
   |                        this type parameter needs to be `std::marker::Sized`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `test-234234` due to previous error
  ```

MVCE:
```
error[E0277]: the size for values of type `Repr` cannot be known at compilation time
  --> src/main.rs:30:43
   |
30 |     fn line_stream<'a, Repr>(&'a self) -> Self::LineStreamFut<'a, Repr> {
   |                        ----               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
   |                        |
   |                        this type parameter needs to be `std::marker::Sized`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `test-234234` due to previous error
```
</details>

<details>
<summary>Error message with <code>nightly-2021-10-23</code></summary>

The code with the original bug report:
```
error[E0271]: type mismatch resolving `<impl futures::Future as futures::Future>::Output == impl futures::Stream`
  --> src/main.rs:23:43
   |
19 |     type LineStream<'a, Repr> = impl Stream<Item = Repr>;
   |                                 ------------------------ the expected opaque type
...
23 |     fn line_stream<'a, Repr>(&'a self) -> Self::LineStreamFut<'a, Repr> {
   |                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected opaque type, found struct `futures::stream::Empty`
   |
   = note: expected opaque type `impl futures::Stream`
                   found struct `futures::stream::Empty<_>`

error: could not find defining uses
  --> src/main.rs:19:33
   |
19 |     type LineStream<'a, Repr> = impl Stream<Item = Repr>;
   |                                 ^^^^^^^^^^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0271`.
error: could not compile `test-234234` due to 2 previous errors
```

MCVE:
```
error[E0271]: type mismatch resolving `<impl Future as Future>::Output == impl Stream`
  --> src/main.rs:30:43
   |
28 |     type LineStream<'a, Repr> = impl Stream<Item = Repr>;
   |                                 ------------------------ the expected opaque type
29 |     type LineStreamFut<'a, Repr> = impl Future<Output = Self::LineStream<'a, Repr>>;
30 |     fn line_stream<'a, Repr>(&'a self) -> Self::LineStreamFut<'a, Repr> {
   |                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected opaque type, found struct `Empty`
   |
   = note: expected opaque type `impl Stream`
                   found struct `Empty<_>`

error: could not find defining uses
  --> src/main.rs:28:33
   |
28 |     type LineStream<'a, Repr> = impl Stream<Item = Repr>;
   |                                 ^^^^^^^^^^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0271`.
error: could not compile `test-234234` due to 2 previous errors
```
</details>

20 months agoRollup merge of #102635 - lcnr:incoherent_auto_trait_objects, r=jackh726
Matthias Krüger [Fri, 21 Oct 2022 22:13:59 +0000 (00:13 +0200)]
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 :sweat_smile:

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.

20 months agorustdoc: remove unused CSS `.out-of-band { font-weight: normal }`
Michael Howell [Fri, 21 Oct 2022 21:12:42 +0000 (14:12 -0700)]
rustdoc: remove unused CSS `.out-of-band { font-weight: normal }`

This CSS was added in 083c3952e0d5473cd5c41a9eb7b4ffca18cc8e5f to
normalize the appearance of out-of-band elements that were nested directly
below headers.

Now, the only use of `out-of-band` is in the main page header, and it is
nested below a wrapper, not the `<h1>` itself.

20 months agoAuto merge of #101263 - lopopolo:lopopolo/c-unwind-fn-ptr-impls, r=thomcc
bors [Fri, 21 Oct 2022 20:59:03 +0000 (20:59 +0000)]
Auto merge of #101263 - lopopolo:lopopolo/c-unwind-fn-ptr-impls, r=thomcc

Add default trait implementations for "c-unwind" ABI function pointers

Following up on #92964, only add default trait implementations for the `c-unwind` family of function pointers. The previous attempt in #92964 added trait implementations for many more ABIs and ran into concerns regarding the increase in size of the libcore rlib.

An attempt to abstract away function pointer types behind a unified trait to reduce the duplication of trait impls is being discussed in #99531 but this change looks to be blocked on a lang MCP.

Following `@RalfJung's` suggestion in https://github.com/rust-lang/rust/pull/99531#issuecomment-1233440142, this commit is another cut at #92964 but it _only_ adds the impls for `extern "C-unwind" fn` and `unsafe extern "C-unwind" fn`.

I am interested in landing this patch to unblock the stabilization of the `c_unwind` feature.

RFC: https://github.com/rust-lang/rfcs/pull/2945
Tracking Issue: https://github.com/rust-lang/rust/issues/74990

20 months agotests
Michael Goulet [Fri, 21 Oct 2022 18:53:27 +0000 (18:53 +0000)]
tests

20 months agoDelay ambiguity span bug in normalize query iff not rustdoc
Michael Goulet [Fri, 21 Oct 2022 18:53:16 +0000 (18:53 +0000)]
Delay ambiguity span bug in normalize query iff not rustdoc

20 months agoAuto merge of #101077 - sunshowers:signal-mask-inherit, r=sunshowers
bors [Fri, 21 Oct 2022 18:09:03 +0000 (18:09 +0000)]
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.

20 months agorustdoc: prevent method summary margin from being applied to docblocks
Michael Howell [Fri, 21 Oct 2022 17:48:41 +0000 (10:48 -0700)]
rustdoc: prevent method summary margin from being applied to docblocks

20 months agorustdoc: merge identical CSS blocks
Michael Howell [Fri, 21 Oct 2022 17:31:33 +0000 (10:31 -0700)]
rustdoc: merge identical CSS blocks

20 months agoReduce false positives in msys2 detection
Chris Denton [Fri, 21 Oct 2022 16:57:22 +0000 (17:57 +0100)]
Reduce false positives in msys2 detection

This checks that:

* the handle is a pipe
* the pipe's file name starts with "msys-" or "cygwin-" rather than looking in the full path.

20 months agoRemove incorrect comment in `Vec::drain`
Maybe Waffle [Fri, 21 Oct 2022 15:29:02 +0000 (15:29 +0000)]
Remove incorrect comment in `Vec::drain`

20 months agoAuto merge of #98450 - lqd:doc-metadata, r=lqd,GuillaumeGomez
bors [Fri, 21 Oct 2022 15:27:56 +0000 (15:27 +0000)]
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`

20 months agoHandle RPITITs properly in register_hidden_type
Michael Goulet [Fri, 21 Oct 2022 14:56:53 +0000 (14:56 +0000)]
Handle RPITITs properly in register_hidden_type

20 months agoRequire Drop impls to have the same constness on its bounds as the bounds on the...
Oli Scherer [Fri, 21 Oct 2022 13:49:11 +0000 (13:49 +0000)]
Require Drop impls to have the same constness on its bounds as the bounds on the struct have

20 months agoRemove needless special cases and dead code
Oli Scherer [Fri, 21 Oct 2022 08:27:39 +0000 (08:27 +0000)]
Remove needless special cases and dead code

20 months agoReduce mutability in std-use of with_metadata_of
Andreas Molzer [Fri, 21 Oct 2022 12:34:16 +0000 (14:34 +0200)]
Reduce mutability in std-use of with_metadata_of

20 months agoArgument type for mutable with_metadata_of (#75091)
Andreas Molzer [Fri, 21 Oct 2022 12:05:45 +0000 (14:05 +0200)]
Argument type for mutable with_metadata_of (#75091)

The method takes two pointer arguments: one `self` supplying the pointer
value, and a second pointer supplying the metadata.

The new parameter type more clearly reflects the actual requirements.
The provenance of the metadata parameter is disregarded completely.
Using a mutable pointer in the call site can be coerced to a const
pointer while the reverse is not true.

An example of the current use:

```rust
// Manually taking an unsized object from a `ManuallyDrop` into another allocation.
let val: &core::mem::ManuallyDrop<T> = …;

let ptr = val as *const _ as *mut T;
let ptr = uninit.as_ptr().with_metadata_of(ptr);
```

This could then instead be simplified to:

```rust
// Manually taking an unsized object from a `ManuallyDrop` into another allocation.
let val: &core::mem::ManuallyDrop<T> = …;

let ptr = uninit.as_ptr().with_metadata_of(&**val);
```

20 months agoAuto merge of #103344 - Dylan-DPC:rollup-d1rpfvx, r=Dylan-DPC
bors [Fri, 21 Oct 2022 12:41:09 +0000 (12:41 +0000)]
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

20 months agoRollup merge of #103321 - notriddle:notriddle/source-page-top-bar-layout, r=Guillaume...
Dylan DPC [Fri, 21 Oct 2022 12:00:00 +0000 (17:30 +0530)]
Rollup merge of #103321 - notriddle:notriddle/source-page-top-bar-layout, r=GuillaumeGomez

rustdoc: improve appearance of source page navigation bar

This commit changes things so that the search bar is exactly centered between the top of the page and the top of the source code content area.

Preview: https://notriddle.com/notriddle-rustdoc-demos/source-page-header/src/std/lib.rs.html

## Before

![image](https://user-images.githubusercontent.com/1593513/197053420-02a64627-48ed-4bb6-9363-a1863d47b092.png)

## After

![image](https://user-images.githubusercontent.com/1593513/197053355-bd6149f9-0f5c-47da-aeb7-590b5eecb5da.png)

20 months agoRollup merge of #103260 - cuviper:needs-asm-support, r=fee1-dead
Dylan DPC [Fri, 21 Oct 2022 11:59:59 +0000 (17:29 +0530)]
Rollup merge of #103260 - cuviper:needs-asm-support, r=fee1-dead

Fixup a few tests needing asm support

20 months agoRollup merge of #103111 - cjgillot:shadow-label, r=estebank
Dylan DPC [Fri, 21 Oct 2022 11:59:59 +0000 (17:29 +0530)]
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`

20 months agoRollup merge of #103051 - davidtwco:translation-tidying-up, r=compiler-errors
Dylan DPC [Fri, 21 Oct 2022 11:59:58 +0000 (17:29 +0530)]
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

20 months agoRollup merge of #102922 - kper:bugfix/102902-filtering-json, r=oli-obk
Dylan DPC [Fri, 21 Oct 2022 11:59:58 +0000 (17:29 +0530)]
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.

20 months agoRollup merge of #102287 - compiler-errors:unused-must-use-also-supertrait, r=fee1...
Dylan DPC [Fri, 21 Oct 2022 11:59:57 +0000 (17:29 +0530)]
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.

20 months agoadd test for issue 97607
Rageking8 [Fri, 21 Oct 2022 10:20:11 +0000 (18:20 +0800)]
add test for issue 97607

20 months agoWinConsole::new is not actually fallible
Ralf Jung [Fri, 21 Oct 2022 10:18:33 +0000 (12:18 +0200)]
WinConsole::new is not actually fallible

20 months agofix some typos
Rageking8 [Fri, 21 Oct 2022 09:40:36 +0000 (17:40 +0800)]
fix some typos

20 months agoAuto merge of #103310 - lcnr:rustc_hir_typeck, r=compiler-errors
bors [Fri, 21 Oct 2022 09:52:18 +0000 (09:52 +0000)]
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`

20 months agoIntroduce deduced parameter attributes, and use them for deducing `readonly` on
Patrick Walton [Tue, 18 Oct 2022 02:42:15 +0000 (19:42 -0700)]
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

20 months agoreplaced wrong test with the correct mcve
Sarthak Singh [Fri, 21 Oct 2022 07:38:30 +0000 (13:08 +0530)]
replaced wrong test with the correct mcve

20 months agoAuto merge of #103308 - sunfishcode:sunfishcode/wasi-io-safety, r=joshtriplett
bors [Fri, 21 Oct 2022 04:05:02 +0000 (04:05 +0000)]
Auto merge of #103308 - sunfishcode:sunfishcode/wasi-io-safety, r=joshtriplett

Mark `std::os::wasi::io::AsFd` etc. as stable.

io_safety was stabilized in Rust 1.63, so mark the io_safety exports in `std::os::wasi::io` as stable.

Fixes #103306.

20 months agoAdd a missing precondition check
Ben Kimock [Fri, 21 Oct 2022 00:40:35 +0000 (20:40 -0400)]
Add a missing precondition check

20 months agoDo not suggest trivially false const predicates
Michael Goulet [Thu, 20 Oct 2022 23:24:45 +0000 (23:24 +0000)]
Do not suggest trivially false const predicates

20 months agoAdd UI regression test when querying visibility of generic parameter
Guillaume Gomez [Tue, 13 Sep 2022 14:56:18 +0000 (16:56 +0200)]
Add UI regression test when querying visibility of generic parameter

20 months agoAdd ui test to ensure attributes generated from macros are kept as expected
Guillaume Gomez [Tue, 13 Sep 2022 13:30:16 +0000 (15:30 +0200)]
Add ui test to ensure attributes generated from macros are kept as expected

20 months agoAdd code comments and documentation
Guillaume Gomez [Tue, 13 Sep 2022 13:29:25 +0000 (15:29 +0200)]
Add code comments and documentation

20 months agoRemove doc comments only for private items or some specific doc comments
Guillaume Gomez [Tue, 13 Sep 2022 13:27:59 +0000 (15:27 +0200)]
Remove doc comments only for private items or some specific doc comments

20 months agoAdd missing @local_only on attributes
Guillaume Gomez [Tue, 13 Sep 2022 13:23:54 +0000 (15:23 +0200)]
Add missing @local_only on attributes

20 months agoChange process spawning to inherit the parent's signal mask by default
Rain [Fri, 23 Sep 2022 05:48:14 +0000 (22:48 -0700)]
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.

20 months agoupdate doc links
lcnr [Thu, 20 Oct 2022 21:47:49 +0000 (23:47 +0200)]
update doc links

20 months agoMake the whole `std::os::wasi::io` module stable.
Dan Gohman [Thu, 20 Oct 2022 21:31:11 +0000 (14:31 -0700)]
Make the whole `std::os::wasi::io` module stable.

20 months agoAuto merge of #103322 - matthiaskrgr:rollup-m9zgpft, r=matthiaskrgr
bors [Thu, 20 Oct 2022 21:08:28 +0000 (21:08 +0000)]
Auto merge of #103322 - matthiaskrgr:rollup-m9zgpft, r=matthiaskrgr

Rollup of 9 pull requests

Successful merges:

 - #103221 (Fix `SelfVisitor::is_self_ty` ICE)
 - #103230 (Clarify startup)
 - #103281 (Adjust `transmute{,_copy}` to be clearer about which of `T` and `U` is input vs output)
 - #103288 (Fixed docs typo in `library/std/src/time.rs`)
 - #103296 (+/- shortcut now only expand/collapse, not both)
 - #103297 (fix typo)
 - #103313 (Don't label `src/test` tests as `A-testsuite`)
 - #103315 (interpret: remove an incorrect assertion)
 - #103319 (Improve "`~const` is not allowed here" message)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup