Commit Graph

35358 Commits

Author SHA1 Message Date
Matthias Krüger
4971d9ffe4
Rollup merge of #124024 - RalfJung:interpret-comment, r=oli-obk
interpret: remove outdated comment

In https://github.com/rust-lang/rust/pull/107756, allocation became generally fallible, so the "only panic if there is provenance" no longer applies.

r? ``@oli-obk``
2024-04-16 17:54:46 +02:00
Matthias Krüger
864ab0cc36
Rollup merge of #124018 - RalfJung:dealloc-memory-kind, r=oli-obk
interpret: pass MemoryKind to before_memory_deallocation

This will be needed for https://github.com/rust-lang/miri/pull/3475.

r? ``@oli-obk``
2024-04-16 17:54:45 +02:00
Matthias Krüger
25fd90cea8
Rollup merge of #124017 - oli-obk:define_opaque_types8, r=compiler-errors
Change a diagnostics-path-only `DefineOpaqueTypes` to `Yes`.

This can't possibly affect compilation, so it's safe to flip, even if I couldn't come up with an affected test

r? ``@compiler-errors``
2024-04-16 17:54:45 +02:00
Matthias Krüger
cad7d94e0f
Rollup merge of #123969 - oli-obk:define_opaque_types6, r=compiler-errors
The new solver ignores `DefineOpaqueTypes`, so switch it to `Yes`

We assert that we are in the new solver in the line above

r? ``@compiler-errors``
2024-04-16 17:54:43 +02:00
Matthias Krüger
dc40da83e3
Rollup merge of #123535 - Jules-Bertholet:mut_dont_reset_binding_mode_2024, r=Nadrieril
Match ergonomics 2024: `mut` doesn't reset binding mode

r? ``@Nadrieril``

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

``@rustbot`` label A-edition-2024 A-patterns
2024-04-16 17:54:42 +02:00
Matthias Krüger
f54219c473
Rollup merge of #123501 - Urgau:stabilize-check-cfg, r=petrochenkov
Stabilize checking of cfgs at compile-time: `--check-cfg` option

This PR stabilize the `--check-cfg` CLI option of `rustc` (and `rustdoc`) 🎉.

In particular this PR does two things:
  1. it makes the `--check-cfg` option stable
  2. and it moves the documentation to the stable books

FCP: https://github.com/rust-lang/rust/issues/82450#issuecomment-1965328542

Resolves #82450

``@rustbot`` labels +S-blocked +F-check-cfg
r? ``@petrochenkov``
2024-04-16 17:54:41 +02:00
Chris Denton
5b024d6550
Cranelift: Revert raw-dylib for Windows futex APIs 2024-04-16 15:53:35 +00:00
Ralf Jung
5b8b9cfaaa interpret: remove outdated comment 2024-04-16 17:33:12 +02:00
Michael Baikov
a03aeca99a Allow workproducts without object files.
This pull request partially reverts changes from e16c3b4a44

Original motivation for this assert was described with "A WorkProduct without a saved file is useless"
which was true at the time but now it is possible to have work products with other types of files
(llvm-ir, asm, etc) and there are bugreports for this failure:

For example: https://github.com/rust-lang/rust/issues/123695

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

Now existing `assert` and `.unwrap_or_else` are unified into a single
check that emits slightly more user friendly error message if an object
files was meant to be produced but it's missing
2024-04-16 11:19:35 -04:00
Ralf Jung
18bfca50f1 interpret: pass MemoryKind to before_memory_deallocation 2024-04-16 16:37:34 +02:00
Oli Scherer
e03926c143 Change a diagnostics-path-only DefineOpaqueTypes to Yes. 2024-04-16 14:00:53 +00:00
DaniPopes
780dfb803f
Outline default query and hook provider function implementations 2024-04-16 15:41:02 +02:00
bors
1dea922ea6 Auto merge of #124015 - GuillaumeGomez:rollup-s46ksxa, r=GuillaumeGomez
Rollup of 14 pull requests

Successful merges:

 - #120781 (Correct usage note on OpenOptions::append())
 - #121694 (sess: stabilize `-Zrelro-level` as `-Crelro-level`)
 - #122521 (doc(bootstrap): add top-level doc-comment to utils/tarball.rs)
 - #123491 (Fix ICE in `eval_body_using_ecx`)
 - #123574 (rustdoc: rename `issue-\d+.rs` tests to have meaningful names (part 6))
 - #123687 (Update ar_archive_writer to 0.2.0)
 - #123721 (Various visionOS fixes)
 - #123797 (Better graphviz output for SCCs and NLL constraints)
 - #123990 (Make `suggest_deref_closure_return` more idiomatic/easier to understand)
 - #123995 (Make `thir_tree` and `thir_flat` into hooks)
 - #123998 (Opaque types have no namespace)
 - #124001 (Fix docs for unstable_features lint.)
 - #124006 (Move size assertions for `mir::syntax` types into the same file)
 - #124011 (rustdoc: update the module-level docs of `rustdoc::clean`)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-04-16 13:26:03 +00:00
Guillaume Gomez
dd083470e1
Rollup merge of #124006 - Zalathar:static-assert, r=nnethercote
Move size assertions for `mir::syntax` types into the same file

A redundant size assertion for `StatementKind` was added in #122937, because the existing assertion was in a different file.

This PR cleans that up, and also moves the `TerminatorKind` assertion into the same file where it belongs, to avoid the same thing happening again.

r? `@nnethercote`
2024-04-16 15:19:16 +02:00
Guillaume Gomez
f5adfa0e69
Rollup merge of #123998 - compiler-errors:opaque-ns, r=davidtwco
Opaque types have no namespace

Opaques are never referenced by name -- even when we have `type X = impl Sized;`, `X` is the name of the type alias, not the opaque.
2024-04-16 15:19:15 +02:00
Guillaume Gomez
6629fe6c6d
Rollup merge of #123995 - compiler-errors:thir-hooks, r=oli-obk
Make `thir_tree` and `thir_flat` into hooks

No need for them to be queries, since they are only called with `-Zunpretty`
2024-04-16 15:19:15 +02:00
Guillaume Gomez
24cdb7ed56
Rollup merge of #123990 - compiler-errors:suggest-closure-ret-deref, r=oli-obk
Make `suggest_deref_closure_return` more idiomatic/easier to understand

The only functional change here really is just making it not use a fresh type variable for upvars. I'll point that out in the code.

The rest of the changes are just stylistic, because reading this code was really confusing me (variable names were vague, ways of accessing types were unidiomatic, order of operations was kind of strange, etc).

This is stacked on #123989.

r? oli-obk since you approved #122213
2024-04-16 15:19:14 +02:00
Guillaume Gomez
9da8f04da3
Rollup merge of #123797 - amandasystems:better-graphviz, r=oli-obk
Better graphviz output for SCCs and NLL constraints

This PR modifies the output for `-Z dump-mir-graphviz=yes`. Specifically, it changes the output of the files `.-------.nll.0.regioncx.all.dot` and `nll.0.regioncx.scc.dot` to be easier to read and contain some information that helped me during debugging. In particular:

- SCC indices are contracted to `SCC(n)` instead of `ConstraintSccIndex(n)` to compress the nodes
- SCC regions are in `{}` rather than `[]` (controversial since they are technically ordered by index, but I figured they're more sets than arrays conceptually since they're equivalence classes).
- For regions in other universes than the root, also show the region universe (as ?8/U1)
- For regions with external names, show the external name in parenthesis
- For the region graph where edges are locations, render the All variant of the enum without the file since it's extremely long and often destroys the rendering
- For region graph edge annotations for single locations, remove the wrapping around the Location variant and just add its contents since this can be unambiguously done

Example output (from the function `foo()` of `tests/ui/error-codes/E0582.rs`) for an SCC graph:
![a graph showing SCCs](https://github.com/rust-lang/rust/assets/102855/0b998338-0379-4829-b99e-d8105c094897)

...and for the constraints:
![a graph showing regions and their constraints](https://github.com/rust-lang/rust/assets/102855/e984c4ca-7aa2-4db2-9878-bf38fe8208d5)

This PR also gives `UniverseIndex`es the `is_root()` method since this is now an operation that happens three times in the borrowck crate.
2024-04-16 15:19:14 +02:00
Guillaume Gomez
1c8bdb93d9
Rollup merge of #123721 - madsmtm:fix-visionos, r=davidtwco
Various visionOS fixes

A few small mistakes was introduced in https://github.com/rust-lang/rust/pull/121419, probably after the rename from `xros` to `visionos`. See the commits for details.

CC `@agg23`

Since you reviewed https://github.com/rust-lang/rust/pull/121419
r? davidtwco
2024-04-16 15:19:13 +02:00
Guillaume Gomez
9a7adb8d81
Rollup merge of #123687 - bjorn3:ar_archive_writer_0_2_0, r=oli-obk
Update ar_archive_writer to 0.2.0

This adds a whole bunch of tests checking for any difference with llvm's archive writer. It also fixes two mistakes in the porting from C++ to Rust. The first one causes a divergence for Mach-O archives which may or may not be harmless. The second will definitively cause issues, but only applies to thin archives, which rustc currently doesn't create.
2024-04-16 15:19:13 +02:00
Guillaume Gomez
ea7eb713d9
Rollup merge of #123491 - gurry:123154-ice-unsized-struct-eval, r=oli-obk
Fix ICE in `eval_body_using_ecx`

Ensures `TypeckResults` is tainted by failing candidate assembly for types with error

Fixes #123154
2024-04-16 15:19:11 +02:00
Guillaume Gomez
26b6a234a1
Rollup merge of #121694 - davidtwco:stabilize-relro-level, r=Mark-Simulacrum
sess: stabilize `-Zrelro-level` as `-Crelro-level`

Stabilise `-Zrelro-level` as `-Crelro-level`. There's no tracking issue for this flag to close.
2024-04-16 15:19:10 +02:00
Oli Scherer
0a88339a57 Don't ICE for kind mismatches during error rendering 2024-04-16 11:52:12 +00:00
bors
4e1f5d90bc Auto merge of #123468 - compiler-errors:precise-capturing, r=oli-obk
Implement syntax for `impl Trait` to specify its captures explicitly (`feature(precise_capturing)`)

Implements `impl use<'a, 'b, T, U> Sized` syntax that allows users to explicitly list the captured parameters for an opaque, rather than inferring it from the opaque's bounds (or capturing *all* lifetimes under 2024-edition capture rules). This allows us to exclude some implicit captures, so this syntax may be used as a migration strategy for changes due to #117587.

We represent this list of captured params as `PreciseCapturingArg` in AST and HIR, resolving them between `rustc_resolve` and `resolve_bound_vars`. Later on, we validate that the opaques only capture the parameters in this list.

We artificially limit the feature to *require* mentioning all type and const parameters, since we don't currently have support for non-lifetime bivariant generics. This can be relaxed in the future.

We also may need to limit this to require naming *all* lifetime parameters for RPITIT, since GATs have no variance. I have to investigate this. This can also be relaxed in the future.

r? `@oli-obk`

Tracking issue:

- https://github.com/rust-lang/rust/issues/123432
2024-04-16 11:22:35 +00:00
Oli Scherer
801413ecd1 Taint const qualifs if a static is referenced that didn't pass wfcheck 2024-04-16 10:43:41 +00:00
Oli Scherer
82e7773bc1 Subtype predicates only exist on inference types, so we can allow them to register opaque types within them. 2024-04-16 08:09:24 +00:00
Gurinder Singh
c30e15aded Fail candidate assembly for erroneous types
Trait predicates for types which have errors may still
evaluate to OK leading to downstream ICEs. Now we return
a selection error for such types in candidate assembly and
thereby prevent such issues
2024-04-16 12:42:48 +05:30
Nicholas Nethercote
b03ae74c84 Rename a tiny module.
So it doesn't clash with `rustc_middle::ty`.
2024-04-16 16:37:28 +10:00
Nicholas Nethercote
4b27cc8b7a Avoid lots of hir::HirId{,Map,Set} qualifiers.
Because they're a bit redundant.
2024-04-16 16:29:15 +10:00
Nicholas Nethercote
e93f754289 Always use ty:: qualifier for TyKind enum variants.
Because that's the way it should be done.
2024-04-16 16:29:13 +10:00
Nicholas Nethercote
27374a0214 Avoid unnecessary rustc_span::DUMMY_SP usage.
In some cases `DUMMY_SP` is already imported. In other cases this commit
adds the necessary import, in files where `DUMMY_SP` is used more than
once.
2024-04-16 15:55:24 +10:00
Zalathar
c0e7659cae Move size assertions for mir::syntax types into the same file
A redundant size assertion for `StatementKind` was added in #122937, because
the existing assertion was in a different file.

This patch cleans that up, and also moves the `TerminatorKind` assertion into
the same file where it belongs, to avoid the same thing happening again.
2024-04-16 15:18:43 +10:00
Jules Bertholet
3efbe3e70c
Simplify calc_default_binding_mode 2024-04-15 23:34:54 -04:00
Jules Bertholet
88cd821e62
Address review comments 2024-04-15 23:34:52 -04:00
Jules Bertholet
e3945bd3a8
Ensure inherited reference is never set to &mut behind an & 2024-04-15 23:34:50 -04:00
Jules Bertholet
b6c409723b
Support let &mut x = &&mut 0; 2024-04-15 23:34:49 -04:00
Jules Bertholet
4cd87c463c
Properly downgrade inherited mutability 2024-04-15 23:34:47 -04:00
Jules Bertholet
93544d5db3
Match ergonomics 2024: Implement eat-one-layer 2024-04-15 23:34:44 -04:00
Jules Bertholet
1b6d435cf3
Mark gate as incomplete 2024-04-15 23:27:22 -04:00
Jules Bertholet
e13911e6e8
Rename feature gate 2024-04-15 23:27:21 -04:00
Jules Bertholet
1b2e471b43
Fix typo
Co-authored-by: Guillaume Boisseau <Nadrieril@users.noreply.github.com>
2024-04-15 23:27:21 -04:00
Jules Bertholet
d5d700d5c6
Temporarily remove future compatibility label from migration lint
The lint is unstable, and the lint group `rust_2024_compatibility` must keep working on stable
2024-04-15 23:27:20 -04:00
Jules Bertholet
83f330fbd4
Migration lint
Rustfix remains TODO
2024-04-15 23:27:19 -04:00
Jules Bertholet
ef1d084c0b
Match ergonomics 2024: mut doesn't reset binding mode 2024-04-15 23:26:22 -04:00
Michael Goulet
00838b3140 Make suggest_deref_closure_return more idiomatic/easier to understand 2024-04-15 23:04:16 -04:00
Nicholas Nethercote
9b0ced000a Move initialize_checked_jobserver.
Currently it's a method on `EarlyDiagCtxt`, which is not the right place
for it at all -- `EarlyDiagCtxt` is used to issue diagnostics, but
shouldn't be doing any of the actual checking.

This commit moves it into a standalone function that takes an
`EarlyDiagCtxt` as an argument, which is more sensible. This does
require adding `EarlyDiagCtxt::early_struct_warn`, so a warning can be
returned and then modified with a note. (And that likely explains why
somebody put `initialize_checked_jobserver` into `EarlyDiagCtxt` in the
first place.)
2024-04-16 13:02:55 +10:00
Nicholas Nethercote
62c32aeeab Construct SourceMap at the same time as SessionGlobals.
Currently `SourceMap` is constructed slightly later than
`SessionGlobals`, and inserted. This commit changes things so they are
done at the same time.

Benefits:
- `SessionGlobals::source_map` changes from
  `Lock<Option<Lrc<SourceMap>>>` to `Option<Lrc<SourceMap>>`. It's still
  optional, but mutability isn't required because it's initialized at
  construction.
- `set_source_map` is removed, simplifying `run_compiler`, which is
  good because that's a critical function and it's nice to make it
  simpler.

This requires moving things around a bit, so the necessary inputs are
available when `SessionGlobals` is created, in particular the `loader`
and `hash_kind`, which are no longer computed by `build_session`. These
inputs are captured by the new `SourceMapInputs` type, which is threaded
through various places.
2024-04-16 13:02:53 +10:00
Nicholas Nethercote
ff2e4ed1f1 Factor out common code in interface tests.
Replacing `mk_session` with `sess_and_cfgs`, which does a bit more of
the shared stuff -- the option parsing and the `build_configuration`
call.
2024-04-16 12:08:25 +10:00
Michael Goulet
c95761385e Make array suggestions slightly more accurate 2024-04-15 21:45:47 -04:00
Michael Goulet
8a981b6fee Use /* value */ as a placeholder 2024-04-15 21:36:52 -04:00
Michael Goulet
8d07d90572 Opaque types have no namespace 2024-04-15 21:27:30 -04:00
Michael Goulet
6288a721f5 Delay span bug when Self resolves to DefKind::{Mod,Trait} 2024-04-15 21:05:15 -04:00
Michael Goulet
81bf9ae263 Make thir_tree and thir_flat into hooks 2024-04-15 20:08:21 -04:00
Maybe Waffle
fa134b5e0f Add graph::depth_first_search_as_undirected 2024-04-15 23:20:52 +00:00
Maybe Waffle
7d2cb3dda7 Make graph::DepthFirstSearch accept G by value
It's required for the next commit.

Note that you can still have `G = &H`, since there are implementations of all
the graph traits for references.
2024-04-15 23:20:52 +00:00
Maybe Waffle
86a576528c Add an opt-in to store incoming edges in VecGraph + some docs 2024-04-15 23:20:52 +00:00
León Orell Valerian Liehr
daa2ebc70c
Rollup merge of #123989 - compiler-errors:type-dependent-def-id, r=oli-obk
Just use `type_dependent_def_id` to figure out what the method is for an expr

The calls to `lookup_method_for_diagnostic` are overkill.

r? oli-obk
2024-04-16 01:12:39 +02:00
León Orell Valerian Liehr
1069ad3982
Rollup merge of #123926 - compiler-errors:no-ann, r=estebank
Fix pretty HIR for anon consts in diagnostics

This removes the `NoAnn` printer which skips over nested bodies altogether, which is confusing, and requires users of `{ty|qpath|pat}_to_string` to pass in `&tcx` which now impleemnts `hir_pretty::PpAnn`.

There's one case where this "regresses" by actually printing out the body of the anon const -- we could suppress that, but I don't expect people to actually get anon consts like that unless they're fuzzing, tbh.

r? estebank
2024-04-16 01:12:38 +02:00
León Orell Valerian Liehr
1ad9fea871
Rollup merge of #123603 - compiler-errors:no-intrinsic, r=estebank
Don't even parse an intrinsic unless the feature gate is enabled

Don't return true in `tcx.is_intrinsic` if the function is defined locally and `#![feature(intrinsics)]` is not enabled. This is a slightly more general fix than #123526, since #123587 shows that we have simplifying assumptions about intrinsics elsewhere in the compiler.

This will make the code ICE again if the user **enables** `#[feature(intrinsics)]`, but I kind of feel like if we want to fix that, we should make the `INTERNAL_FEATURES` lint `Deny` again. Perhaps we could do that on non-nightly compilers. Or we should just stop compilation altogether if they have `#![feature]` enabled on a non-nightly compiler.

As for the UX of *real* cases of hitting these ICEs, I believe pretty strongly that if a compiler/stdlib dev is modifying internal intrinsics (intentionally, like when making a change to rustc) we have no guarantee to make the ICE better looking for them. Honestly, *not* spitting out a stack trace is probably a disservice to the people who hit those ICEs in that case.

r? `@Nilstrieb` `@estebank`
2024-04-16 01:12:37 +02:00
León Orell Valerian Liehr
c5665990c5
Rollup merge of #123462 - fmease:rn-mod-sep-to-path-sep, r=nnethercote
Cleanup: Rename `ModSep` to `PathSep`

`::` is usually referred to as the *path separator* (citation needed).

The existing name `ModSep` for *module separator* is a bit misleading since it in fact separates the segments of arbitrary path segments, not only ones resolving to modules. Let me just give a shout-out to associated items (`T::Assoc`, `<Ty as Trait>::function`) and enum variants (`Option::None`).

Motivation: Reduce friction for new contributors, prevent potential confusion.

cc `@petrochenkov`
r? nnethercote or compiler
2024-04-16 01:12:37 +02:00
León Orell Valerian Liehr
9cc26b598a
Rollup merge of #123016 - compiler-errors:no-type-var-origin, r=lcnr
Remove `TypeVariableOriginKind` and `ConstVariableOriginKind`

It's annoying to have to import `TypeVariableOriginKind` just to fill it with `MiscVariable` for almost every use. Every other usage other than `TypeParameterDefinition` wasn't even used -- I can see how it may have been useful once for debugging, but I do quite a lot of typeck debugging and I've never really needed it.

So let's just remove it, and keep around the only useful thing which is the `DefId` of the param for `var_for_def`.

This is based on #123006, which removed the special use of `TypeVariableOriginKind::OpaqueInference`, which I'm pretty sure I was the one that added.

r? lcnr or re-roll to types
2024-04-16 01:12:36 +02:00
Daniel Paoliello
32f5ca4be7 Add support for Arm64EC to the Standard Library 2024-04-15 16:05:16 -07:00
Michael Goulet
619e044178 Fix pretty hir for anon consts in diagnostics 2024-04-15 18:48:12 -04:00
Michael Goulet
ecef296a03 Simplify shallow resolver to just fold ty/consts 2024-04-15 18:09:16 -04:00
Michael Goulet
98890be9c4 Rebase fallout 2024-04-15 17:37:56 -04:00
Michael Goulet
05bb3d2683 Just use type_dependent_def_id to figure out what the method is for an expr 2024-04-15 17:14:59 -04:00
Michael Goulet
25c0cf0a66 nits 2024-04-15 16:52:51 -04:00
Michael Goulet
ba6c166ee4 Account for Self params properly 2024-04-15 16:52:50 -04:00
Michael Goulet
eb6f856169 Remove ConstVariableOriginKind 2024-04-15 16:52:12 -04:00
Michael Goulet
34bce07e8e Remove TypeVariableOriginKind 2024-04-15 16:51:50 -04:00
Michael Goulet
ac7651ccaf More polishing 2024-04-15 16:45:48 -04:00
Michael Goulet
52c6b101ea Use a path instead of an ident (and stop manually resolving) 2024-04-15 16:45:26 -04:00
Michael Goulet
ce8961039e Some ordering and duplication checks 2024-04-15 16:45:26 -04:00
Michael Goulet
02d7317af2 Add hir::Node::PreciseCapturingNonLifetimeArg 2024-04-15 16:45:25 -04:00
Michael Goulet
42ba57c013 Validation and other things 2024-04-15 16:45:01 -04:00
Michael Goulet
41cf87b71b Lower and resolve precise captures in HIR 2024-04-15 16:45:01 -04:00
Michael Goulet
c897092654 Implement resolution, parse use<Self> 2024-04-15 16:45:01 -04:00
Michael Goulet
fc9e344874 Use dedicated PreciseCapturingArg for representing what goes in use<> 2024-04-15 16:45:01 -04:00
Michael Goulet
647b672f16 Begin AST lowering for precise captures 2024-04-15 16:45:01 -04:00
Michael Goulet
a076eae0d2 Parsing , pre-lowering support for precise captures 2024-04-15 16:45:01 -04:00
Urgau
a20de73ccf Move --check-cfg documentation to stable books 2024-04-15 21:49:56 +02:00
Urgau
909fcfcb6a Stabilize checking of cfgs at compile-time: --check-cfg option 2024-04-15 21:49:55 +02:00
Michael Goulet
20a5fb3b4a
Rollup merge of #123924 - compiler-errors:tuple-sugg, r=estebank
Fix various bugs in `ty_kind_suggestion`

Consolidates two implementations of `ty_kind_suggestion`
Fixes some misuse of the empty param-env
Fixes a problem where we suggested `(42)` instead of `(42,)` for tuple suggestions
Suggest a value when `return;`, making it consistent with `break;`
Fixes #123906
2024-04-15 15:18:06 -04:00
Michael Goulet
314dee528b
Rollup merge of #123900 - compiler-errors:nobound, r=lcnr
Stop using `PolyTraitRef` for closure/coroutine predicates already instantiated w placeholders

r? lcnr
2024-04-15 15:18:05 -04:00
Ralf Jung
b4a4645758 static_mut_refs: use raw pointers to remove the remaining FIXME 2024-04-15 18:45:56 +02:00
Oli Scherer
67334df1ea The new solver ignores DefineOpaqueTypes, so switch it to Yes
We assert that we are in the new solver in the line above
2024-04-15 16:18:32 +00:00
Michael Goulet
9e630d3f21 PolyTraitRefs -> TraitRefs 2024-04-15 12:04:44 -04:00
许杰友 Jieyou Xu (Joe)
4f3a39ba79
Rollup merge of #123941 - Mark-Simulacrum:fix-llvm-ub, r=nikic
Fix UB in LLVM FFI when passing zero or >1 bundle

Rust passes a `*const &OperandBundleDef` to these APIs, usually from a `Vec<&OperandBundleDef>` or so. Previously we were dereferencing that pointer and passing it to the ArrayRef constructor with some length (N).

This meant that if the length was 0, we were dereferencing a pointer to nowhere (if the vector on the Rust side didn't actually get allocated or so), and if the length was >1 then loading the *second* element somewhere in LLVM would've been reading past the end.

Since Rust can't hold OperandBundleDef by-value we're forced to indirect through a vector that copies out the OperandBundleDefs from the by-reference list on the Rust side in order to match the LLVM expected API.
2024-04-15 16:56:19 +01:00
许杰友 Jieyou Xu (Joe)
5580ae9795
Rollup merge of #123934 - WaffleLapkin:graph-mini-refactor, r=fmease
`rustc_data_structures::graph` mini refactor

Who doesn't love to breathe dust from the ancient times?
2024-04-15 16:56:18 +01:00
许杰友 Jieyou Xu (Joe)
b79d0b0849
Rollup merge of #123933 - RalfJung:large-assignments, r=michaelwoerister
move the LargeAssignments lint logic into its own file

The collector is a file full of very subtle logic, so let's try to keep that separate from the logic that only serves to implement this lint.
2024-04-15 16:56:18 +01:00
许杰友 Jieyou Xu (Joe)
313b02a86b
Rollup merge of #123931 - compiler-errors:variance-unnameables, r=fmease
Don't leak unnameable types in `-> _` recover

Fixes #123899
2024-04-15 16:56:17 +01:00
许杰友 Jieyou Xu (Joe)
1870e2d09f
Rollup merge of #123922 - TDecking:base_n_magic_removal, r=jieyouxu
Remove magic constants when using `base_n`.

Some use cases of `base_n` use number literals instead of the predefined constants. The latter are more descriptive so it might be better to use those instead.
2024-04-15 16:56:17 +01:00
许杰友 Jieyou Xu (Joe)
b1d1e081be
Rollup merge of #123919 - RalfJung:discriminant, r=compiler-errors
builtin-derive: tag → discriminant

As far as I can tell, all of this operates on the discriminant, not the tag. After all, with something like `Option<&T>`, the "tag" of the `Some` variant is basically just the reference value, which is never what you want to compare when figuring out which variant the enum is in.

See [here](https://rustc-dev-guide.rust-lang.org/appendix/glossary.html) for an explanation of the difference between tag and discriminant.
2024-04-15 16:56:16 +01:00
许杰友 Jieyou Xu (Joe)
18e6bb2851
Rollup merge of #123896 - JeanCASPAR:rustc_resolve-to-session-diagnostic, r=jieyouxu
Migrate some diagnostics in `rustc_resolve` to session diagnostic

Hello, I migrated some diagnostics in `rustc_resolve` to session diagnostic.

r? ``@davidtwco``
2024-04-15 16:56:15 +01:00
许杰友 Jieyou Xu (Joe)
699612fb8a
Rollup merge of #123864 - oli-obk:define_opaque_types3, r=compiler-errors
Remove a HACK by instead inferring opaque types during expected/formal type checking

I was wondering why I couldn't come up with a test that hits the code path of the argument check checking the types we inferred from the return type... Turns out we reject those attempts early during fudging.

I have absolutely no information for you as to what kind of type inference changes this may incur, but I think we should just land this out of two reasons:

* had I found the other place to use opaque type inference on before I added the hack, we'd be using that today and this PR would never have happened
* if it is possible to hit this path, it requires some god awful recursive RPIT logic that I doubt anyone would have written without actively trying to write obscure code

r? ``@ghost``
2024-04-15 16:56:15 +01:00
Michael Goulet
d2ec957680 Stop using PolyTraitRef for closure/coroutine predicates already instantiated w placeholders 2024-04-15 10:32:21 -04:00
Maybe Waffle
435db9b9bd Use RPITIT for Successors and Predecessors traits
Now with RPITIT instead of GAT!
2024-04-15 13:34:08 +00:00
bors
d493fd148d Auto merge of #115717 - jsgf:stablize-json-unused-externs, r=oli-obk
Stabilize --json unused-externs(-silent)

Implement https://github.com/rust-lang/compiler-team/issues/674 ~~(pending its approval)~~
2024-04-15 10:11:46 +00:00
bors
5dcb678ad8 Auto merge of #122917 - saethlin:atomicptr-to-int, r=nikic
Add the missing inttoptr when we ptrtoint in ptr atomics

Ralf noticed this here: https://github.com/rust-lang/rust/pull/122220#discussion_r1535172094

Our previous codegen forgot to add the cast back to integer type. The code compiles anyway, because of course all locals are in-memory to start with, so previous codegen would do the integer atomic, store the integer to a local, then load a pointer from that local. Which is definitely _not_ what we wanted: That's an integer-to-pointer transmute, so all pointers returned by these `AtomicPtr` methods didn't have provenance. Yikes.

Here's the IR for `AtomicPtr::fetch_byte_add` on 1.76: https://godbolt.org/z/8qTEjeraY
```llvm
define noundef ptr `@atomicptr_fetch_byte_add(ptr` noundef nonnull align 8 %a, i64 noundef %v) unnamed_addr #0 !dbg !7 {
start:
  %0 = alloca ptr, align 8, !dbg !12
  %val = inttoptr i64 %v to ptr, !dbg !12
  call void `@llvm.lifetime.start.p0(i64` 8, ptr %0), !dbg !28
  %1 = ptrtoint ptr %val to i64, !dbg !28
  %2 = atomicrmw add ptr %a, i64 %1 monotonic, align 8, !dbg !28
  store i64 %2, ptr %0, align 8, !dbg !28
  %self = load ptr, ptr %0, align 8, !dbg !28
  call void `@llvm.lifetime.end.p0(i64` 8, ptr %0), !dbg !28
  ret ptr %self, !dbg !33
}
```

r? `@RalfJung`
cc `@nikic`
2024-04-15 08:07:47 +00:00
Mark Rousskov
bf3deccdad Fix UB in LLVM FFI when passing zero or >1 bundle
Rust passes a *const &OperandBundleDef to these APIs, usually from a
Vec<&OperandBundleDef> or so. Previously we were dereferencing that
pointer and passing it to the ArrayRef constructor with some length (N).

This meant that if the length was 0, we were dereferencing a pointer to
nowhere, and if the length was >1 then loading the *second* element
somewhere in LLVM would've been reading past the end.

Since Rust can't hold OperandBundleDef by-value we're forced to indirect
through a vector that copies out the OperandBundleDefs from the
by-reference list on the Rust side in order to match the LLVM expected
API.
2024-04-14 22:18:33 -04:00
Guillaume Gomez
86b791a272
Rollup merge of #123618 - compiler-errors:overflow-ambig, r=spastorino
Discard overflow obligations in `impl_may_apply`

Hacky fix for #123493. Throws away obligations that are overflowing in `impl_may_apply` when we recompute if an impl applies, since those will lead to fatal overflow if processed during fulfillment.

Something about #114811 (I think it's the predicate reordering) caused us to evaluate predicates differently in error reporting leading to fatal overflow, though I believe the underlying overflow is possible to hit since this code was rewritten to use fulfillment.

Fixes #123493
2024-04-14 23:24:33 +02:00
Jeremy Fitzhardinge
fdcb8a9fea Stabilize --json unused-externs(-silent)
Implement https://github.com/rust-lang/compiler-team/issues/674
2024-04-14 14:20:55 -07:00
ninad
4c8d210ab8 Improve semantics of int_ty_max functions 2024-04-15 00:39:28 +05:30
Ralf Jung
80dc3d14c9 move the LargeAssignments lint logic into its own file 2024-04-14 18:09:44 +02:00
Maybe Waffle
e8d2221e3b Make depth_first_search into a standalone function
Does not necessarily change much, but we never overwrite it, so I see no reason
for it to be in the `Successors` trait. (+we already have a similar `is_cyclic`)
2024-04-14 16:03:08 +00:00
Maybe Waffle
3124fa9310 Document ControlFlowGraph 2024-04-14 15:53:38 +00:00
Maybe Waffle
f5144938bd Rename WithNumEdges => NumEdges and WithStartNode => StartNode 2024-04-14 15:51:29 +00:00
Maybe Waffle
0d5fc9bf58 Merge {With,Graph}{Successors,Predecessors} into {Successors,Predecessors}
Now with GAT!
2024-04-14 15:48:53 +00:00
Maybe Waffle
398da593a5 Merge WithNumNodes into DirectedGraph 2024-04-14 15:46:40 +00:00
Michael Goulet
b09c177743 Don't leak unnameable types in -> _ recover 2024-04-14 11:43:05 -04:00
ninad
757f5bb3dc Fix formatting 2024-04-14 20:29:30 +05:30
ninad
857f5dd475 Don't inline integer literals when out of range 2024-04-14 20:17:44 +05:30
Michael Goulet
325b24d763 Fix 1-tuple value suggestion 2024-04-14 09:42:53 -04:00
Michael Goulet
4af94cfa05 Suggest value on bare return 2024-04-14 09:42:53 -04:00
Michael Goulet
e4c71f1fd8 Fix value suggestion for array in generic context 2024-04-14 09:42:53 -04:00
Michael Goulet
d6ac50e547 Consolidate two copies of ty_kind_suggestion 2024-04-14 09:42:53 -04:00
Tobias Decking
e5cf30cd63
Update v0.rs 2024-04-14 15:01:04 +02:00
Tobias Decking
be7fb2ed55
Update encode.rs 2024-04-14 14:56:41 +02:00
Ralf Jung
ec3ac1dcd6 builtin-derive: tag → discriminant 2024-04-14 11:34:15 +02:00
Matthias Krüger
20656d9202
Rollup merge of #123898 - fmease:gci-cmp-impl-item-lt-params, r=compiler-errors
Generic associated consts: Check regions earlier when comparing impl with trait item def

Fixes #123836.

r? compiler-errors or compiler
2024-04-14 09:01:59 +02:00
bors
af6a1613b3 Auto merge of #123175 - Nilstrieb:debug-strict-overflow, r=wesleywiser
Add add/sub methods that only panic with debug assertions to rustc

This mitigates the perf impact of enabling overflow checks on rustc. The change to use overflow checks will be done in a later PR.

For rust-lang/compiler-team#724, based on data gathered in #119440.
2024-04-13 17:18:42 +00:00
bors
618c300497 Auto merge of #123897 - matthiaskrgr:rollup-v0vvcw2, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #123530 (Enable building tier2 target riscv32im-unknown-none-elf)
 - #123642 (do not allow using local llvm while using rustc from ci)
 - #123716 (Update documentation of Path::to_path_buf and Path::ancestors)
 - #123876 (Update backtrace submodule)
 - #123888 (Replace a `DefiningOpaqueTypes::No` with `Yes` by asserting that one side of the comparison is a type variable.)
 - #123890 (removed (mostly) unused code)
 - #123891 (Miri subtree update)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-04-13 15:15:57 +00:00
León Orell Valerian Liehr
dfbdce01e1
Check regions earlier when comparing impl with trait item def 2024-04-13 17:07:02 +02:00
Nilstrieb
5039160c5b Add add/sub methods that only panic with debug assertions to rustc
This mitigates the perf impact of enabling overflow checks on rustc.
The change to use overflow checks will be done in a later PR.
2024-04-13 17:03:12 +02:00
Matthias Krüger
ab47cb467f
Rollup merge of #123890 - klensy:cl, r=fee1-dead
removed (mostly) unused code

First commit removes unused code, second one - some old debug output, probably unused?
2024-04-13 16:42:06 +02:00
Matthias Krüger
3fb529e726
Rollup merge of #123888 - oli-obk:define_opaque_types4, r=compiler-errors
Replace a `DefiningOpaqueTypes::No` with `Yes` by asserting that one side of the comparison is a type variable.

Thus there will never be an opaque type involved in a way that constrains its hidden type, as the other side of the comparison is always a generator witness type

r? ``@compiler-errors``
2024-04-13 16:42:06 +02:00
Jean CASPAR
992c505021 Reorder error messages 2024-04-13 15:11:09 +01:00
Jean CASPAR
cec9f7f716 Migrate more diagnostics 2024-04-13 14:50:25 +01:00
Jean CASPAR
4226dc2045 Migrate some diagnostics 2024-04-13 14:50:25 +01:00
JeanCASPAR
e4f4e58dc3 Port build_reduce_graph 2024-04-13 14:50:25 +01:00
bors
3a0db6c152 Auto merge of #123854 - petrochenkov:searchdirs2, r=lqd
linker: Remove laziness and caching from native search directory walks

It shouldn't be necessary for performance now.

Follow up to https://github.com/rust-lang/rust/pull/123827.
2024-04-13 13:12:56 +00:00
bors
7106800e16 Auto merge of #123656 - lqd:linker-features, r=petrochenkov
Linker flavors next steps: linker features

This is my understanding of the first step towards `@petrochenkov's` vision for the future of linker flavors, described in https://github.com/rust-lang/rust/pull/119906#issuecomment-1895693162 and the discussion that followed.

To summarize: having `Cc` and `Lld` embedded in linker flavors creates tension about naming, and a combinatorial explosion of flavors for each new linker feature we'd want to use. Linker features are an extension mechanism that is complementary to principal flavors, with benefits described in #119906.

The most immediate use of this flag would be to turn self-contained linking on and off via features instead of flavors. For example, `-Clinker-features=+/-lld` would toggle using lld instead of selecting a precise flavor, and would be "generic" and work cross-platform (whereas linker flavors are currently more tied to targets). Under this scheme, MCP510 is expected to be `-Clink-self-contained=+linker -Zlinker-features=+lld -Zunstable-options` (though for the time being, the original flags using lld-cc flavors still work).

I purposefully didn't add or document CLI support for `+/-cc`, as it would be a noop right now. I only expect that we'd initially want to stabilize `+/-lld` to begin with.

r? `@petrochenkov`

You had requested that minimal churn would be done to the 230 target specs and this does none yet: the linker features are inferred from the flavor since they're currently isomorphic. We of course expect this to change sooner rather than later.

In the future, we can allow targets to define linker features independently from their flavor, and remove the cc and lld components from the flavors to use the features instead, this actually doesn't need to block stabilization, as we discussed.

(Best reviewed per commit)
2024-04-13 11:10:01 +00:00
bors
6eaa7fb576 Auto merge of #122603 - estebank:clone-o-rama, r=lcnr
Detect borrow checker errors where `.clone()` would be an appropriate user action

When a value is moved twice, suggest cloning the earlier move:

```
error[E0509]: cannot move out of type `U2`, which implements the `Drop` trait
  --> $DIR/union-move.rs:49:18
   |
LL |         move_out(x.f1_nocopy);
   |                  ^^^^^^^^^^^
   |                  |
   |                  cannot move out of here
   |                  move occurs because `x.f1_nocopy` has type `ManuallyDrop<RefCell<i32>>`, which does not implement the `Copy` trait
   |
help: consider cloning the value if the performance cost is acceptable
   |
LL |         move_out(x.f1_nocopy.clone());
   |                             ++++++++
```

When a value is borrowed by an `fn` call, consider if cloning the result of the call would be reasonable, and suggest cloning that, instead of the argument:

```
error[E0505]: cannot move out of `a` because it is borrowed
  --> $DIR/variance-issue-20533.rs:53:14
   |
LL |         let a = AffineU32(1);
   |             - binding `a` declared here
LL |         let x = bat(&a);
   |                     -- borrow of `a` occurs here
LL |         drop(a);
   |              ^ move out of `a` occurs here
LL |         drop(x);
   |              - borrow later used here
   |
help: consider cloning the value if the performance cost is acceptable
   |
LL |         let x = bat(&a).clone();
   |                        ++++++++
```

otherwise, suggest cloning the argument:

```
error[E0505]: cannot move out of `a` because it is borrowed
  --> $DIR/variance-issue-20533.rs:59:14
   |
LL |         let a = ClonableAffineU32(1);
   |             - binding `a` declared here
LL |         let x = foo(&a);
   |                     -- borrow of `a` occurs here
LL |         drop(a);
   |              ^ move out of `a` occurs here
LL |         drop(x);
   |              - borrow later used here
   |
help: consider cloning the value if the performance cost is acceptable
   |
LL -         let x = foo(&a);
LL +         let x = foo(a.clone());
   |
```

This suggestion doesn't attempt to square out the types between what's cloned and what the `fn` expects, to allow the user to make a determination on whether to change the `fn` call or `fn` definition themselves.

Special case move errors caused by `FnOnce`:

```
error[E0382]: use of moved value: `blk`
  --> $DIR/once-cant-call-twice-on-heap.rs:8:5
   |
LL | fn foo<F:FnOnce()>(blk: F) {
   |                    --- move occurs because `blk` has type `F`, which does not implement the `Copy` trait
LL |     blk();
   |     ----- `blk` moved due to this call
LL |     blk();
   |     ^^^ value used here after move
   |
note: `FnOnce` closures can only be called once
  --> $DIR/once-cant-call-twice-on-heap.rs:6:10
   |
LL | fn foo<F:FnOnce()>(blk: F) {
   |          ^^^^^^^^ `F` is made to be an `FnOnce` closure here
LL |     blk();
   |     ----- this value implements `FnOnce`, which causes it to be moved when called
```

Account for redundant `.clone()` calls in resulting suggestions:

```
error[E0507]: cannot move out of dereference of `S`
  --> $DIR/needs-clone-through-deref.rs:15:18
   |
LL |         for _ in self.clone().into_iter() {}
   |                  ^^^^^^^^^^^^ ----------- value moved due to this method call
   |                  |
   |                  move occurs because value has type `Vec<usize>`, which does not implement the `Copy` trait
   |
note: `into_iter` takes ownership of the receiver `self`, which moves value
  --> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
help: you can `clone` the value and consume it, but this might not be your desired behavior
   |
LL |         for _ in <Vec<usize> as Clone>::clone(&self).into_iter() {}
   |                  ++++++++++++++++++++++++++++++    ~
```

We use the presence of `&mut` values in a move error as a proxy for the user caring about side effects, so we don't emit a clone suggestion in that case:

```
error[E0505]: cannot move out of `s` because it is borrowed
  --> $DIR/borrowck-overloaded-index-move-index.rs:53:7
   |
LL |     let mut s = "hello".to_string();
   |         ----- binding `s` declared here
LL |     let rs = &mut s;
   |              ------ borrow of `s` occurs here
...
LL |     f[s] = 10;
   |       ^ move out of `s` occurs here
...
LL |     use_mut(rs);
   |             -- borrow later used here
```

We properly account for `foo += foo;` errors where we *don't* suggest `foo.clone() += foo;`, instead suggesting `foo += foo.clone();`.

---

Each commit can be reviewed in isolation. There are some "cleanup" commits, but kept them separate in order to show *why* specific changes were being made, and their effect on tests' output.

Fix #49693, CC #64167.
2024-04-13 09:07:26 +00:00
klensy
7085ff2f60 remove some ancient debug output, looks unused? 2024-04-13 11:30:48 +03:00
Oli Scherer
c6a4f810d9 Replace a DefiningOpaqueTypes::No with Yes by asserting that one side of the comparison is a type variable.
Thus there will never be an opaque type involved in a way that constrains its hidden type, as the other side of the comparison is always a generator witness type
2024-04-13 07:26:47 +00:00
bors
f96442b448 Auto merge of #123257 - ChrisDenton:enable-tls, r=fmease
Re-enable `has_thread_local` for i686-msvc

A few years back, `has_thread_local` was disabled as a workaround for a compiler issue. While the exact cause was never tracked down, it was suspected to be caused by the compiler inlining a thread local access across a dylib boundary. This should be fixed now so let's try again.
2024-04-13 07:03:01 +00:00
Oli Scherer
c9889b02b9 fix coroutine witness doctest 2024-04-13 06:17:07 +00:00
bors
9782770a81 Auto merge of #121430 - madsmtm:mac-catalyst-iOSSupport, r=wesleywiser
Add `/System/iOSSupport` to the library search path on Mac Catalyst

On macOS, `/System/iOSSupport` contains iOS frameworks like UIKit, which is the whole idea of Mac Catalyst.

To link to these, we need to explicitly tell the linker about the support library stubs provided in the macOS SDK under the same path.

Concretely, when building a binary for Mac Catalyst, Xcode passes the following flags to the linker:
```
-iframework /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/System/iOSSupport/System/Library/Frameworks
-L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/System/iOSSupport/usr/lib
```

This is not something that can be disabled (it's enabled as soon as you enable `SUPPORTS_MACCATALYST`), so I think it's pretty safe to say that we don't need an option to turn these off.

I've chosen to slightly deviate from what Xcode does and use `-F` instead of `-iframework`, since we don't need to change the header search path, and this way the flags nicely match on all the linkers. From what I could tell by reading Clang sources, there shouldn't be a difference when just running the linker.

CC `@BlackHoleFox,` `@shepmaster` (I accidentally let rustbot choose the reviewer).
2024-04-12 22:27:33 +00:00
Esteban Küber
4c7213c888 review comments
Added comments and reworded messages
2024-04-12 20:57:07 +00:00
bors
79424056b0 Auto merge of #123869 - matthiaskrgr:rollup-9kif9c9, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #123654 (typeck: fix `?` suggestion span)
 - #123807 (Remove `sys_common::thread`)
 - #123834 (Don't do coroutine-closure-specific upvar analysis if tainted by errors)
 - #123847 (Suppress `let else` suggestion for uninitialized refutable `let`s)
 - #123857 (std::net: TcpListener shrinks the backlog argument to 32 for Haiku.)
 - #123858 (zkvm: fix path to cmath in zkvm module)
 - #123867 (Add `unsafe` to two functions with safety invariants)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-04-12 20:23:30 +00:00
Matthias Krüger
e4c8672571
Rollup merge of #123847 - eggyal:issue-123844, r=fmease
Suppress `let else` suggestion for uninitialized refutable `let`s

Fixes #123844

r? `@CAD97`
2024-04-12 21:46:59 +02:00
Matthias Krüger
1524fe04ad
Rollup merge of #123834 - compiler-errors:async-closure-with-tainted-body, r=oli-obk
Don't do coroutine-closure-specific upvar analysis if tainted by errors

See the comment

Fixes #123821
Fixes #123818
2024-04-12 21:46:58 +02:00
Matthias Krüger
ca28e9554f
Rollup merge of #123654 - jieyouxu:question-mark-span, r=Nadrieril
typeck: fix `?` suggestion span

Noticed in <https://github.com/rust-lang/rust/pull/112043#issuecomment-2043565292>, if the

```
use the `?` operator to extract the `Result<(), std::fmt::Error>` value, propagating a `Result::Err` value to the caller
```

suggestion is applied to a macro that comes from a non-local crate (e.g. the stdlib), the suggestion span can become non-local, which will cause newer rustfix versions to fail.

This PR tries to remedy the problem by recursively probing ancestors of the expression span, trying to identify the most ancestor span that is (1) still local, and (2) still shares the same syntax context as the expression.

This is the same strategy used in https://github.com/rust-lang/rust/pull/112043.

The test unfortunately cannot `//@ run-rustfix` because there are two conflicting MaybeIncorrect suggestions that when collectively applied, cause the fixed source file to become non-compilable.

Also avoid running `//@ run-rustfix` for `tests/ui/typeck/issue-112007-leaked-writeln-macro-internals.rs` because that also contains conflicting suggestions.

cc `@ehuss` who noticed this. This question mark span fix + not running rustfix on the tests containing conflicting MaybeIncorrect suggestions should hopefully unblock rustfix from updating.
2024-04-12 21:46:57 +02:00
bors
22a2425c10 Auto merge of #121426 - madsmtm:remove-cc-syslibroot, r=pnkfelix
Remove redundant `-Wl,-syslibroot`

Since `-isysroot` is set, [Clang already passes this when invoking the linker](https://github.com/llvm/llvm-project/blob/llvmorg-17.0.6/clang/lib/Driver/ToolChains/Darwin.cpp#L439-L442).

See https://github.com/rust-lang/rust/pull/56833 for when the `-isysroot` was originally added, but didn't remove the unnecessary linker flag.

CC `@BlackHoleFox`
r? shepmaster
2024-04-12 18:16:47 +00:00
Alan Egerton
ddcfb94b84
Suppress erroneous suggestion
The suggestion to use `let else` with an uninitialized refutable `let`
statement was erroneous: `let else` cannot be used with deferred
initialization.
2024-04-12 17:45:15 +01:00
Oli Scherer
24653a5664 Remove a HACK by instead inferring opaque types during expected/formal type checking 2024-04-12 16:17:31 +00:00
Oli Scherer
0c6077984f Avoid an intermediate Option and just create the resulting enum directly 2024-04-12 16:16:40 +00:00
Michael Goulet
49e73c3e01 Don't do coroutine-closure-specific upvar analysis if tainted by errors 2024-04-12 12:14:29 -04:00
Matthias Krüger
38283bc295
Rollup merge of #123849 - JimmyOhn:first_contribution, r=pnkfelix
Update E0384.md

Add an example for the shadowing usage.
2024-04-12 17:41:35 +02:00
Matthias Krüger
15a8b490ea
Rollup merge of #123841 - Kohei316:remove_qualifier_sugg, r=wesleywiser
Improve diagnostic by suggesting to remove visibility qualifier

Resolves #123529
This PR improve diagnostic by suggesting to remove visibility qualifier.
2024-04-12 17:41:35 +02:00
Matthias Krüger
4a0e9e0deb
Rollup merge of #123249 - goolmoos:naked_variadics, r=pnkfelix
do not add prolog for variadic naked functions

fixes #99858
2024-04-12 17:41:33 +02:00
Matthias Krüger
68359e2284
Rollup merge of #123223 - estebank:issue-123079, r=pnkfelix
Fix invalid silencing of parsing error

Given

```rust
macro_rules! a {
    ( ) => {
        impl<'b> c for d {
            e::<f'g>
        }
    };
}
```

ensure an error is emitted.

Fix #123079.
2024-04-12 17:41:33 +02:00
Matthias Krüger
ffea7e2a9b
Rollup merge of #123204 - notriddle:notriddle/include-str-span, r=pnkfelix
rustdoc: point at span in `include_str!`-ed md file

Fixes #118549
2024-04-12 17:41:32 +02:00
klensy
aff5f47dce remove dead code 2024-04-12 17:54:35 +03:00
Vadim Petrochenkov
ed62b57c86 linker: Remove laziness and caching from native search directory walks
It shouldn't be necessary for performance now.
2024-04-12 17:28:00 +03:00
Jimmy Ohn
0b5653f098 Update compiler/rustc_error_codes/src/error_codes/E0384.md
Add an example for the shadowing usage.
2024-04-12 22:43:38 +09:00
Guy Shefy
9139d7252d do not add prolog for variadic naked functions
fixes #99858
2024-04-12 15:29:39 +03:00
Rémy Rakic
11b6d40a98 make CLI linker features influence the linker flavor
While they're isomorphic, we can flip the lld component where
applicable, so that downstream doesn't have to check both the flavor and
the linker features.
2024-04-12 09:46:38 +00:00
Rémy Rakic
2398d8cf08 add -Z linker-features to toggle lld on the CLI
but don't expose `+/-cc` yet
2024-04-12 09:43:05 +00:00
Rémy Rakic
695aac2c02 introduce LinkerFeatures
They are a flexible complementary mechanism to linker flavors,
that also avoid the combinatorial explosion of mapping linking features
to actual linker flavors.
2024-04-12 09:43:05 +00:00
Rémy Rakic
c39929ce18 remove some unnecessary lifetimes 2024-04-12 09:43:05 +00:00
bors
ab71ee7a92 Auto merge of #123736 - compiler-errors:multiply-on-rhs, r=estebank
Don't delay a bug if we suggest adding a semicolon to the RHS of an assign operator

It only makes sense to delay a bug based on the assumption that "[we] defer to the later error produced by `check_lhs_assignable`" *if* the expression we're erroring actually is an LHS; otherwise, we should still report the error since it's both useful and required.

Fixes #123722
2024-04-12 08:41:20 +00:00
Esteban Küber
dea9b5031c Better account for more cases involving closures 2024-04-12 04:46:31 +00:00
Esteban Küber
3cdc6897c5 Fix rebase 2024-04-12 04:45:50 +00:00
morine0122
ac1bee6493 Improve diagnostic by suggesting to remove visibility qualifier 2024-04-12 12:59:40 +09:00
Matthias Krüger
7f111834ad
Rollup merge of #123827 - petrochenkov:searchdirs, r=Nadrieril
linker: Avoid some allocations in search directory iteration

This is more a cleanup than actual optimization.
2024-04-12 04:38:23 +02:00
Matthias Krüger
41a294dd2b
Rollup merge of #123789 - klensy:rq, r=cjgillot
move QueryKeyStringCache from rustc_middle to rustc_query_impl, where it actually used

Also allows to drop measureme dep on rustc_middle.
2024-04-12 04:38:22 +02:00
Matthias Krüger
f4f644182b
Rollup merge of #123775 - scottmcm:place-val, r=cjgillot
Make `PlaceRef` and `OperandValue::Ref` share a common `PlaceValue` type

Both `PlaceRef` and `OperandValue::Ref` need the triple of the backend pointer immediate, the optional backend metadata for DSTs, and the actual alignment of the place (since it can differ from the ABI alignment).

This PR introduces a new `PlaceValue` type for those three values, leaving [`PlaceRef`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_codegen_ssa/mir/place/struct.PlaceRef.html) with the `TyAndLayout` and a `PlaceValue`, just like how [`OperandRef`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_codegen_ssa/mir/operand/struct.OperandRef.html) is a `TyAndLayout` and an `OperandValue`.

This means that various places that use `Ref`s as places can just pass the `PlaceValue` along, like in the below excerpt from the diff:
```diff
        match operand.val {
-            OperandValue::Ref(ptr, meta, align) => {
-                debug_assert_eq!(meta, None);
+            OperandValue::Ref(source_place_val) => {
+                debug_assert_eq!(source_place_val.llextra, None);
                debug_assert!(matches!(operand_kind, OperandValueKind::Ref));
-                let fake_place = PlaceRef::new_sized_aligned(ptr, cast, align);
+                let fake_place = PlaceRef { val: source_place_val, layout: cast };
                Some(bx.load_operand(fake_place).val)
            }
```

There's more refactoring that I'd like to do after this, but I wanted to stop the PR here where it's hopefully easy (albeit probably not quick) to review since I tried to keep every change line-by-line clear.  (Most are just adding `.val` to get to a field.)

You can also go commit-at-a-time if you'd like.  Each passed tidy and the codegen tests on my machine (though I didn't run the cg_gcc ones).
2024-04-12 04:38:21 +02:00
Matthias Krüger
6f78bf2322
Rollup merge of #123599 - matthiaskrgr:rm, r=cjgillot
remove some things that do not need to be
2024-04-12 04:38:21 +02:00
bors
a07f3eb43a Auto merge of #123823 - matthiaskrgr:rollup-8zdtggx, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #122882 (Avoid a panic in `set_output_capture` in the default panic handler)
 - #123523 (Account for trait/impl difference when suggesting changing argument from ref to mut ref)
 - #123744 (Silence `unused_imports` for redundant imports)
 - #123784 (Replace `document.write` with `document.head.insertAdjacent`)
 - #123798 (Avoid invalid socket address in length calculation)
 - #123804 (Stop using `HirId` for fn-like parents since closures are not `OwnerNode`s)
 - #123806 (Panic on overflow in `BorrowedCursor::advance`)
 - #123820 (Add my former address to .mailmap)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-04-11 21:56:11 +00:00
Vadim Petrochenkov
4ded0b82ca linker: Avoid some allocations in search directory iteration 2024-04-12 00:41:08 +03:00
Matthias Krüger
17a8ee636f
Rollup merge of #123804 - compiler-errors:podcrab-fix, r=jieyouxu
Stop using `HirId` for fn-like parents since closures are not `OwnerNode`s

This is a minimal fix for #123273.

I'm overall pretty disappointed w/ the state of this code; although it's "just diagnostics", it still should be maintainable and understandable and neither of those are true. I believe this code really needs some major overhauling before anything more should be added to it, because there are subtle invariants that are being exercised and subsequently broken all over the place, and I don't think we should just paper over them (e.g.) by delaying bugs or things like that. I wouldn't be surprised if fixing up this code would also yield better diagnostics.
2024-04-11 22:38:56 +02:00
Matthias Krüger
da75aaf13d
Rollup merge of #123744 - compiler-errors:redundant-due-to-glob, r=petrochenkov
Silence `unused_imports` for redundant imports

Quick fix for https://github.com/rust-lang/rust/issues/121708#issuecomment-2048105393

r? `@petrochenkov` cc `@joshtriplett`

I think this is right, would like confirmation. I also think it's weird that we're using `=` to assign to `is_redundant` but using `per_ns` for the actual spans. Seems like this could be weirdly order dependent, but that's unrelated to this change.
2024-04-11 22:38:54 +02:00
Matthias Krüger
ec91d71a38
Rollup merge of #123523 - estebank:issue-123414, r=BoxyUwU
Account for trait/impl difference when suggesting changing argument from ref to mut ref

Do not ICE when encountering a lifetime error involving an argument with an immutable reference of a method that differs from the trait definition.

Fix #123414.
2024-04-11 22:38:54 +02:00
Matthias Krüger
f9ca213510 remove some things that do not need to be 2024-04-11 21:09:52 +02:00
Michael Goulet
0db2a4010a Silence unused_imports lint for redundant imports 2024-04-11 14:38:21 -04:00
Matthias Krüger
08ebea2d7a
Rollup merge of #123777 - oli-obk:operator_cleanup, r=jieyouxu
Deduplicate some function implementations between the parser and AST/HIR

These functions already existed on parser binops, so just convert back to them back and invoke the equivalent method.
2024-04-11 20:20:51 +02:00
Matthias Krüger
074269f7a1
Rollup merge of #123740 - veera-sivarajan:reduce-size-of-modifierinfo, r=petrochenkov
Reduce Size of `ModifierInfo`

I added `ModifierInfo` in #121940 and had used a `u64` for  the `size` field even though the largest value it holds is `512`.

This PR changes the type of the `size` field to `u16`.
2024-04-11 20:20:50 +02:00
Esteban Küber
d97d2fe744 Mention when the type of the moved value doesn't implement Clone 2024-04-11 16:41:42 +00:00
Esteban Küber
d578ac9e47 Account for move error in the spread operator on struct literals
We attempt to suggest an appropriate clone for move errors on expressions
like `S { ..s }` where a field isn't `Copy`. If we can't suggest, we still don't
emit the incorrect suggestion of `S { ..s }.clone()`.

```
error[E0509]: cannot move out of type `S<K>`, which implements the `Drop` trait
  --> $DIR/borrowck-struct-update-with-dtor.rs:28:19
   |
LL |         let _s2 = S { a: 2, ..s0 };
   |                   ^^^^^^^^^^^^^^^^
   |                   |
   |                   cannot move out of here
   |                   move occurs because `s0.c` has type `K`, which does not implement the `Copy` trait
   |
help: clone the value from the field instead of using the spread operator syntax
   |
LL |         let _s2 = S { a: 2, c: s0.c.clone(), ..s0 };
   |                           +++++++++++++++++
```
```
error[E0509]: cannot move out of type `S<()>`, which implements the `Drop` trait
  --> $DIR/borrowck-struct-update-with-dtor.rs:20:19
   |
LL |         let _s2 = S { a: 2, ..s0 };
   |                   ^^^^^^^^^^^^^^^^
   |                   |
   |                   cannot move out of here
   |                   move occurs because `s0.b` has type `B`, which does not implement the `Copy` trait
   |
note: `B` doesn't implement `Copy` or `Clone`
  --> $DIR/borrowck-struct-update-with-dtor.rs:4:1
   |
LL | struct B;
   | ^^^^^^^^
help: if `B` implemented `Clone`, you could clone the value from the field instead of using the spread operator syntax
   |
LL |         let _s2 = S { a: 2, b: s0.b.clone(), ..s0 };
   |                           +++++++++++++++++
```
2024-04-11 16:41:42 +00:00
Esteban Küber
4ca876b7a4 Better account for FnOnce in move errors
```
error[E0382]: use of moved value: `blk`
  --> $DIR/once-cant-call-twice-on-heap.rs:8:5
   |
LL | fn foo<F:FnOnce()>(blk: F) {
   |                    --- move occurs because `blk` has type `F`, which does not implement the `Copy` trait
LL |     blk();
   |     ----- `blk` moved due to this call
LL |     blk();
   |     ^^^ value used here after move
   |
note: `FnOnce` closures can only be called once
  --> $DIR/once-cant-call-twice-on-heap.rs:6:10
   |
LL | fn foo<F:FnOnce()>(blk: F) {
   |          ^^^^^^^^ `F` is made to be an `FnOnce` closure here
LL |     blk();
   |     ----- this value implements `FnOnce`, which causes it to be moved when called
```
2024-04-11 16:41:42 +00:00
Esteban Küber
dfe28debb9 Account for assign binops in clone suggestions
Explicitly look for `expr += other_expr;` and avoid suggesting
`expr.clone() += other_expr;`, instead suggesting `expr += other_expr.clone();`.
2024-04-11 16:41:41 +00:00
Esteban Küber
a1a3abb08f When possible, suggest cloning the result of a call instead of an argument
```
error[E0505]: cannot move out of `a` because it is borrowed
  --> $DIR/variance-issue-20533.rs:28:14
   |
LL |         let a = AffineU32(1);
   |             - binding `a` declared here
LL |         let x = foo(&a);
   |                     -- borrow of `a` occurs here
LL |         drop(a);
   |              ^ move out of `a` occurs here
LL |         drop(x);
   |              - borrow later used here
   |
help: consider cloning the value if the performance cost is acceptable
   |
LL |         let x = foo(&a).clone();
   |                        ++++++++
```
2024-04-11 16:41:41 +00:00
Esteban Küber
7f7f6792f1 Do not recomment cloning explicit &mut expressions 2024-04-11 16:41:41 +00:00
Esteban Küber
5a7caa3174 Fix accuracy of T: Clone check in suggestion 2024-04-11 16:41:41 +00:00
Esteban Küber
259348cf7e Remove unnecessary argument from suggest_cloning 2024-04-11 16:41:41 +00:00
Esteban Küber
01b810e052 Silence redundant clone suggestion 2024-04-11 16:41:41 +00:00
Esteban Küber
065454dd1d More move error suggestions to clone
```
error[E0507]: cannot move out of `val`, a captured variable in an `FnMut` closure
  --> $DIR/issue-87456-point-to-closure.rs:10:28
   |
LL |     let val = String::new();
   |         --- captured outer variable
LL |
LL |     take_mut(|| {
   |              -- captured by this `FnMut` closure
LL |
LL |         let _foo: String = val;
   |                            ^^^ move occurs because `val` has type `String`, which does not implement the `Copy` trait
   |
help: consider borrowing here
   |
LL |         let _foo: String = &val;
   |                            +
help: consider cloning the value if the performance cost is acceptable
   |
LL |         let _foo: String = val.clone();
   |                               ++++++++
```
2024-04-11 16:41:41 +00:00
Esteban Küber
10c2fbec24 Suggest .clone() in some move errors
```
error[E0507]: cannot move out of `*x` which is behind a shared reference
  --> $DIR/borrowck-fn-in-const-a.rs:6:16
   |
LL |         return *x
   |                ^^ move occurs because `*x` has type `String`, which does not implement the `Copy` trait
   |
help: consider cloning the value if the performance cost is acceptable
   |
LL -         return *x
LL +         return x.clone()
   |
```
2024-04-11 16:41:41 +00:00
Esteban Küber
bce78102c3 Account for unops when suggesting cloning 2024-04-11 16:41:41 +00:00
Esteban Küber
fa2fc3ab96 Suggest .clone() when moved while borrowed 2024-04-11 16:41:41 +00:00
Esteban Küber
5eb573a343 Account for .clone() when suggesting <T as Clone>::clone 2024-04-11 16:41:40 +00:00
Michael Goulet
68d7c837fc Stop using HirId for fn-like parents 2024-04-11 11:56:47 -04:00
bors
df7daa815f Auto merge of #123795 - matthiaskrgr:rollup-deesd9c, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #123660 (Make the computation of `coroutine_captures_by_ref_ty` more sophisticated)
 - #123738 (Call lower_const_param instead of duplicating the code)
 - #123774 (Fix typo MaybeUnit -> MaybeUninit)
 - #123790 (correct the handling of `bootstrap-cache-path` option)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-04-11 15:46:42 +00:00
Amanda Stjerna
800c50608c Slightly more readable NLL/constraint graph dumps 2024-04-11 17:14:35 +02:00
Matthias Krüger
8c13ff768c
Rollup merge of #123774 - Lee-Janggun:master, r=lqd
Fix typo MaybeUnit -> MaybeUninit
2024-04-11 16:57:41 +02:00
Matthias Krüger
c71a50d1fa
Rollup merge of #123738 - spastorino:reuse-lower-const-param, r=compiler-errors
Call lower_const_param instead of duplicating the code

Follow up of #123689

r? `@oli-obk`

I had this commit in my old branch that I had forgotten about, `@fmease` pointed about this in #123689

I've left the branches that are not `Range` as do nothing as that's what we are currently doing but maybe we want to err or something.
2024-04-11 16:57:40 +02:00
Matthias Krüger
ee73660368
Rollup merge of #123660 - compiler-errors:coroutine-closure-env, r=oli-obk
Make the computation of `coroutine_captures_by_ref_ty` more sophisticated

Currently, we treat all the by-(mut/)ref borrows of a coroutine-closure as having a "closure env" borrowed lifetime.

When we have the given code:
```rust
let x: &'a i32 = ...;
let c = async || {
    let _x = *x;
};
```

Then when we call:
```rust
c()
// which, because `AsyncFn` takes a `&self`, we insert an autoref:
(&c /* &'env {coroutine-closure} */)()
```

We will return a future whose captures contain `&'env i32` instead of `&'a i32`, which is way more restrictive than necessary. We should be able to drop `c` while the future is alive since it's not actually borrowing any data *originating from within* the closure's captures, but since the capture has that `'env` lifetime, this is not possible.

This wouldn't be true, for example, if the closure captured `i32` instead of `&'a i32`, because the `'env` lifetime is actually *necessary* since the data (`i32`) is owned by the closure.

This PR identifies two criteria where we *need* to take the borrow with the closure env lifetime:
1. If the closure borrows data from inside the closure's captures. This is not true if the parent capture is by-ref, OR if the parent capture is by-move and the child capture begins with a deref projection. This is the example described above.
2. If we're dealing with mutable references, since we cannot reborrow `&'env mut &'a mut i32` into `&'a mut i32`, *only* `&'env mut i32`.

See the documentation on `should_reborrow_from_env_of_parent_coroutine_closure` for more info.

**important:** As disclaimer states on that function, luckily, if this heuristic is not correct, then the program is not unsound, since we still borrowck and validate the choices made from this function -- the only side-effect is that the user may receive unnecessary borrowck errors.

Fixes #123241
2024-04-11 16:57:40 +02:00
bors
72fe8a0f00 Auto merge of #123788 - bjorn3:disable_ctrlc_on_wasi, r=Nilstrieb,lcnr
Disable Ctrl-C handling on WASM

WASM fundamentally doesn't support signals. If WASI ever gets support for notifying the guest process of a Ctrl-C that happened, this would have to be done through the guest process polling for the signal, which will require thread support in WASI too to be compatible with the api provided by the ctrlc crate.
2024-04-11 13:43:14 +00:00
Santiago Pastorino
d51fda8bec
Call lower_const_param instead of duplicating the code 2024-04-11 09:49:01 -03:00