Commit Graph

29257 Commits

Author SHA1 Message Date
bohan
482275b194 use visibility to check unused imports and delete some stmts 2023-10-22 21:27:46 +08:00
dirreke
dc00d03a11 add target csky-unknown-linux-gnuabiv2hf 2023-10-22 21:20:30 +08:00
Zalathar
6af9fef085 coverage: Emit the filenames section before encoding per-function mappings
Most coverage metadata is encoded into two sections in the final executable.
The `__llvm_covmap` section mostly just contains a list of filenames, while the
`__llvm_covfun` section contains encoded coverage maps for each instrumented
function.

The catch is that each per-function record also needs to contain a hash of the
filenames list that it refers to. Historically this was handled by assembling
most of the per-function data into a temporary list, then assembling the
filenames buffer, then using the filenames hash to emit the per-function data,
and then finally emitting the filenames table itself.

However, now that we build the filenames table up-front (via a separate
traversal of the per-function data), we can hash and emit that part first, and
then emit each of the per-function records immediately after building. This
removes the awkwardness of having to temporarily store nearly-complete
per-function records.
2023-10-22 23:17:15 +11:00
Ethan Brierley
24cdb27e28 let_chainify suggest_coercing_result_via_try_operator 2023-10-22 12:05:28 +01:00
Zalathar
de4cfbca2e coverage: Encode function mappings without re-sorting them
The main change here is that `VirtualFileMapping` now uses an internal hashmap
to de-duplicate incoming global file IDs. That removes the need for
`encode_mappings_for_function` to re-sort its mappings by filename in order to
de-duplicate them.

(We still de-duplicate runs of identical filenames to save work, but this is
not load-bearing for correctness, so a sort is not necessary.)
2023-10-22 20:37:39 +11:00
Zalathar
88159cafa7 coverage: Encapsulate local-to-global file mappings 2023-10-22 20:37:39 +11:00
Zalathar
e985ae5a45 coverage: Build the global file table ahead of time 2023-10-22 20:37:37 +11:00
Zalathar
86b55cccff coverage: Fetch expressions and mappings separately
The combined `get_expressions_and_counter_regions` method was an artifact of
having to prepare the expressions and mappings at the same time, to avoid
ownership/lifetime problems with temporary data used by both.

Now that we have an explicit transition from `FunctionCoverageCollector` to the
final `FunctionCoverage`, we can prepare any shared data during that step and
store it in the final struct.
2023-10-22 20:11:48 +11:00
Zalathar
371883a05a coverage: Split FunctionCoverage into distinct collector/finished phases
This gives us a clearly-defined place to run code after the instance's MIR has
been traversed by codegen, but before we emit its `__llvm_covfun` record.
2023-10-22 20:11:45 +11:00
Matthias Krüger
4681eb6c94
Rollup merge of #117034 - Nadrieril:fix-117033, r=cjgillot
Don't crash on empty match in the `nonexhaustive_omitted_patterns` lint

Oops

Fixes https://github.com/rust-lang/rust/issues/117033
2023-10-22 09:15:42 +02:00
bors
97a2894062 Auto merge of #117031 - bjorn3:sync_cg_clif-2023-10-21, r=bjorn3
Sync rustc_codegen_cranelift

The main highlights this time is new support for riscv64 linux enabled by a cranelift update. I have also updated some of the crates built as part of cg_clif's test suite which enabled removing several patches for them. And finally I have fixed a couple of tests in rustc's test suite with cg_clif.

r? `@ghost`

`@rustbot` label +A-codegen +A-cranelift +T-compiler +subtree-sync
2023-10-22 00:05:49 +00:00
Nadrieril
a134f1624c Fix #117033 2023-10-21 23:04:17 +02:00
bjorn3
e07f47b6c5 Merge commit 'c07d1e2f88cb3b1a0604ae8f18b478c1aeb7a7fa' into sync_cg_clif-2023-10-21 2023-10-21 19:54:51 +00:00
Matthias Krüger
31865b7bfb
Rollup merge of #116992 - estebank:issue-69492, r=oli-obk
Mention the syntax for `use` on `mod foo;` if `foo` doesn't exist

Newcomers might get confused that `mod` is the only way of defining scopes, and that it can be used as if it were `use`.

Fix #69492.
2023-10-21 21:23:01 +02:00
Matthias Krüger
a3b22e1cdb
Rollup merge of #116981 - Dirreke:csky-unknown-linux-gunabiv2, r=bjorn3
update the registers of csky target
2023-10-21 21:23:01 +02:00
Matthias Krüger
d6ac149b4f
Rollup merge of #116312 - c410-f3r:try, r=Mark-Simulacrum
Initiate the inner usage of `cfg_match` (Compiler)

cc #115585

Dogfood to test the implementation and remove dependencies.
2023-10-21 21:22:59 +02:00
bors
0d1664674a Auto merge of #116922 - Zalathar:unused, r=cjgillot
coverage: Emit mappings for unused functions without generating stubs

For a while I've been annoyed by the fact that generating coverage maps for unused functions involves generating a stub function at the LLVM level.

As I suspected, generating that stub function isn't actually necessary, as long as we specifically tell LLVM about the symbol names of all the functions that have coverage mappings but weren't codegenned (due to being unused).

---

There is some helper code that gets moved around in the follow-up patches, so look at the first patch to see the most important functional changes.

---

`@rustbot` label +A-code-coverage
2023-10-21 16:47:30 +00:00
Camille GILLOT
8c1b039d48 Use a ConstValue instead. 2023-10-21 16:26:05 +00:00
Camille GILLOT
31d101093c Generate ValTrees in DataflowConstProp. 2023-10-21 16:20:46 +00:00
Esteban Küber
2cca435717 Mention the syntax for use on mod foo; if foo doesn't exist
Newcomers might get confused that `mod` is the only way of defining
scopes, and that it can be used as if it were `use`.

Fix #69492.
2023-10-21 15:56:01 +00:00
dirreke
31daed1b64 update the registers of csky 2023-10-21 23:42:09 +08:00
León Orell Valerian Liehr
4aaf8e03e1
on unresolved import disambiguate suggested path if it would collide 2023-10-21 15:40:32 +02:00
bors
26f340a0d5 Auto merge of #117020 - matthiaskrgr:rollup-cg62m4h, r=matthiaskrgr
Rollup of 3 pull requests

Successful merges:

 - #106601 (Suggest `;` after bare `match` expression E0308)
 - #116975 (Move `invalid-llvm-passes` test to `invalid-compile-flags` folder)
 - #117019 (fix spans for removing `.await` on `for` expressions)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-10-21 12:58:16 +00:00
Camille GILLOT
c8f33ec35f Typo. 2023-10-21 12:14:17 +00:00
Camille GILLOT
abb723dea2 Remove redundant checks. 2023-10-21 12:10:30 +00:00
Camille GILLOT
7ae1851803 Use terse form for Fn bound. 2023-10-21 12:09:02 +00:00
Matthias Krüger
bd1046d26a
Rollup merge of #117019 - lukas-code:for-await, r=compiler-errors
fix spans for removing `.await` on `for` expressions

We need to use a span with the outer syntax context of a desugared `for` expression to join it with the `.await` span.

fixes https://github.com/rust-lang/rust/issues/117014
2023-10-21 13:58:34 +02:00
Matthias Krüger
05e154fdb7
Rollup merge of #106601 - estebank:match-semi, r=cjgillot
Suggest `;` after bare `match` expression E0308

Fix #72634.
2023-10-21 13:58:33 +02:00
Lukas Markeffsky
ccc4638d73 fix spans for removing .await on for expressions 2023-10-21 13:18:00 +02:00
bors
786c94a4eb Auto merge of #116734 - Nadrieril:lint-per-column, r=cjgillot
Lint `non_exhaustive_omitted_patterns` by columns

This is a rework of the `non_exhaustive_omitted_patterns` lint to make it more consistent. The intent of the lint is to help consumers of `non_exhaustive` enums ensure they stay up-to-date with all upstream variants. This rewrite fixes two cases we didn't handle well before:

First, because of details of exhaustiveness checking, the following wouldn't lint `Enum::C` as missing:
```rust
match Some(x) {
    Some(Enum::A) => {}
    Some(Enum::B) => {}
    _ => {}
}
```

Second, because of the fundamental workings of exhaustiveness checking, the following would treat the `true` and `false` cases separately and thus lint about missing variants:
```rust
match (true, x) {
    (true, Enum::A) => {}
    (true, Enum::B) => {}
    (false, Enum::C) => {}
    _ => {}
}
```
Moreover, it would correctly not lint in the case where the pair is flipped, because of asymmetry in how exhaustiveness checking proceeds.

A drawback is that it no longer makes sense to set the lint level per-arm. This will silently break the lint for current users of it (but it's behind a feature gate so that's ok).

The new approach is now independent of the exhaustiveness algorithm; it's a separate pass that looks at patterns column by column. This is another of the motivations for this: I'm glad to move it out of the algorithm, it was akward there.

This PR is almost identical to https://github.com/rust-lang/rust/pull/111651. cc `@eholk` who reviewed it at the time. Compared to then, I'm more confident this is the right approach.
2023-10-21 11:04:19 +00:00
Camille GILLOT
547af00019 Remove on_all_drop_children_bits.
As drop elaboration only tracks places that need dropping, is has become
equivalent to `on_all_children_bits`.
2023-10-21 10:33:37 +00:00
Camille GILLOT
c9c0c0cbca Do not create move paths that do not need dropping. 2023-10-21 10:32:59 +00:00
Camille GILLOT
f038882fc0 Give collect_drop_flags and elaborate_drops closer structure. 2023-10-21 10:32:21 +00:00
Camille GILLOT
252c64722f Parametrize gather_moves by filter. 2023-10-21 10:31:39 +00:00
Camille GILLOT
4bedd7de6e Stop computing error info in move path builder. 2023-10-21 10:30:58 +00:00
Camille GILLOT
90e6d29955 Avoid using a magic value for untracked locals. 2023-10-21 10:30:16 +00:00
Camille GILLOT
8d535070a2 Do not report errors from move path builder. 2023-10-21 10:29:40 +00:00
Camille GILLOT
a8e56d0b0b Remove is_terminal_path.
That information is redundant. Is the path is terminal, `first_child` will
already be `None`.
2023-10-21 10:26:28 +00:00
Nilstrieb
5acf26b97e Make ty::print::Printer take &mut self instead of self
This simplifies the code by removing all the `self` assignments and
makes the flow of data clearer - always into the printer.
Especially in v0 mangling, which already used  `&mut self` in some
places, it gets a lot more uniform.
2023-10-21 11:33:05 +02:00
Matthias Krüger
e9d18f5f78
Rollup merge of #116995 - estebank:issue-69944, r=compiler-errors
Point at assoc fn definition on type param divergence

When the number of type parameters in the associated function of an impl and its trait differ, we now *always* point at the trait one, even if it comes from a foreign crate. When it is local, we point at the specific params, when it is foreign, we point at the whole associated item.

Fix #69944.
2023-10-21 10:08:18 +02:00
Matthias Krüger
dd66bc86be
Rollup merge of #116990 - estebank:issue-68445, r=cjgillot
Mention `into_iter` on borrow errors suggestions when appropriate

If we encounter a borrow error on `vec![1, 2, 3].iter()`, suggest `into_iter`.

Fix #68445.
2023-10-21 10:08:18 +02:00
Matthias Krüger
e9df0b6b40
Rollup merge of #116974 - Zalathar:signature-spans, r=oli-obk,cjgillot
coverage: Fix inconsistent handling of function signature spans

While doing some more cleanup of `spans`, I noticed a strange inconsistency in how function signatures are handled. Normally the function signature span is treated as though it were executable as part of the start of the function, but in some cases the signature span disappears entirely from coverage, for no obvious reason.

This is caused by the fact that spans created by `CoverageSpan::for_fn_sig` don't add the span to their `merged_spans` field (unlike normal statement/terminator spans). In cases where the span-processing code looks at those merged spans, it thinks the signature span is no longer visible and deletes it.

Adding the signature span to `merged_spans` resolves the inconsistency.

(Prior to #116409 this wouldn't have been possible, because there was no case in the old `CoverageStatement` enum representing a signature. Now that `merged_spans` is just a list of spans, that's no longer an obstacle.)
2023-10-21 10:08:17 +02:00
Matthias Krüger
b7035198e6
Rollup merge of #116964 - celinval:smir-mono-body, r=oli-obk
Add stable Instance::body() and RustcInternal trait

The `Instance::body()` returns a monomorphized body.

For that, we had to implement visitor that monomorphize types and constants. We are also introducing the RustcInternal trait that will allow us to convert back from Stable to Internal.

Note that this trait is not yet visible for our users as it depends on Tables. We should probably add a new trait that can be exposed.

The tests here are very simple, and I'm planning on creating more exhaustive tests in the project-mir repo. But I was hoping to get some feedback here first.

r? ```@oli-obk```
2023-10-21 10:08:17 +02:00
Matthias Krüger
c5dd84d493
Rollup merge of #116961 - estebank:issue-60164, r=oli-obk
Typo suggestion to change bindings with leading underscore

When encountering a binding that isn't found but has a typo suggestion for a binding with a leading underscore, suggest changing the binding definition instead of the use place.

Fix #60164.
2023-10-21 10:08:16 +02:00
Matthias Krüger
ad574d9799
Rollup merge of #116917 - Zalathar:injection, r=cjgillot
coverage: Simplify the injection of coverage statements

This is a follow-up to #116046 that I left out of that PR because I didn't want to make it any larger.

After the various changes we've made to how coverage data is stored and transferred, the old code structure for injecting coverage statements into MIR is built around a lot of constraints that don't exist any more. We can simplify it by replacing it with a handful of loops over the BCB node/edge counters and the BCB spans.

---

`@rustbot` label +A-code-coverage
2023-10-21 10:08:16 +02:00
Matthias Krüger
3fd7175db4
Rollup merge of #116911 - estebank:issue-85378, r=oli-obk
Suggest relaxing implicit `type Assoc: Sized;` bound

Fix #85378.
2023-10-21 10:08:15 +02:00
Camille GILLOT
dd08dd42e5 Expand comment on disappearing edge. 2023-10-21 07:08:53 +00:00
Camille GILLOT
8fb99afb02 Correct loop_headers logic. 2023-10-21 07:08:53 +00:00
Camille GILLOT
54b61d6e1a Reword TO application comments. 2023-10-21 07:08:53 +00:00
Camille GILLOT
66ec098ea7 Simplify static if handling. 2023-10-21 07:08:53 +00:00
Camille GILLOT
d5b21ef96b Explicit notation. 2023-10-21 07:08:53 +00:00
Camille GILLOT
98b86fa9e5 Document Condition. 2023-10-21 07:03:23 +00:00
Camille GILLOT
47056248e5 Make polarity an enum. 2023-10-21 07:02:45 +00:00
Camille GILLOT
b5aa1ef9b4 Document mutated_statement. 2023-10-21 07:02:06 +00:00
Camille GILLOT
4abea83663 Improve naming and comments. 2023-10-21 07:01:25 +00:00
Camille GILLOT
df9e5ee038 Handle more terminators. 2023-10-21 07:01:24 +00:00
Camille GILLOT
0d0a536777 Do not thread through loop headers. 2023-10-21 06:59:37 +00:00
Camille GILLOT
751a079413 Implement JumpThreading pass. 2023-10-21 06:58:38 +00:00
Camille GILLOT
3cb0c2e385 Make instance an option in CostChecker. 2023-10-21 06:58:00 +00:00
Camille GILLOT
8252ad02c4 Extract cost checker from inliner. 2023-10-21 06:57:49 +00:00
Zalathar
ff02d9200c coverage: Simplify the injection of coverage statements 2023-10-21 12:33:33 +11:00
Zalathar
6f1ca8d9eb coverage: Change query codegened_and_inlined_items to a plain function
This query has a name that sounds general-purpose, but in fact it has
coverage-specific semantics, and (fortunately) is only used by coverage code.

Because it is only ever called once (from one designated CGU), it doesn't need
to be a query, and we can change it to a regular function instead.
2023-10-21 12:20:05 +11:00
Zalathar
cdeeffde64 coverage: Move unused-function helpers closer to where they are used 2023-10-21 12:20:05 +11:00
Zalathar
e964ea5bf5 coverage: Emit mappings for unused functions without generating stubs 2023-10-21 12:20:05 +11:00
Zalathar
319693a927 coverage: Simplify initial creation of coverage spans 2023-10-21 11:56:15 +11:00
Zalathar
e16494469e coverage: Don't create an intermediate vec for each BCB's initial spans 2023-10-21 11:53:27 +11:00
Zalathar
a17ff82aae coverage: Handle fn signature spans more consistently near ? 2023-10-21 11:53:27 +11:00
Michael Goulet
573f475853 Uplift ClauseKind and PredicateKind 2023-10-20 17:14:49 -07:00
Esteban Küber
939a224ce3 Point at assoc fn definition on type param divergence
When the number of type parameters in the associated function of an impl
and its trait differ, we now *always* point at the trait one, even if it
comes from a foreign crate. When it is local, we point at the specific
params, when it is foreign, we point at the whole associated item.

Fix #69944.
2023-10-20 22:11:01 +00:00
Oli Scherer
258af95a60 Replace all uses of generator in markdown documentation with coroutine 2023-10-20 21:14:02 +00:00
Oli Scherer
8c66e117e2 Re-add generators as a removed feature and point to the new feature name 2023-10-20 21:14:02 +00:00
Oli Scherer
2d91c76d5d Rename CoroutineKind::Gen to ::Coroutine 2023-10-20 21:14:01 +00:00
Oli Scherer
e96ce20b34 s/generator/coroutine/ 2023-10-20 21:14:01 +00:00
Oli Scherer
60956837cf s/Generator/Coroutine/ 2023-10-20 21:10:38 +00:00
Rémy Rakic
d9c213cd5e slight Default cleanup for option 2023-10-20 20:59:27 +00:00
Rémy Rakic
fa45efaafb consider a loan escapes the function via applied member constraints 2023-10-20 20:59:20 +00:00
Esteban Küber
88bccf454f Mention into_iter on borrow errors suggestions when appropriate
If we encounter a borrow error on `vec![1, 2, 3].iter()`, suggest
`into_iter`.

Fix #68445.
2023-10-20 18:50:25 +00:00
Esteban Küber
b0d17f35d9 Typo suggestion to change bindings with leading underscore
When encountering a binding that isn't found but has a typo suggestion
for a binding with a leading underscore, suggest changing the binding
definition instead of the use place.

Fix #60164.
2023-10-20 15:58:25 +00:00
Michael Goulet
c3fd4383fb Move some files around 2023-10-20 15:52:57 +00:00
Michael Goulet
5ceda6b016 Adjust imports 2023-10-20 15:52:57 +00:00
Celina G. Val
6e643e12bb
Remove obsolete comment 2023-10-20 08:23:16 -07:00
bors
274455a9d1 Auto merge of #116965 - estebank:issue-65329, r=cjgillot
Move where doc comment meant as comment check

The new place makes more sense and covers more cases beyond individual statements.

```
error: expected one of `.`, `;`, `?`, `else`, or an operator, found doc comment `//!foo
  --> $DIR/doc-comment-in-stmt.rs:25:22
   |
LL |     let y = x.max(1) //!foo
   |                      ^^^^^^ expected one of `.`, `;`, `?`, `else`, or an operator
   |
help: add a space before `!` to write a regular comment
   |
LL |     let y = x.max(1) // !foo
   |                        +
```

Fix #65329.
2023-10-20 13:02:11 +00:00
bors
f31316f7a9 Auto merge of #116962 - estebank:issue-63835, r=oli-obk
Do not bold main message in `--error-format=short`

Fix #63835.

Before:

<img width="484" alt="Screenshot 2023-10-19 at 3 52 53 PM" src="https://github.com/rust-lang/rust/assets/1606434/9bd6cbd5-a4ce-4cc3-8c5f-60a8d3ad38da">

After:

<img width="492" alt="Screenshot 2023-10-19 at 3 52 32 PM" src="https://github.com/rust-lang/rust/assets/1606434/0cf2417a-08f2-4074-860c-a88a838a4209">
2023-10-20 10:52:24 +00:00
Ethan Brierley
6c97f13612 Invalid ? suggestion on mismatched Ok(T) 2023-10-20 10:13:19 +01:00
Oli Scherer
eb99a89bd7 Ensure we never accidentally serialize an ErrorGuaranteed 2023-10-20 08:46:30 +00:00
Oli Scherer
fd9ef69adf Avoid a track_errors by bubbling up most errors from check_well_formed 2023-10-20 08:46:27 +00:00
bors
c7f3948028 Auto merge of #116946 - compiler-errors:movability-and-mutability, r=lcnr
Uplift movability and mutability, the simple way

Just make type_ir a dependency of ast. This can be relaxed later if we want to make the dependency less heavy. Part of rust-lang/types-team#124.

r? `@lcnr` or `@jackh726`
2023-10-20 08:19:54 +00:00
Esteban Küber
20de5c762d Move where doc comment meant as comment check
The new place makes more sense and covers more cases beyond individual
statements.

```
error: expected one of `.`, `;`, `?`, `else`, or an operator, found doc comment `//!foo
  --> $DIR/doc-comment-in-stmt.rs:25:22
   |
LL |     let y = x.max(1) //!foo
   |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected one of `.`, `;`, `?`, `else`, or an operator
   |
help: add a space before `!` to write a regular comment
   |
LL |     let y = x.max(1) // !foo
   |                        +
```

Fix #65329.
2023-10-20 02:54:45 +00:00
bors
ae466d2d0a Auto merge of #116838 - gurry:116836-dup-macro-invoc-diag, r=petrochenkov
Fix duplicate labels emitted in `render_multispan_macro_backtrace()`

This PR replaces the `Vec` used to store labels with an `FxIndexSet` in order to eliminate duplicates

Fixes #116836
2023-10-20 02:07:05 +00:00
Celina G. Val
6ed2a76bcc Add stable Instance::body() and RustcInternal trait
The `Instance::body()` returns a monomorphized body.

For that, we had to implement visitor that monomorphize types and
constants. We are also introducing the RustcInternal trait that will
allow us to convert back from Stable to Internal.

Note that this trait is not yet visible for our users as it depends on
Tables. We should probably add a new trait that can be exposed.
2023-10-19 17:12:26 -07:00
bors
5cee4f305a Auto merge of #116875 - nnethercote:rustc_monomorphize, r=wesleywiser
`rustc_monomorphize` cleanups

Just some small improvements I found while looking over this code.

r? `@wesleywiser`
2023-10-20 00:03:47 +00:00
Caio
6379013876 Initiate the inner usage of cfg_match 2023-10-19 20:18:51 -03:00
Esteban Küber
fd49590ee0 Do not bold main message in --error-format=short
Fix #63835.
2023-10-19 22:52:30 +00:00
bors
4578435e16 Auto merge of #116874 - compiler-errors:elaborator-nits, r=wesleywiser
Some small elaborator nits

Didn't want to fold these into a totally unrelated pr.
2023-10-19 21:42:17 +00:00
Rémy Rakic
c69bd9480a make applied_member_constraints accept an SCC instead of a region 2023-10-19 21:25:12 +00:00
bors
94c4e5c411 Auto merge of #115214 - Urgau:rfc-3127-trim-paths, r=compiler-errors
Implement rustc part of RFC 3127 trim-paths

This PR implements (or at least tries to) [RFC 3127 trim-paths](https://github.com/rust-lang/rust/issues/111540), the rustc part. That is `-Zremap-path-scope` with all of it's components/scopes.

`@rustbot` label: +F-trim-paths
2023-10-19 19:09:29 +00:00
Michael Goulet
e8e9f6a32a Uplift movability and mutability, the simple way 2023-10-19 16:42:58 +00:00
Georg Semmler
9017b974ee
Improve the warning messages for the #[diagnostic::on_unimplemented]
This commit improves warnings emitted for malformed on unimplemented
attributes by:

* Improving the span of the warnings
* Adding a label message to them
* Separating the messages for missing and unexpected options
* Adding a help message that says which options are supported
2023-10-19 15:00:47 +02:00
Matthias Krüger
c9764263d2
Rollup merge of #116906 - compiler-errors:version-0, r=oli-obk
Use v0.0.0 in compiler crates

I may be totally off base here, but my understanding is that it's conventional to use v0.0.0 to reflect the unversioned nature of the compiler crates. Fix that for some of the compiler crates that were created recently.
2023-10-19 14:38:27 +02:00
Matthias Krüger
096943a534
Rollup merge of #116896 - cjgillot:single-inline, r=oli-obk
Only check in a single place if a pass is enabled.

Fixes https://github.com/rust-lang/rust/issues/116294
2023-10-19 14:38:26 +02:00
Matthias Krüger
1d46614335
Rollup merge of #116650 - RalfJung:miri-intptrcast, r=oli-obk
add some comments and some cleanup around Miri intptrcast

`@saethlin` maybe this helps a bit?
2023-10-19 14:38:26 +02:00
León Orell Valerian Liehr
8aa1d7124a
Rollup merge of #116912 - compiler-errors:rustc_type_ir-bikeshedding, r=jackh726
Some renaming nits for `rustc_type_ir`

tl;dr:
* `ListTy` -> `Tys`
* `PlaceholderType` -> `PlaceholderTy`
* `RegionVid` -> `InferRegion`
* `ListBinderExistentialPredicate` -> `BoundExistentialPredicates`
* `GenericArgsRef` -> `GenericArgs`

r? jackh726
2023-10-19 04:34:48 +02:00
León Orell Valerian Liehr
64ed233fc1
Rollup merge of #116908 - estebank:issue-78206, r=compiler-errors
Tweak wording of type errors involving type params

Fix #78206.
2023-10-19 04:34:47 +02:00
León Orell Valerian Liehr
2eb6e5f740
Rollup merge of #116829 - fmease:rust-aint-c, r=compiler-errors
Make `#[repr(Rust)]` incompatible with other (non-modifier) representation hints like `C` and `simd`

Read more about this change here: https://github.com/rust-lang/rust/pull/116829#issuecomment-1768618240.

Fixes [after backport] #116825.
2023-10-19 04:34:46 +02:00
León Orell Valerian Liehr
2dd1c8f693
Rollup merge of #116663 - compiler-errors:resolve-regions, r=lcnr
Don't ICE when encountering unresolved regions in `fully_resolve`

We can encounter unresolved regions due to unconstrained impl lifetime arguments because `collect_return_position_impl_trait_in_trait_tys` runs before WF actually checks that the impl is well-formed.

Fixes #116525
2023-10-19 04:34:45 +02:00
Gurinder Singh
0091166b57 Fix duplicate labels emitted in render_multispan_macro_backtrace()
Using hash set instead of vec to weed out duplicates
2023-10-19 08:03:40 +05:30
Esteban Küber
e8d4fb8aaa Suggest relaxing implicit type Assoc: Sized; bound
Fix #85378.
2023-10-19 00:07:16 +00:00
Esteban Küber
bd8b46800d Tweak wording of type errors involving type params
Fix #78206.
2023-10-18 23:53:18 +00:00
Michael Goulet
189e6a833e Some renaming nits for rustc_type_ir 2023-10-18 23:29:28 +00:00
Michael Goulet
8d20182999 Remove unused variant BinderListTy 2023-10-18 23:09:17 +00:00
Michael Goulet
60c95448c3 Use v0.0.0 in compiler crates 2023-10-18 21:55:15 +00:00
Vitaliy Busko
e68edb89ad
refactor(compiler/resolve): simplify some code
Removes unnecessary allocates and double-sorting the same vector,
makes the code a little nicer.
2023-10-19 04:45:06 +07:00
bors
0039d739d4 Auto merge of #116493 - compiler-errors:coinductive-cycle-lint, r=lcnr
Bump `COINDUCTIVE_OVERLAP_IN_COHERENCE` to deny + warn in deps

1.73 is the first place this shows up in stable (recall that there was only 1 regression), so let's bump this to deny on nightly.

r? lcnr
2023-10-18 21:41:50 +00:00
Rémy Rakic
0b40c7c682 make self_contained return LinkSelfContainedComponents 2023-10-18 21:24:02 +00:00
Michael Goulet
ea73f10867 Don't ICE when encountering unresolved regions in fully_resolve 2023-10-18 20:39:29 +00:00
Michael Goulet
973d589582 Bump COINDUCTIVE_OVERLAP_IN_COHERENCE 2023-10-18 18:54:11 +00:00
bors
cc705b8012 Auto merge of #116046 - Zalathar:fn-cov-info, r=cjgillot
coverage: Move most per-function coverage info into `mir::Body`

Currently, all of the coverage information collected by the `InstrumentCoverage` pass is smuggled through MIR in the form of individual `StatementKind::Coverage` statements, which must then be reassembled by coverage codegen.

That's awkward for a number of reasons:
- While some of the coverage statements do care about their specific position in the MIR control-flow graph, many of them don't, and are just tacked onto the function's first BB as metadata carriers.
- MIR inlining can result in coverage statements being duplicated, so coverage codegen has to jump through hoops to avoid emitting duplicate mappings.
- MIR optimizations that would delete coverage statements need to carefully copy them into the function's first BB so as not to omit them from coverage reports.
- The order in which coverage codegen sees coverage statements is dependent on MIR optimizations/inlining, which can cause unnecessary churn in the emitted coverage mappings.
- We don't have a good way to annotate MIR-level functions with extra coverage info that doesn't belong in a statement.

---

This PR therefore takes most of the per-function coverage info and stores it in a field in `mir::Body` as `Option<Box<FunctionCoverageInfo>>`.

(This adds one pointer to the size of `mir::Body`, even when coverage is not enabled.)

Coverage statements still need to be injected into MIR in some cases, but only when they actually affect codegen (counters) or are needed to detect code that has been optimized away as unreachable (counters/expressions).

---

By the end of this PR, the information stored in `FunctionCoverageInfo` is:

- A hash of the function's source code (needed by LLVM's coverage map format)
- The number of coverage counters added by coverage instrumentation
- A table of coverage expressions, associating each expression ID with its operator (add or subtract) and its two operands
- The list of mappings, associating each covered code region with a counter/expression/zero value

---

~~This is built on top of #115301, so I'll rebase and roll a reviewer once that lands.~~
r? `@ghost`
`@rustbot` label +A-code-coverage
2023-10-18 18:48:34 +00:00
Camille GILLOT
c1c5a1d69a Only check in a single place if a pass is enabled. 2023-10-18 16:59:23 +00:00
León Orell Valerian Liehr
d0b99e3efe
Make #[repr(Rust)] and #[repr(C)] incompatible with one another 2023-10-18 17:25:23 +02:00
bors
e1aa9edde0 Auto merge of #116887 - lcnr:alias-ty-constructor, r=compiler-errors
`TyCtxt::mk_alias_ty` -> `AliasTy::new`
2023-10-18 15:17:48 +00:00
Rémy Rakic
e569a3691a unify LinkSelfContained and LinkSelfContainedDefault
Removes the backwards-compatible `LinkSelfContainedDefault`, by
incorporating the remaining specifics into `LinkSelfContained`.

Then renames the modern options to keep the old name.
2023-10-18 13:38:17 +00:00
Zalathar
33da0978ac coverage: Explicitly note that counter/expression IDs are function-local 2023-10-18 23:44:36 +11:00
Zalathar
753caf292c coverage: Update docs for StatementKind::Coverage
This new description reflects the changes made in this PR, and should hopefully
be more useful to non-coverage developers who need to care about coverage
statements.
2023-10-18 23:44:36 +11:00
Zalathar
13b2d604ec coverage: Store expression data in function coverage info
Even though expression details are now stored in the info structure, we still
need to inject `ExpressionUsed` statements into MIR, because if one is missing
during codegen then we know that it was optimized out and we can remap all of
its associated code regions to zero.
2023-10-18 23:44:34 +11:00
Zalathar
7d38f4a611 Remove unused TyCtxt from remove_dead_blocks
This context was only needed by code for processing coverage statements, which
has been removed.
2023-10-18 23:42:45 +11:00
Zalathar
6da319f635 coverage: Store all of a function's mappings in function coverage info
Previously, mappings were attached to individual coverage statements in MIR.
That necessitated special handling in MIR optimizations to avoid deleting those
statements, since otherwise codegen would be unable to reassemble the original
list of mappings.

With this change, a function's list of mappings is now attached to its MIR
body, and survives intact even if individual statements are deleted by
optimizations.
2023-10-18 23:42:39 +11:00
lcnr
306a7ea8b4 AliasTy::new instead of tcx method 2023-10-18 13:57:19 +02:00
bors
e1de04ad4e Auto merge of #116885 - aliemjay:rollup-plbeppt, r=aliemjay
Rollup of 5 pull requests

Successful merges:

 - #116812 (Disable missing_copy_implementations lint on non_exhaustive types)
 - #116856 (Disable effects in libcore again)
 - #116865 (Suggest constraining assoc types in more cases)
 - #116870 (Don't compare host param by name)
 - #116879 (revert #114586)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-10-18 11:55:41 +00:00
Rémy Rakic
b816207e05 limit lld flavors to the llvm backend 2023-10-18 11:33:40 +00:00
Rémy Rakic
5f24e314ef use asymmetric json roundtripping
this ensures roundtripping of stable and unstable values:
- backwards-compatible values can be deserialized, as well as the new
  unstable values
- unstable values are serialized.
2023-10-18 11:33:40 +00:00
Zalathar
4099ab1997 coverage: Make expression simplification non-destructive
Instead of modifying the accumulated expressions in-place, we now build a set
of expressions that are known to be zero, and then consult that set on the fly
when converting the expression data for FFI.

This will be necessary when moving mappings and expression data into function
coverage info, which can't be mutated during codegen.
2023-10-18 22:29:31 +11:00
Ali MJ Al-Nasrawy
8489bce7f5
Rollup merge of #116879 - aliemjay:revert-opaque-bubble, r=oli-obk
revert #114586

Reverts #114586.

cc #116877 (not closing until this gets a beta backport)
fixes #116684
fixes https://github.com/rust-lang/rust/pull/114586#issuecomment-1751967321

r? `@oli-obk` or `@lcnr`
2023-10-18 14:24:52 +03:00
Ali MJ Al-Nasrawy
42e5f415fe
Rollup merge of #116870 - compiler-errors:host-param-by-name, r=fee1-dead
Don't compare host param by name

Seems sketchy to be searching for `sym::host` by name, especially when we can get the actual index with not very much work.

r? fee1-dead
2023-10-18 14:24:52 +03:00
Ali MJ Al-Nasrawy
d69cdb2ceb
Rollup merge of #116865 - estebank:issue-46969, r=compiler-errors
Suggest constraining assoc types in more cases

Fix #46969.

```
error[E0308]: mismatched types
  --> $DIR/suggest-contraining-assoc-type-because-of-assoc-const.rs:12:21
   |
LL |     const N: C::M = 4u8;
   |                     ^^^ expected associated type, found `u8`
   |
   = note: expected associated type `<C as O>::M`
                         found type `u8`
help: consider constraining the associated type `<C as O>::M` to `u8`
   |
LL | impl<C: O<M = u8>> U<C> for u16 {
   |          ++++++++

```
2023-10-18 14:24:51 +03:00
Ali MJ Al-Nasrawy
0653d7eebf
Rollup merge of #116812 - rmehri01:missing_copy_implementations_non_exhaustive, r=petrochenkov
Disable missing_copy_implementations lint on non_exhaustive types

Fixes #116766
2023-10-18 14:24:50 +03:00
Zalathar
8efdd4cca6 coverage: Collect a function's coverage mappings into a single list
This is an intermediate step towards being able to store all of a function's
mappings in function coverage info.
2023-10-18 21:24:01 +11:00
Zalathar
79f935b96c coverage: Rename Operand to CovTerm
Later patches in this PR will use `CovTerm` to represent things that are not
expression operands.
2023-10-18 21:23:58 +11:00
Zalathar
a18c5f3b75 coverage: Store the number of counters/expressions in function coverage info
Coverage codegen can now allocate arrays based on the number of
counters/expressions originally used by the instrumentor.

The existing query that inspects coverage statements is still used for
determining the number of counters passed to `llvm.instrprof.increment`. If
some high-numbered counters were removed by MIR optimizations, the instrumented
binary can potentially use less memory and disk space at runtime.
2023-10-18 21:22:40 +11:00
Zalathar
c479bc7f3b coverage: Attach an optional FunctionCoverageInfo to mir::Body
This allows coverage information to be attached to the function as a whole when
appropriate, instead of being smuggled through coverage statements in the
function's basic blocks.

As an example, this patch moves the `function_source_hash` value out of
individual `CoverageKind::Counter` statements and into the per-function info.

When synthesizing unused functions for coverage purposes, the absence of this
info is taken to indicate that a function was not eligible for coverage and
should not be synthesized.
2023-10-18 21:20:29 +11:00
bors
e8b8c78d84 Auto merge of #116815 - Nilstrieb:more-funny-pretty-printers, r=compiler-errors
Remove lots of generics from `ty::print`

All of these generics mostly resolve to the same thing, which means we can remove them, greatly simplifying the types involved in pretty printing and unlocking another simplification (that is not performed in this PR): Using `&mut self` instead of passing `self` through the return type.

cc `@eddyb` you probably know why it's like this, just checking in and making sure I didn't do anything bad

r? oli-obk
2023-10-18 09:57:07 +00:00
Rémy Rakic
0bca45f620 allow target specs to declare self-contained linking components 2023-10-18 09:26:05 +00:00
bors
6d7160ce97 Auto merge of #116814 - estebank:windows-ice-path, r=petrochenkov
Use `YYYY-MM-DDTHH_MM_SS` as datetime format for ICE dump files

Windows paths do not support `:`, so use a datetime format in ICE dump paths that Windows will accept.

CC #116809, fix #115180.
2023-10-18 07:45:56 +00:00
Ali MJ Al-Nasrawy
a1e274f172 revert rust-lang/rust#114586 2023-10-18 06:19:04 +00:00
bors
b9832e72c9 Auto merge of #116713 - estebank:issue-116703, r=compiler-errors
Properly account for self ty in method disambiguation suggestion

Fix #116703.
2023-10-18 05:51:40 +00:00
bors
862bba6093 Auto merge of #116830 - nnethercote:rustc_type_ir, r=compiler-errors
Remove `IdFunctor` trait.

It's defined in `rustc_data_structures` but is only used in
`rustc_type_ir`. The code is shorter and easier to read if we remove
this layer of abstraction and just do the things directly where they are
needed.

r? `@BoxyUwU`
2023-10-18 03:55:36 +00:00
Nicholas Nethercote
a145b498e0 Remove UnknownPartitionStrategy error.
This became unused in #112053, when `-Zcgu-partitioning-strategy` was
removed.
2023-10-18 14:42:58 +11:00
Nicholas Nethercote
4f923376b6 Streamline build_skip_move_check_fns.
It's just a `filter_map(...).collect()`.
2023-10-18 14:42:57 +11:00
Nicholas Nethercote
55c5ab9fbc Inline and remove item_requires_monomorphization.
It's very simple and has a single call site.
2023-10-18 14:26:19 +11:00
Nicholas Nethercote
42c8803fe8 Remove empty MirUsedCollector::visit_local.
It has not effect, because the default `visit_local` in `mir::Visitor`
is already empty.
2023-10-18 14:24:15 +11:00
Nicholas Nethercote
025eb20a86 Remove unneeded dependencies from rustc_monomorphize. 2023-10-18 14:23:51 +11:00
Michael Goulet
232f3146b3 Make sure that non-pretty-printing usages are using the correct elaborator 2023-10-18 03:05:38 +00:00
Michael Goulet
910bb4fe25 Simplify transitive_bounds_that_define_assoc_item 2023-10-18 03:00:51 +00:00
Michael Goulet
9917ef9a66 Don't compare host param by name 2023-10-18 02:38:54 +00:00
Ben Kimock
33b0e4be06 Automatically enable cross-crate inlining for small functions 2023-10-17 19:53:51 -04:00
Esteban Küber
dee86bff40 Suggest constraining assoc types in more cases
Fix #46969.
2023-10-17 23:50:13 +00:00
Esteban Küber
890e92feed Unify suggestion wording 2023-10-17 17:33:55 +00:00
Esteban Küber
6cf01fcf1e review comments + more tests 2023-10-17 17:33:08 +00:00
Esteban Küber
5cc9216ff3 Properly account for self ty in method disambiguation suggestion
Fix #116703.
2023-10-17 17:33:08 +00:00
Esteban Küber
e1aa5adc78 Use YYYY-MM-DDTHH_MM_SS as datetime format for ICE dump files
Windows paths do not support `:`, so use a datetime format in ICE dump
paths that Windows will accept.

Fix #116809, fix #115180.
2023-10-17 17:31:47 +00:00
Matthias Krüger
6e6cd68cd0
Rollup merge of #116827 - nnethercote:pub-handle_options, r=compiler-errors
Make `handle_options` public again.

r? ``@compiler-errors``
2023-10-17 19:07:24 +02:00
Matthias Krüger
3ea438eb3a
Rollup merge of #116787 - a-lafrance:span-internal-lint, r=oli-obk
Implement an internal lint encouraging use of `Span::eq_ctxt`

Adds a new Rustc internal lint that forbids use of `.ctxt() == .ctxt()` for spans, encouraging use of `.eq_ctxt()` instead (see https://github.com/rust-lang/rust/issues/49509).

Also fixed a few violations of the lint in the Rustc codebase (a fun additional way I could test my code). Edit: MIR opt folks I believe that's why you're CC'ed, just a heads up.

Two things I'm not sure about:
1. The way I chose to detect calls to `Span::ctxt`. I know adding diagnostic items to methods is generally discouraged, but after some searching and experimenting I couldn't find anything else that worked, so I went with it. That said, I'm happy to implement something different if there's a better way out there. (For what it's worth, if there is a better way, it might be worth documenting in the rustc-dev-guide, which I'm happy to take care of)
2. The error message for the lint. Ideally it would probably be good to give some context as to why the suggestion is made (e.g. `rustc::default_hash_types` tells the user that it's because of performance), but I don't have that context so I couldn't put it in the error message. Happy to iterate on the error message based on feedback during review.

r? ``@oli-obk``
2023-10-17 19:07:23 +02:00
Matthias Krüger
00f529d246
Rollup merge of #116719 - celinval:smir-mono, r=oli-obk
Add MonoItems and Instance to stable_mir

Also add a few methods to instantiate instances and get an instance definition. We're still missing support to actually monomorphize the instance body.

This is related to https://github.com/rust-lang/project-stable-mir/issues/36

r? ``@oli-obk``

``@oli-obk`` is that what you were thinking? I incorporated ``@bjorn3`` idea of just adding a Shim instance definition in https://github.com/rust-lang/rust/pull/116465.
2023-10-17 19:07:23 +02:00
Matthias Krüger
a5aa52c23a
Rollup merge of #116717 - estebank:issue-9082, r=oli-obk
Special case iterator chain checks for suggestion

When encountering method call chains of `Iterator`, check for trailing `;` in the body of closures passed into `Iterator::map`, as well as calls to `<T as Clone>::clone` when `T` is a type param and `T: !Clone`.

Fix #9082.
2023-10-17 19:07:22 +02:00
Matthias Krüger
ce407429dd
Rollup merge of #111072 - Urgau:check-cfg-new-syntax, r=petrochenkov
Add new simpler and more explicit syntax for check-cfg

<details>
<summary>
Old proposition (before the MCP)
</summary>

This PR adds a new simpler and more explicit syntax for check-cfg. It consist of two new form:
 - `exhaustive(names, values)`
 - `configure(name, "value1", "value2", ... "valueN")`

The preview forms `names(...)` and `values(...)` have implicit meaning that are not strait-forward. In particular `values(foo)`&`values(bar)` and `names(foo, bar)` are not equivalent which has created [some confusions](https://github.com/rust-lang/rust/pull/98080).

Also the `names()` and `values()` form are not clear either and again created some confusions where peoples believed that `values()`&`values(foo)` could be reduced to just `values(foo)`.

To fix that the two new forms are made to be explicit and simpler. See the table of correspondence:
  - `names()` -> `exhaustive(names)`
  - `values()` -> `exhaustive(values)`
  - `names(foo)` -> `exhaustive(names)`&`configure(foo)`
  - `values(foo)` -> `configure(foo)`
  - `values(feat, "foo", "bar")` -> `configure(feat, "foo", "bar")`
  - `values(foo)`&`values(bar)` -> `configure(foo, bar)`
  - `names()`&`values()`&`values(my_cfg)` -> `exhaustive(names, values)`&`configure(my_cfg)`

Another benefits of the new syntax is that it allow for further options (like conditional checking for --cfg, currently always on) without syntax change.

The two previous forms are deprecated and will be removed once cargo and beta rustc have the necessary support.

</details>

This PR is the first part of the implementation of [MCP636 - Simplify and improve explicitness of the check-cfg syntax](https://github.com/rust-lang/compiler-team/issues/636).

## New `cfg` form

It introduces the new [`cfg` form](https://github.com/rust-lang/compiler-team/issues/636) and deprecate the other two:
```
rustc --check-cfg 'cfg(name1, ..., nameN, values("value1", "value2", ... "valueN"))'
```

## Default built-in names and values

It also changes the default for the built-in names and values checking.

 - Built-in values checking would always be activated as long as a `--check-cfg` argument is present
 - Built-in names checking would always be activated as long as a `--check-cfg` argument is present **unless** if any `cfg(any())` arg is passed

~~**Note: depends on https://github.com/rust-lang/rust/pull/111068 but is reviewable (last two commits)!**~~

Resolve https://github.com/rust-lang/compiler-team/issues/636

r? `@petrochenkov`
2023-10-17 19:07:21 +02:00
Nilstrieb
6fc6a6d783 Remove Print::Error
All printing goes through `fmt::Error` now.
2023-10-17 18:02:57 +02:00
Nilstrieb
6038888118 Remove Printer::Error
It's always a `fmt::Error` except in some cases where it was `!`, but
we're not really winning anything in that case.
2023-10-17 18:02:55 +02:00
Nilstrieb
0b5a4c1adf Remove Print::Output
Now that `Printer` doesn't have subprinters anymore, the output of a
printing operation is always the same.
2023-10-17 18:01:07 +02:00
Nilstrieb
3895f0e9af Remove "subprinter" types from Printer
These are `Self` in almost all printers except one, which can just store
the state as a field instead. This simplifies the printer and allows for
further simplifications, for example using `&mut self` instead of
passing around the printer.
2023-10-17 18:01:05 +02:00
Ryan Mehri
a8e7e79101 disable missing_copy_implementations lint on non_exhaustive types
use is_variant_list_non_exhaustive/is_field_list_non_exhaustive

remove unused tcx

inline non_exhaustive def/variant check
2023-10-17 08:33:37 -07:00
bors
616e37919c Auto merge of #116756 - fee1-dead-contrib:dupe-those-bounds, r=oli-obk
Duplicate `~const` bounds with a non-const one in effects desugaring

This should unblock #116058.

r? `@oli-obk`
2023-10-17 12:16:54 +00:00
Urgau
eccc9e6628 [RFC 3127 - Trim Paths]: Condition remapped filepath on remap scopes 2023-10-17 10:11:30 +02:00
Urgau
30f94717ca [RFC 3127 - Trim Paths]: Add unstable option and parsing 2023-10-17 10:11:30 +02:00
Nicholas Nethercote
178ba0e85c Rewrite Box<T>::try_fold_with.
It can be written more simply, without needing `unsafe`.
2023-10-17 16:26:37 +11:00
Nicholas Nethercote
847c8ba70d Remove IdFunctor trait.
It's defined in `rustc_data_structures` but is only used in
`rustc_type_ir`. The code is shorter and easier to read if we remove
this layer of abstraction and just do the things directly where they are
needed.
2023-10-17 16:26:35 +11:00
Nicholas Nethercote
4175c9b595 Remove unused features from rustc_data_structures. 2023-10-17 16:26:12 +11:00
bors
631a116cd3 Auto merge of #116822 - notriddle:notriddle/rust-logo, r=fmease
docs: add Rust logo to more compiler crates

c6e6ecb1af added it to some of the compiler's crates, but avoided adding it to all of them to reduce bit-rot. This commit adds to more.

r? `@GuillaumeGomez`
2023-10-17 04:41:20 +00:00
Arthur Lafrance
52ad8199d5 tweak pass description and fix lint fail post-rebase 2023-10-16 19:50:31 -07:00
Arthur Lafrance
5895102c4d debug Span::ctxt() call detection 2023-10-16 19:50:29 -07:00
bors
c07693c160 Auto merge of #116477 - nnethercote:tidy-alpha-deps, r=wesleywiser
Use tidy to enforce alphabetical dependency ordering

I get annoyed when dependencies in `Cargo.toml` files are not in alphabetical order. The [style guide](https://github.com/rust-lang/rust/blob/master/src/doc/style-guide/src/cargo.md) agrees with me.

There are ongoing efforts to provide linting/formatting of `Cargo.toml` files, e.g. https://github.com/rust-lang/rustfmt/pull/5240, https://crates.io/crates/cargo-toml-lint, and https://github.com/TimonPost/cargo-toml-format. But it's far from clear what's the right approach.

So this PR does something very simple: it uses the order checking already present in tidy. This allows incremental application of ordering, starting right now, and avoiding the need for any kind of all-at-once conversion.

If we do end up using some more comprehensive `Cargo.toml` linting/formatting solution in the future, the `tidy-alphabetical` lines will be easy to remove.

r? `@wesleywiser`
2023-10-17 02:48:03 +00:00
Arthur Lafrance
f77dea89e1 basic lint v2 implemented 2023-10-16 19:47:33 -07:00
Arthur Lafrance
8769e02d0b implement the basics of the lint static analysis 2023-10-16 19:47:33 -07:00
Nicholas Nethercote
b0e1a52e37 Make handle_options public again. 2023-10-17 13:25:58 +11:00
bors
39164b84e0 Auto merge of #116826 - nnethercote:fix-116780-116797, r=compiler-errors
Fix a performance regression in obligation deduplication.

Commit 8378487 from #114611 changed the location of an obligation deduplication step in `opt_normalize_projection_type`. This meant that deduplication stopped happening on one path where it was still necessary, causing a couple of drastic performance regressions.

This commit moves the deduplication back to the old location. The good news is that #114611 had four commits and 8378487 was of minimal importance, so the perf benefits from that PR remain.

Fixes #116780, #116797.

r? `@compiler-errors`
2023-10-17 00:53:53 +00:00
Nicholas Nethercote
91f2fbc867 Fix a performance regression in obligation deduplication.
Commit 8378487 from #114611 changed the location of an obligation
deduplication step in `opt_normalize_projection_type`. This meant that
deduplication stopped happening on one path where it was still
necessary, causing a couple of drastic performance regressions.

This commit moves the deduplication back to the old location. The good
news is that #114611 had four commits and 8378487 was of minimal
importance, so the perf benefits from that PR remain.

Fixes #116780, #116797.
2023-10-17 11:02:59 +11:00
Michael Howell
2ff2624722 docs: add Rust logo to more compiler crates
c6e6ecb1af added it to some of the
compiler's crates, but avoided adding it to all of them to reduce
bit-rot. This commit adds to more.
2023-10-16 15:38:08 -07:00
Guillaume Gomez
05e2056746
Rollup merge of #116811 - narpfel:unpretty-unicode-escape-in-format-string-literal, r=Nilstrieb
Preserve unicode escapes in format string literals when pretty-printing AST

Fixes #116799

Thanks to `@Nilstrieb` for the pointer to the correct location, that was really helpful for someone unfamiliar with the codebase.
2023-10-16 23:58:06 +02:00
Guillaume Gomez
347f7f3bf4
Rollup merge of #116805 - Nilstrieb:onunimplemented-std-core-alloc-whatever-who-cares, r=compiler-errors
Make `rustc_onunimplemented` export path agnostic

This makes it so that all the matchers that match against paths use the definition path instead of the export path. This removes all duplication around `std`/`alloc`/`core`.

This is not necessarily optimal because we now depend on internal implementation details like `core::ops::control_flow::ControlFlow`, which is not very nice and probably not acceptable for a stable `on_unimplemented`.

An alternative would be to just string-replace normalize away `alloc`/`core` to `std` as a special case, keeping the export paths but making it so that we're still fully standard library flavor agnostic.

Looking at the diff, I'm starting to think that some simple string replacement would go a long way towards fixing the problem of duplication while keeping export paths...

What do you prefer?

Also `@weiznich` for your thoughts about the stable version.

r? compiler-errors
2023-10-16 23:58:05 +02:00
Guillaume Gomez
d0ade3f1ba
Rollup merge of #116800 - compiler-errors:rpitit-gat-outlives, r=jackh726
Fix implied outlives check for GAT in RPITIT

We enforce certain `Self: 'lt` bounds for GATs to save space for more sophisticated implied bounds, but those currently operate on the HIR. Code was easily reworked to operate on def-ids so that we can properly let these suggestions propagate through synthetic associated types like RPITITs and AFITs.

r? `@jackh726` or `@aliemjay`

Fixes #116789
2023-10-16 23:58:04 +02:00
Guillaume Gomez
581f88deda
Rollup merge of #116754 - Zalathar:spans, r=oli-obk
coverage: Several small cleanups in `spans`

While investigating the details of coverage span processing, I noticed several opportunities to make the code simpler and clearer.

---

`@rustbot` label +A-code-coverage
2023-10-16 23:58:03 +02:00
Esteban Küber
26954f60ff address review comment 2023-10-16 19:48:53 +00:00
Paul Gey
587899e9ca Preserve unicode escapes in format string literals when pretty-printing AST 2023-10-16 21:20:21 +02:00
Celina G. Val
364f1a3f16 Add MonoItems and Instance to stable_mir
Also add a few methods to instantiate instances and get an instance
definition.

We're still missing support to actually monomorphize the instance body.
2023-10-16 12:01:24 -07:00
bors
a76ec181fb Auto merge of #116804 - matthiaskrgr:rollup-m2qm8ul, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #114157 (Enable triagebot no-merges check)
 - #116257 (Suggest trait bounds for used associated type on type param)
 - #116430 (vendoring in tarball sources)
 - #116709 (Update minifier version to 0.2.3)
 - #116786 (Update my mailmap entry)
 - #116790 (opt-dist: disable unused features for tabled crate)
 - #116802 (Remove `DefiningAnchor::Bubble` from opaque wf check)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-10-16 18:57:44 +00:00
Nilstrieb
414135d522 Make rustc_onunimplemented export path agnostic
This makes it so that all the matchers that match against paths use the
definition path instead of the export path. This removes all duplication
around `std`/`alloc`/`core`.

This is not necessarily optimal because we now depend on internal
implementation details like `core::ops::control_flow::ControlFlow`,
which is not very nice and probably not acceptable for a stable
`on_unimplemented`.

An alternative would be to just string-replace normalize away
`alloc`/`core` to `std` as a special case, keeping the export paths but
making it so that we're still fully standard library flavor agnostic.
2023-10-16 19:37:12 +02:00
Matthias Krüger
b0572f1a12
Rollup merge of #116802 - compiler-errors:anchor-opaque-wf, r=oli-obk
Remove `DefiningAnchor::Bubble` from opaque wf check

Set the defining anchor to `DefiningAnchor::Bind(parent_def_id)` where `parent_def_id` is the first parent def-id that isn't an opaque.

This "fixes" some of the nested-return-type wf tests. If we *do* want these to be hard-errors for TAITs, we should probably make those error separately from this check (i.e. via some check like the code in the `OPAQUE_HIDDEN_INFERRED_BOUND` lint). The fact that some of these tests fail but not all of them seems kinda coincidental.

r? oli-obk
2023-10-16 19:10:51 +02:00
Matthias Krüger
14663e09b7
Rollup merge of #116257 - estebank:issue-101351, r=b-naber
Suggest trait bounds for used associated type on type param

Fix #101351.

When an associated type on a type parameter is used, and the type parameter isn't constrained by the correct trait, suggest the appropriate trait bound:

```
error[E0220]: associated type `Associated` not found for `T`
 --> file.rs:6:15
  |
6 |     field: T::Associated,
  |               ^^^^^^^^^^ there is a similarly named associated type `Associated` in the trait `Foo`
  |
help: consider restricting type parameter `T`
  |
5 | struct Generic<T: Foo> {
  |                 +++++
  ```

When an associated type on a type parameter has a typo, suggest fixing
it:

```
error[E0220]: associated type `Baa` not found for `T`
  --> $DIR/issue-55673.rs:9:8
   |
LL |     T::Baa: std::fmt::Debug,
   |        ^^^ there is a similarly named associated type `Bar` in the trait `Foo`
   |
help: change the associated type name to use `Bar` from `Foo`
   |
LL |     T::Bar: std::fmt::Debug,
   |        ~~~
```
2023-10-16 19:10:49 +02:00
bors
4af886f8ab Auto merge of #116731 - Alexendoo:hash-untracked-state, r=oli-obk
Add `Config::hash_untracked_state` callback

For context, I'm looking to use [late module passes](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/context/struct.LintStore.html#structfield.late_module_passes) in Clippy which unlike regular late passes run incrementally per module

However we have a config file which can change between runs, we need changes to that to invalidate the `lint_mod` query. This PR adds a side channel for us to hash some extra state into `Options` in order to do that

This does not make any changes to Clippy, I plan to do that in a PR to the Clippy repo along with some other required changes

An alternative implementation would be to add a new query to track this state and override the `lint_mod` query in Clippy to first call that

cc `@rust-lang/clippy`
2023-10-16 16:33:42 +00:00
Matthew Jasper
8aea0e9590 Address review comments
Clean up code and add comments.
Use InlineConstant to wrap range patterns.
2023-10-16 15:58:01 +00:00
Matthew Jasper
5cc83fd4a5 Fix inline const pattern unsafety checking in THIR
THIR unsafety checking was getting a cycle of
function unsafety checking
-> building THIR for the function
-> evaluating pattern inline constants in the function
-> building MIR for the inline constant
-> checking unsafety of functions (so that THIR can be stolen)
This is fixed by not stealing THIR when generating MIR but instead when
unsafety checking.
This leaves an issue with pattern inline constants not being unsafety
checked because they are evaluated away when generating THIR.
To fix that we now represent inline constants in THIR patterns and
visit them in THIR unsafety checking.
2023-10-16 15:57:59 +00:00
Michael Goulet
743e6d1601 Remove DefiningAnchor::Bubble from opaque wf check 2023-10-16 15:50:31 +00:00
Michael Goulet
17ec3cd5bf Fix outlives suggestion for GAT in RPITIT 2023-10-16 15:42:26 +00:00
bors
98c1e3d95b Auto merge of #116550 - nnethercote:rustc-features-more, r=Nilstrieb
Cleanup `rustc_features` some more

The sequel to #116437.

r? `@Nilstrieb`
2023-10-16 14:34:53 +00:00
bors
e7bdc5f9f8 Auto merge of #114330 - RalfJung:dagling-ptr-deref, r=oli-obk
don't UB on dangling ptr deref, instead check inbounds on projections

This implements https://github.com/rust-lang/reference/pull/1387 in Miri. See that PR for what the change is about.

Detecting dangling references in `let x = &...;` is now done by validity checking only, so some tests need to have validity checking enabled. There is no longer inherently a "nodangle" check in evaluating the expression `&*ptr` (aside from the aliasing model).

r? `@oli-obk`

Based on:
- https://github.com/rust-lang/reference/pull/1387
- https://github.com/rust-lang/rust/pull/115524
2023-10-16 12:40:16 +00:00
Jonáš Fiala
2bba98b121 Avoid unnecessary renumbering 2023-10-16 14:29:36 +02:00
bors
a00c09e9d8 Auto merge of #116724 - RalfJung:alloc-bytes, r=oli-obk
interpret: clean up AllocBytes

Fixes https://github.com/rust-lang/miri/issues/2836
Nothing has moved here in half a year, so let's just remove these unused stubs -- they need a proper re-design anyway.

r? `@oli-obk`
2023-10-16 10:45:00 +00:00
Zalathar
7aa1b8390b coverage: Explain why we temporarily steal pending_dups 2023-10-16 21:05:46 +11:00
Zalathar
5e5a8e7769 coverage: Inline span_bcb_dominates
Interacting with `basic_coverage_blocks` directly makes it easier to satisfy
the borrow checker when mutating `pending_dups` while reading other fields.
2023-10-16 21:05:46 +11:00
Zalathar
4ab4273d64 coverage: Inline prev_starts_after_next 2023-10-16 21:05:46 +11:00
Zalathar
25e6303202 coverage: Move take_curr and note what its callers are doing 2023-10-16 21:05:46 +11:00
Zalathar
41038dbe4a coverage: Call prev/curr less in other places
This reduces clutter, and makes it easier to notice regions where mutations
definitely don't occur.
2023-10-16 21:05:46 +11:00
Zalathar
b1c44f4a25 coverage: Call prev/curr less in to_refined_spans
This makes it easier to see that the non-initial cases assume that `prev` and
`curr` are set, and all operate on the same prev/curr references.
2023-10-16 21:05:46 +11:00
Zalathar
9bb27f3adf coverage: Remove redundant field prev_expn_span
This span can always be retrieved from `prev`, so there is no need to store it
separately.
2023-10-16 21:05:45 +11:00
Zalathar
7bbe4be568 coverage: Flatten guard logic in maybe_flush_pending_dups 2023-10-16 21:05:45 +11:00
Zalathar
97d1a9120e coverage: Flatten guard logic in maybe_push_macro_name_span 2023-10-16 21:05:33 +11:00
Zalathar
5f1e8f9950 coverage: Simplify push_refined_span
It turns out that all of the `len` manipulation here was just reimplementing
`last_mut`.
2023-10-16 20:54:36 +11:00
Zalathar
fa2e26285c coverage: Use DUMMY_SP instead of creating a dummy span manually
This patch also sorts the constructor fields into declaration order.
2023-10-16 20:54:36 +11:00
Zalathar
d928d3e5d8 coverage: Rename hold_pending_dups_unless_dominated to update_pending_dups 2023-10-16 20:54:16 +11:00
Zalathar
9b6ce4fb3c coverage: Rename check_pending_dups to maybe_flush_pending_dups
This method's main responsibility is to flush the pending dups into refined
spans, if appropriate.
2023-10-16 20:53:41 +11:00
Zalathar
46c545c1ba coverage: Rename check_invoked_macro_name_span to maybe_push_macro_name_span 2023-10-16 20:52:20 +11:00
Matthias Krüger
1de910fc0d
Rollup merge of #115196 - chenyukang:yukang-fix-86094, r=estebank
Suggest adding `return` if the for semi which can coerce to the fn return type

Fixes #86094
r? `@estebank`
2023-10-16 06:26:20 +02:00
Nicholas Nethercote
d284c8a2d7 Rename ACTIVE_FEATURES as UNSTABLE_FEATURES.
It's a better name, and lets "active features" refer to the features
that are active in a particular program, due to being declared or
enabled by the edition.

The commit also renames `Features::enabled` as `Features::active` to
match this; I changed my mind and have decided that "active" is a little
better thatn "enabled" for this, particularly because a number of
pre-existing comments use "active" in this way.

Finally, the commit renames `Status::Stable` as `Status::Accepted`, to
match `ACCEPTED_FEATURES`.
2023-10-16 08:17:23 +11:00
Nicholas Nethercote
41b6899487 Remove rustc_feature::State.
`State` is used to distinguish active vs accepted vs removed features.
However, these can also be distinguished by their location, in
`ACTIVE_FEATURES`, `ACCEPTED_FEATURES`, and `REMOVED_FEATURES`.

So this commit removes `State` and moves the internals of its variants
next to the `Feature` in each element of `*_FEATURES`, introducing new
types `ActiveFeature` and `RemovedFeature`. (There is no need for
`AcceptedFeature` because `State::Accepted` had no fields.)

This is a tighter type representation, avoids the need for some runtime
checks, and makes the code a bit shorter.
2023-10-16 08:15:30 +11:00
Matthias Krüger
51be0df011
Rollup merge of #116522 - bvanjoi:fix-115599, r=oli-obk
use `PatKind::Error` when an ADT const value has violation

Fixes #115599

Since the [to_pat](https://github.com/rust-lang/rust/pull/111913/files#diff-6d8d99538aca600d633270051580c7a9e40b35824ea2863d9dda2c85a733b5d9R126-R155) behavior has been changed in the #111913 update, the kind of `inlined_const_ast_pat` has transformed from `PatKind::Leaf { pattern: Pat { kind: Wild, ..} } ` to `PatKind::Constant`. This caused a scenario where there are no matched candidates, leading to a testing of the candidates. This process ultimately attempts to test the string const, triggering the `bug!` invocation finally.

r? ``@oli-obk``
2023-10-15 21:29:07 +02:00
Ralf Jung
28b0c87ad6 update MIR place semantics UB comment 2023-10-15 18:13:33 +02:00
Ralf Jung
b131fc10ae separate bounds-check from alignment check 2023-10-15 18:13:33 +02:00
Ralf Jung
e24835c6e0 more precise error for 'based on misaligned pointer' case 2023-10-15 18:13:33 +02:00
Ralf Jung
cbf47a17d2 avoid computing misalignment if we won't act on it 2023-10-15 18:13:33 +02:00
Ralf Jung
f3f9b795bd place evaluation: require the original pointer to be aligned if an access happens 2023-10-15 18:13:31 +02:00
Ralf Jung
ea9a24e32e avoid re-checking the offset while iterating an array/slice 2023-10-15 18:12:46 +02:00
Ralf Jung
b1ebf002c3 don't UB on dangling ptr deref, instead check inbounds on projections 2023-10-15 18:12:46 +02:00
yukang
25d38c48c3 Suggest adding return if the type of unused semi return value can coerce to the fn return type 2023-10-15 22:57:03 +08:00
bors
a48396984a Auto merge of #116688 - compiler-errors:rustfmt-up, r=WaffleLapkin,Nilstrieb
Format all the let-chains in compiler crates

Since rust-lang/rustfmt#5910 has landed, soon we will have support for formatting let-chains (as soon as rustfmt syncs and beta gets bumped).

This PR applies the changes [from master rustfmt to rust-lang/rust eagerly](https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/out.20formatting.20of.20prs/near/374997516), so that the next beta bump does not have to deal with a 200+ file diff and can remain concerned with other things like `cfg(bootstrap)` -- #113637 was a pain to land, for example, because of let-else.

I will also add this commit to the ignore list after it has landed.

The commands that were run -- I'm not great at bash-foo, but this applies rustfmt to every compiler crate, and then reverts the two crates that should probably be formatted out-of-tree.
```
~/rustfmt $ ls -1d ~/rust/compiler/* | xargs -I@ cargo run --bin rustfmt -- `@/src/lib.rs` --config-path ~/rust --edition=2021 # format all of the compiler crates
~/rust $ git checkout HEAD -- compiler/rustc_codegen_{gcc,cranelift} # revert changes to cg-gcc and cg-clif
```

cc `@rust-lang/rustfmt`
r? `@WaffleLapkin` or `@Nilstrieb` who said they may be able to review this purely mechanical PR :>

cc `@Mark-Simulacrum` and `@petrochenkov,` who had some thoughts on the order of operations with big formatting changes in https://github.com/rust-lang/rust/pull/95262#issue-1178993801. I think the situation has changed since then, given that let-chains support exists on master rustfmt now, and I'm fairly confident that this formatting PR should land even if *bootstrap* rustfmt doesn't yet format let-chains in order to lessen the burden of the next beta bump.
2023-10-15 13:23:55 +00:00
bohan
223674a824 use PatKind::error when an ADT const value has violation 2023-10-15 19:20:06 +08:00
Matthias Krüger
23d8847ae9
Rollup merge of #116748 - scottmcm:oops-typo, r=fee1-dead
Fix a spot I wrote the wrong word

I was reading this comment while I was looking at #116505, and it garden-path-sentence'd me, so fix that for people in the future.
2023-10-15 11:37:24 +02:00
Deadbeef
f0f89d6d43 Duplicate ~const bounds with a non-const one in effects desugaring 2023-10-15 08:59:38 +00:00
Scott McMurray
5e572c7207 Fix a spot I wrote the wrong word 2023-10-14 15:22:41 -07:00
Guillaume Gomez
03cbf50c34
Rollup merge of #116576 - eduardosm:const-eval-wasm-target-features, r=RalfJung
const-eval: allow calling functions with targat features disabled at compile time in WASM

This is not unsafe on WASM, see https://github.com/rust-lang/rust/pull/84988

r? `@RalfJung`

Fixes https://github.com/rust-lang/rust/issues/116516
2023-10-14 22:35:05 +02:00
Eduardo Sánchez Muñoz
f9b1af6587 const-eval: allow calling functions with targat features disabled at compile time in WASM
This is not unsafe on WASM, see https://github.com/rust-lang/rust/pull/84988
2023-10-14 20:15:05 +02:00
Nadrieril
ca869e3334 Lint non_exhaustive_omitted_patterns per column 2023-10-14 19:39:18 +02:00
Nadrieril
272c914bdd Distinguish user patterns from reconstructed witnesses 2023-10-14 19:39:18 +02:00
Matthias Krüger
7d1b24f4bc
Rollup merge of #116715 - Nadrieril:patkind-error, r=oli-obk
Prevent more spurious unreachable pattern lints

Continues the work of https://github.com/rust-lang/rust/pull/115937 by introducing `PatKind::Error`, to be used instead of `PatKind::Wild` when an error was raised during pattern lowering. Most of match checking lints are skipped when a `PatKind::Error` is encountered. This avoids confusing extra warnings when a pattern is malformed. Now `PatKind::Wild` should indicate an actual wildcard pattern.

r? `@oli-obk`
2023-10-14 19:22:17 +02:00
Alex Macleod
59f6f044f5 Add Config::hash_untracked_state callback 2023-10-14 15:54:26 +00:00
bors
0233608c67 Auto merge of #116727 - matthiaskrgr:rollup-3qqdrny, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #116630 (Add ability to get lines/filename for Span in smir)
 - #116644 (remove outdated bootstrap FIXME)
 - #116695 (Fix a comment)
 - #116696 (Misc improvements)
 - #116704 (Fix AFIT lint message to mention pitfall)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-10-14 15:07:25 +00:00
bors
495c5ddcf7 Auto merge of #116728 - matthiaskrgr:rollup-4xzcsnv, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #115653 (Guarantee that Layout::align returns a non-zero power of two)
 - #116577 (add `SAFETY` block on the usage of unsafe `getuid`)
 - #116618 (Add the V (vector) extension to the riscv64-linux-android target spec)
 - #116679 (Remove some unnecessary `unwrap`s)
 - #116689 (explicitly handle auto trait leakage in coherence)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-10-14 13:17:25 +00:00
Matthias Krüger
45bcef3cd5
Rollup merge of #116689 - lcnr:auto-trait-hidden-ty-leak, r=compiler-errors
explicitly handle auto trait leakage in coherence

does not impact behavior but may avoid weird bugs in the future, cc https://github.com/rust-lang/trait-system-refactor-initiative/issues/65

r? ``@compiler-errors``
2023-10-14 13:48:20 +02:00
Matthias Krüger
30b2cc0cc3
Rollup merge of #116679 - estebank:rewrap-unwrap, r=oli-obk
Remove some unnecessary `unwrap`s
2023-10-14 13:48:19 +02:00
Matthias Krüger
f29dbe8885
Rollup merge of #116618 - chriswailes:riscv64-linux-android-vector, r=workingjubilee
Add the V (vector) extension to the riscv64-linux-android target spec

This feature has been enabled and tested internally in the Android project.
2023-10-14 13:48:19 +02:00
Nadrieril
89f75ff4d0 Skip most of check_match checks in the presence of PatKind::Error 2023-10-14 13:38:04 +02:00
Nadrieril
8646afb9c5 Use PatKind::Error instead of PatKind::Wild to report errors 2023-10-14 13:38:04 +02:00
Nadrieril
aab3b9327e Propagate pattern errors via a new PatKind::Error variant
Instead of via `Const::new_error`
2023-10-14 13:38:02 +02:00