Commit Graph

32931 Commits

Author SHA1 Message Date
bors 2bf78d12d3 Auto merge of #119673 - petrochenkov:dialoc5, r=compiler-errors,cjgillot
macro_rules: Preserve all metavariable spans in a global side table

This PR preserves spans of `tt` metavariables used to pass tokens to declarative macros.
Such metavariable spans can then be used in span combination operations like `Span::to` to improve all kinds of diagnostics.

Spans of non-`tt` metavariables are currently kept in nonterminal tokens, but the long term plan is remove all nonterminal tokens from rustc parser and rely on the proc macro model with invisible delimiters (#114647, #67062).
In particular, `NtIdent` nonterminal (corresponding to `ident` metavariables) becomes easy to remove when this PR lands (#119412 does it).

The metavariable spans are kept in a global side table keyed by `Span`s of original tokens.
The alternative to the side table is keeping them in `SpanData` instead, but the performance regressions would be large because any spans from tokens passed to declarative macros would stop being inline and would work through span interner instead, and the penalty would be paid even if we never use the metavar span for the given original span.
(But also see the comment on `fn maybe_use_metavar_location` describing the map collision issues with the side table approach.)

There are also other alternatives - keeping the metavar span in `Token` or `TokenTree`, but associating it with `Span` itsel is the most natural choice because metavar spans are used in span combining operations, and those operations are not necessarily tied to tokens.
2024-02-18 20:51:16 +00:00
bors 8a497723e3 Auto merge of #121271 - matthiaskrgr:rollup-56ru17w, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #118569 (Move `OsStr::slice_encoded_bytes` validation to platform modules)
 - #121067 (make "invalid fragment specifier" translatable)
 - #121224 (Remove unnecessary unit binding)
 - #121247 (Add help to `hir_analysis_unrecognized_intrinsic_function`)
 - #121257 (remove extraneous text from example config)
 - #121260 (Remove const_prop.rs)
 - #121266 (Add uncontroversial syscall doc aliases to std docs)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-02-18 18:52:11 +00:00
Matthias Krüger d35c4f9cdb
Rollup merge of #121260 - gurry:constprop-lint-cleanup, r=oli-obk
Remove const_prop.rs

Removed const_prop.rs and moved its contents to const_prop_lint.rs and dataflow_const_prop.rs where they are used.

const_prop.rs does not actually do any const propagation any more. After #116012 all it contains is code that is used by const_prop_lint.rs and one macro that is used by dataflow_const_prop.rs. So it made sense to just move it to those two places and remove this file.
2024-02-18 18:54:34 +01:00
Matthias Krüger 57d9523a95
Rollup merge of #121247 - scottmcm:intrinsic-reminder, r=petrochenkov
Add help to `hir_analysis_unrecognized_intrinsic_function`

To help remind forgetful people like me what step they forgot.

(If this just ICE'd, https://github.com/rust-lang/compiler-team/issues/620 style, the stack trace would point me here, but since there's a "nice" error that information is lost.)
2024-02-18 18:54:33 +01:00
Matthias Krüger ddf6c6dbc6
Rollup merge of #121067 - tshepang:make-expand-translatable, r=fmease
make "invalid fragment specifier" translatable
2024-02-18 18:54:32 +01:00
bors c9c83cca51 Auto merge of #121265 - klensy:bump-18-02-24, r=Mark-Simulacrum
bump some deps

First commit dedupes darling* crates and remove one more syn 1.* dep
Second one bumps windows crate to 0.52
2024-02-18 16:54:15 +00:00
bors 8b21296b5d Auto merge of #117772 - surechen:for_117448, r=petrochenkov
Tracking import use types for more accurate redundant import checking

fixes #117448

By tracking import use types to check whether it is scope uses or the other situations like module-relative uses,  we can do more accurate redundant import checking.

For example unnecessary imports in std::prelude that can be eliminated:

```rust
use std::option::Option::Some;//~ WARNING the item `Some` is imported redundantly
use std::option::Option::None; //~ WARNING the item `None` is imported redundantly
```
2024-02-18 13:56:07 +00:00
klensy 35fe26757a windows bump to 0.52 2024-02-18 16:02:16 +03:00
Gurinder Singh 50e316bdc0 Remove const_prop.rs
and move its content to const_prop_lint.rs and dataflow_const_prop.rs where it is used
2024-02-18 15:31:44 +05:30
surechen a61126cef6 By tracking import use types to check whether it is scope uses or the other situations like module-relative uses, we can do more accurate redundant import checking.
fixes #117448

For example unnecessary imports in std::prelude that can be eliminated:

```rust
use std::option::Option::Some;//~ WARNING the item `Some` is imported redundantly
use std::option::Option::None; //~ WARNING the item `None` is imported redundantly
```
2024-02-18 16:38:11 +08:00
Vadim Petrochenkov 9f8d05f29f macro_rules: Preserve all metavariable spans in a global side table 2024-02-18 11:19:24 +03:00
bors bcb3545164 Auto merge of #121034 - obeis:improve-static-mut-ref, r=RalfJung
Improve wording of `static_mut_ref`

Close #120964
2024-02-18 08:00:34 +00:00
Scott McMurray 5793f82030 Add help to `hir_analysis_unrecognized_intrinsic_function`
To help remind forgetful people like me what step they forgot.
2024-02-17 23:16:30 -08:00
bors 23a3d777c8 Auto merge of #121252 - fmease:rollup-x7zogl8, r=fmease
Rollup of 7 pull requests

Successful merges:

 - #120526 (rustdoc: Correctly handle long crate names on mobile)
 - #121100 (Detect when method call on argument could be removed to fulfill failed trait bound)
 - #121160 (rustdoc: fix and refactor HTML rendering a bit)
 - #121198 (Add more checks for `unnamed_fields` during HIR analysis)
 - #121218 (Fix missing trait impls for type in rustc docs)
 - #121221 (AstConv: Refactor lowering of associated item bindings a bit)
 - #121237 (Use better heuristic for printing Cargo specific diagnostics)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-02-18 06:02:16 +00:00
León Orell Valerian Liehr 5628786484
Rollup merge of #121237 - Urgau:better-cargo-heuristic, r=compiler-errors
Use better heuristic for printing Cargo specific diagnostics

It was [reported](https://github.com/rust-lang/rust/issues/82450#issuecomment-1948574677) in the check-cfg call for testing that the Rust for Linux project is setting the `CARGO` env without compiling with it, which is an issue since we are using the `CARGO` env as a proxy for "was launched from Cargo".

This PR switch to the `CARGO_CRATE_NAME` [Cargo env](https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-crates), which shouldn't collide (as much) with other build systems. I also took the opportunity to consolidate all the checks under the same function.
2024-02-18 05:10:18 +01:00
León Orell Valerian Liehr 9811358f59
Rollup merge of #121221 - fmease:refactor-astconv-assoc-item-bindings, r=compiler-errors
AstConv: Refactor lowering of associated item bindings a bit

Split off from #119385 as discussed, namely the first two commits (modulo one `FIXME` getting turned into a `NOTE`).

The second commit removes `astconv::ConvertedBinding{,Kind}` in favor of `hir::TypeBinding{,Kind}`. The former was a — in my opinion — super useless intermediary. As you can tell from the diff, its removal shaves off some code. Furthermore, yeeting it will make it easier to implement the type resolution fixes in #119385.

Nothing in this PR should have any semantic effect.

r? `@compiler-errors`

<sub>**Addendum** as in #118668: What I call “associated item bindings” are commonly referred to as “type bindings” for historical reasons. Nowadays, “type bindings” include assoc type bindings, assoc const bindings and RTN (return type notation) which is why I prefer not to use this outdated term.</sub>
2024-02-18 05:10:18 +01:00
León Orell Valerian Liehr 68cf5372b3
Rollup merge of #121198 - clubby789:unnamed-fields-hir-checks, r=compiler-errors
Add more checks for `unnamed_fields` during HIR analysis

Fixes #121151

I also found that we don't prevent enums here so
```rs
#[repr(C)]
#[derive(Debug)]
enum A {
    #[default]
    B,
    C,
}

#[repr(C)]
#[derive(Debug)]
struct D {
    _: A,
}
```
leads to an ICE on an `self.is_struct() || self.is_union()` assertion, so fixed that too.
2024-02-18 05:10:17 +01:00
León Orell Valerian Liehr 6499eb5577
Rollup merge of #121100 - estebank:issue-71252, r=compiler-errors
Detect when method call on argument could be removed to fulfill failed trait bound

When encountering

```rust
struct Foo;
struct Bar;
impl From<Bar> for Foo {
    fn from(_: Bar) -> Self { Foo }
}
fn qux(_: impl From<Bar>) {}
fn main() {
    qux(Bar.into());
}
```

Suggest removing `.into()`:

```
error[E0283]: type annotations needed
 --> f100.rs:8:13
  |
8 |     qux(Bar.into());
  |     ---     ^^^^
  |     |
  |     required by a bound introduced by this call
  |
  = note: cannot satisfy `_: From<Bar>`
note: required by a bound in `qux`
 --> f100.rs:6:16
  |
6 | fn qux(_: impl From<Bar>) {}
  |                ^^^^^^^^^ required by this bound in `qux`
help: try using a fully qualified path to specify the expected types
  |
8 |     qux(<Bar as Into<T>>::into(Bar));
  |         +++++++++++++++++++++++   ~
help: consider removing this method call, as the receiver has type `Bar` and `Bar: From<Bar>` trivially holds
  |
8 -     qux(Bar.into());
8 +     qux(Bar);
  |
```

Fix #71252
2024-02-18 05:10:16 +01:00
bors d3df8ff851 Auto merge of #120780 - fmease:lta-in-impls, r=oli-obk
Properly deal with weak alias types as self types of impls

Fixes #114216.
Fixes #116100.

Not super happy about the two ad hoc “normalization” implementations for weak alias types:

1. In `inherent_impls`: The “peeling”, normalization to [“WHNF”][whnf]: Semantically that's exactly what we want (neither proper normalization nor shallow normalization would be correct here). Basically a weak alias type is “nominal” (well...^^) if the WHNF is nominal. [#97974](https://github.com/rust-lang/rust/pull/97974) followed the same approach.
2. In `constrained_generic_params`: Generic parameters are constrained by a weak alias type if the corresp. “normalized” type constrains them (where we only normalize *weak* alias types not arbitrary ones). Weak alias types are injective if the corresp. “normalized” type is injective.

Both have ad hoc overflow detection mechanisms.

**Coherence** is handled in #117164.

r? `@oli-obk` or types

[whnf]: https://en.wikipedia.org/wiki/Lambda_calculus_definition#Weak_head_normal_form
2024-02-18 03:58:56 +00:00
Obei Sideg 408eeae59d Improve wording of static_mut_ref
Rename `static_mut_ref` lint to `static_mut_refs`.
2024-02-18 06:01:40 +03:00
Matthias Krüger eafa74ab62
Rollup merge of #121231 - matthiaskrgr:cloone, r=compiler-errors
remove a couple of redundant clones
2024-02-17 18:47:43 +01:00
Matthias Krüger a78e4610d0
Rollup merge of #121210 - madsmtm:fix-target-abi-i386-apple-ios, r=workingjubilee
Fix `cfg(target_abi = "sim")` on `i386-apple-ios`

Since https://github.com/rust-lang/rust/issues/80970 is stabilizing, I went and had a look, and found that the result was wrong on `i386-apple-ios`.

r? rust-lang/macos
2024-02-17 18:47:42 +01:00
Matthias Krüger a387b71b0c
Rollup merge of #121209 - nnethercote:infallible-join_codegen, r=bjorn3
Make `CodegenBackend::join_codegen` infallible.

Because they all are, in practice.

r? ```@bjorn3```
2024-02-17 18:47:42 +01:00
Matthias Krüger df3712ce21
Rollup merge of #121193 - compiler-errors:coherence-fulfillment, r=lcnr
Use fulfillment in next trait solver coherence

Use fulfillment in the new trait solver's `impl_intersection_has_impossible_obligation` routine. This means that inference that falls out of processing other obligations can influence whether we can determine if an obligation is impossible to satisfy. See the committed test.

This should be completely sound, since evaluation and fulfillment both respect intercrate mode equally.

We run the risk of breaking coherence later if we were to change the rules of fulfillment and/or inference during coherence, but this is a problem which affects evaluation, as nested obligations from a trait goal are processed together and can influence each other in the same way.

r? lcnr
cc #114862

Also changed obligationctxt -> fulfillmentctxt because it feels kind of redundant to use an ocx here. I don't really care enough and can change it back if it really matters much.
2024-02-17 18:47:42 +01:00
Matthias Krüger 45d5773704
Rollup merge of #121085 - davidtwco:always-eager-diagnostics, r=nnethercote
errors: only eagerly translate subdiagnostics

Subdiagnostics don't need to be lazily translated, they can always be eagerly translated. Eager translation is slightly more complex as we need to have a `DiagCtxt` available to perform the translation, which involves slightly more threading of that context.

This slight increase in complexity should enable later simplifications - like passing `DiagCtxt` into `AddToDiagnostic` and moving Fluent messages into the diagnostic structs rather than having them in separate files (working on that was what led to this change).

r? ```@nnethercote```
2024-02-17 18:47:40 +01:00
Urgau d988d8f4ba Use better heuristic for printing Cargo specific diagnostics 2024-02-17 16:49:01 +01:00
clubby789 62b789fba4 Add more checks for `unnamed_field` during HIR analysis 2024-02-17 15:12:33 +00:00
Matthias Krüger 87b6f415f2 remove a couple of redundant clones 2024-02-17 12:46:18 +01:00
Guillaume Boisseau 936b666c4a
Rollup merge of #121192 - oli-obk:intrinsics2.0, r=WaffleLapkin
Give some intrinsics fallback bodies

cc #93145
2024-02-17 11:23:08 +01:00
Guillaume Boisseau c7701ba803
Rollup merge of #121135 - Zalathar:no-whole-body-span, r=wesleywiser
coverage: Discard spans that fill the entire function body

While debugging some other coverage changes, I discovered a frustrating inconsistency that occurs in functions containing closures, if they end with an implicit `()` return instead of an explicit trailing-expression.

This turns out to have been caused by the corresponding node in MIR having a span that covers the entire function body. When preparing coverage spans, any span that fills the whole body tends to cause more harm than good, so this PR detects and discards those spans.

(This isn't the first time whole-body spans have caused problems; we also eliminated some of them in #118525.)
2024-02-17 11:23:04 +01:00
Guillaume Boisseau 5ff9022306
Rollup merge of #121059 - compiler-errors:extension, r=davidtwco,Nilstrieb
Add and use a simple extension trait derive macro in the compiler

Adds `#[extension]` to `rustc_macros` for implementing an extension trait. This expands an impl (with an optional visibility) into two parallel trait + impl definitions.

before:
```rust
pub trait Extension {
  fn a();
}
impl Extension for () {
  fn a() {}
}
```

to:
```rust
#[extension]
pub impl Extension for () {
  fn a() {}
}
```

Opted to just implement it by hand because I couldn't figure if there was a "canonical" choice of extension trait macro in the ecosystem. It's really lightweight anyways, and can always be changed.

I'm interested in adding this because I'd like to later split up the large `TypeErrCtxtExt` traits into several different files. This should make it one step easier.
2024-02-17 11:23:04 +01:00
Guillaume Boisseau f70f13a1d3
Rollup merge of #120932 - RalfJung:mut-ptr-to-static, r=oli-obk
const_mut_refs: allow mutable pointers to statics

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

Writing this PR became a bit messy, see [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/146212-t-compiler.2Fconst-eval/topic/Statics.20pointing.20to.20interior.20mutable.20statics) for some of my journey.^^ Turns out there was a long-standing bug in our qualif logic that led to us incorrectly classifying certain places as "no interior mut" when they actually had interior mut. Due to that the `const_refs_to_cell` feature gate was required far less often than it otherwise would, e.g. in [this code](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=9e0c042c451b3d11d64dd6263679a164). Fixing this however would be a massive breaking change all over libcore and likely the wider ecosystem. So I also changed the const-checking logic to just not require the feature gate for the affected cases. While doing so I discovered a bunch of logic that is not explained and that I could not explain. However I think stabilizing some const-eval feature will make most of that logic inconsequential so I just added some FIXMEs and left it at that.

r? `@oli-obk`
2024-02-17 11:23:03 +01:00
Ralf Jung 340f8aac7e const_mut_refs: allow mutable refs to statics 2024-02-17 10:19:17 +01:00
León Orell Valerian Liehr fde4556785
Properly check constrainedness of gen params in the presence of weak alias types 2024-02-17 08:39:01 +01:00
León Orell Valerian Liehr 8677d64c72
Support weak alias types as self type of inherent impls 2024-02-17 08:38:59 +01:00
León Orell Valerian Liehr 38a2a65f0b
Remove astconv::ConvertedBinding 2024-02-17 08:20:05 +01:00
León Orell Valerian Liehr f62a695572
Update comments and variable names 2024-02-17 08:19:23 +01:00
Gurinder Singh 5010ca001c Enable `ConstPropLint` for promoteds
This fixes the issue wherein the lint didn't fire for promoteds
in the case of SHL/SHR operators in non-optimized builds
and all arithmetic operators in optimized builds
2024-02-17 10:44:46 +05:30
Mads Marquart d80198595c Fix comment 2024-02-17 01:17:43 +01:00
Mads Marquart dae22a598b Fix `cfg(target_abi = "sim")` on i386-apple-ios
i386-apple-ios is also a simulator target
2024-02-17 01:15:08 +01:00
Michael Goulet 228441dbd6 Use fulfillment in next trait solver coherence 2024-02-16 23:53:09 +00:00
Nicholas Nethercote ede99234c4 Make `CodegenBackend::join_codegen` infallible.
Because they all are, in practice.
2024-02-17 10:51:35 +11:00
Oli Scherer dd40a80102 Give the (`un`)`likely` intrinsics fallback bodies 2024-02-16 22:26:01 +00:00
Oli Scherer 6a671bdbf1 Give the `assume` intrinsic a fallback body 2024-02-16 22:24:50 +00:00
Tshepang Mbambo 3a917cdfcb make "invalid fragment specifier" translatable 2024-02-16 20:15:07 +02:00
Guillaume Gomez f82875e242
Rollup merge of #121181 - oli-obk:normalize_with_conflicting_impls, r=cjgillot
Fix an ICE in the recursion lint

fixes #121170

I looked into it, and there is no good path towards tainting mir_build (where the ICE happens), but using `try_normalize` in a lint seems generally better anyway
2024-02-16 17:08:14 +01:00
Guillaume Gomez 0c92146034
Rollup merge of #121179 - RalfJung:zst-mutable-refs, r=oli-obk
allow mutable references in const values when they point to no memory

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

The second commit is just some drive-by test suite cleanup.

r? `@oli-obk`
2024-02-16 17:08:13 +01:00
Guillaume Gomez f60576b3df
Rollup merge of #121137 - GuillaumeGomez:add-clippy-cfg, r=Urgau,Nilstrieb
Add clippy into the known `cfg` list

In clippy, we are removing the `feature = "cargo-clippy"` cfg to replace it with `clippy` in https://github.com/rust-lang/rust-clippy/pull/12292. But for it to work, we need to declare `clippy` as cfg. It makes it more coherent with other existing tools like rustdoc.

cc `@flip1995`
2024-02-16 17:08:13 +01:00
Guillaume Gomez 670bdbf808
Rollup merge of #121111 - trevyn:associated-type-suggestion, r=davidtwco
For E0038, suggest associated type if available

Closes #116434
2024-02-16 17:08:12 +01:00
Guillaume Gomez e5a743c4c2
Rollup merge of #121020 - oli-obk:diagnostics_ice, r=davidtwco
Avoid an ICE in diagnostics

fixes #121004

just a slice usage in diagnostics code. Sadly we can't yet bubble the `ErrorGuaranteed` from wf check to borrowck for these cases, as that causes cycle errors iirc
2024-02-16 17:08:12 +01:00