Commit Graph

37743 Commits

Author SHA1 Message Date
Maybe Lapkin f3c13bf280 Allow casting `*mut dyn T`->`*mut (dyn T + Send)` if `T` has `Send` super trait 2024-07-07 20:07:01 +02:00
Maybe Lapkin 7fd0c55a1a Fix conflicts after rebase
- r-l/r 126784
- r-l/r 127113
- r-l/miri 3562
2024-07-07 18:16:38 +02:00
Maybe Lapkin 54e11cf378 add an assertion that machine hook doesn't return NoCleanup 2024-07-07 18:16:38 +02:00
Maybe Waffle dd5a447b5a Do renames proposed by review 2024-07-07 18:16:38 +02:00
Maybe Waffle 236352024b make `StackPop` field names less confusing 2024-07-07 18:16:38 +02:00
Maybe Waffle cda6f0c25d doc fixups from review 2024-07-07 18:16:38 +02:00
Maybe Waffle 6d4995f4e6 add miri tests and a fixme 2024-07-07 18:16:38 +02:00
Maybe Waffle cda25e56c8 Refactor & fixup interpreter implementation of tail calls 2024-07-07 18:16:38 +02:00
Michael Goulet 15d16f1cd6 Finish uplifting supertraits 2024-07-07 11:28:01 -04:00
Michael Goulet 66eb346770 Get rid of the redundant elaboration in middle 2024-07-07 11:28:01 -04:00
Michael Goulet 90423a7abb Uplift elaboration 2024-07-07 11:28:01 -04:00
Michael Goulet c895985e75 Make push_outlives_components into a visitor 2024-07-07 11:22:52 -04:00
Maybe Waffle 5f4caae11c Fix unconditional recursion lint wrt tail calls 2024-07-07 17:11:05 +02:00
Maybe Waffle 45c70318f7 Refactor common part of evaluating `Call`&`TailCall` in the interpreter 2024-07-07 17:11:05 +02:00
Maybe Waffle 3b5a5ee6c8 Support tail calls in the interpreter 2024-07-07 17:11:05 +02:00
DrMeepster 4187cdc013 Properly handle drops for tail calls 2024-07-07 17:11:05 +02:00
Maybe Waffle 484152d562 Support tail calls in mir via `TerminatorKind::TailCall` 2024-07-07 17:11:04 +02:00
Michael Goulet ab27c2fa77 Get rid of trait_ref_is_knowable from delegate 2024-07-07 11:10:48 -04:00
Michael Goulet a982471e07 Uplift trait_ref_is_knowable and friends 2024-07-07 11:10:32 -04:00
Michael Goulet b2e30bdec4 Add fundamental to trait def 2024-07-07 11:10:32 -04:00
Matthias Krüger 1ee6345b7b
Rollup merge of #127409 - gurry:127332-ice-with-expr-not-struct, r=oli-obk
Emit a wrap expr span_bug only if context is not tainted

Fixes #127332

The ICE occurs because of this `span_bug`: 51917e2e69/compiler/rustc_hir_typeck/src/expr_use_visitor.rs (L732-L738)
which is triggered by the fact that we're trying to use an `enum` in a `with` expression instead of a `struct`.

The issue originates in commit 814bfe9335   from PR #127202. As per the title of that commit the ICEing code should not be reachable any more, but looks like it still is.

This PR changes the code so that the `span_bug` will be emitted only if the context is not tainted by a previous error.
2024-07-07 14:22:02 +02:00
Matthias Krüger 510020ad4c
Rollup merge of #127308 - nnethercote:Attribute-cleanups, r=petrochenkov
Attribute cleanups

More refactoring done while trying to fix the final remaining test failure for #124141.

r? `@petrochenkov`
2024-07-07 14:22:01 +02:00
Deadbeef 4f54193ccf Fix intrinsic const parameter counting with `effects` 2024-07-07 11:30:03 +00:00
Gurinder Singh 9da3638c6a Move a span_bug under a condition that cx is tainted
Fixes an ICE caused when a with expression is not a struct
2024-07-07 15:44:55 +05:30
Nicholas Nethercote 9e0aab71a4 Use `filter_map` instead of `flat_map` in `configure_tokens`.
All the branches produce either zero or one elements.
2024-07-07 16:34:29 +10:00
Nicholas Nethercote 9f16f1f6f6 Add an size assertion.
`Option<LazyAttrTokenStream>` is the type that's actually used in all
the aST nodes.
2024-07-07 16:25:22 +10:00
Nicholas Nethercote 022582ca46 Remove `Clone` derive from `LazyAttrTokenStreamImpl`. 2024-07-07 16:24:51 +10:00
Nicholas Nethercote 3a5c4b6e4e Rename some attribute types for consistency.
- `AttributesData` -> `AttrsTarget`
- `AttrTokenTree::Attributes` -> `AttrTokenTree::AttrsTarget`
- `FlatToken::AttrTarget` -> `FlatToken::AttrsTarget`
2024-07-07 16:14:30 +10:00
Nicholas Nethercote 9d33a8fe51 Simplify `ReplaceRange`.
Currently the second element is a `Vec<(FlatToken, Spacing)>`. But the
vector always has zero or one elements, and the `FlatToken` is always
`FlatToken::AttrTarget` (which contains an `AttributesData`), and the
spacing is always `Alone`. So we can simplify it to
`Option<AttributesData>`.

An assertion in `to_attr_token_stream` can can also be removed, because
`new_tokens.len()` was always 0 or 1, which means than `range.len()`
is always greater than or equal to it, because `range.is_empty()` is
always false (as per the earlier assertion).
2024-07-07 15:58:36 +10:00
Nicholas Nethercote b261501b71 Remove `HasSpan` trait.
The only place it is meaningfully used is in a panic message in
`TokenStream::from_ast`. But `node.span()` doesn't need to be printed
because `node` is also printed and it must contain the span.
2024-07-07 15:58:34 +10:00
Nicholas Nethercote 88373e9f0c Remove an unnecessary local variable. 2024-07-07 15:58:12 +10:00
Nicholas Nethercote 14b859fa3b Rename `Attribute::tokens` (the inherent method).
To distinguish it from the `HasTokens` method.
2024-07-07 15:58:10 +10:00
Michael Goulet 58aad3c72c iter_identity is a better name 2024-07-07 00:12:35 -04:00
bors 9e27377bec Auto merge of #127404 - compiler-errors:rpitit-entailment-false-positive, r=oli-obk
Don't try to label `ObligationCauseCode::CompareImplItem` for an RPITIT, since it has no name

The old (current) trait solver has a limitation that when a where clause in param-env must be normalized using the same where clause, then we get spurious errors in `normalize_param_env_or_error`. I don't think there's an issue tracking it, but it's the root cause for many of the "fixed-by-next-solver" labeled issues.

Specifically, these errors may occur when checking predicate entailment of the GAT that comes out of desugaring RPITITs. Since we use `ObligationCauseCode::CompareImplItem` for these predicates, we try calling `item_name` on an RPITIT which fails, since the RPITIT has no name.

We simply suppress this logic when we're reporting a predicate entailment error for an RPITIT. RPITITs should never have predicate entailment errors, *by construction*, but they may due to this bug in the old solver.

Addresses the ICE in #127331, though doesn't fix the underlying issue (which is fundamental to the old solver).

r? types
2024-07-07 03:22:12 +00:00
bors 6ba80a9f8d Auto merge of #126987 - petrochenkov:atvisord2, r=pnkfelix
out_of_scope_macro_calls: Detect calls inside attributes more precisely

Fixes https://github.com/rust-lang/rust/issues/126984.
2024-07-06 22:53:07 +00:00
Michael Goulet 87d61f2540 Don't track visited outlives bounds when decomposing verify for alias 2024-07-06 18:49:20 -04:00
Caio c990e00f15 Add support for literals 2024-07-06 18:00:04 -03:00
Oli Scherer 8c2ea715e9 Use field ident spans directly instead of the full field span in diagnostics on local fields 2024-07-06 19:22:05 +00:00
Michael Goulet d6276b37ea Don't try to label ObligationCauseCode::CompareImplItem for an RPITIT, since it has no name 2024-07-06 15:20:37 -04:00
Michael Goulet 413345c61d
Rollup merge of #127417 - chenyukang:yukang-method-output-diff, r=oli-obk
Show fnsig's unit output  explicitly when there is output diff in diagnostics

Fixes #127263
2024-07-06 14:55:25 -04:00
Michael Goulet 9352026d26
Rollup merge of #127410 - trevyn:patch-1, r=compiler-errors
Correct description of E0502

Closes #126495
2024-07-06 14:55:24 -04:00
Michael Goulet f664171cb5
Rollup merge of #127405 - compiler-errors:uplift-predicate-emitting-relation, r=lcnr
uplift `PredicateEmittingRelation`

Small follow-up to #127333

r? lcnr
2024-07-06 14:55:24 -04:00
Michael Goulet dfc02d28c7
Rollup merge of #127386 - compiler-errors:uplift-outlives-components, r=lcnr
Uplift outlives components to `rustc_type_ir`

We need this to uplift `push_outlives_components`, since the elaborator uses `push_outlives_components` to elaborate type outlives obligations and I want to uplift elaboration.

This ends up reworking and inlining a fair portion of the `GenericArg::walk_shallow` function, whose only callsite was this one. I believe I got the logic correct, but may be worthwhile to look at it closely just in case. Unfortunately github was too dumb to understand that this is a rename + change -- I could also rework the git history to split the "copy the file over" part from the actual logical changes if that makes this easier to review.

r? lcnr
2024-07-06 14:55:23 -04:00
bors 8a8ad3433e Auto merge of #127388 - compiler-errors:elaboration-tweaks, r=lcnr
Elaboration tweaks

Removes `Filter::OnlySelfThatDefines` and reimplements `transitive_bounds_that_define_assoc_item` as a separate function, since I don't want to have to uplift that mode since it's both an implementation detail (only exists to avoid cycles in astconv) and requires exposing `Ident` as an associated type on `Interner`.

r? lcnr
2024-07-06 15:56:16 +00:00
yukang 81c86ddf8e show fnsig's output when there is difference 2024-07-06 23:29:58 +08:00
Michael Goulet c2a88ea6ca Remove walk_shallow 2024-07-06 10:47:46 -04:00
Michael Goulet cc6c5de39d Import via rustc_type_ir::outlives
We could use rustc_middle::ty::outlives I guess?
2024-07-06 10:47:46 -04:00
Michael Goulet 23c6f23b21 Uplift push_outlives_components 2024-07-06 10:47:46 -04:00
Michael Goulet e5d6a416e8 Uplift PredicateEmittingRelation first 2024-07-06 10:05:49 -04:00
yukang f46c4129e0 show unit output when there is only output diff in diagnostics 2024-07-06 21:00:30 +08:00
Vadim Petrochenkov 83cf471361 out_of_scope_macro_calls: Detect calls inside attributes more precisely 2024-07-06 15:36:30 +03:00
Camille GILLOT 0184c6f52e Cache hir_owner_nodes in ParentHirIterator. 2024-07-06 11:56:37 +00:00
Matthias Krüger 1e0028197f
Rollup merge of #127391 - estebank:null_mut, r=cjgillot
Use verbose suggestion for `ptr::null_mut()`
2024-07-06 13:26:26 +02:00
Matthias Krüger 2137d19ef6
Rollup merge of #127275 - RalfJung:offset-from-isize-min, r=Amanieu
offset_from, offset: clearly separate safety requirements the user needs to prove from corollaries that automatically follow

By landing https://github.com/rust-lang/rust/pull/116675 we decided that objects larger than `isize::MAX` cannot exist in the address space of a Rust program, which lets us simplify these rules.

For `offset_from`, we can even state that the *absolute* distance fits into an `isize`, and therefore exclude `isize::MIN`. This PR also changes Miri to treat an `isize::MIN` difference like the other isize-overflowing cases.
2024-07-06 13:26:25 +02:00
Camille Gillot 12edc8db87
Update compiler/rustc_mir_transform/src/gvn.rs
Co-authored-by: Michael Goulet <michael@errs.io>
2024-07-06 12:45:23 +02:00
Jubilee 853148752f
Rollup merge of #127392 - estebank:arg-type, r=jieyouxu
Use verbose suggestion for changing arg type
2024-07-05 23:23:36 -07:00
Jubilee d0f61ce214
Rollup merge of #127383 - estebank:arg-removal, r=compiler-errors
Use verbose style for argument removal suggestion
2024-07-05 23:23:36 -07:00
Jubilee 3ba4195a68
Rollup merge of #127369 - Jules-Bertholet:match-ergonomics-2021, r=Nadrieril
Match ergonomics 2024: align with RFC again

- `&` matches `&mut` on old editions
- Add some more tests

r? ``@Nadrieril``

cc https://github.com/rust-lang/rust/issues/123076

``@rustbot`` label A-edition-2024 A-patterns
2024-07-05 23:23:35 -07:00
trevyn 09b3fcebf4
Correct description of E0502 2024-07-06 09:13:14 +03:00
Michael Goulet aeb1a65dbf
Rollup merge of #127368 - YohDeadfall:dots-in-docs, r=fmease
Added dots at the sentence ends of rustc AST doc

Just a tiny improvement for the AST documentation by bringing consistency to sentence ends. I intentionally didn't terminate every sentence, there are still some members not having them, but at least there's no mixing style on the type level.
2024-07-05 20:49:34 -04:00
Michael Goulet a3535b963b
Rollup merge of #127366 - oli-obk:falliblevisitor, r=compiler-errors
Use `ControlFlow` results for visitors that are only looking for a single value

These visitors all had a `Option<Value>` or `bool` field, that, once set, was never unset or modified again. They have been refactored by removing the field and returning `ControlFlow` directly from the visitor
2024-07-05 20:49:34 -04:00
Michael Goulet 16ba4b773d
Rollup merge of #127333 - compiler-errors:infer_ctxt_like-again, r=lcnr
Split `SolverDelegate` back out from `InferCtxtLike`

This is because in order to uplift things like the `Generalizer` and other `TypeRelation`s, we want to be able to interface with `InferCtxtLike` (and `InferCtxt` as its implementation), rather that `SolverDelegate`, which only really exists as a hack to be able to define some downstream methods in `rustc_type_ir`.

r? lcnr
2024-07-05 20:49:32 -04:00
Michael Goulet 865518d1f2
Rollup merge of #127221 - Urgau:check-cfg-std-diag, r=pnkfelix
Improve well known value check-cfg diagnostic for the standard library

This PR adjust the current logic for hidding the rustc/Cargo suggestion to add a value to a well-known name to exclude the standard library and rustc crates.

This is done in order to improve the contributor experience, in particular when adding a new target, which often requires adding some cfgs like `target_os` which may not be available yet in stage0.

<details>

The diagnostic code would look like this.

```text
error: unexpected `cfg` condition value: `blable`
   --> library/core/src/lib.rs:369:7
    |
369 | #[cfg(target_os = "blable")]
    |       ^^^^^^^^^^^^^^^^^^^^
    |
    = note: expected values for `target_os` are: `aix`, `android`, `cuda`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `hurd`, `illumos`, `ios`, `l4re`, `linux`, `macos`, `netbsd`, `none`, `nto`, `openbsd`, `psp`, `redox`, `solaris`, `solid_asp3`, `teeos`, `tvos`, `uefi`, `unknown`, `visionos`, `vita`, `vxworks`, `wasi`, `watchos`, and `windows` and 2 more
    = help: consider using a Cargo feature instead
    = help: or consider adding in `Cargo.toml` the `check-cfg` lint config for the lint:
             [lints.rust]
             unexpected_cfgs = { level = "warn", check-cfg = ['cfg(target_os, values("blable"))'] }
    = help: or consider adding `println!("cargo::rustc-check-cfg=cfg(target_os, values(\"blable\"))");` to the top of the `build.rs`
    = note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about checking conditional configuration
    = note: `-D unexpected-cfgs` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(unexpected_cfgs)]`
```

</details>
2024-07-05 20:49:32 -04:00
Michael Goulet 31fe9628cf
Rollup merge of #127107 - mu001999-contrib:dead/enhance-2, r=pnkfelix
Improve dead code analysis

Fixes #120770

1. check impl items later if self ty is private although the trait method is public, cause we must use the ty firstly if it's private
2. mark the adt live if it appears in pattern, like generic argument, this implies the use of the adt
3. based on the above, we can handle the case that private adts impl Default, so that we don't need adding rustc_trivial_field_reads on Default, and the logic in should_ignore_item

r? ``@pnkfelix``
2024-07-05 20:49:31 -04:00
Michael Goulet 99429a6a18 Split out transitive_bounds_that_define_assoc_item 2024-07-05 20:21:16 -04:00
Camille GILLOT b97f83b27f Verify that allocations output by GVN are sufficiently aligned. 2024-07-05 22:59:10 +00:00
Esteban Küber 75692056e1 Use verbose suggestion for changing arg type 2024-07-05 20:58:33 +00:00
Michael Goulet 27588d1de3 Split SolverDelegate back out from InferCtxtLike 2024-07-05 16:39:39 -04:00
Esteban Küber fca286a39e Use verbose suggestion for `ptr::null_mut()` 2024-07-05 20:38:21 +00:00
Maybe Lapkin 073f3a263b Equate types instead of using `Unsize` 2024-07-05 22:35:14 +02:00
Michael Goulet e5412da723 Supertrait elaboration doesn't need to use Predicates 2024-07-05 15:51:53 -04:00
Esteban Küber 8e9a3661a8 Use verbose style for argument removal suggestion 2024-07-05 19:40:09 +00:00
Michael Goulet 465e7d546e Rework receiver_is_valid 2024-07-05 11:59:54 -04:00
Michael Goulet fb8d5f1e13 Actually just make can_eq process obligations (almost) everywhere 2024-07-05 11:59:54 -04:00
Michael Goulet fdde66acee Process alias-relate obligations when proving receiver_is_valid 2024-07-05 11:59:52 -04:00
Jules Bertholet 5a35fc446e
Match ergonomics 2024: `&` matches `&mut` on old editions 2024-07-05 11:17:13 -04:00
Yoh Deadfall 291ed596f7 Added dots at the sentence ends of rustc AST doc 2024-07-05 18:10:05 +03:00
Oli Scherer 7dca61b68b Use `ControlFlow` results for visitors that are only looking for a single value 2024-07-05 15:00:40 +00:00
Alona Enraght-Moony f763d62149 Fix a few doc comment for compiler-interal API docs.
They only used `//` instead of `///` so weren't picked up by rustdoc.
2024-07-05 14:14:35 +00:00
bors 11dd90f761 Auto merge of #127360 - GuillaumeGomez:rollup-f0zs1qr, r=GuillaumeGomez
Rollup of 7 pull requests

Successful merges:

 - #124290 (DependencyList: removed outdated comment)
 - #126709 (Migrate `include_bytes_deps`, `optimization-remarks-dir-pgo`, `optimization-remarks-dir`, `issue-40535` and `rmeta-preferred` `run-make` tests to rmake)
 - #127214 (Use the native unwind function in miri where possible)
 - #127320 (Update windows-bindgen to 0.58.0)
 - #127349 (Tweak `-1 as usize` suggestion)
 - #127352 (coverage: Rename `mir::coverage::BranchInfo` to `CoverageInfoHi`)
 - #127359 (Improve run make llvm ident code)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-07-05 11:32:40 +00:00
Guillaume Gomez e4d7f7c9e6
Rollup merge of #127352 - Zalathar:coverage-info, r=oli-obk
coverage: Rename `mir::coverage::BranchInfo` to `CoverageInfoHi`

This opens the door to collecting and storing coverage information that is unrelated to branch coverage or MC/DC, during MIR building.

There is no change to the output of coverage instrumentation, but one deliberate change is that functions now *always* have an attached `CoverageInfoHi` (if coverage is enabled and they are eligible), even if they didn't collect any interesting branch information.

---

`@rustbot` label +A-code-coverage
2024-07-05 11:33:17 +02:00
Guillaume Gomez 6d3f2b1040
Rollup merge of #127349 - estebank:negative-unsigned-literal, r=petrochenkov
Tweak `-1 as usize` suggestion

When writing a negative unsigned integer literal, use a verbose suggestion and account for `as` casting.
2024-07-05 11:33:17 +02:00
Guillaume Gomez 7a79392c82
Rollup merge of #124290 - klensy:dep-format, r=jieyouxu
DependencyList: removed outdated comment

Comment was outdated. Didn't updated description, as `Linkage` enum have descriptive names.

Also added fixme about moving this file to rustc_metadata.
2024-07-05 11:33:14 +02:00
bors 2ad6630673 Auto merge of #127008 - Jules-Bertholet:tc-ergonomics, r=Nadrieril
Match ergonomics 2024: Implement TC's match ergonomics proposal

Under gate `ref_pat_eat_one_layer_2024_structural`. Enabling `ref_pat_eat_one_layer_2024` at the same time allows the union of what the individual gates allow. `@traviscross`

r? `@Nadrieril`

cc https://github.com/rust-lang/rust/issues/123076

`@rustbot` label A-edition-2024 A-patterns
2024-07-05 09:10:17 +00:00
Zalathar f96f443631 Tweak how the extra newline is printed after coverage info 2024-07-05 13:53:05 +10:00
Zalathar f095de4bf1 coverage: Rename `mir::coverage::BranchInfo` to `CoverageInfoHi`
This opens the door to collecting and storing coverage information that is
unrelated to branch coverage or MC/DC.
2024-07-05 13:53:05 +10:00
bors 51917ba8f2 Auto merge of #126171 - RalfJung:simd_bitmask_multibyte, r=workingjubilee
simd_bitmask intrinsic: add a non-power-of-2 multi-byte example

r? `@calebzulawski` `@workingjubilee`
2024-07-05 01:58:22 +00:00
Esteban Küber 86a19467c1 Tweak `-1 as usize` suggestion
When writing a negative unsigned integer literal, use a verbose suggestion and account for `as` casting.
2024-07-05 00:52:01 +00:00
bors 489233170a Auto merge of #123781 - RalfJung:miri-fn-identity, r=oli-obk
Miri function identity hack: account for possible inlining

Having a non-lifetime generic is not the only reason a function can be duplicated. Another possibility is that the function may be eligible for cross-crate inlining. So also take into account the inlining attribute in this Miri hack for function pointer identity.

That said, `cross_crate_inlinable` will still sometimes return true even for `inline(never)` functions:
- when they are `DefKind::Ctor(..) | DefKind::Closure` -- I assume those cannot be `InlineAttr::Never` anyway?
- when `cross_crate_inline_threshold == InliningThreshold::Always`

so maybe this is still not quite the right criterion to use for function pointer identity.
2024-07-04 23:45:56 +00:00
Nicholas Nethercote dd790ab8ef Remove some unnecessary integer conversions.
These should have been removed in #127233 when the positions were
changed from `usize` to `u32`.
2024-07-05 08:27:17 +10:00
bors cc8da78a03 Auto merge of #127288 - lqd:typelen-cache, r=compiler-errors
cache type sizes in type-size limit visitor

This is basically https://github.com/rust-lang/rust/pull/125507#issuecomment-2206813779 as lcnr can't open the PR now.

Locally it reduces the `itertools` regression by quite a bit, to "only +50%" compared to nightly (that includes overhead from the local lack of artifact post-processing, and is just a data point to compare to the 10-20x timings without the cache).

```console
Benchmark 1: cargo +stage1 build --release
  Time (mean ± σ):      2.721 s ±  0.009 s    [User: 2.446 s, System: 0.325 s]
  Range (min … max):    2.710 s …  2.738 s    10 runs

Benchmark 2: cargo +nightly build --release
  Time (mean ± σ):      1.784 s ±  0.005 s    [User: 1.540 s, System: 0.279 s]
  Range (min … max):    1.778 s …  1.792 s    10 runs

Summary
  cargo +nightly build --release ran
    1.52 ± 0.01 times faster than cargo +stage1 build --release
```

On master, it's from 34s to the 2.7s above.

r? compiler-errors
2024-07-04 21:17:19 +00:00
Maybe Lapkin 56de9da1f8 Sort trait names before printing 2024-07-04 18:38:18 +02:00
bors 8a9cccb100 Auto merge of #127326 - matthiaskrgr:rollup-kz7vd3w, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #123043 (Disable dead variant removal for `#[repr(C)]` enums.)
 - #126405 (Migrate some rustc_builtin_macros to SessionDiagnostic)
 - #127037 (Remove some duplicated tests)
 - #127283 (Reject SmartPointer constructions not serving the purpose)
 - #127301 (Tweak some structured suggestions to be more verbose and accurate)
 - #127307 (Allow to have different types for arguments of `Rustc::remap_path_prefix`)
 - #127309 (jsondocck: add `$FILE` built-in variable)
 - #127314 (Trivial update on tidy bless note)
 - #127319 (Remove a use of `StructuredDiag`, which is incompatible with automatic error tainting and error translations)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-07-04 16:37:39 +00:00
Matthias Krüger dd42f7a0a6
Rollup merge of #127319 - oli-obk:fail2taint, r=compiler-errors
Remove a use of `StructuredDiag`, which is incompatible with automatic error tainting and error translations

fixes #127219

I want to remove all of `StructuredDiag`, but it's a bit more involved as it is also used from the `ItemCtxt`, which doesn't support tainting yet.
2024-07-04 18:16:26 +02:00
Matthias Krüger 54bd3a7b8d
Rollup merge of #127301 - estebank:fix-suggestions, r=Urgau
Tweak some structured suggestions to be more verbose and accurate

Addressing some issues I found while working on #127282.
```
error: this URL is not a hyperlink
  --> $DIR/auxiliary/include-str-bare-urls.md:1:11
   |
LL | HEADS UP! https://example.com MUST SHOW UP IN THE STDERR FILE!
   |           ^^^^^^^^^^^^^^^^^^^
   |
   = note: bare URLs are not automatically turned into clickable links
note: the lint level is defined here
  --> $DIR/include-str-bare-urls.rs:14:9
   |
LL | #![deny(rustdoc::bare_urls)]
   |         ^^^^^^^^^^^^^^^^^^
help: use an automatic link instead
   |
LL | HEADS UP! <https://example.com> MUST SHOW UP IN THE STDERR FILE!
   |           +                   +
```
```
error[E0384]: cannot assign twice to immutable variable `v`
  --> $DIR/assign-imm-local-twice.rs:7:5
   |
LL |     v = 1;
   |     ----- first assignment to `v`
LL |     println!("v={}", v);
LL |     v = 2;
   |     ^^^^^ cannot assign twice to immutable variable
   |
help: consider making this binding mutable
   |
LL |     let mut v: isize;
   |         +++
```
```
error[E0393]: the type parameter `Rhs` must be explicitly specified
  --> $DIR/issue-22560.rs:9:23
   |
LL | trait Sub<Rhs=Self> {
   | ------------------- type parameter `Rhs` must be specified for this
...
LL | type Test = dyn Add + Sub;
   |                       ^^^
   |
   = note: because of the default `Self` reference, type parameters must be specified on object types
help: set the type parameter to the desired type
   |
LL | type Test = dyn Add + Sub<Rhs>;
   |                          +++++
```
```
error[E0596]: cannot borrow `v` as mutable, as it is not declared as mutable
  --> $DIR/issue-33819.rs:4:34
   |
LL |         Some(ref v) => { let a = &mut v; },
   |                                  ^^^^^^ cannot borrow as mutable
   |
help: try removing `&mut` here
   |
LL -         Some(ref v) => { let a = &mut v; },
LL +         Some(ref v) => { let a = v; },
   |
```
```
help: remove the invocation before committing it to a version control system
   |
LL -     dbg!();
   |
```
```
error[E0308]: mismatched types
  --> $DIR/issue-39974.rs:1:21
   |
LL | const LENGTH: f64 = 2;
   |                     ^ expected `f64`, found integer
   |
help: use a float literal
   |
LL | const LENGTH: f64 = 2.0;
   |                      ++
```
```
error[E0529]: expected an array or slice, found `Vec<i32>`
  --> $DIR/match-ergonomics.rs:8:9
   |
LL |         [&v] => {},
   |         ^^^^ pattern cannot match with input type `Vec<i32>`
   |
help: consider slicing here
   |
LL |     match x[..] {
   |            ++++
```
```
error[E0609]: no field `0` on type `[u32; 1]`
  --> $DIR/parenthesized-deref-suggestion.rs:10:21
   |
LL |     (x as [u32; 1]).0;
   |                     ^ unknown field
   |
help: instead of using tuple indexing, use array indexing
   |
LL |     (x as [u32; 1])[0];
   |                    ~ +
```
2024-07-04 18:16:24 +02:00
Matthias Krüger d27136fb29
Rollup merge of #127283 - dingxiangfei2009:check-repr-transparent, r=davidtwco
Reject SmartPointer constructions not serving the purpose

Tracking issue: #123430

With this PR we will reject a row of malformed `SmartPointer` implementor candidates.

cc `@Darksonn` `@davidtwco` for context.
2024-07-04 18:16:23 +02:00
Matthias Krüger b16a711191
Rollup merge of #126405 - He1pa:translate_builtin_macro_diag, r=davidtwco
Migrate some rustc_builtin_macros to SessionDiagnostic

<!--
If this PR is related to an unstable feature or an otherwise tracked effort,
please link to the relevant tracking issue here. If you don't know of a related
tracking issue or there are none, feel free to ignore this.

This PR will get automatically assigned to a reviewer. In case you would like
a specific user to review your work, you can assign it to them by using

    r​? <reviewer name>
-->

Part of https://github.com/rust-lang/rust/issues/100717.
pick up abandoned pr: #101935
`@rustbot` label +A-translation
2024-07-04 18:16:22 +02:00
Matthias Krüger f0a0f8f7e8
Rollup merge of #123043 - GoldsteinE:fix/repr-c-dead-branches, r=oli-obk
Disable dead variant removal for `#[repr(C)]` enums.

This prevents removing dead branches from a `#[repr(C)]` enum (they now get discriminants allocated as if they were inhabited).

Implementation notes: ABI of something like

```rust
#[repr(C)]
enum Foo {
    Foo(!),
}
```

is still `Uninhabited`, but its layout is now computed as if all the branches were inhabited.
This seemed to me like a proper way to do it, especially given that ABI sanity check explicitly asserts that type-level uninhabitedness implies ABI uninhabitedness.

This probably needs some sort of FCP (given that it changes `#[repr(C)]` layout, which is a stable guarantee), but I’m not sure how to call for one or which team is the most relevant.

See https://github.com/rust-lang/unsafe-code-guidelines/issues/500.
2024-07-04 18:16:22 +02:00
Maybe Lapkin a1f20f17c8 Properly normalize types in bck when checking pointer casts 2024-07-04 17:57:31 +02:00
Maybe Lapkin 9ef533e8de Fill in tracking issue 2024-07-04 17:57:31 +02:00
Maybe Lapkin 52ba120700 Remove unhelpful comments and add helpful ones 2024-07-04 17:57:31 +02:00
Maybe Lapkin dc420a282b Use `DiagSymbolList` for a lint diagnostic 2024-07-04 17:57:31 +02:00
Maybe Lapkin b16f803431 Make `DiagSymbolList` more generic 2024-07-04 17:57:31 +02:00
Maybe Lapkin cf7032f751 Small fixes from review 2024-07-04 17:57:31 +02:00
Maybe Lapkin 340d69be12 Align the changes to the lang decision 2024-07-04 17:57:29 +02:00
Waffle Lapkin c7435571ad Actually check that the traits are the same for casting pointers to dyn _ 2024-07-04 17:56:09 +02:00
Waffle Lapkin eac4916c90 Disallow `dyn Trait -> dyn Auto` back
I think it's fine, but let's ask T-lang separately.
2024-07-04 17:56:09 +02:00
Maybe Waffle 5645e8e285 Add more checks for pointers with vtable meta
The rules for casting `*mut X<dyn A>` -> `*mut Y<dyn B>` are as follows:
- If `B` has a principal
  - `A` must have exactly the same principal (including generics)
  - Auto traits of `B` must be a subset of autotraits in `A`

Note that `X<_>` and `Y<_>` can be identity, or arbitrary structs with last field being the dyn type.
The lifetime of the trait object itself (`dyn ... + 'a`) is not checked.

This prevents a few soundness issues with `#![feature(arbitrary_self_types)]` and trait upcasting.
Namely, these checks make sure that vtable is always valid for the pointee.
2024-07-04 17:56:09 +02:00
Maybe Waffle d06cf5b399 Forbid casts of raw pointers to trait objects with the same trait, but different args 2024-07-04 17:56:08 +02:00
bors 9f877c9cd2 Auto merge of #127170 - bjorn3:no_specialize_index_borrowck, r=michaelwoerister
Stop using specialization in rustc_index and rustc_borrowck

For rustc_borrowck the version with specialization isn't much more readable anyway IMO. For rustc_index it probably doesn't affect perf in any noticeable way anyway.
2024-07-04 14:24:43 +00:00
mu001999 0adb82528f Improve dead code analysis 2024-07-04 22:05:00 +08:00
Oli Scherer 0d54fe0d02 Remove a use of `StructuredDiag`, which is incompatible with automatic error tainting and error translations 2024-07-04 12:20:51 +00:00
Ralf Jung 273d253ce6 offset_from: "the difference must fit in an isize" is a corollary
also, isize::MIN is an impossible distance
2024-07-04 14:12:23 +02:00
Ding Xiang Fei 0b4edb2487
reject SmartPointer constructions not serving the purpose 2024-07-04 16:41:23 +08:00
bors 486bc278ab Auto merge of #127293 - ldm0:ldm_coroutine, r=saethlin
Use `IndexVec` for coroutine local mapping

Resolves a old FIXME
2024-07-04 06:18:55 +00:00
Esteban Küber a5e7da0cf6 Tweak raw-pointer field access and array indexing suggestions 2024-07-04 06:06:33 +00:00
Esteban Küber 8ea1066fe6 Tweak slice and as_deref suggestion span
Use multispan suggestion.
2024-07-04 05:50:21 +00:00
Esteban Küber ff92ab0903 More accurate mutability suggestion 2024-07-04 05:36:34 +00:00
Esteban Küber 2699d8108c Use shorter span for float literal suggestion 2024-07-04 05:19:35 +00:00
Esteban Küber a06a18a47f Properly handle removal suggestion rendering
Do not leave a `+ ` line with only whitespace. In reality, the user will want to remove the entire line.
2024-07-04 05:04:48 +00:00
Esteban Küber 9344779f71 Fix `&mut` removal suggestion 2024-07-04 04:36:52 +00:00
bors f6fa358a18 Auto merge of #127226 - mat-1:optimize-siphash-round, r=nnethercote
Optimize SipHash by reordering compress instructions

This PR optimizes hashing by changing the order of instructions in the sip.rs `compress` macro so the CPU can parallelize it better. The new order is taken directly from Fig 2.1 in [the SipHash paper](https://eprint.iacr.org/2012/351.pdf) (but with the xors moved which makes it a little faster). I attempted to optimize it some more after this, but I think this might be the optimal instruction order. Note that this shouldn't change the behavior of hashing at all, only statements that don't depend on each other were reordered.

It appears like the current order hasn't changed since its [original implementation from 2012](fada46c421 (diff-b751133c229259d7099bbbc7835324e5504b91ab1aded9464f0c48cd22e5e420R35)) which doesn't look like it was written with data dependencies in mind.

Running `./x bench library/core --stage 0 --test-args hash` before and after this change shows the following results:

Before:
```
benchmarks:
    hash::sip::bench_bytes_4             7.20/iter +/- 0.70
    hash::sip::bench_bytes_7             9.01/iter +/- 0.35
    hash::sip::bench_bytes_8             8.12/iter +/- 0.10
    hash::sip::bench_bytes_a_16         10.07/iter +/- 0.44
    hash::sip::bench_bytes_b_32         13.46/iter +/- 0.71
    hash::sip::bench_bytes_c_128        37.75/iter +/- 0.48
    hash::sip::bench_long_str          121.18/iter +/- 3.01
    hash::sip::bench_str_of_8_bytes     11.20/iter +/- 0.25
    hash::sip::bench_str_over_8_bytes   11.20/iter +/- 0.26
    hash::sip::bench_str_under_8_bytes   9.89/iter +/- 0.59
    hash::sip::bench_u32                 9.57/iter +/- 0.44
    hash::sip::bench_u32_keyed           6.97/iter +/- 0.10
    hash::sip::bench_u64                 8.63/iter +/- 0.07
```
After:
```
benchmarks:
    hash::sip::bench_bytes_4             6.64/iter +/- 0.14
    hash::sip::bench_bytes_7             8.19/iter +/- 0.07
    hash::sip::bench_bytes_8             8.59/iter +/- 0.68
    hash::sip::bench_bytes_a_16          9.73/iter +/- 0.49
    hash::sip::bench_bytes_b_32         12.70/iter +/- 0.06
    hash::sip::bench_bytes_c_128        32.38/iter +/- 0.20
    hash::sip::bench_long_str          102.99/iter +/- 0.82
    hash::sip::bench_str_of_8_bytes     10.71/iter +/- 0.21
    hash::sip::bench_str_over_8_bytes   11.73/iter +/- 0.17
    hash::sip::bench_str_under_8_bytes  10.33/iter +/- 0.41
    hash::sip::bench_u32                10.41/iter +/- 0.29
    hash::sip::bench_u32_keyed           9.50/iter +/- 0.30
    hash::sip::bench_u64                 8.44/iter +/- 1.09
```
I ran this on my computer so there's some noise, but you can tell at least `bench_long_str` is significantly faster (~18%).

Also, I noticed the same compress function from the library is used in the compiler as well, so I took the liberty of copy-pasting this change to there as well.

Thanks `@semisol` for porting SipHash for another project which led me to notice this issue in Rust, and for helping investigate. <3
2024-07-04 04:03:45 +00:00
Esteban Küber f63d2bc657 Better suggestion span for missing type parameter 2024-07-04 02:41:13 +00:00
Esteban Küber 89ecae5d85 Better span for "make binding mutable" suggestion 2024-07-04 02:02:21 +00:00
bors 66b4f0021b Auto merge of #127127 - notriddle:notriddle/pulldown-cmark-0.11, r=GuillaumeGomez
rustdoc: update to pulldown-cmark 0.11

r? rustdoc

This pull request updates rustdoc to the latest version of pulldown-cmark. Along with adding new markdown extensions (which this PR doesn't enable), the new pulldown-cmark version also fixes a large number of bugs. Because all text files successfully parse as markdown, these bugfixes change the output, which can break people's existing docs.

A crater run, https://github.com/rust-lang/rust/pull/121659, has already been run for this change.

The first commit upgrades and fixes rustdoc. The second commit adds a lint for the footnote and block quote parser changes, which break the largest numbers of docs in the Crater run. The strikethrough change was mitigated in pulldown-cmark itself.

Unblocks https://github.com/rust-lang/rust-clippy/pull/12876
2024-07-04 01:50:31 +00:00
Matthias Krüger 79bdb89a4a
Rollup merge of #127294 - ldm0:ldm_coroutine2, r=lcnr
Less magic number for corountine
2024-07-03 23:30:10 +02:00
Matthias Krüger 603130948b
Rollup merge of #127253 - chenyukang:yukang-fix-126246-fn-parameters-check, r=estebank
Fix incorrect suggestion for extra argument with a type error

Fixes #126246

I tried to fix it in the `find_errors` of ArgMatrix, but seems it's hard to avoid breaking some other test cases.

The root cause is we eliminate the first argument even with a type error at here:
6292b2af62/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs (L664)

So the left argument is always treated as extra one.

But if there is already a type error, an error message will be generated firstly, which make this issue a trivial one.
2024-07-03 23:30:08 +02:00
Matthias Krüger 9f8cf64105
Rollup merge of #127184 - bjorn3:interface_refactor2, r=Nadrieril
More refactorings to rustc_interface

Follow up to https://github.com/rust-lang/rust/pull/126834
2024-07-03 23:30:07 +02:00
Matthias Krüger 33e9f25e91
Rollup merge of #127092 - compiler-errors:rtn-dots-redux, r=estebank
Change return-type-notation to use `(..)`

Aligns the syntax with the current wording of [RFC 3654](https://github.com/rust-lang/rfcs/pull/3654). Also implements rustfmt support (along with making a match exhaustive).

Tracking:
* https://github.com/rust-lang/rust/issues/109417
2024-07-03 23:30:07 +02:00
Liu Dingming 4930937960 Less magic number for corountine 2024-07-04 05:13:35 +08:00
Liu Dingming a9194f30eb Use `IndexVec` for coroutine local mapping 2024-07-04 05:09:23 +08:00
Rémy Rakic 529a3f4ce6 cache type sizes in type-size limit visitor 2024-07-03 20:32:54 +00:00
bors 2b90614e94 Auto merge of #127036 - cjgillot:sparse-state, r=oli-obk
Make jump threading state sparse

Continuation of https://github.com/rust-lang/rust/pull/127024

Both dataflow const-prop and jump threading involve cloning the state vector a lot. This PR replaces the data structure by a sparse vector, considering:
- that jump threading state is typically very sparse (at most 1 or 2 set entries);
- that dataflow const-prop is disabled by default;
- that place/value map is very eager, and prone to creating an overly large state.

The first commit is shared with the previous PR to avoid needless conflicts.

r? `@oli-obk`
2024-07-03 18:52:04 +00:00
bors 1cfd47fe0b Auto merge of #127278 - matthiaskrgr:rollup-fjexkdr, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #126803 (Change `asm-comments` to `verbose-asm`, always emit user comments)
 - #127050 (Make mtime of reproducible tarballs dependent on git commit)
 - #127145 (Add `as_lang_item` to `LanguageItems`, new trait solver)
 - #127202 (Remove global error count checks from typeck)
 - #127233 (Some parser cleanups)
 - #127248 (Add parse fail test using safe trait/impl trait)
 - #127264 (Small `run-make-support` API improvements)
 - #127270 (bootstrap: pass correct struct size to winapi)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-07-03 16:31:16 +00:00
Deadbeef 46af987072 Add `constness` to `TraitDef` 2024-07-03 15:37:34 +00:00
Matthias Krüger 7fdb2f5cab
Rollup merge of #127233 - nnethercote:parser-cleanups, r=petrochenkov
Some parser cleanups

Cleanups I made while looking closely at this code.

r? ``@petrochenkov``
2024-07-03 17:26:55 +02:00
Matthias Krüger 9b05e7b66e
Rollup merge of #127202 - oli-obk:do_not_count_errors, r=wesleywiser
Remove global error count checks from typeck

Some of these are not reachable anymore, others can now rely on information local to the current typeck run. One check was actually invalid, because it was relying on wfcheck running before typeck, which is not guaranteed in the query system and usually easy to create ICEing examples for via const eval (which runs typeck before wfcheck)
2024-07-03 17:26:55 +02:00
Matthias Krüger 02916a3193
Rollup merge of #127145 - compiler-errors:as_lang_item, r=lcnr
Add `as_lang_item` to `LanguageItems`, new trait solver

Add `as_lang_item` which turns `DefId` into a `TraitSolverLangItem` in the new trait solver, so we can turn the large chain of if statements in `assemble_builtin_impl_candidates` into a match instead.

r? lcnr
2024-07-03 17:26:54 +02:00
Matthias Krüger c74d620635
Rollup merge of #126803 - tgross35:verbose-asm, r=Amanieu
Change `asm-comments` to `verbose-asm`, always emit user comments

Implements what is described in https://github.com/rust-lang/compiler-team/issues/762

Tracking issue: https://github.com/rust-lang/rust/issues/126802
2024-07-03 17:26:53 +02:00
bors 1086affd98 Auto merge of #126094 - petrochenkov:libsearch, r=michaelwoerister
linker: Link dylib crates by path

Linkers seem to support linking dynamic libraries by path.
Not sure why the previous scheme with splitting the path into a directory (passed with `-L`) and a name (passed with `-l`) was used (upd: likely due to https://github.com/rust-lang/rust/pull/126094#issuecomment-2155063414).

When we split a library path `some/dir/libfoo.so` into `-L some/dir` and `-l foo` we add `some/dir` to search directories for *all* libraries looked up by the linker, not just `foo`, and `foo` is also looked up in *all* search directories not just `some/dir`.
Technically we may find some unintended libraries this way.
Therefore linking dylibs via a full path is both simpler and more reliable.

It also makes the set of search directories more easily reproducible when we need to lookup some native library manually (like in https://github.com/rust-lang/rust/pull/123436).
2024-07-03 14:15:31 +00:00
bors c872a1418a Auto merge of #125507 - compiler-errors:type-length-limit, r=lcnr
Re-implement a type-size based limit

r? lcnr

This PR reintroduces the type length limit added in #37789, which was accidentally made practically useless by the caching changes to `Ty::walk` in #72412, which caused the `walk` function to no longer walk over identical elements.

Hitting this length limit is not fatal unless we are in codegen -- so it shouldn't affect passes like the mir inliner which creates potentially very large types (which we observed, for example, when the new trait solver compiles `itertools` in `--release` mode).

This also increases the type length limit from `1048576 == 2 ** 20` to `2 ** 24`, which covers all of the code that can be reached with craterbot-check. Individual crates can increase the length limit further if desired.

Perf regression is mild and I think we should accept it -- reinstating this limit is important for the new trait solver and to make sure we don't accidentally hit more type-size related regressions in the future.

Fixes #125460
2024-07-03 11:56:36 +00:00
Jacob Pratt b1b9804f5a
Rollup merge of #126403 - compiler-errors:better-type-errors, r=lcnr
Actually report normalization-based type errors correctly for alias-relate obligations in new solver

We have some special casing to report type mismatch errors that come from projection predicates, but we don't do that for alias-relate obligations. This PR implements that. There's a bit of code duplication, but 🤷

Best reviewed without whitespace.

r? lcnr
2024-07-03 03:03:14 -04:00
bors d163e5e515 Auto merge of #123737 - compiler-errors:alias-wf, r=lcnr
Check alias args for WF even if they have escaping bound vars

#### What

This PR stops skipping arguments of aliases if they have escaping bound vars, instead recursing into them and only discarding the resulting obligations referencing bounds vars.

#### An example:

From the test:
```
trait Trait {
    type Gat<U: ?Sized>;
}

fn test<T>(f: for<'a> fn(<&'a T as Trait>::Gat<&'a [str]>)) where for<'a> &'a T: Trait {}
//~^ ERROR the size for values of type `[()]` cannot be known at compilation time

fn main() {}
```

We now prove that `str: Sized` in order for `&'a [str]` to be well-formed. We were previously unconditionally skipping over `&'a [str]` as it referenced a buond variable. We now recurse into it and instead only discard the `[str]: 'a` obligation because of the escaping bound vars.

#### Why?

This is a change that improves consistency about proving well-formedness earlier in the pipeline, which is necessary for future work on where-bounds in binders and correctly handling higher-ranked implied bounds. I don't expect this to fix any unsoundness.

#### What doesn't it fix?

Specifically, this doesn't check projection predicates' components are well-formed, because there are too many regressions: https://github.com/rust-lang/rust/pull/123737#issuecomment-2052198478
2024-07-03 03:48:06 +00:00
Trevor Gross c15a698f56 Rename the `asm-comments` compiler flag to `verbose-asm`
Since this codegen flag now only controls LLVM-generated comments rather than
all assembly comments, make the name more accurate (and also match Clang).
2024-07-02 21:42:01 -04:00
Trevor Gross 64a3bd84d8 Always preserve user-written comments in assembly 2024-07-02 21:41:59 -04:00
bors 67f0d43890 Auto merge of #123720 - amandasystems:dyn-enable-refactor, r=nikomatsakis
Rewrite handling of universe-leaking placeholder regions into outlives constraints

This commit prepares for Polonius by moving handling of leak check/universe errors out of the inference step by rewriting any universe error into an outlives-static constraint.

This variant is a work in progress but seems to pass most tests.

Note that a few debug assertions no longer hold; a few extra eyes on those changes are appreciated!
2024-07-03 01:24:07 +00:00
yukang 9f32459c98 Fix incorrect suggestion for extra argument with a type error 2024-07-03 06:15:24 +08:00
Michael Goulet b1059ccda2 Instance::resolve -> Instance::try_resolve, and other nits 2024-07-02 17:28:03 -04:00
Michael Goulet ecdaff240d Actually report normalization-based type errors correctly for alias-relate obligations in new solver 2024-07-02 16:39:57 -04:00
Michael Goulet 5a837515f2 Make fn traits into first-class TraitSolverLangItems to avoid needing fn_trait_kind_from_def_id 2024-07-02 16:37:24 -04:00