Commit Graph

242691 Commits

Author SHA1 Message Date
Esteban Küber
0487500776 Provide better suggestions when encountering a bare trait as a type
Add the following suggestions:

```
error[E0782]: trait objects must include the `dyn` keyword
  --> $DIR/not-on-bare-trait-2021.rs:11:11
   |
LL | fn bar(x: Foo) -> Foo {
   |           ^^^
   |
help: use a generic type parameter, constrained by the trait `Foo`
   |
LL | fn bar<T: Foo>(x: T) -> Foo {
   |       ++++++++    ~
help: you can also use `impl Foo`, but users won't be able to specify the type paramer when calling the `fn`, having to rely exclusively on type inference
   |
LL | fn bar(x: impl Foo) -> Foo {
   |           ++++
help: alternatively, use a trait object to accept any type that implements `Foo`, accessing its methods at runtime using dynamic dispatch
   |
LL | fn bar(x: &dyn Foo) -> Foo {
   |           ++++

error[E0782]: trait objects must include the `dyn` keyword
  --> $DIR/not-on-bare-trait-2021.rs:11:19
   |
LL | fn bar(x: Foo) -> Foo {
   |                   ^^^
   |
help: use `impl Foo` to return an opaque type, as long as you return a single underlying type
   |
LL | fn bar(x: Foo) -> impl Foo {
   |                   ++++
help: alternatively, you can return an owned trait object
   |
LL | fn bar(x: Foo) -> Box<dyn Foo> {
   |                   +++++++    +
```
2024-01-03 18:59:42 +00:00
bors
139fb22146 Auto merge of #119549 - fmease:rollup-jxvbfes, r=fmease
Rollup of 21 pull requests

Successful merges:

 - #119086 (Query panic!() to useful diagnostic)
 - #119239 (Remove unnecessary arm in `check_expr_yield`)
 - #119298 (suppress change-tracker warnings in CI containers)
 - #119319 (Document that File does not buffer reads/writes)
 - #119434 (rc: Take *const T in is_dangling)
 - #119444 (Rename `TyCtxt::is_closure` to `TyCtxt::is_closure_or_coroutine`)
 - #119474 (Update tracking issue of naked_functions)
 - #119476 (Pretty-print always-const trait predicates correctly)
 - #119477 (rustdoc ui: adjust tooltip z-index to be above sidebar)
 - #119479 (Remove two unused feature gates from rustc_query_impl)
 - #119487 (Minor improvements in comment on `freshen.rs`)
 - #119492 (Update books)
 - #119494 (Deny defaults for higher-ranked generic parameters)
 - #119498 (Update deadlinks of `strict_provenance` lints)
 - #119505 (Don't synthesize host effect params for trait associated functions marked const)
 - #119510 (Report I/O errors from rmeta encoding with emit_fatal)
 - #119512 (Mark myself as back from leave)
 - #119514 (coverage: Avoid a query stability hazard in `function_coverage_map`)
 - #119523 (llvm: Allow `noundef` in codegen tests)
 - #119534 (Update `thread_local` examples to use `local_key_cell_methods`)
 - #119544 (Fix: Properly set vendor in i686-win7-windows-msvc target)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-01-03 18:37:41 +00:00
bohan
862368db9f fallback visibility for unexpected trait item 2024-01-04 02:02:57 +08:00
Daniel Paoliello
bc3b7c9930 Enable address sanitizer for MSVC targets using INFERASANLIBS linker flag 2024-01-03 10:00:15 -08:00
bors
1a47f5b448 Auto merge of #119485 - weihanglo:update-cargo, r=weihanglo
Update cargo

11 commits in ac6bbb33293d8d424c17ecdb42af3aac25fb7295..add15366eaf3f3eb84717d3b8b71902ca36a7c84
2023-12-26 23:22:08 +0000 to 2024-01-02 03:24:42 +0000
- chore(deps): update gix (rust-lang/cargo#13230)
- chore(deps): update alpine docker tag to v3.19 (rust-lang/cargo#13228)
- rustfix: Support inserting new lines. (rust-lang/cargo#13226)
- Fix fix::fix_in_dependency to not rely on rustc (rust-lang/cargo#13220)
- cleanup: Remove error-format special-case in `cargo fix` (rust-lang/cargo#13224)
- `cargo fix`: always inherit the jobserver (rust-lang/cargo#13225)
- Bump cargo-credential to 0.4.3 (rust-lang/cargo#13221)
- `cargo add` - fix for adding features from repository with multiple packages. (rust-lang/cargo#13213)
- Remove repetitive words (rust-lang/cargo#13216)
- Add cargo:rustc-cdylib-link-arg into RESERVED_PREFIXES list (rust-lang/cargo#13212)
- chore(doc): doc for custom subcommands look up. (rust-lang/cargo#13203)
2024-01-03 16:39:17 +00:00
León Orell Valerian Liehr
9b2a44adc2
Rollup merge of #119544 - roblabla:new-win7-targets, r=Nilstrieb
Fix: Properly set vendor in i686-win7-windows-msvc target

In #118150 , setting the `vendor` field of the `i686-win7-windows-msvc` target was forgotten, preventing us from easily checking the target using `cfg(target_vendor)`.

With this PR, we set the target vendor to "win7".
2024-01-03 16:08:33 +01:00
León Orell Valerian Liehr
a79fccc288
Rollup merge of #119534 - tgross35:thread-local-example-updates, r=JohnTitor
Update `thread_local` examples to use `local_key_cell_methods`

`local_key_cell_methods` has been stable for a while and provides a much less clunky way to interface with thread-local

Additionaly add context to the documentation about why types with interior mutability are needed.

r? libs
2024-01-03 16:08:33 +01:00
León Orell Valerian Liehr
fcec407f4a
Rollup merge of #119523 - maurer:fix-sparc-llvm-18, r=nikic
llvm: Allow `noundef` in codegen tests

LLVM 18 will automatically infer `noundef` in some situations. Adjust codegen tests to accept this.

See llvm/llvm-project#76553 for why `noundef` is being generated now.

``@rustbot`` label:+llvm-main
2024-01-03 16:08:32 +01:00
León Orell Valerian Liehr
ea39f19fab
Rollup merge of #119514 - Zalathar:query-stability, r=wesleywiser
coverage: Avoid a query stability hazard in `function_coverage_map`

When #118865 started enforcing the `rustc::potential_query_instability` lint in `rustc_codegen_llvm`, it added an exemption for this site, arguing that the entries are only used to create a list of filenames that is later sorted.

However, the list of entries also gets traversed when creating the function coverage records in LLVM IR, which may be sensitive to hash-based ordering.

This patch therefore changes `function_coverage_map` to use `FxIndexMap`, which should avoid hash-based instability by iterating in insertion order.

cc ``@Enselic``
2024-01-03 16:08:32 +01:00
León Orell Valerian Liehr
c2debecf98
Rollup merge of #119512 - oli-obk:unleave, r=oli-obk
Mark myself as back from leave
2024-01-03 16:08:31 +01:00
León Orell Valerian Liehr
a34754e7d5
Rollup merge of #119510 - saethlin:fatal-io-errors, r=WaffleLapkin,Nilstrieb
Report I/O errors from rmeta encoding with emit_fatal

https://github.com/rust-lang/rust/issues/119456 reminded me that I never did systematic testing to provoke the out-of-disk ICEs so I grepped through a recent crater run (https://github.com/rust-lang/rust/pull/119440#issuecomment-1873393963) for more out-of-disk ICEs on current master and yep there's 2 in there.

So I finally cooked up a way to provoke for these crashes. I wrote a little `cdylib` crate that has a `#[no_mangle] pub extern "C" fn write` which occasionally reports `ENOSPC`, and prints a backtrace when it does.
<details><summary><strong>code for the dylib</strong></summary>
<p>

```rust
// cargo add libc rand backtrace
use rand::Rng;

#[no_mangle]
pub extern "C" fn write(
    fd: libc::c_int,
    buf: *const libc::c_void,
    count: libc::size_t,
) -> libc::ssize_t {
    if fd > 2 && rand::thread_rng().gen::<u8>() == 0 {
        let mut count = 0;
        backtrace::trace(|frame| {
            backtrace::resolve_frame(frame, |symbol| {
                if let Some(name) = symbol.name() {
                    if count > 3 {
                        eprintln!("{}", name);
                    }
                }
                count += 1;
            });
            true
        });

        unsafe {
            *libc::__errno_location() = libc::ENOSPC;
        }
        return -1;
    } else {
        unsafe {
            let res =
                libc::syscall(libc::SYS_write, fd as usize, buf as usize, count as usize) as isize;
            if res < 0 {
                *libc::__errno_location() = -res as i32;
                -1
            } else {
                res
            }
        }
    }
}
```

</p>
</details>

Then `LD_PRELOAD` that dylib and repeatedly build a big project until it ICEs, such as with this:
```bash
while true; do
    cargo clean
    LD_PRELOAD=/home/ben/evil/target/release/libevil.so cargo +stage1 check 2> errors
    if grep "thread 'rustc' panicked" errors; then
        break
    fi
done
```
My "big project" for testing was an otherwise-empty project with `cargo add axum`.

Before this PR, the above procedure finds a crash in between 1 and 15 minutes. With this PR, I have not found a crash in 30 minutes, and I'll be leaving this to run overnight (starting now). (A night has now passed, no crashes were found)

I believe the problem is that even though since https://github.com/rust-lang/rust/pull/117301 we correctly check `FileEncoder` for errors on all paths, we use `emit_err`, so there is a window of time between the call to `emit_err` and the full error reporting where rustc believes it has emitted a valid rmeta file and will permit Cargo to launch a build for a dependent crate. Changing these calls to `emit_fatal` closes that window.

I think there are a number of other cases where `emit_err` has been used instead of the more-correct `emit_fatal` such as e51e98dde6/compiler/rustc_codegen_ssa/src/back/write.rs (L542) but unlike rmeta encoding I am not aware of those cases of those causing problems.

r? ``@WaffleLapkin``
2024-01-03 16:08:31 +01:00
León Orell Valerian Liehr
8bce6fc35e
Rollup merge of #119505 - fmease:no-host-param-for-trait-fns, r=fee1-dead
Don't synthesize host effect params for trait associated functions marked const

Fixes #113378.

r? fee1-dead or compiler
2024-01-03 16:08:30 +01:00
León Orell Valerian Liehr
39c2e6db3f
Rollup merge of #119498 - ShE3py:provenance-lints-doc, r=Nilstrieb
Update deadlinks of `strict_provenance` lints

Some hyperlinks on the following page redirect to 404 pages:
<https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html#explanation-5>

---

```@rustbot``` label +A-docs
2024-01-03 16:08:30 +01:00
León Orell Valerian Liehr
b5618bc222
Rollup merge of #119494 - fmease:deny-hr-param-defaults, r=compiler-errors
Deny defaults for higher-ranked generic parameters

Fixes #119489 (incl. https://github.com/rust-lang/rust/issues/119489#issuecomment-1873399208).
Partially reverts #119042.

cc ```@bvanjoi```
r? ```@compiler-errors``` or compiler
2024-01-03 16:08:29 +01:00
León Orell Valerian Liehr
14226154c4
Rollup merge of #119492 - rustbot:docs-update, r=ehuss
Update books

## rust-lang/reference

1 commits in f9f5b5babd95515e7028c32d6ca4d9790f64c146..3565c7978cfc9662f5963b135690ff9cbbfa0318
2023-12-29 21:01:19 UTC to 2023-12-29 21:01:19 UTC

- Use proper footnote for number literals `_` separator note (rust-lang/reference#1444)

## rust-lang/rust-by-example

1 commits in 4c2b24ff9d9cf19f2fcff799a3a49b9a2c50ae8e..c0be6299e52e4164c30ba6f41bd0ad0aaee64972
2023-12-21 15:22:11 UTC to 2023-12-21 15:22:11 UTC

- point to raw indentifiers, talking about fields (rust-lang/rust-by-example#1789)

## rust-lang/rustc-dev-guide

5 commits in 0610665a8687b1b0aa037917a1598b9f2a21e3ef..d13e85152a977cd0bcaf583cf5f49e86225697de
2023-12-30 09:58:25 UTC to 2023-12-19 10:02:34 UTC

- Prominently mention `profiler = true` on the coverage page (rust-lang/rustc-dev-guide#1844)
- Add a description of `unpretty=hir` to the HIR docs (rust-lang/rustc-dev-guide#1842)
- Fix typo in unsize docs (rust-lang/rustc-dev-guide#1843)
- Suggest `gcc_multi` to make `mir_opts` run on nixos (rust-lang/rustc-dev-guide#1841)
- bootstrapping: Clarify that stage0 std code is not executed to produce stage1 compiler (rust-lang/rustc-dev-guide#1840)
2024-01-03 16:08:29 +01:00
León Orell Valerian Liehr
5d6e35b811
Rollup merge of #119487 - gurry:improve-freshner-comment, r=Nilstrieb
Minor improvements in comment on `freshen.rs`

- Removed a stray "if"
- Changed a numeric "2" to "two" because it reads better
2024-01-03 16:08:28 +01:00
León Orell Valerian Liehr
394aaeed05
Rollup merge of #119479 - bjorn3:remove_unused_feature_gates, r=compiler-errors
Remove two unused feature gates from rustc_query_impl
2024-01-03 16:08:28 +01:00
León Orell Valerian Liehr
493792b37b
Rollup merge of #119477 - lukas-code:tooltip-z-index, r=notriddle
rustdoc ui: adjust tooltip z-index to be above sidebar

In https://github.com/rust-lang/rust/pull/115660 the sidebar's z-index was changed to 100. This PR changes the tooltip's z-index to 101 to be above the sidebar again.

Fixes [after beta-backport] https://github.com/rust-lang/rust/issues/119472.
2024-01-03 16:08:27 +01:00
León Orell Valerian Liehr
b41b16971c
Rollup merge of #119476 - fmease:pp-always-const-trait-preds, r=compiler-errors
Pretty-print always-const trait predicates correctly

Follow-up to #119099.

r? fee1-dead
2024-01-03 16:08:27 +01:00
León Orell Valerian Liehr
699a70bdbd
Rollup merge of #119474 - nbdd0121:naked, r=Nilstrieb
Update tracking issue of naked_functions

The original tracking issue #32408 was superseded by the new one #90957 (constrainted naked functions) and therefore is closed.
2024-01-03 16:08:26 +01:00
León Orell Valerian Liehr
3053ced813
Rollup merge of #119444 - compiler-errors:closure-or-coroutine, r=oli-obk
Rename `TyCtxt::is_closure` to `TyCtxt::is_closure_or_coroutine`

This function has always been used to test whether the def-id was a closure **or** coroutine: https://github.com/rust-lang/rust/pull/118311/files#diff-69ebec59f7d38331dd1be84ede7957977dcaa39e30ed2869b04aa8c99b2079ccR552 -- the name is just confusing because it disagrees with other fns named `is_closure`, like `Ty::is_closure`.

So let's rename it.
2024-01-03 16:08:26 +01:00
León Orell Valerian Liehr
34ef194859
Rollup merge of #119434 - taiki-e:rc-is-dangling, r=Mark-Simulacrum
rc: Take *const T in is_dangling

It is not important which one is used since `is_dangling` does not access memory, but `*const` removes the needs of `*const T` -> `*mut T` casts in `from_raw_in`.
2024-01-03 16:08:25 +01:00
León Orell Valerian Liehr
4e265d9fe0
Rollup merge of #119319 - chfogelman:buffered-file-doc, r=the8472
Document that File does not buffer reads/writes

...and refer to `BufReader`/`BufWriter`.

This is a common source of efficiency issues in Rust programs written naively. Including this information with the `File` docs, and adding a link to the wrapper types, will help discoverability.
2024-01-03 16:08:25 +01:00
León Orell Valerian Liehr
907922b472
Rollup merge of #119298 - onur-ozkan:silence-change-tracker-warning-for-ci, r=Mark-Simulacrum
suppress change-tracker warnings in CI containers

Fixes #119296
2024-01-03 16:08:24 +01:00
León Orell Valerian Liehr
893b6f6538
Rollup merge of #119239 - compiler-errors:yield-coercion, r=davidtwco
Remove unnecessary arm in `check_expr_yield`

We always set up the `resume_yield_tys` for async blocks and fns, so this arm was unreachable.
2024-01-03 16:08:24 +01:00
León Orell Valerian Liehr
093bd0888a
Rollup merge of #119086 - RossSmyth:query_panics, r=compiler-errors
Query panic!() to useful diagnostic

Changes some more ICEs from bare panic!()s

Adds an `expect_job()` helper method as that is a moral equivalent of what was happening at the uses.

re:#118955
2024-01-03 16:08:23 +01:00
Ross Smyth
0d421c5ace Add useful panic messages if queries fail to start 2024-01-03 09:51:58 -05:00
Lieselotte
4e0baddbbf
Recover parentheses in range patterns
Co-authored-by: León Orell Valerian Liehr <me@fmease.dev>
2024-01-03 15:27:58 +01:00
bors
2e79c8deb0 Auto merge of #119546 - jdno:temporarily-disable-m1-runners, r=Kobzol
Temporarily disable M1 runners on GitHub Actions

This commit temporarily reverts the addition of M1 runners on GitHub Actions to work around a billing issue related to their beta.

The runners for `dist-aarch64-apple` were originally changed in 821b03d767, and the `aarch64-apple` job was added in 6909992501.
2024-01-03 14:27:31 +00:00
Jan David
0f9844d10c
Temporarily disable M1 runners on GitHub Actions
This commit temporarily reverts the addition of M1 runners on GitHub
Actions to work around a billing issue related to their beta. It also
removes the `aarch64-apple` job, which was only added after the addition
of M1 runners. Since it has never been tested on the prior hardware, we
are skipping the tests to reduce the risk of build failures.
2024-01-03 15:20:03 +01:00
roblabla
d9d23fa68d Fix: Properly set vendor in i686-win7-windows-msvc target 2024-01-03 14:09:31 +01:00
Laurențiu Nicola
b91d1c0cf9 Add proc_macro_def_site to r-a ALLOW_FEATURES 2024-01-03 11:37:06 +02:00
Laurențiu Nicola
a8f2484733 Allow unexpected_cfgs in proc-macro-test imp 2024-01-03 11:36:05 +02:00
Laurențiu Nicola
f0108b9d5e Merge commit '426d2842c1f0e5cc5e34bb37c7ac3ee0945f9746' into sync-from-ra2 2024-01-03 11:35:07 +02:00
Taiki Endo
ee41651d2f Support reg_addr register class in s390x inline assembly 2024-01-03 18:00:37 +09:00
Nicholas Nethercote
b4a6239984 Fix forward! so it doesn't require trailing commas in some cases. 2024-01-03 19:40:43 +11:00
Nicholas Nethercote
caefa55347 Fix up forward! decls.
- Move comments onto corresponding `Diagnostic` methods.
- Make formatting more consistent.
2024-01-03 19:40:43 +11:00
Nicholas Nethercote
096b844a2b Remove forward for downgrade_to_delayed_bug.
It's not used, and doesn't quite fit the general pattern.

Also, `Diagnostic::downgrade_to_delayed_bug` doesn't need to return
`&mut Self` for the same reason.
2024-01-03 19:40:43 +11:00
Nicholas Nethercote
5fe5d5da4e Remove lots of rustc_errors:: qualifiers in lints.rs. 2024-01-03 19:40:43 +11:00
Nicholas Nethercote
505c1371d0 Rename some Diagnostic setters.
`Diagnostic` has 40 methods that return `&mut Self` and could be
considered setters. Four of them have a `set_` prefix. This doesn't seem
necessary for a type that implements the builder pattern. This commit
removes the `set_` prefixes on those four methods.
2024-01-03 19:40:20 +11:00
León Orell Valerian Liehr
695a02e0d8
Don't synthesize host effect args inside trait object types 2024-01-03 09:25:27 +01:00
Trevor Gross
6f49080fa8 Update thread_local examples to use local_key_cell_methods
`local_key_cell_methods` has been stable for a while and provides a much less
clunky way to interface with thread-local variables.

Additionaly add context to the documentation about why types with interior
mutability are needed.
2024-01-02 22:24:26 -06:00
George Bateman
f0c0a498b8
Update after rebase 2024-01-02 23:13:08 +00:00
George Bateman
09bb07e38f
Make offset_of field parsing use metavariable which handles any spacing 2024-01-02 22:18:35 +00:00
Jake Goulding
26194a3ffa Rename unused_tuple_struct_fields in rustfmt
Otherwise tests fail due to unknown lint and dead code warnings.
2024-01-02 15:34:37 -05:00
Jake Goulding
10f4023192 Allow unused tuple struct fields in Miri tests
Otherwise the newly-detected dead code causes new output
2024-01-02 15:34:37 -05:00
Jake Goulding
93f553049b Remove #[allow(unused_tuple_struct_fields)] from Clippy tests 2024-01-02 15:34:37 -05:00
Jake Goulding
53eca9fa87 Adjust compiler tests for unused_tuple_struct_fields -> dead_code 2024-01-02 15:34:37 -05:00
Jake Goulding
5772818dc8 Adjust library tests for unused_tuple_struct_fields -> dead_code 2024-01-02 15:34:37 -05:00
Jake Goulding
9fcf9c1410 Merge unused_tuple_struct_fields into dead_code
This implicitly upgrades the lint from `allow` to `warn` and places it
into the `unused` lint group.
2024-01-02 15:34:37 -05:00