Commit Graph

29257 Commits

Author SHA1 Message Date
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
Matthias Krüger
24116aebe0
Rollup merge of #116704 - compiler-errors:afit-lint-plus, r=tmandry
Fix AFIT lint message to mention pitfall

Addresses https://github.com/rust-lang/rust/pull/116184#issuecomment-1745194387 by adding a short note. Not sure exactly of the wording -- I don't think this should be a blocker for the stabilization PR since we can iterate on this lint's messaging in the next few weeks in the worst case.

r? `@tmandry` cc `@traviscross` `@jonhoo`
2023-10-14 13:36:29 +02:00
Matthias Krüger
6fef4f089f
Rollup merge of #116696 - c410-f3r:in-doc, r=petrochenkov
Misc improvements

cc https://github.com/rust-lang/rust/pull/116323#discussion_r1355282195

r? `@petrochenkov`
2023-10-14 13:36:28 +02:00
Matthias Krüger
e515116083
Rollup merge of #116695 - fee1-dead-contrib:fix-cmt, r=compiler-errors
Fix a comment
2023-10-14 13:36:28 +02:00
Matthias Krüger
3890ba9f14
Rollup merge of #116630 - ouz-a:smir_span_better, r=oli-obk
Add ability to get lines/filename for Span in smir

Wasn't sure about how to structure lines, so went with safest option, also I'm not sure why `span_to_lines` returns `vec`.

Addresses https://github.com/rust-lang/project-stable-mir/issues/44

r? ``@oli-obk``
2023-10-14 13:36:27 +02:00
bors
96c4dba794 Auto merge of #116702 - durin42:compress-debuginfo, r=compiler-errors
linker: also pass debuginfo compression flags

We support compressing debuginfo during codegen, but until this patch we didn't pass the flag to the linker. Doing so means we'll respect the requested compression even when building binaries or dylibs. This produces much smaller binaries: in my testing a debug build of ripgrep goes from 85M to 32M, and the target/ directory (after a clean build in both cases) goes from 508M to 329M just by enabling zlib compression of debuginfo.
2023-10-14 11:05:04 +00:00
Ralf Jung
9c417a4ad4 interpret: clean up AllocBytes 2023-10-14 12:29:16 +02:00
bors
139f63a6eb Auto merge of #116015 - EvanMerlock:master, r=oli-obk
const_eval: allow function pointer signatures containing &mut T in const contexts

potentially fixes #114994

We utilize a `TypeVisitor` here in order to more easily handle control flow.
- In the event the typekind the Visitor sees is a function pointer, we skip over it
- However, otherwise we do one of two things:
   - If we find a mutable reference, check it, then continue visiting types
   - If we find any other type, continue visiting types

This means we will check if the function pointer _itself_ is mutable, but not if any of the types _within_ are.
2023-10-14 09:18:28 +00:00
bors
481d45abec Auto merge of #115822 - compiler-errors:stabilize-rpitit, r=jackh726
Stabilize `async fn` and return-position `impl Trait` in trait

# Stabilization report

This report proposes the stabilization of `#![feature(return_position_impl_trait_in_trait)]` ([RPITIT][RFC 3425]) and `#![feature(async_fn_in_trait)]` ([AFIT][RFC 3185]). These are both long awaited features that increase the expressiveness of the Rust language and trait system.

Closes #91611

[RFC 3185]: https://rust-lang.github.io/rfcs/3185-static-async-fn-in-trait.html
[RFC 3425]: https://rust-lang.github.io/rfcs/3425-return-position-impl-trait-in-traits.html

## Updates from thread

The thread has covered two major concerns:

* [Given that we don't have RTN, what should we stabilize?](https://github.com/rust-lang/rust/pull/115822#issuecomment-1731149475) -- proposed resolution is [adding a lint](https://github.com/rust-lang/rust/pull/115822#issuecomment-1728354622) and [careful messaging](https://github.com/rust-lang/rust/pull/115822#issuecomment-1731136169)
* [Interaction between outlives bounds and capture semantics](https://github.com/rust-lang/rust/pull/115822#issuecomment-1731153952) -- This is fixable in a forwards-compatible way via #116040, and also eventually via ATPIT.

## Stabilization Summary

This stabilization allows the following examples to work.

### Example of return-position `impl Trait` in trait definition

```rust
trait Bar {
    fn bar(self) -> impl Send;
}
```

This declares a trait method that returns *some* type that implements `Send`.  It's similar to writing the following using an associated type, except that the associated type is anonymous.

```rust
trait Bar {
    type _0: Send;
    fn bar(self) -> Self::_0;
}
```

### Example of return-position `impl Trait` in trait implementation

```rust
impl Bar for () {
    fn bar(self) -> impl Send {}
}
```

This defines a method implementation that returns an opaque type, just like [RPIT][RFC 1522] does, except that all in-scope lifetimes are captured in the opaque type (as is already true for `async fn` and as is expected to be true for RPIT in Rust Edition 2024), as described below.

[RFC 1522]: https://rust-lang.github.io/rfcs/1522-conservative-impl-trait.html

### Example of `async fn` in trait

```rust
trait Bar {
    async fn bar(self);
}

impl Bar for () {
    async fn bar(self) {}
}
```

This declares a trait method that returns *some* [`Future`](https://doc.rust-lang.org/core/future/trait.Future.html) and a corresponding method implementation.  This is equivalent to writing the following using RPITIT.

```rust
use core::future::Future;

trait Bar {
    fn bar(self) -> impl Future<Output = ()>;
}

impl Bar for () {
    fn bar(self) -> impl Future<Output = ()> { async {} }
}
```

The desirability of this desugaring being available is part of why RPITIT and AFIT are being proposed for stabilization at the same time.

## Motivation

Long ago, Rust added [RPIT][RFC 1522] and [`async`/`await`][RFC 2394].  These are major features that are widely used in the ecosystem.  However, until now, these feature could not be used in *traits* and trait implementations.  This left traits as a kind of second-class citizen of the language.  This stabilization fixes that.

[RFC 2394]: https://rust-lang.github.io/rfcs/2394-async_await.html

### `async fn` in trait

Async/await allows users to write asynchronous code much easier than they could before. However, it doesn't play nice with other core language features that make Rust the great language it is, like traits. Support for `async fn` in traits has been long anticipated and was not added before due to limitations in the compiler that have now been lifted.

`async fn` in traits will unblock a lot of work in the ecosystem and the standard library. It is not currently possible to write a trait that is implemented using `async fn`. The workarounds that exist are undesirable because they require allocation and dynamic dispatch, and any trait that uses them will become obsolete once native `async fn` in trait is stabilized.

We also have ample evidence that there is demand for this feature from the [`async-trait` crate][async-trait], which emulates the feature using dynamic dispatch. The async-trait crate is currently the #5 async crate on crates.io ranked by recent downloads, receiving over 78M all-time downloads. According to a [recent analysis][async-trait-analysis], 4% of all crates use the `#[async_trait]` macro it provides, representing 7% of all function and method signatures in trait definitions on crates.io. We think this is a *lower bound* on demand for the feature, because users are unlikely to use `#[async_trait]` on public traits on crates.io for the reasons already given.

[async-trait]: https://crates.io/crates/async-trait
[async-trait-analysis]: https://rust-lang.zulipchat.com/#narrow/stream/315482-t-compiler.2Fetc.2Fopaque-types/topic/RPIT.20capture.20rules.20.28capturing.20everything.29/near/389496292

### Return-position `impl Trait` in trait

`async fn` always desugars to a function that returns `impl Future`.

```rust!
async fn foo() -> i32 { 100 }

// Equivalent to:
fn foo() -> impl Future<Output = i32> { async { 100 } }
```

All `async fn`s today can be rewritten this way. This is useful because it allows adding behavior that runs at the time of the function call, before the first `.await` on the returned future.

In the spirit of supporting the same set of features on `async fn` in traits that we do outside of traits, it makes sense to stabilize this as well. As described by the [RPITIT RFC][rpitit-rfc], this includes the ability to mix and match the equivalent forms in traits and their corresponding impls:

```rust!
trait Foo {
    async fn foo(self) -> i32;
}

// Can be implemented as:
impl Foo for MyType {
    fn foo(self) -> impl Future<Output = i32> {
        async { 100 }
    }
}
```

Return-position `impl Trait` in trait is useful for cases beyond async, just as regular RPIT is. As a simple example, the RFC showed an alternative way of writing the `IntoIterator` trait with one fewer associated type.

```rust!
trait NewIntoIterator {
    type Item;
    fn new_into_iter(self) -> impl Iterator<Item = Self::Item>;
}

impl<T> NewIntoIterator for Vec<T> {
    type Item = T;
    fn new_into_iter(self) -> impl Iterator<Item = T> {
        self.into_iter()
    }
}
```

[rpitit-rfc]: https://rust-lang.github.io/rfcs/3425-return-position-impl-trait-in-traits.html

## Major design decisions

This section describes the major design decisions that were reached after the RFC was accepted:

- EDIT: Lint against async fn in trait definitions

    - Until the [send bound problem](https://smallcultfollowing.com/babysteps/blog/2023/02/01/async-trait-send-bounds-part-1-intro/) is resolved, the use of `async fn` in trait definitions could lead to a bad experience for people using work-stealing executors (by far the most popular choice). However, there are significant use cases for which the current support is all that is needed (single-threaded executors, such as those used in embedded use cases, as well as thread-per-core setups). We are prioritizing serving users well over protecting people from misuse, and therefore, we opt to stabilize the full range of functionality; however, to help steer people correctly, we are will issue a warning on the use of `async fn` in trait definitions that advises users about the limitations. (See [this summary comment](https://github.com/rust-lang/rust/pull/115822#issuecomment-1731149475) for the details of the concern, and [this comment](https://github.com/rust-lang/rust/pull/115822#issuecomment-1728354622) for more details about the reasoning that led to this conclusion.)

- Capture rules:

    - The RFC's initial capture rules for lifetimes in impls/traits were found to be imprecisely precise and to introduce various inconsistencies. After much discussion, the decision was reached to make `-> impl Trait` in traits/impls capture *all* in-scope parameters, including both lifetimes and types. This is a departure from the behavior of RPITs in other contexts; an RFC is currently being authored to change the behavior of RPITs in other contexts in a future edition.

    - Major discussion links:

        - [Lang team design meeting from 2023-07-26](https://hackmd.io/sFaSIMJOQcuwCdnUvCxtuQ?view)

- Refinement:

    - The [refinement RFC] initially proposed that impl signatures that are more specific than their trait are not allowed unless the `#[refine]` attribute was included, but left it as an open question how to implement this. The stabilized proposal is that it is not a hard error to omit `#[refine]`, but there is a lint which fires if the impl's return type is more precise than the trait. This greatly simplified the desugaring and implementation while still achieving the original goal of ensuring that users do not accidentally commit to a more specific return type than they intended.

    - Major discussion links:

        - [Zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/.60.23.5Brefine.5D.60.20as.20a.20lint)

[refinement RFC]: https://rust-lang.github.io/rfcs/3245-refined-impls.html

## What is stabilized

### Async functions in traits and trait implementations

* `async fn` are now supported in traits and trait implementations.
* Associated functions in traits that are `async` may have default bodies.

### Return-position impl trait in traits and trait implementations

* Return-position `impl Trait`s are now supported in traits and trait implementations.
    * Return-position `impl Trait` in implementations are treated like regular return-position `impl Trait`s, and therefore behave according to the same inference rules for hidden type inference and well-formedness.
* Associated functions in traits that name return-position `impl Trait`s may have default bodies.
* Implementations may provide either concrete types or `impl Trait` for each corresponding `impl Trait` in the trait method signature.

For a detailed exploration of the technical implementation of return-position `impl Trait` in traits, see [the dev guide](https://rustc-dev-guide.rust-lang.org/return-position-impl-trait-in-trait.html).

### Mixing `async fn` in trait and return-position `impl Trait` in trait

A trait function declaration that is `async fn ..() -> T` may be satisfied by an implementation function that returns `impl Future<Output = T>`, or vice versa.

```rust
trait Async {
    async fn hello();
}

impl Async for () {
    fn hello() -> impl Future<Output = ()> {
        async {}
    }
}

trait RPIT {
    fn hello() -> impl Future<Output = String>;
}

impl RPIT for () {
    async fn hello() -> String {
        "hello".to_string()
    }
}
```

### Return-position `impl Trait` in traits and trait implementations capture all in-scope lifetimes

Described above in "major design decisions".

### Return-position `impl Trait` in traits are "always revealing"

When a trait uses `-> impl Trait` in return position, it logically desugars to an associated type that represents the return (the actual implementation in the compiler is different, as described below). The value of this associated type is determined by the actual return type written in the impl; if the impl also uses `-> impl Trait` as the return type, then the value of the associated type is an opaque type scoped to the impl method (similar to what you would get when calling an inherent function returning `-> impl Trait`). As with any associated type, the value of this special associated type can be revealed by the compiler if the compiler can figure out what impl is being used.

For example, given this trait:

```rust
trait AsDebug {
    fn as_debug(&self) -> impl Debug;
}
```

A function working with the trait generically is only able to see that the return value is `Debug`:

```rust
fn foo<T: AsDebug>(t: &T) {
    let u = t.as_debug();
    println!("{}", u); // ERROR: `u` is not known to implement `Display`
}
```

But if a function calls `as_debug` on a known type (say, `u32`), it may be able to resolve the return type more specifically, if that implementation specifies a concrete type as well:

```rust
impl AsDebug for u32 {
    fn as_debug(&self) -> u32 {
        *self
    }
}

fn foo(t: &u32) {
    let u: u32 = t.as_debug(); // OK!
    println!("{}",  t.as_debug()); // ALSO OK (since `u32: Display`).
}
```

The return type used in the impl therefore represents a **semver binding** promise from the impl author that the return type of `<u32 as AsDebug>::as_debug` will not change. This could come as a surprise to users, who might expect that they are free to change the return type to any other type that implements `Debug`. To address this, we include a [`refining_impl_trait` lint](https://github.com/rust-lang/rust/pull/115582) that warns if the impl uses a specific type -- the `impl AsDebug for u32` above, for example, would toggle the lint.

The lint message explains what is going on and encourages users to `allow` the lint to indicate that they meant to refine the return type:

```rust
impl AsDebug for u32 {
    #[allow(refining_impl_trait)]
    fn as_debug(&self) -> u32 {
        *self
    }
}
```

[RFC #3245](https://github.com/rust-lang/rfcs/pull/3245) proposed a new attribute, `#[refine]`, that could also be used to "opt-in" to refinements like this (and which would then silence the lint). That RFC is not currently implemented -- the `#[refine]` attribute is also expected to reveal other details from the signature and has not yet been fully implemented.

### Return-position `impl Trait` and `async fn` in traits are opted-out of object safety checks when the parent function has `Self: Sized`

```rust
trait IsObjectSafe {
    fn rpit() -> impl Sized where Self: Sized;
    async fn afit() where Self: Sized;
}
```

Traits that mention return-position `impl Trait` or `async fn` in trait when the associated function includes a `Self: Sized` bound will remain object safe. That is because the associated function that defines them will be opted-out of the vtable of the trait, and the associated types will be unnameable from any trait object.

This can alternatively be seen as a consequence of https://github.com/rust-lang/rust/pull/112319#issue-1742251747 and the desugaring of return-position `impl Trait` in traits to associated types which inherit the where-clauses of the associated function that defines them.

## What isn't stabilized (aka, potential future work)

### Dynamic dispatch

As stabilized, traits containing RPITIT and AFIT are **not dyn compatible**. This means that you cannot create `dyn Trait` objects from them and can only use static dispatch. The reason for this limitation is that dynamic dispatch support for RPITIT and AFIT is more complex than static dispatch, as described on the [async fundamentals page](https://rust-lang.github.io/async-fundamentals-initiative/evaluation/challenges/dyn_traits.html). The primary challenge to using `dyn Trait` in today's Rust is that **`dyn Trait` today must list the values of all associated types**. This means you would have to write `dyn for<'s> Trait<Foo<'s> = XXX>` where `XXX` is the future type defined by the impl, such as `F_A`. This is not only verbose (or impossible), it also uniquely ties the `dyn Trait` to a particular impl, defeating the whole point of `dyn Trait`.

The precise design for handling dynamic dispatch is not yet determined. Top candidates include:

- [callee site selection][], in which we permit unsized return values so that the return type for an `-> impl Foo` method be can be `dyn Foo`, but then users must specify the type of wide pointer at the call-site in some fashion.

- [`dyn*`][], where we create a built-in encapsulation of a "wide pointer" and map the associated type corresponding to an RPITIT to the corresponding `dyn*` type (`dyn*` itself is not exposed to users as a type in this proposal, though that could be a future extension).

[callee site selection]: https://smallcultfollowing.com/babysteps/blog/2022/09/21/dyn-async-traits-part-9-callee-site-selection/

[`dyn*`]: https://smallcultfollowing.com/babysteps/blog/2022/03/29/dyn-can-we-make-dyn-sized/

### Where-clause bounds on return-position `impl Trait` in traits or async futures (RTN/ART)

One limitation of async fn in traits and RPITIT as stabilized is that there is no way for users to write code that adds additional bounds beyond those listed in the `-> impl Trait`. The most common example is wanting to write a generic function that requires that the future returned from an `async fn` be `Send`:

```rust
trait Greet {
    async fn greet(&self);
}

fn greet_in_parallel<G: Greet>(g: &G) {
    runtime::spawn(async move {
        g.greet().await; //~ ERROR: future returned by `greet` may not be `Send`
    })
}
```

Currently, since the associated types added for the return type are anonymous, there is no where-clause that could be added to make this code compile.

There have been various proposals for how to address this problem (e.g., [return type notation][rtn] or having an annotation to give a name to the associated type), but we leave the selection of one of those mechanisms to future work.

[rtn]: https://smallcultfollowing.com/babysteps/blog/2023/02/13/return-type-notation-send-bounds-part-2/

In the meantime, there are workarounds that one can use to address this problem, listed below.

#### Require all futures to be `Send`

For many users, the trait may only ever be used with `Send` futures, in which case one can write an explicit `impl Future + Send`:

```rust
trait Greet {
    fn greet(&self) -> impl Future<Output = ()> + Send;
}
```

The nice thing about this is that it is still compatible with using `async fn` in the trait impl. In the async working group case studies, we found that this could work for the [builder provider API](https://rust-lang.github.io/async-fundamentals-initiative/evaluation/case-studies/builder-provider-api.html). This is also the default approach used by the `#[async_trait]` crate which, as we have noted, has seen widespread adoption.

#### Avoid generics

This problem only applies when the `Self` type is generic. If the `Self` type is known, then the precise return type from an `async fn` is revealed, and the `Send` bound can be inferred thanks to auto-trait leakage. Even in cases where generics may appear to be required, it is sometimes possible to rewrite the code to avoid them. The [socket handler refactor](https://rust-lang.github.io/async-fundamentals-initiative/evaluation/case-studies/socket-handler.html) case study provides one such example.

### Unify capture behavior for `-> impl Trait` in inherent methods and traits

As stabilized, the capture behavior for `-> impl Trait` in a trait (whether as part of an async fn or a RPITIT) captures all types and lifetimes, whereas the existing behavior for inherent methods only captures types and lifetimes that are explicitly referenced. Capturing all lifetimes in traits was necessary to avoid various surprising inconsistencies; the expressed intent of the lang team is to extend that behavior so that we also capture all lifetimes in inherent methods, which would create more consistency and also address a common source of user confusion, but that will have to happen over the 2024 edition. The RFC is in progress. Should we opt not to accept that RFC, we can bring the capture behavior for `-> impl Trait` into alignment in other ways as part of the 2024 edition.

### `impl_trait_projections`

Orthgonal to `async_fn_in_trait` and `return_position_impl_trait_in_trait`, since it can be triggered on stable code. This will be stabilized separately in [#115659](https://github.com/rust-lang/rust/pull/115659).

<details>
If we try to write this code without `impl_trait_projections`, we will get an error:

```rust
#![feature(async_fn_in_trait)]

trait Foo {
    type Error;
    async fn foo(&mut self) -> Result<(), Self::Error>;
}

impl<T: Foo> Foo for &mut T {
    type Error = T::Error;
    async fn foo(&mut self) -> Result<(), Self::Error> {
        T::foo(self).await
    }
}
```

The error relates to the use of `Self` in a trait impl when the self type has a lifetime. It can be worked around by rewriting the impl not to use `Self`:

```rust
#![feature(async_fn_in_trait)]

trait Foo {
    type Error;
    async fn foo(&mut self) -> Result<(), Self::Error>;
}

impl<T: Foo> Foo for &mut T {
    type Error = T::Error;
    async fn foo(&mut self) -> Result<(), <&mut T as Foo>::Error> {
        T::foo(self).await
    }
}
```
</details>

## Tests

Tests are generally organized between return-position `impl Trait` and `async fn` in trait, when the distinction matters.
* RPITIT: https://github.com/rust-lang/rust/tree/master/tests/ui/impl-trait/in-trait
* AFIT: https://github.com/rust-lang/rust/tree/master/tests/ui/async-await/in-trait

## Remaining bugs and open issues

* #112047: Indirection introduced by `async fn` and return-position `impl Trait` in traits may hide cycles in opaque types, causing overflow errors that can only be discovered by monomorphization.
* #111105 - `async fn` in trait is susceptible to issues with checking auto traits on futures' generators, like regular `async`. This is a manifestation of #110338.
    * This was deemed not blocking because fixing it is forwards-compatible, and regular `async` is subject to the same issues.
* #104689: `async fn` and return-position `impl Trait` in trait requires the late-bound lifetimes in a trait and impl function signature to be equal.
    * This can be relaxed in the future with a smarter lexical region resolution algorithm.
* #102527: Nesting return-position `impl Trait` in trait deeply may result in slow compile times.
    * This has only been reported once, and can be fixed in the future.
* #108362: Inference between return types and generics of a function may have difficulties when there's an `.await`.
    * This isn't related to AFIT (https://github.com/rust-lang/rust/issues/108362#issuecomment-1717927918) -- using traits does mean that there's possibly easier ways to hit it.
* #112626: Because `async fn` and return-position `impl Trait` in traits lower to associated types, users may encounter strange behaviors when implementing circularly dependent traits.
    * This is not specific to RPITIT, and is a limitation of associated types: https://github.com/rust-lang/rust/issues/112626#issuecomment-1603405105
* **(Nightly)** #108309: `async fn` and return-position `impl Trait` in trait do not support specialization. This was deemed not blocking, since it can be fixed in the future (e.g. #108321) and specialization is a nightly feature.

#### (Nightly) Return type notation bugs

RTN is not being stabilized here, but there are some interesting outstanding bugs. None of them are blockers for AFIT/RPITIT, but I'm noting them for completeness.

<details>

* #109924 is a bug that occurs when a higher-ranked trait bound has both inference variables and associated types. This is pre-existing -- RTN just gives you a more convenient way of producing them. This should be fixed by the new trait solver.
* #109924 is a manifestation of a more general issue with `async` and auto-trait bounds: #110338. RTN does not cause this issue, just allows us to put `Send` bounds on the anonymous futures that we have in traits.
* #112569 is a bug similar to associated type bounds, where nested bounds are not implied correctly.

</details>

## Alternatives

### Do nothing

We could choose not to stabilize these features. Users that can use the `#[async_trait]` macro would continue to do so. Library maintainers would continue to avoid async functions in traits, potentially blocking the stable release of many useful crates.

### Stabilize `impl Trait` in associated type instead

AFIT and RPITIT solve the problem of returning unnameable types from trait methods. It is also possible to solve this by using another unstable feature, `impl Trait` in an associated type. Users would need to define an associated type in both the trait and trait impl:

```rust!
trait Foo {
    type Fut<'a>: Future<Output = i32> where Self: 'a;
    fn foo(&self) -> Self::Fut<'_>;
}

impl Foo for MyType {
    type Fut<'a> where Self: 'a = impl Future<Output = i32>;
    fn foo(&self) -> Self::Fut<'_> {
        async { 42 }
    }
}
```

This also has the advantage of allowing generic code to bound the associated type. However, it is substantially less ergonomic than either `async fn` or `-> impl Future`, and users still expect to be able to use those features in traits. **Even if this feature were stable, we would still want to stabilize AFIT and RPITIT.**

That said, we can have both. `impl Trait` in associated types is desireable because it can be used in existing traits with explicit associated types, among other reasons. We *should* stabilize this feature once it is ready, but that's outside the scope of this proposal.

### Use the old capture semantics for RPITIT

We could choose to make the capture rules for RPITIT consistent with the existing rules for RPIT. However, there was strong consensus in a recent [lang team meeting](https://hackmd.io/sFaSIMJOQcuwCdnUvCxtuQ?view) that we should *change* these rules, and furthermore that new features should adopt the new rules.

This is consistent with the tenet in RFC 3085 of favoring ["Uniform behavior across editions"](https://rust-lang.github.io/rfcs/3085-edition-2021.html#uniform-behavior-across-editions) when possible. It greatly reduces the complexity of the feature by not requiring us to answer, or implement, the design questions that arise out of the interaction between the current capture rules and traits. This reduction in complexity – and eventual technical debt – is exactly in line with the motivation listed in the aforementioned RFC.

### Make refinement a hard error

Refinement (`refining_impl_trait`) is only a concern for library authors, and therefore doesn't really warrant making into a deny-by-default warning or an error.

Additionally, refinement is currently checked via a lint that compares bounds in the `impl Trait`s in the trait and impl syntactically. This is good enough for a warning that can be opted-out, but not if this were a hard error, which would ideally be implemented using fully semantic, implicational logic. This was implemented (#111931), but also is an unnecessary burden on the type system for little pay-off.

## History

- Dec 7, 2021: [RFC #3185: Static async fn in traits](https://rust-lang.github.io/rfcs/3185-static-async-fn-in-trait.html) merged
- Sep 9, 2022: [Initial implementation](https://github.com/rust-lang/rust/pull/101224) of AFIT and RPITIT landed
- Jun 13, 2023: [RFC #3425: Return position `impl Trait` in traits](https://rust-lang.github.io/rfcs/3425-return-position-impl-trait-in-traits.html) merged

<!--These will render pretty when pasted into github-->
Non-exhaustive list of PRs that are particularly relevant to the implementation:

- #101224
- #103491
- #104592
- #108141
- #108319
- #108672
- #112988
- #113182 (later made redundant by #114489)
- #113215
- #114489
- #115467
- #115582

Doc co-authored by `@nikomatsakis,` `@tmandry,` `@traviscross.` Thanks also to `@spastorino,` `@cjgillot` (for changes to opaque captures!), `@oli-obk` for many reviews, and many other contributors and issue-filers. Apologies if I left your name off 😺
2023-10-14 07:29:08 +00:00
bors
39acbed8d6 Auto merge of #116407 - Mark-Simulacrum:bootstrap-bump, r=onur-ozkan
Bump bootstrap compiler to just-released beta

https://forge.rust-lang.org/release/process.html#master-bootstrap-update-t-2-day-tuesday
2023-10-14 05:44:48 +00:00
Esteban Küber
6d23ee8430 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-14 04:11:54 +00:00
bors
75a5dd05bc Auto merge of #115524 - RalfJung:misalign, r=wesleywiser
const-eval: make misalignment a hard error

It's been a future-incompat error (showing up in cargo's reports) since https://github.com/rust-lang/rust/pull/104616, Rust 1.68, released in March.  That should be long enough.

The question for the lang team is simply -- should we move ahead with this, making const-eval alignment failures a hard error? (It turns out some of them accidentally already were hard errors since #104616. But not all so this is still a breaking change. Crater found no regression.)
2023-10-14 00:57:09 +00:00
Michael Goulet
ef04c9795b Deprecate E0706 2023-10-13 21:01:36 +00:00
Michael Goulet
59315b8a63 Stabilize AFIT and RPITIT 2023-10-13 21:01:36 +00:00
Esteban Küber
feedd68f80 Remove some unnecessary unwraps 2023-10-13 20:36:41 +00:00
bors
09eff44889 Auto merge of #116645 - estebank:issue-116608, r=oli-obk
Detect ruby-style closure in parser

When parsing a closure without a body that is surrounded by a block, suggest moving the opening brace after the closure head.

Fix #116608.
2023-10-13 19:26:27 +00:00
Esteban Küber
20c622e456 Tweak wording 2023-10-13 19:18:46 +00:00
Esteban Küber
781e86477c 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-13 19:13:56 +00:00
Michael Goulet
362b75badf Fix AFIT lint message to mention pitfall 2023-10-13 19:13:18 +00:00
Augie Fackler
321572503d linker: also pass debuginfo compression flags
We support compressing debuginfo during codegen, but until this patch we
didn't pass the flag to the linker. Doing so means we'll respect the
requested compression even when building binaries or dylibs. This
produces much smaller binaries: in my testing a debug build of ripgrep
goes from 85M to 32M, and the target/ directory (after a clean build in
both cases) goes from 508M to 329M just by enabling zlib compression of
debuginfo.
2023-10-13 13:49:36 -04:00
Chris Wailes
166c353484 Lowercase the feature flags for riscv64-linux-android 2023-10-13 10:01:14 -07:00
Caio
6b59f6fbea Misc improvements 2023-10-13 10:22:33 -03:00
Deadbeef
eae6e02eba Fix a comment 2023-10-13 12:57:38 +00:00
Urgau
e5e95eba45 MCP636: Add simpler and more explicit syntax to check-cfg
This add a new form and deprecated the other ones:
 - cfg(name1, ..., nameN, values("value1", "value2", ... "valueN"))
 - cfg(name1, ..., nameN) or cfg(name1, ..., nameN, values())
 - cfg(any())

It also changes the default exhaustiveness to be enable-by-default in
the presence of any --check-cfg arguments.
2023-10-13 13:34:21 +02:00
bors
34bc5716b5 Auto merge of #116676 - estebank:issue-116658, r=compiler-errors
On type error involving closure, avoid ICE

When we encounter a type error involving a closure, we try to typeck prior closure invocations to see if they influenced the current expected type. When trying to do so, ensure that the closure was defined in our current scope.

Fix #116658.
2023-10-13 10:29:55 +00:00
lcnr
1bc6ae4401 explicitly handle auto trait leakage in coherence 2023-10-13 09:42:51 +00:00
Michael Goulet
e805151fd4 Bless tests and new warnings due to formatting changes 2023-10-13 09:31:36 +00:00
Michael Goulet
b2d2184ede Format all the let chains in compiler 2023-10-13 08:59:36 +00:00
Oğuz Ağcayazı
d6a55d3409 change fn name, return loc info, local name 2023-10-13 11:44:38 +03:00
bors
a4a10bdf29 Auto merge of #116666 - Urgau:check-cfg-pre-mcp636, r=petrochenkov
Improve check-cfg diagnostics

This PR tries to improve some of the diagnostics of check-cfg.

The main changes is the unexpected name or value being added to the main diagnostic:
```diff
- warning: unexpected `cfg` condition name
+ warning: unexpected `cfg` condition name: `widnows`
```

It also cherry-pick the better sensible logic for when we print the list of expected values when we have a matching value for a very similar name.

Address https://github.com/rust-lang/rust/pull/111072#discussion_r1356818100

r? `@petrochenkov`
2023-10-13 08:37:27 +00:00
Ralf Jung
1ee055f0ec add some comments and some cleanup around Miri intptrcast 2023-10-13 07:42:07 +02:00
bors
2763ca50da Auto merge of #116619 - nnethercote:rustc_driver_impl, r=compiler-errors
Streamline `rustc_driver_impl` pretty-printing.

This PR simplifies a lot of unnecessary structure in
`rustc_driver_impl/src/pretty.rs`. It removes some traits and functions,
simplifies some structs, renames some things for increased consistency, and
eliminates some boilerplate code. Overall it cuts more than 150 lines of code.

r? `@compiler-errors`
2023-10-13 05:35:29 +00:00
bors
130ff8cb6c Auto merge of #115964 - bjorn3:cgu_reuse_tracker_global_state, r=cjgillot
Remove cgu_reuse_tracker from Session

This removes a bit of global mutable state.

It will now miss post-lto cgu reuse when ThinLTO determines that a cgu doesn't get changed, but there weren't any tests for this anyway and a test for it would be fragile to the exact implementation of ThinLTO in LLVM.
2023-10-13 00:09:30 +00:00
Esteban Küber
e7618756c0 On type error involving closure, avoid ICE
When we encounter a type error involving a closure, we try to typeck
prior closure invocations to see if they influenced the current expected
type. When trying to do so, ensure that the closure was defined in our
current scope.

Fix #116658.
2023-10-12 23:29:02 +00:00
Esteban Küber
6b2c6c7fd3 Detect ruby-style closure in parser
When parsing a closure without a body that is surrounded by a block,
suggest moving the opening brace after the closure head.

Fix #116608.
2023-10-12 21:50:18 +00:00
bors
e20cb77021 Auto merge of #116391 - Nadrieril:constructorset, r=cjgillot
exhaustiveness: Rework constructor splitting

`SplitWildcard` was pretty opaque. I replaced it with a more legible abstraction: `ConstructorSet` represents the set of constructors for patterns of a given type. This clarifies responsibilities: `ConstructorSet` handles one clear task, and diagnostic-related shenanigans can be done separately.

I'm quite excited, I had has this in mind for years but could never quite introduce it. This opens up possibilities, including type-specific optimisations (like using a `FxHashSet` to collect enum variants, which had been [hackily attempted some years ago](https://github.com/rust-lang/rust/pull/76918)), my one-pass rewrite (https://github.com/rust-lang/rust/pull/116042), and future librarification.
2023-10-12 21:33:31 +00:00
Nicholas Nethercote
2b4c33817a Remove unneeded pubs. 2023-10-13 06:35:19 +11:00
Nicholas Nethercote
2e2924f263 Split and rename the annotation structs.
`NoAnn` and `IdentifiedAnnotation` impl both `pprust_ast::PpAnn` and
`pprust_hir::PpAnn`, which is a bit confusing, because the optional
`tcx` is only needed for the HIR cases. (Currently the `tcx` is
unnecessarily provided in the `expanded` AST cases.)

This commit splits each one into `Ast` and `Hir` versions, which makes
things clear about where the `tcx` is needed. The commit also renames
all the traits so they consistently end with `Ann`.
2023-10-13 06:35:19 +11:00
Nicholas Nethercote
b65227a9ee Make needs_analysis true for PpHirMode::Typed.
This avoids the need for a bespoke `tcx.analysis()` call.
2023-10-13 06:35:19 +11:00
Nicholas Nethercote
ba58e3213d Rename some 'hir lifetimes as 'tcx.
Because they all end up within a `TyCtxt`.
2023-10-13 06:35:19 +11:00
Nicholas Nethercote
060851b764 Remove pretty-printing traits.
`call_with_pp_support_ast` and `call_with_pp_support_hir` how each have
a single call site. This commit inlines and removes them, which also
removes the need for all the supporting traits: `Sess`,
`AstPrinterSupport`, and `HirPrinterSupport`. The `sess` member is also
removed from several structs.
2023-10-13 06:35:17 +11:00
Nicholas Nethercote
7d145a0fde Merge print_* functions.
The handling of the `PpMode` variants is currently spread across three
functions: `print_after_parsing`, `print_after_hir_lowering`, and
`print_with_analysis`. Each one handles some of the variants. This split
is primarily because `print_after_parsing` has slightly different
arguments to the other two.

This commit changes the structure. It merges the three functions into a
single `print` function, and encapsulates the different arguments in a
new enum `PrintExtra`.

Benefits:
- The code is a little shorter.
- All the `PpMode` variants are handled in a single `match`, with no
  need for `unreachable!` arms.
- It enables the trait removal in the subsequent commit by reducing
  the number of `call_with_pp_support_ast` call sites from two to one.
2023-10-13 06:34:55 +11:00
Nicholas Nethercote
e3d8bbbfe2 Simplify support traits.
First, both `AstPrinterSupport` and `HirPrinterSupport` have a `sess`
method. This commit introduces a `Sess` trait and makes the support
traits be subtraits of `Sess`, to avoid some duplication.

Second, both support traits have a `pp_ann` method that isn't needed if
we enable `trait_upcasting`. This commit removes those methods.

(Both of these traits will be removed in a subsequent commit, as will
the `trait_upcasting` use.)
2023-10-13 06:20:11 +11:00
Nicholas Nethercote
d5e7c5f3cc Remove unused PrinterSupport::hir_map method. 2023-10-13 06:20:11 +11:00
Nicholas Nethercote
1467ba06b6 Remove PpAstTreeMode.
It's simpler to distinguish the two AST modes directly in `PpMode`.
2023-10-13 06:20:11 +11:00
Nicholas Nethercote
87090a97e3 Remove an outdated comment.
`phase_3_run_analysis_passes` no longer exists, and AFAICT this code has
been refactored so much since this comment was written that it no longer
has any useful meaning.
2023-10-13 06:20:11 +11:00
Nicholas Nethercote
c5cfcdc4ac Remove unnecessary call to call_with_pp_support_hir.
The callback is trivial and no pp support is actually needed. This makes
the `HirTree` case more like the `AstTree` case above.
2023-10-13 06:20:11 +11:00
Nicholas Nethercote
ef8701a4a0 Rename some things.
- Rename `pprust` as `pprust_ast`, to align with `pprust_hir`.
- Rename `PrinterSupport` as `AstPrinterSupport`, to align with
  `HirPrinterSupport`.
2023-10-13 06:20:11 +11:00
bors
df4379b4eb Auto merge of #116510 - scottmcm:no-1-simd-v2, r=compiler-errors
Copy 1-element arrays as scalars, not vectors

For `[T; 1]` it's silly to copy as `<1 x T>` when we can just copy as `T`.

Inspired by https://github.com/rust-lang/rust/issues/101210#issuecomment-1732470941, which pointed out that `Option<[u8; 1]>` was codegenning worse than `Option<u8>`.

(I'm not sure *why* LLVM doesn't optimize out `<1 x u8>`, but might as well just not emit it in the first place in this codepath.)

---

I think I bit off too much in #116479; let me try just the scalar case first.

r? `@ghost`
2023-10-12 18:45:01 +00:00
Urgau
001a65c4b0 check-cfg: only print the list of expected names once 2023-10-12 18:39:35 +02:00
Urgau
dcfc484b09 check-cfg: mention the unexpected name and value in the primary message 2023-10-12 18:39:04 +02:00
Urgau
72815dc08f check-cfg: adjust expected names and values when useful 2023-10-12 18:39:04 +02:00
Matthias Krüger
4832811b0d
Rollup merge of #116654 - Zalathar:reloop-traversal, r=oli-obk
coverage: Clarify loop-edge detection and graph traversal

This is a collection of improvements to two semi-related pieces of code:

- The code in `counters` that detects which graph edges don't exit a loop, and would therefore be good candidates to have their coverage computed as an expression rather than having a physical counter.
- The code in `graph` that traverses the coverage BCB graph in a particular order, and tracks loops and loop edges along the way (which is relevant to the above).

I was originally only planning to make the `graph` changes, but there was going to be a lot of indentation churn in `counters` anyway, and once I started looking I noticed a lot of opportunities for simplification.

---

`@rustbot` label +A-code-coverage
2023-10-12 18:36:44 +02:00
Matthias Krüger
5f90bee663
Rollup merge of #116642 - weiznich:diagnostic_on_unimplemented_improvements, r=compiler-errors
Handle several `#[diagnostic::on_unimplemented]` attributes correctly

This PR fixes an issues where rustc would ignore subsequent `#[diagnostic::on_unimplemented]` attributes. The [corresponding RFC](https://rust-lang.github.io/rfcs/3368-diagnostic-attribute-namespace.html) specifies that the first matching instance of each option is used. Invalid attributes are linted and otherwise ignored.
2023-10-12 18:36:44 +02:00
Matthias Krüger
4b1867a9ee
Rollup merge of #116625 - nnethercote:rustc_hir_pretty, r=fee1-dead
`rustc_hir_pretty` cleanups

Just some improvements I found while looking through this code.

r? ``@fee1-dead``
2023-10-12 18:36:43 +02:00
bors
19149d1ea9 Auto merge of #116649 - nnethercote:improve-print_tts-precursors, r=petrochenkov
Token cleanups

Some precursors to #114571 that are worth merging even if the main part of #114571 doesn't get merged.

r? `@petrochenkov`
2023-10-12 13:10:14 +00:00
Zalathar
d99ab97b02 coverage: Simplify adding BCB successors to the traversal worklists 2023-10-12 22:37:58 +11:00
Zalathar
59f4f1c89d coverage: Don't store loop backedges in the traversal context
As long as we store the loop header BCB, we can look up its incoming loop
backedges as needed.
2023-10-12 21:41:13 +11:00
Zalathar
15360b3bc8 coverage: Store a graph reference in the graph traversal struct
Having to keep passing in a graph reference was a holdover from when the graph
was partly mutated during traversal. As of #114354 that is no longer necessary,
so we can simplify the traversal code by storing a graph reference as a field
in `TraverseCoverageGraphWithLoops`.
2023-10-12 21:41:13 +11:00
Zalathar
ea3fb7bc2c coverage: Use a VecDeque for loop traversal worklists
The previous code was storing the worklist in a vector, and then selectively
adding items to the start or end of the vector. That's a perfect use-case for a
double-ended queue.

This change also reveals that the existing code was a bit confused about which
end of the worklist is the front or back. For now, items are always removed
from the front of the queue (instead of the back), and code that adds items to
the queue has been flipped, to preserve the existing behaviour.
2023-10-12 21:41:13 +11:00
Zalathar
d1920c5181 coverage: Rename next_bcb to just bcb
This is the only BCB that `TraverseCoverageGraphWithLoops::next` works with, so
calling it `next_bcb` just makes the code less clear.
2023-10-12 21:41:13 +11:00
Zalathar
a7ae2a6e6c coverage: Simplify the detection of reloop edges to be given expressions 2023-10-12 21:41:13 +11:00
bors
4f05e95452 Auto merge of #116628 - gurry:116293-dup-note.rs, r=petrochenkov
Fix duplicate note on internal feature gates with associated issues

Fixes #116293

Note sure if I should add tests because the issue occurs only for feature gates having associated issues and that set of feature gates will change unpredictably leading to an unnecessary churn in tests.
2023-10-12 07:57:51 +00:00
bors
3d575a2f2e Auto merge of #113487 - estebank:sugg-113174, r=oli-obk
Use structured suggestion for #113174

When encountering a for loop that is rejected by the borrow checker because it is being advanced within its body, provide a structured suggestion for `while let Some(pat) = iter.next()`.
2023-10-12 02:34:07 +00:00
Gurinder Singh
66e643d0f8 Fix duplicate note on internal feature gate
The BuiltinInternalFeatures gate already has a struct level #[note]
attribute. The additional note field in it caused a duplicate to be
displayed when it was set to Some(...) which happened when the
feature had an associated issue
2023-10-12 07:22:41 +05:30
Nicholas Nethercote
66c2b77a4a Rename tt_prepend_space as space_between.
And reorder the arguments. I find it easier to think about this way.
2023-10-12 08:50:42 +11:00
Nicholas Nethercote
33aff5b152 Use TokenStream::token_alone in one place. 2023-10-12 08:46:16 +11:00
Nicholas Nethercote
bb9c2f50c3 Reorder an expression to improve readability. 2023-10-12 08:46:15 +11:00
Nicholas Nethercote
becf4942a2 Rename Token::is_op as Token::is_punct.
For consistency with `proc_macro::Punct`.
2023-10-12 08:46:15 +11:00
Georg Semmler
232aaeba7c
Handle several #[diagnostic::on_unimplemented] attributes correctly
This PR fixes an issues where rustc would ignore subsequent
`#[diagnostic::on_unimplemented]` attributes. The [corresponding
RFC](https://rust-lang.github.io/rfcs/3368-diagnostic-attribute-namespace.html)
specifies that the first matching instance of each option is used.
Invalid attributes are linted and otherwise ignored.
2023-10-11 22:01:59 +02:00
bors
475c71da07 Auto merge of #116640 - matthiaskrgr:rollup-xt9r5ir, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #116219 (Relate alias ty with variance)
 - #116315 (Do not check for impossible predicates in const-prop lint.)
 - #116436 (Structurally normalize for closure)
 - #116597 (Prevent showing methods from blanket impls of not available foreign traits to show up in the search results)
 - #116627 (small cleanup)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-10-11 19:02:49 +00:00
Esteban Küber
a53f280bfc Suggest ; after bare match expression E0308
Fix #72634.
2023-10-11 18:51:56 +00:00
Esteban Küber
9d2eb66e1a Use structured suggestion for #113174
When encountering a for loop that is rejected by the borrow checker
because it is being advanced within its body, provide a structured
suggestion for `while let Some(pat) = iter.next()`.
2023-10-11 18:26:44 +00:00
Matthias Krüger
8374805d67
Rollup merge of #116627 - fee1-dead-contrib:cleanup, r=spastorino
small cleanup

this is exactly the same as the `lower_param_bounds` function, so use that instead
2023-10-11 20:08:22 +02:00
Matthias Krüger
3712ea82f3
Rollup merge of #116436 - compiler-errors:structurally-normalize-for-closure, r=lcnr
Structurally normalize for closure

Fixes some signature deduction problems in the new trait solver (and in the case of async, an ICE).

r? lcnr
2023-10-11 20:08:21 +02:00
Matthias Krüger
9b7e0af80d
Rollup merge of #116315 - cjgillot:cpl-clean, r=petrochenkov
Do not check for impossible predicates in const-prop lint.

The enclosing query already checks for them, and replaces the body with a single `unreachable` if they are indeed impossible.
2023-10-11 20:08:20 +02:00
Matthias Krüger
8ddc0df1f1
Rollup merge of #116219 - compiler-errors:relate-alias-ty-with-variance, r=lcnr
Relate alias ty with variance

In the new solver, turns out that the subst-relate branch of the alias-relate predicate was relating args invariantly even for opaques, which have variance 💀.

This change is a bit more invasive, but I'd rather not special-case it [here](aeaa5c30e5/compiler/rustc_trait_selection/src/solve/alias_relate.rs (L171-L190)) and then have it break elsewhere. I'm doing a perf run to see if the extra call to `def_kind` is that expensive, if it is, I'll reconsider.

r? ``@lcnr``
2023-10-11 20:08:20 +02:00
bors
c1691db366 Auto merge of #113218 - lqd:polonius-scopes, r=jackh726
Compute NLL loan scopes using the polonius model

For a *location-insensitive* analysis (that is, without expressiveness improvements for users yet), this PR implements loans going out of scope using reachability and liveness, rather than checking if the issuing region's values contain a given CFG point. This is equivalent to NLL scopes and computes the same data.

r? `@matthewjasper`

A couple of notes:
- there are some assumptions about SCC representatives, placeholders, free regions, and member constraints that I believe hold, and they're documented in the code
- this passes all the UI tests with `-Zpolonius=next` -- the perf is [not terrible](https://github.com/rust-lang/rust/pull/112432#issuecomment-1749685862) and there are a bunch of ways to improve it in the future.
- there's a fixme left, hopefully Matthew you know a clean way to get the information it mentions.
2023-10-11 16:46:03 +00:00
Oğuz Ağcayazı
1d9481fdc8 implement get_filename/lines for span 2023-10-11 17:55:57 +03:00
bors
3c23df4935 Auto merge of #115937 - oli-obk:spurious_unreachable_pattern, r=Nadrieril
Prevent spurious `unreachable pattern` lints

But it means we'll get more `non-exhaustive` patterns

fixes https://github.com/rust-lang/rust/issues/78057

r? `@Nadrieril` `@RalfJung`
2023-10-11 14:49:49 +00:00
Oli Scherer
eca786cd14 Remember the ErrorReported used to silence follow up errors instead of recreating it with delay_span_bug 2023-10-11 12:49:57 +00:00
Oli Scherer
e83467c3b8 Avoid emitting the non_exhaustive error if other errors already occurred 2023-10-11 12:49:57 +00:00
Oli Scherer
d1fd11f3f9 Prevent spurious unreachable pattern lints
Means you'll get more `non-exhaustive` patterns
2023-10-11 12:49:57 +00:00
bors
5aa23be6b6 Auto merge of #116014 - lqd:mcp510-2-electric-boogaloo, r=petrochenkov
Implement `-Clink-self-contained=-linker` opt out

This implements the `-Clink-self-contained` opt out necessary to switch to lld by changing rustc's defaults instead of cargo's.

Components that are enabled and disabled on the CLI are recorded, for the purpose of being merged with the ones which the target spec will declare (I'll open another PR for that tomorrow, for easier review).

For MCP510, we now check whether using the self-contained linker is disabled on the CLI. Right now it would only be sensible to with `-Zgcc-ld=lld` (and I'll add some checks that we don't both enable and disable a component on the CLI in a future PR), but the goal is to simplify adding the check of the target's enabled components here in the follow-up PRs.

r? `@petrochenkov`
2023-10-11 12:11:39 +00:00
bors
71704c4f84 Auto merge of #116623 - Nadrieril:validate-range-endpoints, r=oli-obk
Fix overflow checking in range patterns

When a range pattern contains an overflowing literal, if we're not careful we might not notice the overflow and use the wrapped value. This makes for confusing error messages because linting against overflowing literals is only done in a later pass. So when a range is invalid we check for overflows to provide a better error.

This check didn't use to handle negative types; this PR fixes that. First commit adds tests, second cleans up without changing behavior, third does the fix.

EDIT: while I was at it, I fixed a small annoyance about the span of the overflow lint on negated literals.

Fixes https://github.com/rust-lang/rust/issues/94239
2023-10-11 10:07:19 +00:00
Deadbeef
50b6f46f71 small cleanup 2023-10-11 08:25:43 +00:00
bors
6d05c430d2 Auto merge of #115948 - notriddle:notriddle/logo-lockup, r=fmease
rustdoc: show crate name beside smaller logo

*Blocked on https://github.com/rust-lang/cargo/pull/12800*

## Summary

In this PR, the crate name and version are always shown in the sidebar, even in subpages, and the lateral navigation is always shown in the sidebar, even in modules.

Clicking the crate name does the same thing clicking the logo always did: take you to the crate root (the crate's home page, at least within Rustdoc).

The Rust logo is also no longer shown by default for non-Rust docs.

### Screenshots

<details><summary>Before</summary>

| | Macro | Module |
|--|-------|--------|
| In crate | ![image](https://github.com/rust-lang/rust/assets/1593513/d5db0a46-2bb6-44a2-a3aa-2d915ecb8595) |![image](https://github.com/rust-lang/rust/assets/1593513/61f8c1ee-c298-4e2c-b791-18ecb79ab83b)
| In module[^1] | ![image](https://github.com/rust-lang/rust/assets/1593513/73abca59-0b69-4650-a1e2-7278ca34795c) | ![image](https://github.com/rust-lang/rust/assets/1593513/0baf02c2-2ec7-4674-80e5-a6a74a973376)

[^1]: This PR also includes a bug fix for derive macros not showing up in the lateral navigation part of the sidebar

</details>

#### Whole sidebar screenshots

| | Macro | Module |
|--|-------|--------|
| In crate | ![image](https://github.com/rust-lang/rust/assets/1593513/75d1bd07-41f7-4f11-ba24-fd5476e0586a) | ![image](https://github.com/rust-lang/rust/assets/1593513/52960259-2b65-4131-b380-01826f0a0eb7)
| In module | ![image](https://github.com/rust-lang/rust/assets/1593513/06e57928-8cb0-41bd-b152-be16cc53e5ec) | ![image](https://github.com/rust-lang/rust/assets/1593513/37291c69-2a07-4467-a382-d9b029084a47)

#### Different logo configurations

|         | Short crate name | Long crate name |
|---------|------------------|-----------------|
| Root    | ![short-root]    | ![long-root]
| Subpage | ![short-subpage] | ![long-subpage]

[short-root]: https://github.com/rust-lang/rust/assets/1593513/9e2b4fa8-f581-4106-b562-1e0372c13f79
[short-subpage]: https://github.com/rust-lang/rust/assets/1593513/8331cdb8-fa13-4671-a1e2-dcc1cdca7451
[long-root]: https://github.com/rust-lang/rust/assets/1593513/7d377fec-0f1d-4343-9f82-0e35a8f58056
[long-subpage]: https://github.com/rust-lang/rust/assets/1593513/3b3094a4-63c9-477c-8c15-b6075837df30

##### Without a logo

![image](https://github.com/rust-lang/rust/assets/1593513/66672b79-6c59-4be8-a527-25ef6f0b04ab)

### Preview pages

https://notriddle.com/rustdoc-html-demo-5/sidebar-layout-rocket/rocket/index.html

https://notriddle.com/rustdoc-html-demo-5/sidebar-layout-rocket/rocket_sync_db_pools/index.html

https://notriddle.com/rustdoc-html-demo-5/sidebar-layout-rust-compiler/index.html

https://notriddle.com/rustdoc-html-demo-5/sidebar-layout-rust/std/index.html

https://notriddle.com/rustdoc-html-demo-5/sidebar-layout-rocket/tokio/index.html

## Motivation

This improves visual information density (the construct with the logo and crate name is *shorter* than the logo on its own, because it's not square) and navigation clarity (we can now see what clicking the Rust logo does, specifically).

Compare this with the layout at [Phoenix's Hexdocs] (which is what this proposal is closely based on), the old proposal on [Internals Discourse] (which always says "Rust standard library" in the sidebar, but doesn't do the side-by-side layout).

[Phoenix's Hexdocs]: https://hexdocs.pm/phoenix/1.7.7/overview.html
[Internals Discourse]: https://internals.rust-lang.org/t/poc-of-a-new-design-for-the-generated-rustdoc/11018

## Guide-level explanation

This PR cleans up some of the sidebar navigation.

It makes the logo in the desktop sidebar a bit smaller, and puts the crate name and version next to it (either beside it, or below it, depending on if there's space), making it clearer what clicking on it does: click the crate name to open the crate's home page. It also removes the Rust logo from non-official-Rust crates, again to make the navigation and supply chain clearer (since the crate name has been added, the logo is no longer necessary for navigation).

It adds a bit more clarifying information for lateral navigation. On items that don't add their own sidebar items, it just shows its siblings directly below the crate name and logo, but for other items, it shows "In crate alloc" instead of just "In alloc". It also shows the lateral navigation tools on module pages, making modules consistent with every other item.

## Drawbacks

While this actually takes up less screen real estate than the old layout on desktop, it takes up more HTML. It's also a bit more visually complex.

## Rationale and alternatives

I could do what the Internals POC did and keep the vertically stacked layout all the time, instead of doing a horizontal stack where possible. It would take up more screen real estate, though.

## Prior art

This design is lifted almost verbatim from Hexdocs. It seems to work for them. [`opentelemetry_process_propagator`], for example, has a long application name.

[`opentelemetry_process_propagator`]: https://hexdocs.pm/opentelemetry_process_propagator/OpentelemetryProcessPropagator.html

## Unresolved questions

Maybe we should encourage crate authors to include their own logo more often? It certainly helps give people a better sense of "place." This seems to be blocked on coming up with an API to do it without requiring them to host the file somewhere.

## Future possibilities

Beyond this, plenty of other changes could be made to improve the layout, like

* Fix things so that clicking an item in the sidebar doesn't cause it to scroll back to the top.
  * The [Internals demo](https://utherii.github.io/new.html) does this right: clicking an item in the sidebar changes the content area, but the sidebar itself does not change. This is nice, because clicking is cheap and I can skim the opening few paragraphs while browsing.
  * The layout of the docs sidebar causes trouble to implement this, because it's different on different pages, but at least fix this on the file browser.
* Come up with a less cluttered way to do disclosure. There's a lot of `[-]` on the page.
  * We don't lack ideas to fix this one. We have *too many*.
* Do a better job of separating local navigation (vec::Vec links to vec::IntoIter) and the table of contents (vec::Vec links to vec::Vec::new).
  * A possibility: add a Back arrow next to the "In [module]" header?
    ![image](https://github.com/rust-lang/rust/assets/1593513/e969faf7-7722-457a-b8c6-8d962e9e1e23)
* Give readers more control of how much rustdoc shows them, and giving doc authors more control of how much it generates. Basically, https://github.com/rust-lang/rust/pull/115660 is great, let's do it too.

But those are mostly orthogonal, not future possibilities unlocked by this change.
2023-10-11 06:28:36 +00:00
Nadrieril
dcdddb7a60 Fix span of overflow lint for negated literals 2023-10-11 04:55:55 +02:00
Nadrieril
1baf8bf54d Fix range overflow checking 2023-10-11 04:55:55 +02:00
Nadrieril
1e1174b034 Rework error handling when lowering range endpoints 2023-10-11 04:54:49 +02:00
bors
36cbf944b3 Auto merge of #116621 - aliemjay:rollup-0e2of3c, r=aliemjay
Rollup of 4 pull requests

Successful merges:

 - #95967 (Add explicit-endian String::from_utf16 variants)
 - #116530 (delay a bug when encountering an ambiguity in MIR typeck)
 - #116611 (Document `diagnostic_namespace` feature)
 - #116612 (Remove unused dominator iterator)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-10-11 01:49:27 +00:00
Ali MJ Al-Nasrawy
88a929ba32
Rollup merge of #116612 - tmiasko:rm-dom-iter, r=cjgillot
Remove unused dominator iterator
2023-10-11 03:53:18 +03:00
Ali MJ Al-Nasrawy
a7042a94a3
Rollup merge of #116530 - aliemjay:ice-on-ambiguity, r=compiler-errors
delay a bug when encountering an ambiguity in MIR typeck

We shouldn't have any trait selection ambiguities in MIR typeck.

See https://github.com/rust-lang/rust/pull/114586#issuecomment-1751967321

r? `@oli-obk` `@compiler-errors` `@lcnr`
2023-10-11 03:53:17 +03:00
bors
dcf89f43a5 Auto merge of #116578 - antoyo:subtree-update_cg_gcc_2023-10-09, r=bjorn3
subtree update cg_gcc 2023/10/09
2023-10-11 00:04:04 +00:00
Nicholas Nethercote
7d35902c62 Fiddle with State functions.
Remove and inline `new_from_input`, because it has a single call site.
And move `attrs` into the earlier `impl` block.
2023-10-11 10:46:55 +11:00
Nicholas Nethercote
494bc8514a Tweak comments.
- Remove an out-of-date comment. (There is no `PpAnn` implementation for `hir::Crate`.)
- Remove a low-value comment.
- And break a very long comment.
2023-10-11 10:46:33 +11:00
Chris Wailes
6efc71c920 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-10 16:26:26 -07:00
Nicholas Nethercote
664b1858aa Remove many unneeded pubs. 2023-10-11 09:28:06 +11:00
bors
d627cf07ce Auto merge of #113915 - cjgillot:ssa-call, r=tmiasko
Also consider call and yield as MIR SSA.

The SSA analysis on MIR only considered `Assign` statements as defining a SSA local.
This PR adds assignments as part of a `Call` or `Yield` terminator in that category.

This mainly allows to perform CopyProp on a call return place.

The only subtlety is in the dominance property: the assignment is only complete at the beginning of the target block.
2023-10-10 20:37:55 +00:00
Tomasz Miąsko
b61a6d59e4 Remove unused dominator iterator 2023-10-10 21:39:59 +02:00
Guillaume Gomez
100713ef08
Rollup merge of #116560 - ouz-a:efficient_ids, r=oli-obk
In smir use `FxIndexMap` to store indexed ids

Previously we used `vec` for storing indexed types, which is fine for small cases but will lead to huge performance issues when we use `smir` for real world cases.

Addresses https://github.com/rust-lang/project-stable-mir/issues/35

r? ``@oli-obk``
2023-10-10 18:44:46 +02:00