Commit Graph

38601 Commits

Author SHA1 Message Date
Matthias Krüger
25fc71b7a1
Rollup merge of #128795 - zachs18:e0517-update-for-rfc-2195, r=jieyouxu
Update E0517 message to reflect RFC 2195.

E0517 occurs when a `#[repr(..)]` attribute is placed on an unsupported item. Currently, the explanation of the error implies that `#[repr(u*/i*)]` cannot be placed on fieldful enums, which is no longer the case since [RFC 2195](https://github.com/rust-lang/rfcs/pull/2195) was [stabilized](https://github.com/rust-lang/rust/issues/60553), which allows placing `#[repr(u*/i*)]` and/or `#[repr(C)]` on fieldful enums to produce a defined layout.

This PR doesn't (currently) add a description of the semantics of placing `#[repr(u*/i*)]` on a fieldful enum to the error explanation, it just removes the claims/implications that it is not allowed.
2024-08-08 18:57:02 +02:00
Matthias Krüger
2d7075cf00
Rollup merge of #128612 - compiler-errors:validate-mir-opt-mir, r=davidtwco
Make `validate_mir` ensure the final MIR for all bodies

A lot of the crashes tests use `-Zpolymorphize` or `-Zdump-mir` for their side effect of computing the `optimized_mir` for all bodies, which will uncover bugs with late MIR passes like the inliner. I don't like having all these tests depend on `-Zpolymorphize` (or other hacky ways) for no reason, so this PR extends the `-Zvalidate-mir` flag to ensure `optimized_mir`/`mir_for_ctfe` for all body owners during the analysis phase.

Two thoughts:
1. This could be moved later in the compilation pipeline I guess? I don't really think it matters, though.
1. This could alternatively be expressed using a new flag, though I don't necessarily see much value in separating these.

For example, #128171 could have used this flag, in the `tests/ui/polymorphization/inline-incorrect-early-bound.rs`.

r? mir
2024-08-08 18:57:00 +02:00
Michael Goulet
b916431976 Rename struct_tail_erasing_lifetimes to struct_tail_for_codegen 2024-08-08 12:15:16 -04:00
Michael Goulet
f81549c9ca Normalize struct tail properly in disalignment check 2024-08-08 11:58:11 -04:00
Michael Goulet
d9dd5509dc Normalize when computing offset_of for slice tail 2024-08-08 11:58:11 -04:00
Michael Goulet
85b5e42d5e Do normalize when computing struct tails in codegen 2024-08-08 11:58:11 -04:00
Esteban Küber
95c1c34fff review comments 2024-08-08 14:58:52 +00:00
Esteban Küber
ae696f847d Split ColorConfig off of HumanReadableErrorType
The previous setup tied two unrelated things together. Splitting these two is a better model.
2024-08-08 14:41:33 +00:00
Alex Macleod
9289f5691b Only suggest #[allow] for --warn and --deny lint level flags 2024-08-08 13:09:58 +00:00
Guillaume Gomez
6d69b2e408 Update compiler-builtins version to 0.1.118 2024-08-08 14:47:49 +02:00
bohan
9c29e0b818 rm declared_features field in resolver 2024-08-08 20:30:20 +08:00
Nadrieril
09ae438eb0 Add Steal::is_stolen() 2024-08-08 12:11:05 +02:00
bors
d3a393932e Auto merge of #128465 - GrigorenkoPV:128200, r=estebank
Some `const { }` asserts for #128200

The correctness of code in #128200 relies on an array being sorted (so that it can be used in binary search later), which is currently enforced with `// tidy-alphabetical` (and characters being written in `\u{XXXX}` form), as well as lack of duplicate entries with conflicting keys, which is not currently enforced.

This PR changes it to using a `const{ }` assertion (and also checks for duplicate entries). Sadly, we cannot use the recently-stabilized `is_sorted_by_key` here, because it is not const (but it would not allow us to check for uniqueness anyways). Instead, let's write a manual loop.

Alternative approach (perfect hash function): #128463

r? `@ghost`
2024-08-08 09:59:09 +00:00
Zachary S
7869400e58 Update E0517 message to reflect RFC 2195. 2024-08-07 23:11:30 -05:00
bors
9337f7afa6 Auto merge of #128805 - tgross35:rollup-wajzi6w, r=tgross35
Rollup of 7 pull requests

Successful merges:

 - #128520 (Skip over args when determining if async-closure's inner coroutine consumes its upvars)
 - #128552 (Emit an error for invalid use of the `#[no_sanitize]` attribute)
 - #128691 (Update `compiler-builtins` to 0.1.117)
 - #128702 (Add -Zmetrics-dir=PATH to save diagnostic metadata to disk)
 - #128797 (Fuchsia Test Runner: enable ffx repository server)
 - #128798 (refactor(rustc_expand::mbe): Don't require full ExtCtxt when not necessary)
 - #128800 (Add tracking issue to core-pattern-type)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-08-08 04:10:56 +00:00
Trevor Gross
fbbabb9d15
Rollup merge of #128798 - futile:refactor/mbe-diagnostics, r=petrochenkov
refactor(rustc_expand::mbe): Don't require full ExtCtxt when not necessary

Refactor `mbe::diagnostics::failed_to_match_macro()` to not require a full `ExtCtxt`, but only a `&ParseSess`. It hard-required the `ExtCtxt` only for a call to `cx.trace_macros_diag()`, which we move instead to the only call-site of the function.

Note: This could be a potential change in observed behavior, because a call to `cx.trace_macros_diag()` now always happens after `failed_to_match_macro()` was called, where before it was only called at the end of the main return path of the function. But since `trace_macros_diag()` "flushes" out any not-yet-reported errors, it should be ok to call it for all paths, since there shouldn't be any on the non-main paths I think. However, I don't know the rest of the codebase well enough to say that with 100% confidence, but `tests/ui` still pass, which gives at least some confidence in the change.

Also concretize the return type from `Box<dyn MacResult>` to `(Span, ErrorGuaranteed)`, because this function will _always_ return an error, and never any other kind of result.

Was part of #128605 and #128747, but is a standalone refactoring.

r? ``@petrochenkov``
2024-08-07 20:49:05 -05:00
Trevor Gross
ca5e8a7c4d
Rollup merge of #128702 - yaahc:metrics-flag, r=estebank
Add -Zmetrics-dir=PATH to save diagnostic metadata to disk

r? ``@estebank``
2024-08-07 20:49:03 -05:00
Trevor Gross
6c2e06746d
Rollup merge of #128552 - s7tya:check-no-sanitize-attribute-pos, r=BoxyUwU
Emit an error for invalid use of the `#[no_sanitize]` attribute

fixes #128487.

Currently, the use of the `#[no_sanitize]` attribute for Mod, Impl,... is incorrectly permitted. This PR will correct this issue by generating errors, and I've also added some UI test cases for it.

Referenced #128458. As far as I know, the `#[no_sanitize]` attribute can only be used with functions, so I changed that part to `Fn` and `Method` using `check_applied_to_fn_or_method`. However, I couldn't find explicit documentation on this, so I could be mistaken...
2024-08-07 20:49:02 -05:00
Trevor Gross
2a177c2047
Rollup merge of #128520 - compiler-errors:more-precisely-force-move, r=BoxyUwU
Skip over args when determining if async-closure's inner coroutine consumes its upvars

#125306 implements a strategy for when we have an `async move ||` async-closure that is inferred to be `async FnOnce`, it will force the inner coroutine to also be `move`, since we cannot borrow any upvars from the parent async-closure (since `FnOnce` is not lending):

8e86c95671/compiler/rustc_hir_typeck/src/upvar.rs (L211-L229)

However, when this strategy was implemented, it reused the `ExprUseVisitor` data from visiting the whole coroutine, which includes additional statements due to `async`-specific argument desugaring:

8e86c95671/compiler/rustc_ast_lowering/src/item.rs (L1197-L1228)

Well, it turns out that we don't care about these argument desugaring parameters, because arguments to the async-closure are not the *async-closure*'s captures -- they exist for only one invocation of the closure, and they're always consumed by construction (see the argument desugaring above), so they will force the coroutine's inferred kind to `FnOnce`. (Unless they're `Copy`, because we never consider `Copy` types to be consumed):

8e86c95671/compiler/rustc_hir_typeck/src/expr_use_visitor.rs (L60-L66)

However, since we *were* visiting these arg exprs, this resulted in us too-aggressively applying `move` to the inner coroutine, resulting in regressions. For example, this PR fixes #128516. Fascinatingly, the note above about how we never consume `Copy` types is why this only regressed when the argument types weren't all `Copy`.

I tried to leave some comments inline to make this more clear :)
2024-08-07 20:49:02 -05:00
bors
0d65e5a180 Auto merge of #128550 - compiler-errors:shadowed-params-perf, r=petrochenkov
Only walk ribs to collect possibly shadowed params if we are adding params in our new rib

No need to collect params from parent ribs if we literally have no params to declare in this new rib.

Attempt to win back some of the perf in https://github.com/rust-lang/rust/pull/128357#issuecomment-2262677031.

Please review with whitespace *off*, the diff should be like 2 lines.

r? petrochenkov
2024-08-08 01:46:21 +00:00
bors
8b3870784f Auto merge of #128796 - matthiaskrgr:rollup-r7l68ph, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #128221 (Add implied target features to target_feature attribute)
 - #128261 (impl `Default` for collection iterators that don't already have it)
 - #128353 (Change generate-copyright to generate HTML, with cargo dependencies included)
 - #128679 (codegen: better centralize function declaration attribute computation)
 - #128732 (make `import.vis` is immutable)
 - #128755 (Integrate crlf directly into related test file instead via of .gitattributes)
 - #128772 (rustc_codegen_ssa: Set architecture for object crate for 32-bit SPARC)
 - #128782 (unused_parens: do not lint against parens around &raw)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-08-07 20:00:29 +00:00
Felix Rath
a70c9e1f86 refactor(rustc_expand::mbe): Don't require full ExtCtxt when not necessary 2024-08-07 21:58:05 +02:00
Matthias Krüger
aba506b12a
Rollup merge of #128782 - RalfJung:raw-addr-of-parens, r=compiler-errors
unused_parens: do not lint against parens around &raw

Requested by `@tmandry` in https://github.com/rust-lang/rust/pull/127679: with `&raw` one somewhat regularly has to write code like `(&raw const (*myptr).field).method()`, so parentheses around the expression are often required. To avoid churn between adding and removing parentheses as method calls appear and disappear, the proposal was made to silence the lint for unnecessary parentheses around `&raw` expressions. This PR implements that.
2024-08-07 20:28:20 +02:00
Matthias Krüger
04ab8e385c
Rollup merge of #128772 - glaubitz:sparc-elf-fix, r=nagisa
rustc_codegen_ssa: Set architecture for object crate for 32-bit SPARC

The `object` crate was recently updated to recognize the 32-bit SPARC ELF targets `EM_SPARC` and `EM_SPARC32PLUS`, so the proper architecture for 32-bit SPARC can now be set in `rustc_codegen_ssa`.

r? nagisa
2024-08-07 20:28:19 +02:00
Matthias Krüger
8f5b50d4ba
Rollup merge of #128732 - bvanjoi:immutable-import-vis, r=petrochenkov
make `import.vis` is immutable

r? `@petrochenkov`
2024-08-07 20:28:18 +02:00
Matthias Krüger
8f39b86a6a
Rollup merge of #128679 - RalfJung:codegen-fn-attrs, r=nikic
codegen: better centralize function declaration attribute computation

For some reason, the codegen backend has two functions that compute which attributes a function declaration gets: `apply_attrs_llfn` and `attributes::from_fn_attrs`. They are called in different places, on entirely different layers of abstraction.

To me the code seems cleaner if we centralize this entirely in `apply_attrs_llfn`, so that's what this PR does.
2024-08-07 20:28:18 +02:00
Matthias Krüger
904f5795a0
Rollup merge of #128221 - calebzulawski:implied-target-features, r=Amanieu
Add implied target features to target_feature attribute

See [zulip](https://rust-lang.zulipchat.com/#narrow/stream/208962-t-libs.2Fstdarch/topic/Why.20would.20target-feature.20include.20implied.20features.3F) for some context.  Adds implied target features, e.g. `#[target_feature(enable = "avx2")]` acts like `#[target_feature(enable = "avx2,avx,sse4.2,sse4.1...")]`.  Fixes #128125, fixes #128426

The implied feature sets are taken from [the rust reference](https://doc.rust-lang.org/reference/attributes/codegen.html?highlight=target-fea#x86-or-x86_64), there are certainly more features and targets to add.

Please feel free to reassign this to whoever should review it.

r? ``@Amanieu``
2024-08-07 20:28:16 +02:00
Jane Losare-Lusby
5212c75907 Add -Zerror-metrics=PATH to save diagnostic metadata to disk 2024-08-07 11:16:55 -07:00
Ralf Jung
273c67db83 codegen: better centralize function attribute computation 2024-08-07 19:49:48 +02:00
bors
ce20e15f01 Auto merge of #126158 - Urgau:disallow-cfgs, r=petrochenkov
Disallow setting some built-in cfg via set the command-line

This PR disallow users from setting some built-in cfg via set the command-line in order to prevent incoherent state, eg. `windows` cfg active but target is Linux based.

This implements MCP https://github.com/rust-lang/compiler-team/issues/610, with the caveat that we disallow cfgs no matter if they make sense or not, since I don't think it's useful to allow users to set a cfg that will be set anyway. It also complicates the implementation.

------

The `explicit_builtin_cfgs_in_flags` lint detects builtin cfgs set via the `--cfg` flag.

*(deny-by-default)*

### Example

```text
rustc --cfg unix
```

```rust,ignore (needs command line option)
fn main() {}
```

This will produce:

```text
error: unexpected `--cfg unix` flag
  |
  = note: config `unix` is only supposed to be controlled by `--target`
  = note: manually setting a built-in cfg can and does create incoherent behaviours
  = note: `#[deny(explicit_builtin_cfgs_in_flags)]` on by default
```

### Explanation

Setting builtin cfgs can and does produce incoherent behaviour, it's better to the use the appropriate `rustc` flag that controls the config. For example setting the `windows` cfg but on Linux based target.

-----

r? `@petrochenkov`
cc `@jyn514`

try-job: aarch64-apple
try-job: test-various
try-job: armhf-gnu
try-job: x86_64-msvc
try-job: x86_64-mingw
try-job: i686-msvc
try-job: i686-mingw
try-job: x86_64-gnu-llvm-17
try-job: dist-various-1
2024-08-07 17:32:16 +00:00
bohan
8c06dc4dda make import.vis is not mutable 2024-08-07 22:13:23 +08:00
Guillaume Gomez
888d157417
Rollup merge of #128753 - compiler-errors:arbitrary-upper, r=spastorino
Don't arbitrarily choose one upper bound for hidden captured region error message

You could argue that the error message is objectively worse, even though it's more accurate. I guess we could also add a note explaining like "cannot capture the intersection of two regions" or something, though I'm not sure if that is confusing due to being totally technical jargon.

This addresses the fact that #128752 says "add `+ 'b`" even though it does nothing to fix the issue. It doesn't fix the issue's root cause, though.

r? `@spastorino`
2024-08-07 15:59:38 +02:00
Guillaume Gomez
493233ce29
Rollup merge of #128527 - estebank:ambiguity-suggestion, r=Nadrieril
More information for fully-qualified suggestion when there are multiple impls

```
error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type
  --> $DIR/E0283.rs:30:21
   |
LL |     fn create() -> u32;
   |     ------------------- `Coroutine::create` defined here
...
LL |     let cont: u32 = Coroutine::create();
   |                     ^^^^^^^^^^^^^^^^^^^ cannot call associated function of trait
   |
help: use a fully-qualified path to a specific available implementation
   |
LL |     let cont: u32 = <Impl as Coroutine>::create();
   |                     ++++++++          +
LL |     let cont: u32 = <AnotherImpl as Coroutine>::create();
   |                     +++++++++++++++          +
```
2024-08-07 15:59:36 +02:00
Guillaume Gomez
a6caceee4d
Rollup merge of #128424 - fee1-dead-contrib:fx-clean, r=oli-obk
minor `effects` cleanups

* remove the fixme comment about not needing defaults because it turns out we do need defaults (if I made it None instead it would ice a bunch of tests)
* remove the part that special cased trait args when lowering them. This is now historical because effects doesn't add host args to traits anymore (we use associated types now)
2024-08-07 15:59:35 +02:00
Guillaume Gomez
355eb9c79f
Rollup merge of #128206 - bjorn3:import_lib_writing_refactor, r=jieyouxu
Make create_dll_import_lib easier to implement

This will make it easier to implement raw-dylib support in cg_clif and cg_gcc. This PR doesn't yet include an create_dll_import_lib implementation for cg_clif as I need to correctly implement dllimport in cg_clif first before raw-dylib can work at all with cg_clif.

Required for https://github.com/rust-lang/rustc_codegen_cranelift/issues/1345
2024-08-07 15:59:35 +02:00
Ralf Jung
c1897960c0 unused_parens: do not lint against parens around &raw 2024-08-07 15:29:00 +02:00
Urgau
c0c57b3e29 Disallow setting built-in cfgs via set the command-line 2024-08-07 14:08:34 +02:00
Urgau
eedb32dd12 Make Span optional in BufferedEarlyLint 2024-08-07 14:08:34 +02:00
Zalathar
482412c98a Use TyCtxt::is_diagnostic_item 2024-08-07 21:44:53 +10:00
Zalathar
29245ec759 Avoid using ty::tls::with in write_struct_like 2024-08-07 21:44:53 +10:00
Zalathar
582208b0f2 Simplify hoisting of ref patterns (& and &mut) 2024-08-07 21:44:53 +10:00
Zalathar
a245bfa617 Simplify hoisting of array/slice patterns
We can replace some tricky iterator-mutation code with a much simpler version
that uses `while let` to shrink a slice.

We also check whether a subpattern would be a wildcard _before_ hoisting it,
which will be very useful when trying to get rid of `print::PatKind` later.
2024-08-07 21:44:52 +10:00
León Orell Valerian Liehr
c4c518d2d4
Use more slice patterns inside the compiler 2024-08-07 13:37:52 +02:00
Zalathar
c764bea0c3 Simplify hoisting of struct-like patterns 2024-08-07 20:52:47 +10:00
Zalathar
a5ed6fb646 Split out hoisting/printing of box patterns 2024-08-07 20:52:47 +10:00
Zalathar
7f48851416 Split out a hoist helper in hoist_witness_pat 2024-08-07 20:52:46 +10:00
Zalathar
e98e19e491 Replace an unnecessary slice pattern with has_dot_dot: bool 2024-08-07 20:52:46 +10:00
Zalathar
4cd800503f Remove an impossible case under EnumInfo::NotEnum 2024-08-07 20:52:46 +10:00
Zalathar
74f76ae5ea Unify Variant and Leaf into print::PatKind::StructLike 2024-08-07 20:52:46 +10:00
Zalathar
ccfd94e334 Break up print::Pat printing into several helper functions 2024-08-07 20:52:46 +10:00
bjorn3
f58e737554 Update ar_archive_writer to 0.3.3
Version 0.3.1 has added support for writing import libraries. Version
0.3.2 fixed creating archives containing members of import libraries.
Version 0.3.3 fixed building on big-endian systems.
2024-08-07 10:52:02 +00:00
John Paul Adrian Glaubitz
d1d21ede82 rustc_codegen_ssa: Set architecture for object crate for 32-bit SPARC
The object crate was recently updated to recognize the 32-bit SPARC
ELF targets EM_SPARC and EM_SPARC32PLUS, so the proper architecture
for 32-bit SPARC can now be set in rustc_codegen_ssa.
2024-08-07 09:56:28 +02:00
Caleb Zulawski
8818c95528 Disallow enabling features without their implied features 2024-08-07 00:45:00 -04:00
Caleb Zulawski
0b98a0c727 Fix typo
Co-authored-by: Amanieu d'Antras <amanieu@gmail.com>
2024-08-07 00:43:56 -04:00
Caleb Zulawski
83276f5680 Hide implicit target features from diagnostics when possible 2024-08-07 00:43:52 -04:00
Caleb Zulawski
6b96a60611 Add implied features to non-target-feature functions 2024-08-07 00:41:48 -04:00
Caleb Zulawski
5006711744 Remove redundant implied features 2024-08-07 00:41:48 -04:00
Caleb Zulawski
a25da077cf Don't use LLVM to compute -Ctarget-feature 2024-08-07 00:41:48 -04:00
Caleb Zulawski
484aca8857 Don't use LLVM's target features 2024-08-07 00:41:48 -04:00
Caleb Zulawski
fbd618d4aa Refactor and fill out target feature lists 2024-08-07 00:41:48 -04:00
Caleb Zulawski
c866e1f812 Add missing features 2024-08-07 00:41:48 -04:00
Caleb Zulawski
22c5952944 Add test to ensure implied target features work with asm, and fix failing tests 2024-08-07 00:41:48 -04:00
Caleb Zulawski
74653b61a6 Add implied target features to target_feature attribute 2024-08-07 00:41:48 -04:00
Trevor Gross
b3bfd66627
Rollup merge of #128417 - tgross35:f16-f128-math, r=dtolnay
Add `f16` and `f128` math functions

This adds intrinsics and math functions for `f16` and `f128` floating point types. Support is quite limited and some things are broken so tests don't run on many platforms, but this provides a starting point.
2024-08-06 22:17:32 -05:00
bors
6696447f78 Auto merge of #128761 - matthiaskrgr:rollup-5p1mlqq, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #124944 (On trait bound mismatch, detect multiple crate versions in dep tree)
 - #125048 (PinCoerceUnsized trait into core)
 - #128406 (implement BufReader::peek)
 - #128539 (Forbid unused unsafe in vxworks-specific std modules)
 - #128687 (interpret: refactor function call handling to be better-abstracted)
 - #128692 (Add a triagebot mention for `library/Cargo.lock`)
 - #128710 (Don't ICE when getting an input file name's stem fails)
 - #128718 (Consider `cfg_attr` checked by `CheckAttrVisitor`)
 - #128751 (std:🧵 set_name implementation proposal for vxWorks.)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-08-07 00:46:06 +00:00
Matthias Krüger
3158a86b67
Rollup merge of #128718 - jieyouxu:check-cfg_attr, r=nnethercote
Consider `cfg_attr` checked by `CheckAttrVisitor`

I forgor about `cfg_attr` in #128581, it should be treated like `cfg`.

Fixes #128716.
2024-08-07 00:34:14 +02:00
Matthias Krüger
f9325b72d9
Rollup merge of #128710 - ChrisDenton:null, r=jieyouxu
Don't ICE when getting an input file name's stem fails

Fixes #128681

The file stem is only used as a user-friendly prefix on intermediary files. While nice to have, it's not the end of the world if it fails so there's no real reason to emit an error here. We can continue with a fixed name as we do when an anonymous string is used.
2024-08-07 00:34:14 +02:00
Matthias Krüger
52c365b731
Rollup merge of #128687 - RalfJung:interpret-call-refactor, r=WaffleLapkin
interpret: refactor function call handling to be better-abstracted

Add a new function `init_stack_frame` that pushes a stack frame and passes the arguments, and use that basically everywhere that the raw underlying `push_stack_frame` used to be called. This splits the previous monster function `eval_fn_call` into two parts: figuring out the MIR to call and the arguments to pass, and then actually setting up the stack frame.

Also re-organize the files a bit:
- The previous `terminator.rs` is split into a new `call.rs` with all the argument-passing logic, and the rest goes into `step.rs` where the other main dispatcher functions already live (in particular, `eval_statement`).
- All the stack frame handling from `eval_context.rs` is moved to a new `stack.rs`.
2024-08-07 00:34:13 +02:00
Matthias Krüger
16b251be10
Rollup merge of #125048 - dingxiangfei2009:stable-deref, r=amanieu
PinCoerceUnsized trait into core

cc ``@Darksonn`` ``@wedsonaf`` ``@ojeda``

This is a PR to introduce a `PinCoerceUnsized` trait in order to make trait impls generated by the proc-macro `#[derive(SmartPointer)]`, proposed by [RFC](e17e19ac7a/text/3621-derive-smart-pointer.md (pincoerceunsized-1)), sound. There you may find explanation, justification and discussion about the alternatives.

Note that we do not seek stabilization of this `PinCoerceUnsized` trait in the near future. The stabilisation of this trait does not block the eventual stabilization process of the `#[derive(SmartPointer)]` macro. Ideally, use of `DerefPure` is more preferrable except this will actually constitute a breaking change. `PinCoerceUnsized` emerges as a solution to the said soundness hole while avoiding the breaking change. More details on the `DerefPure` option have been described in this [section](e17e19ac7a/text/3621-derive-smart-pointer.md (derefpure)) of the RFC linked above.

Earlier discussion can be found in this [Zulip stream](https://rust-lang.zulipchat.com/#narrow/stream/136281-t-opsem/topic/Pin.20and.20soundness.20of.20unsizing.20coercions) and [rust-for-linux thread](https://rust-lang.zulipchat.com/#narrow/stream/425075-rust-for-linux/topic/.23.5Bderive.28SmartPointer.29.5D.20and.20pin.20unsoundness.20rfc.233621).

try-job: dist-various-2
2024-08-07 00:34:11 +02:00
Michael Goulet
c656ce7aeb Don't arbitrarily choose one upper bound for hidden captured region 2024-08-06 15:43:41 -04:00
Esteban Küber
034b73ba54 fix test 2024-08-06 19:09:52 +00:00
Matthias Krüger
8912318a4c
Rollup merge of #128720 - y21:issue119620, r=compiler-errors
Pass the right `ParamEnv` to `might_permit_raw_init_strict`

Fixes #119620

`might_permit_raw_init_strict` currently passes an empty `ParamEnv` to the `InterpCx`, instead of the actual `ParamEnv` that was passed in to `check_validity_requirement` at callsite.

This leads to ICEs such as the linked issue where for `UnsafeCell<*mut T>` we initially get the layout with the right `ParamEnv` (which suceeds because it can prove that `T: Sized` and therefore `UnsafeCell<*mut T>` has a known layout) but then do the rest with an empty `ParamEnv` where `T: Sized` is not known to hold so getting the layout for `*mut T` later fails.

This runs into an assertion in other layout code where it's making the (valid) assumption that, when we already have a layout for a struct (`UnsafeCell<*mut T>`), getting the layout of one of its fields (`*mut T`) should also succeed, which wasn't the case here due to using the wrong `ParamEnv`.

So, this PR changes it to just use the same `ParamEnv` all the way throughout.
2024-08-06 20:23:41 +02:00
Matthias Krüger
5f9ebb5d26
Rollup merge of #128517 - clubby789:overflowing-lit-span, r=petrochenkov
Fallback to string formatting if source is not available for lint

Fixes #128445
2024-08-06 20:23:39 +02:00
Matthias Krüger
333c63b9fc
Rollup merge of #128377 - veera-sivarajan:fix-128249, r=davidtwco
Fix ICE Caused by Incorrectly Delaying E0107

Fixes  #128249

For the following code:
```rust
trait Foo<T> {}
impl Foo<T: Default> for u8 {}
```
#126054 added some logic to delay emitting E0107 as the names of associated type `T` in the impl header and generic parameter `T` in `trait Foo` match.

But it failed to ensure whether such unexpected associated type bounds are coming from a impl block header. This caused an ICE as the compiler was delaying E0107 for code like:
```rust
trait Trait<Type> {
    type Type;

    fn method(&self) -> impl Trait<Type: '_>;
}
```
because it assumed the associated type bound `Type: '_` is for the generic parameter `Type` in `trait Trait` since the names are same.

This PR adds a check to ensure that E0107 is delayed only in the context of impl block header.
2024-08-06 20:23:39 +02:00
Matthias Krüger
d3d9aae960
Rollup merge of #128369 - GrigorenkoPV:let-underscore-translatable, r=davidtwco
rustc_lint: make `let-underscore-lock` translatable
2024-08-06 20:23:38 +02:00
Esteban Küber
edd4162393 fix rebase 2024-08-06 17:54:39 +00:00
Esteban Küber
d8b07718f4 Add help about using cargo tree 2024-08-06 17:54:39 +00:00
Esteban Küber
4868680ee9 On trait bound mismatch, detect multiple crate versions in dep tree
When encountering an E0277, if the type and the trait both come from a crate with the same name but different crate number, we explain that there are multiple crate versions in the dependency tree.

If there's a type that fulfills the bound, and it has the same name as the passed in type and has the same crate name, we explain that the same type in two different versions of the same crate *are different*.

```
error[E0277]: the trait bound `Type: dependency::Trait` is not satisfied
 --> src/main.rs:4:18
  |
4 |     do_something(Type);
  |     ------------ ^^^^ the trait `dependency::Trait` is not implemented for `Type`
  |     |
  |     required by a bound introduced by this call
  |
help: you have multiple different versions of crate `dependency` in your dependency graph
 --> src/main.rs:1:5
  |
1 | use bar::do_something;
  |     ^^^ one version of crate `dependency` is used here, as a dependency of crate `bar`
2 | use dependency::Type;
  |     ^^^^^^^^^^ one version of crate `dependency` is used here, as a direct dependency of the current crate
note: two types coming from two different versions of the same crate are different types even if they look the same
 --> /home/gh-estebank/crate_versions/baz-2/src/lib.rs:1:1
  |
1 | pub struct Type;
  | ^^^^^^^^^^^^^^^ this type doesn't implement the required trait
  |
 ::: /home/gh-estebank/crate_versions/baz/src/lib.rs:1:1
  |
1 | pub struct Type;
  | ^^^^^^^^^^^^^^^ this type implements the required trait
2 | pub trait Trait {}
  | --------------- this is the required trait
note: required by a bound in `bar::do_something`
 --> /home/gh-estebank/crate_versions/baz/src/lib.rs:4:24
  |
4 | pub fn do_something<X: Trait>(_: X) {}
  |                        ^^^^^ required by this bound in `do_something`
```

Address #22750.
2024-08-06 17:54:39 +00:00
Esteban Küber
db6c05f9b9 Maintain highlighting in note and help even when they have a span 2024-08-06 17:54:37 +00:00
Michael Goulet
79228526bf Cache supertrait outlives of impl header for soundness check 2024-08-06 13:33:32 -04:00
Michael Goulet
cc96efd7e3 Stop unnecessarily taking GenericPredicates by &self 2024-08-06 11:54:45 -04:00
Ralf Jung
1c2705c622 various cleanups based on review 2024-08-06 13:49:26 +02:00
Ralf Jung
5783e73f46 make some Frame fields more private 2024-08-06 11:08:14 +02:00
Ralf Jung
522af10ccc interpret: refactor function call handling to be better-abstracted 2024-08-06 11:08:12 +02:00
bors
93ea767e29 Auto merge of #126804 - estebank:short-error-primary-label, r=davidtwco
On short error format, append primary span label to message

The `error-format=short` output only displays the path, error code and main error message all in the same line. We now add the primary span label as well after the error message, to provide more context.
2024-08-06 07:06:24 +00:00
Pavel Grigorenko
15982b2fca rustc_errors: fix inaccurate comment 2024-08-06 09:26:47 +03:00
Pavel Grigorenko
b0a8944120 rustc_errors: enforce OUTPUT_REPLACEMENTS is sorted with a compile-time assertion 2024-08-06 09:26:47 +03:00
许杰友 Jieyou Xu (Joe)
97cbc2083f check_attr: treat cfg_attr like cfg 2024-08-06 06:12:10 +00:00
Esteban Küber
1bbaf6eb2f On short error format, append primary span label to message
The `error-format=short` output only displays the path, error code and
main error message all in the same line. We now add the primary span label
as well after the error message, to provide more context.
2024-08-06 04:08:10 +00:00
bors
8c7e0e1608 Auto merge of #128200 - estebank:normalize-whitespace, r=pnkfelix
Change output normalization logic to be linear against size of output

Modify the rendered output normalization routine to scan each character *once* and construct a `String` to be printed out to the terminal *once*, instead of using `String::replace` in a loop multiple times. The output doesn't change, but the time spent to prepare a diagnostic is now faster (or rather, closer to what it was before #127528).
2024-08-06 03:44:38 +00:00
bors
c9687a95a6 Auto merge of #125558 - Amanieu:const-asm-type, r=lcnr
Tweak type inference for `const` operands in inline asm

Previously these would be treated like integer literals and default to `i32` if a type could not be determined. To allow for forward-compatibility with `str` constants in the future, this PR changes type inference to use an unbound type variable instead.

The actual type checking is deferred until after typeck where we still ensure that the final type for the `const` operand is an integer type.

<!--
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>
-->
2024-08-06 01:20:43 +00:00
Noah Lev
9479792cb4 WF-check struct field types at construction site
Rustc of course already WF-checked the field types at the definition
site, but for error tainting of consts to work properly, there needs to
be an error emitted at the use site. Previously, with no use-site error,
we proceeded with CTFE and ran into ICEs since we are running code with
type errors.

Emitting use-site errors also brings struct-like constructors more in
line with fn-like constructors since they already emit use-site errors
for WF issues.
2024-08-05 17:37:12 -07:00
y21
fdf3b31165 pass the right ParamEnv to might_permit_raw_init_strict 2024-08-06 01:53:50 +02:00
Chris Denton
c6d94821f0
Don't ICE if getting the input's file_stem fails 2024-08-05 22:30:13 +00:00
Matthias Krüger
c53698b399
Rollup merge of #128697 - RalfJung:nullary-op, r=compiler-errors
interpret: move nullary-op evaluation into operator.rs

We call it an operator, so we might as well treat it like one. :)

Also use more consistent naming for the "evaluate intrinsic" functions. "emulate" is really the wrong term, this *is* a genuine implementation of the intrinsic semantics after all.
2024-08-05 23:35:24 +02:00
Matthias Krüger
77f57cbcac
Rollup merge of #128694 - compiler-errors:norm, r=WaffleLapkin
Normalize when equating `dyn` tails in MIR borrowck

See the explanation in the comment.

Fixes #128621
cc `@WaffleLapkin`
2024-08-05 23:35:23 +02:00
Matthias Krüger
83155b3900
Rollup merge of #128688 - RalfJung:custom-mir-tail-calls, r=compiler-errors
custom MIR: add support for tail calls

Cc ``@WaffleLapkin``
2024-08-05 23:35:23 +02:00
Matthias Krüger
9cb3688f1f
Rollup merge of #128580 - compiler-errors:cfi-param-env, r=lcnr
Use `ParamEnv::reveal_all` in CFI

I left a huge comment for why this ICEs in the test I committed.

`typeid_for_instance` should only be called on monomorphic instances during codegen, and we should just be using `ParamEnv::reveal_all()` rather than the param-env of the instance itself. I added an assertion to ensure that we only do this for fully substituted instances (this may break with polymorphization, but I kinda don't care lol).

Fixes #114160
cc `@rcvalle`
2024-08-05 23:35:22 +02:00
Matthias Krüger
8cbf1c1b22
Rollup merge of #122049 - Amanieu:riscv64-musl-tier2, r=Mark-Simulacrum
Promote riscv64gc-unknown-linux-musl to tier 2
2024-08-05 23:35:22 +02:00
Ralf Jung
46896d6f66 interpret: move nullary-op evaluation into operator.rs 2024-08-05 22:42:34 +02:00