Commit Graph

2003 Commits

Author SHA1 Message Date
Matthias Krüger
d6656af16a
Rollup merge of #119107 - lcnr:uwuwu, r=compiler-errors
subtype_predicate: remove unnecessary probe

There is no reason to probe here. The failure either results in an actual type error, in which cases the probe is useless, or it is used inside of evaluate, in which case we're already inside of the `fn evaluation_probe`, so it is also not necessary.
2023-12-20 09:46:13 +01:00
bors
5810deef69 Auto merge of #119096 - compiler-errors:yeet-unnecessary-param-envs, r=lcnr
Yeet unnecessary param envs

We don't need to pass in param-envs around in the lexical region resolution code (or in `MatchAgainstFreshVars` in the solver), since it is only used to eval some consts in `structurally_relate_tys` which I removed.

This is in preparation for normalizing the outlives clauses in `ParamEnv` for the new trait solver.

r? lcnr
2023-12-20 05:15:44 +00:00
bors
57ad5058d6 Auto merge of #119084 - aliemjay:perf-env-bounds, r=compiler-errors
fast path for declared_generic_bounds_from_env

~2% perf gain for diesel
2023-12-19 19:17:25 +00:00
jyn
b5d8361909 rename to verbose-internals 2023-12-19 13:35:37 -05:00
Michael Goulet
a75d0021ed Remove param env from relation altogether 2023-12-19 17:13:10 +00:00
Ali MJ Al-Nasrawy
27e964dbfb fast path for declared_generic_bounds_from_env 2023-12-19 16:07:01 +00:00
Michael Goulet
009cd9c815 Remove unnecessary param-env from lexical region resolution and fully structural relations 2023-12-19 15:10:26 +00:00
lcnr
df5b604945 subtype_predicate: remove unnecessary probe 2023-12-19 07:40:06 +01:00
Nicholas Nethercote
cea683c08f Use .into_diagnostic() less.
This commit replaces this pattern:
```
err.into_diagnostic(dcx)
```
with this pattern:
```
dcx.create_err(err)
```
in a lot of places.

It's a little shorter, makes the error level explicit, avoids some
`IntoDiagnostic` imports, and is a necessary prerequisite for the next
commit which will add a `level` arg to `into_diagnostic`.

This requires adding `track_caller` on `create_err` to avoid mucking up
the output of `tests/ui/track-diagnostics/track4.rs`. It probably should
have been there already.
2023-12-18 20:46:13 +11:00
Nicholas Nethercote
09af8a667c Rename Session::span_diagnostic as Session::dcx. 2023-12-18 16:06:21 +11:00
Ali MJ Al-Nasrawy
9f7d0e91b5 use Vec for region constraints 2023-12-17 07:31:07 +00:00
Jubilee
c5a3d98cc6
Rollup merge of #119004 - matthiaskrgr:conv, r=compiler-errors
NFC don't convert types to identical types
2023-12-15 21:33:00 -08:00
Matthias Krüger
8479945c08 NFC don't convert types to identical types 2023-12-15 23:56:24 +01:00
Jubilee
1d54949765
Rollup merge of #118396 - compiler-errors:ast-lang-items, r=cjgillot
Collect lang items from AST, get rid of `GenericBound::LangItemTrait`

r? `@cjgillot`
cc #115178

Looking forward, the work to remove `QPath::LangItem` will also be significantly more difficult, but I plan on doing it as well. Specifically, we have to change:
1. A lot of `rustc_ast_lowering` for things like expr `..`
2. A lot of astconv, since we actually instantiate lang and non-lang paths quite differently.
3. A ton of diagnostics and clippy lints that are special-cased via `QPath::LangItem`

Meanwhile, it was pretty easy to remove `GenericBound::LangItemTrait`, so I just did that here.
2023-12-15 14:08:15 -08:00
Michael Goulet
0184c7616e Move nll_relate to relate::nll submodule 2023-12-15 18:13:40 +00:00
Michael Goulet
807cd85dfa Add higher_ranked to relate submodule 2023-12-15 18:13:40 +00:00
Michael Goulet
5b0b7cd8f9 Move type relations into submodule in rustc_infer 2023-12-15 18:13:40 +00:00
Michael Goulet
fc010de26b banish hir::GenericBound::LangItemTrait 2023-12-15 16:17:27 +00:00
Michael Goulet
70b9dad3dc Annotate some bugs 2023-12-15 14:45:06 +00:00
Ali MJ Al-Nasrawy
707c4f967e unify query canonicalization mode 2023-12-15 06:59:42 +00:00
Michael Goulet
146e345d8b Opportunistically resolve region var in canonicalizer 2023-12-15 05:02:37 +00:00
lcnr
11d16c4082 update use of feature flags 2023-12-14 15:22:37 +01:00
bors
d23e1a6894 Auto merge of #117749 - aliemjay:perf-canon-cache, r=lcnr
cache param env canonicalization

Canonicalize ParamEnv only once and store it. Then whenever we try to canonicalize `ParamEnvAnd<'tcx, T>` we only have to canonicalize `T` and then merge the results.

Prelimiary results show ~3-4% savings in diesel and serde benchmarks.

Best to review commits individually. Some commits have a short description.

Initial implementation had a soundness bug (https://github.com/rust-lang/rust/pull/117749#issuecomment-1840453387) due to cache invalidation:
- When canonicalizing `Ty<'?0>` we first try to resolve region variables in the current InferCtxt which may have a constraint `?0 == 'static`. This means that we register `Ty<'?0> => Canonical<Ty<'static>>` in the cache, which is obviously incorrect in another inference context.
- This is fixed by not doing region resolution when canonicalizing the query *input* (vs. response), which is the only place where ParamEnv is used, and then in a later commit we *statically* guard against any form of inference variable resolution of the cached canonical ParamEnv's.

r? `@ghost`
2023-12-14 04:04:10 +00:00
Ali MJ Al-Nasrawy
e452c94912 remove canonicalize_query_preserving_universes
unused!
2023-12-14 03:03:03 +00:00
Ali MJ Al-Nasrawy
3b55869615 make infcx optional in canonicalizer
This doesn't change behavior.
It should prevent unintentional resolution of inference variables
during canonicalization, which previously caused a soundness bug.
See PR description for more.
2023-12-14 03:03:03 +00:00
Esteban Küber
9d846fcc11 Tweak short_ty_string to reduce number of files
When shortening types and writing them to disk, make `short_ty_string`
capable of reusing the same file, instead of writing a file per
shortened type.
2023-12-13 23:07:10 +00:00
Ali MJ Al-Nasrawy
fafe66d438 don't resolve regions in query input
fixes a soundness regression described in the PR description.
2023-12-13 14:57:52 +00:00
Ali MJ Al-Nasrawy
85338197d4 don't store OriginalQueryValues::universe_map
ParamEnv is canonicalized in *queries input* rather than query response.
In such case we don't "preserve universes" of canonical variable.
This means that `universe_map` always has the default value, which is
wasteful to store in the cache.
2023-12-13 14:57:52 +00:00
Ali MJ Al-Nasrawy
f38d1e971d global param_env canonicalization cache 2023-12-13 14:57:52 +00:00
bors
56d25ba5ea Auto merge of #118500 - ZetaNumbers:tcx_hir_refactor, r=petrochenkov
Move some methods from `tcx.hir()` to `tcx`

https://github.com/rust-lang/rust/pull/118256#issuecomment-1826442834

Renamed:
- find -> opt_hir_node
- get -> hir_node
- find_by_def_id -> opt_hir_node_by_def_id
- get_by_def_id -> hir_node_by_def_id
2023-12-13 10:31:56 +00:00
Jubilee
4583a0134f
Rollup merge of #118889 - matthiaskrgr:compl_2023_2, r=WaffleLapkin
more clippy::complexity fixes

      redundant_guards
      redundant_slicing
      filter_next
      needless_borrowed_reference
      useless_format
2023-12-12 18:48:54 -08:00
Matthias Krüger
3795cc8eb0 more clippy::complexity fixes
redundant_guards
      redundant_slicing
      filter_next
      needless_borrowed_reference
      useless_format
2023-12-12 20:41:51 +01:00
zetanumbers
24f009c5e5 Move some methods from tcx.hir() to tcx
Renamings:
- find -> opt_hir_node
- get -> hir_node
- find_by_def_id -> opt_hir_node_by_def_id
- get_by_def_id -> hir_node_by_def_id

Fix rebase changes using removed methods

Use `tcx.hir_node_by_def_id()` whenever possible in compiler

Fix clippy errors

Fix compiler

Apply suggestions from code review

Co-authored-by: Vadim Petrochenkov <vadim.petrochenkov@gmail.com>

Add FIXME for `tcx.hir()` returned type about its removal

Simplify with with `tcx.hir_node_by_def_id`
2023-12-12 06:40:29 -08:00
lcnr
6ffe36b37d refactor writeback: emit normalization errors with new solver 2023-12-12 12:20:54 +00:00
bors
5f5d248602 Auto merge of #118742 - lcnr:infer-var-cleanup, r=compiler-errors
refactor infer var storage

cleanup the code, discovered while working on #118725
2023-12-12 03:23:37 +00:00
bors
6f40082313 Auto merge of #118661 - fee1-dead-contrib:restore-const-partialEq, r=compiler-errors
Restore `const PartialEq`

And thus fixes a number of tests. There is a bug that still needs to be fixed, so WIP for now.

r? `@compiler-errors`
2023-12-11 10:34:51 +00:00
bors
84f6130fe3 Auto merge of #118692 - surechen:remove_unused_imports, r=petrochenkov
remove redundant imports

detects redundant imports that can be eliminated.

for #117772 :

In order to facilitate review and modification, split the checking code and removing redundant imports code into two PR.

r? `@petrochenkov`
2023-12-10 11:55:48 +00:00
Deadbeef
d1f4bc5a19 Revert "Don't print host effect param in pretty path_generic_args"
This reverts commit f1bf874fb1.
2023-12-10 10:17:28 +00:00
surechen
40ae34194c remove redundant imports
detects redundant imports that can be eliminated.

for #117772 :

In order to facilitate review and modification, split the checking code and
removing redundant imports code into two PR.
2023-12-10 10:56:22 +08:00
Michael Goulet
f1bf874fb1 Don't print host effect param in pretty path_generic_args 2023-12-09 17:42:33 +00:00
Matthias Krüger
943fa33daf
Rollup merge of #118730 - jyn514:cmp_refs, r=estebank,compiler-errors
recurse into refs when comparing tys for diagnostics

before:
![image](https://github.com/rust-lang/rust/assets/23638587/bf6abd62-c7f3-4c09-a47e-31b6e129de19)

after:
![image](https://github.com/rust-lang/rust/assets/23638587/b704d728-ddba-4204-aebe-c07dcbbcb55c)

this diff from the test suite is also quite nice imo:
```diff
`@@` -4,8 +4,8 `@@` error[E0308]: mismatched types
 LL |     debug_assert_eq!(iter.next(), Some(value));
    |                                   ^^^^^^^^^^^ expected `Option<<I as Iterator>::Item>`, found `Option<&<I as Iterator>::Item>`
    |
-   = note: expected enum `Option<<I as Iterator>::Item>`
-              found enum `Option<&<I as Iterator>::Item>`
+   = note: expected enum `Option<_>`
+              found enum `Option<&_>`
```
2023-12-08 23:15:13 +01:00
Michael Goulet
cb41509601 Uplift canonicalizer into new trait solver crate 2023-12-08 17:44:01 +00:00
lcnr
75cfeb1854 cleanup type variable storage 2023-12-08 14:28:57 +01:00
jyn
eb53721a34 recurse into refs when comparing tys for diagnostics 2023-12-07 23:00:46 -05:00
lcnr
ac50f4b571 update fixme 2023-12-08 02:16:29 +01:00
lcnr
ffb4c08a81 implement and use NormalizesTo 2023-12-08 01:31:18 +01:00
lcnr
3978f545ba add unused NormalizesTo predicate 2023-12-07 17:52:51 +01:00
lcnr
40aa9f4fd9 avoid instantiating infer vars with infer 2023-12-07 16:13:09 +01:00
Michael Goulet
b97ff8eb16 Add print_trait_sugared 2023-12-05 17:15:46 +00:00
lcnr
407c117e88 cleanup and comments 2023-12-04 10:40:36 +01:00
lcnr
f69d67221e generalize: handle occurs check failure in aliases 2023-12-04 10:39:00 +01:00
lcnr
2d0ec174e4 do not fetch variance info during generalization 2023-12-04 10:38:43 +01:00
Nicholas Nethercote
a179a53565 Use Session::diagnostic in more places. 2023-12-02 09:01:35 +11:00
Nicholas Nethercote
c9008c6c8b Rename Handler::delay_good_path_bug as Handler::good_path_delayed_bug.
In line with the previous commits.
2023-12-02 09:01:34 +11:00
Nicholas Nethercote
2c337a072c Rename HandlerInner::delayed_span_bugs as HandlerInner::span_delayed_bugs.
For reasons similar to the previous commit.
2023-12-02 09:01:34 +11:00
Nicholas Nethercote
5d1d384443 Rename HandlerInner::delay_span_bug as HandlerInner::span_delayed_bug.
Because the corresponding `Level` is `DelayedBug` and `span_delayed_bug`
follows the pattern used everywhere else: `span_err`, `span_warning`,
etc.
2023-12-02 09:01:19 +11:00
Matthias Krüger
68d31b1906
Rollup merge of #118269 - compiler-errors:poly, r=wesleywiser
Unify `TraitRefs` and `PolyTraitRefs` in `ValuePairs`

I did this recently with `FnSigs` and `PolyFnSigs` but didn't think to do it with `TraitRefs` and `PolyTraitRefs`.
2023-11-29 04:23:22 +01:00
bors
6eb9524047 Auto merge of #117200 - rmehri01:repeated_help, r=WaffleLapkin
Don't add redundant help for object safety violations

Fixes #117186

r? WaffleLapkin
2023-11-27 19:37:35 +00:00
Ryan Mehri
ee96a7a288
move comment about local trait 2023-11-26 10:09:25 -08:00
Ryan Mehri
af6b84aaab
don't add redundant help for object safety violations 2023-11-26 09:53:58 -08:00
Guillaume Gomez
c67613bef9
Rollup merge of #118302 - mu001999:dead_code/clean, r=cjgillot
Clean dead codes

Clean dead codes detected by #118257
2023-11-26 15:44:54 +01:00
Vadim Petrochenkov
c697927f44 rustc: hir().local_def_id_to_hir_id() -> tcx.local_def_id_to_hir_id() cleanup 2023-11-26 12:41:21 +03:00
r0cky
91aee2de15 Clean dead codes 2023-11-26 09:25:07 +08:00
Michael Goulet
f4b7f35c4d
Rollup merge of #118201 - compiler-errors:obligation-causes, r=cjgillot
Miscellaneous `ObligationCauseCode` cleanups

Remove some dead code/unused `ObligationCauseCode`s.
2023-11-25 17:23:34 -05:00
Michael Goulet
3b2f33ee28
Rollup merge of #118158 - nnethercote:reduce-fluent-boilerplate, r=compiler-errors
Reduce fluent boilerplate

Best reviewed one commit at a time.

r? `@davidtwco`
2023-11-25 17:23:33 -05:00
Michael Goulet
3e769c55b8 Remove some more unused codepaths in (region) error reporting 2023-11-25 22:10:38 +00:00
Nicholas Nethercote
57cd5e6551 Use rustc_fluent_macro::fluent_messages! directly.
Currently we always do this:
```
use rustc_fluent_macro::fluent_messages;
...
fluent_messages! { "./example.ftl" }
```
But there is no need, we can just do this everywhere:
```
rustc_fluent_macro::fluent_messages! { "./example.ftl" }
```
which is shorter.
2023-11-26 08:38:40 +11:00
Nicholas Nethercote
a733082be9 Avoid need for {D,Subd}iagnosticMessage imports.
The `fluent_messages!` macro produces uses of
`crate::{D,Subd}iagnosticMessage`, which means that every crate using
the macro must have this import:
```
use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage};
```

This commit changes the macro to instead use
`rustc_errors::{D,Subd}iagnosticMessage`, which avoids the need for the
imports.
2023-11-26 08:38:00 +11:00
Guillaume Gomez
8fb68fc3b0
Rollup merge of #118199 - compiler-errors:qpath, r=lcnr
Remove `HirId` from `QPath::LangItem`

Remove `HirId` from `QPath::LangItem`, since there was only *one* use-case (`ObligationCauseCode::AwaitableExpr`), which we can instead recover by walking the HIR tree.
2023-11-25 19:51:55 +01:00
Guillaume Gomez
9a59b059d5
Rollup merge of #117871 - klensy:unused-pub, r=cjgillot
remove unused pub fns

This removes some unused `pub fn`; also fixes few obsoleted fn names or added fixmes with reminders to update them.
2023-11-25 19:51:54 +01:00
Michael Goulet
fa7633dda1 Remove HirId from QPath::LangItem 2023-11-25 18:02:11 +00:00
León Orell Valerian Liehr
7c2244a625
Rollup merge of #118259 - spastorino:move-eager-resolver-to-infer, r=compiler-errors
Move EagerResolution to rustc_infer::infer::resolve

`EagerResolver` fits better in `rustc_infer::infer::resolver`.

Started to disentagle #118118 that has a lot of unrelated things.

r? `@compiler-errors` `@lcnr`
2023-11-25 10:21:07 +01:00
Michael Goulet
e511cc7d49 Unify TraitRefs and PolyTraitRefs 2023-11-24 22:54:12 +00:00
Santiago Pastorino
798d2cb6e2
Move EagerResolution to rustc_infer::infer::resolve 2023-11-24 16:22:35 -03:00
David Tolnay
8cc7073d64
Replace option.map(cond) == Some(true) with option.is_some_and(cond) 2023-11-24 09:14:09 -08:00
bors
41fe75ec6b Auto merge of #118189 - compiler-errors:cache-flags-for-const, r=nnethercote
Cache flags for `ty::Const`

Not sure if this has been attempted yet, but worth a shot. It does make the code simpler in `rustc_type_ir`, since we can assume that consts have a `flags` method that is no-cost.

r? `@ghost`
2023-11-24 04:54:35 +00:00
klensy
aff6c741d4 remove unused pub fn 2023-11-23 14:11:02 +03:00
Michael Goulet
4ec68576d3 Cache flags for ty::Const 2023-11-22 23:28:28 +00:00
bors
1e9dda77b5 Auto merge of #118120 - compiler-errors:closure-kind, r=lcnr
Remove `PredicateKind::ClosureKind`

We don't need the `ClosureKind` predicate kind -- instead, `Fn`-family trait goals are left as ambiguous, and we only need to make progress on `FnOnce` projection goals for inference purposes.

This is similar to how we do confirmation of `Fn`-family trait and projection goals in the new trait solver, which also doesn't use the `ClosureKind` predicate.

Some hacky logic is added in the second commit so that we can keep the error messages the same.
2023-11-22 21:09:01 +00:00
Michael Goulet
040151a4be
Rollup merge of #118147 - Nilstrieb:no-redundant-casts, r=WaffleLapkin
Fix some unnecessary casts

`x clippy compiler -Aclippy::all -Wclippy::unnecessary_cast --fix` with some manual review to ensure every fix is correct.
2023-11-22 09:28:51 -08:00
Nicholas Nethercote
7060fc8327 Replace no_ord_impl with orderable.
Similar to the previous commit, this replaces `newtype_index`'s opt-out
`no_ord_impl` attribute with the opt-in `orderable` attribute.
2023-11-22 18:38:17 +11:00
Nicholas Nethercote
3ef9d4d0ed Replace custom_encodable with encodable.
By default, `newtype_index!` types get a default `Encodable`/`Decodable`
impl. You can opt out of this with `custom_encodable`. Opting out is the
opposite to how Rust normally works with autogenerated (derived) impls.

This commit inverts the behaviour, replacing `custom_encodable` with
`encodable` which opts into the default `Encodable`/`Decodable` impl.
Only 23 of the 59 `newtype_index!` occurrences need `encodable`.

Even better, there were eight crates with a dependency on
`rustc_serialize` just from unused default `Encodable`/`Decodable`
impls. This commit removes that dependency from those eight crates.
2023-11-22 18:37:14 +11:00
Nilstrieb
c089a162d8 Fix some unnecessary casts
`x clippy compiler -Aclippy::all -Wclippy::unnecessary_cast --fix`
with some manual review to ensure every fix is correct.
2023-11-21 22:11:08 +01:00
Nilstrieb
21a870515b Fix clippy::needless_borrow in the compiler
`x clippy compiler -Aclippy::all -Wclippy::needless_borrow --fix`.

Then I had to remove a few unnecessary parens and muts that were exposed
now.
2023-11-21 20:13:40 +01:00
Michael Goulet
128feaa2b4 Restore closure-kind error messages 2023-11-21 18:35:47 +00:00
Michael Goulet
93298ee0dd Remove ClosureKind predicate kind 2023-11-21 18:35:45 +00:00
Michael Goulet
253f5023c3 Don't require intercrate mode for negative coherence 2023-11-20 18:49:48 +00:00
Michael Goulet
8f267e2b87 Make regionck care about placeholders in outlives components 2023-11-19 19:12:20 +00:00
Matthias Krüger
aa2289d3bc
Rollup merge of #117549 - DaniPopes:more-copied, r=b-naber
Use `copied` instead of manual `map`
2023-11-17 23:04:22 +01:00
lcnr
41cfb20abb replace unnecessary folder impls with fold_region 2023-11-17 08:58:18 +00:00
Mark Rousskov
917f6540ed Re-format code with new rustfmt 2023-11-15 21:45:48 -05:00
Mark Rousskov
db3e2bacb6 Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
lcnr
8fcbd1991f review + fix CI 2023-11-14 13:41:28 +00:00
lcnr
15f21562e6 finish RegionKind rename
- `ReFree` -> `ReLateParam`
- `ReEarlyBound` -> `ReEarlyParam`
2023-11-14 13:13:27 +00:00
bors
d5375d0587 Auto merge of #117773 - nnethercote:rm-Zperf-stats, r=wesleywiser
Remove `-Zperf-stats`.

The included measurements have varied over the years. At one point there were quite a few more, but #49558 deleted a lot that were no longer used. Today there's just four, and it's a motley collection that doesn't seem particularly valuable.

I think it has been well and truly subsumed by self-profiling, which collects way more data.

r? `@wesleywiser`
2023-11-14 02:24:05 +00:00
lcnr
dd0739aabe continue renaming
- `RegionVariableOrigin::~~Late~~BoundRegion`
- `~~Late~~BoundRegionConversionTime`
2023-11-13 14:13:54 +00:00
lcnr
86fa1317a3 rename ReLateBound to ReBound
other changes:
- `Region::new_late_bound` -> `Region::new_bound`
- `Region::is_late_bound` -> `Region::is_bound`
2023-11-13 14:13:54 +00:00
Nicholas Nethercote
aefbb616af Remove -Zperf-stats.
The included measurements have varied over the years. At one point there
were quite a few more, but #49558 deleted a lot that were no longer
used. Today there's just four, and it's a motley collection that doesn't
seem particularly valuable.

I think it has been well and truly subsumed by self-profiling, which
collects way more data.
2023-11-13 09:45:20 +11:00
bohan
a4768fea35 fallback for construct_generic_bound_failure 2023-11-04 22:15:22 +08:00
DaniPopes
27364309a5
compiler: use copied instead of manual map 2023-11-03 17:18:56 +01:00
bors
9c20ddd956 Auto merge of #117507 - nnethercote:rustc_span, r=Nilstrieb
`rustc_span` cleanups

Just some things I found while looking over this crate.

r? `@oli-obk`
2023-11-03 14:57:40 +00:00
Michael Goulet
4d5d763e05 Don't check for alias bounds in liveness when aliases have escaping bound vars 2023-11-02 10:25:57 +00:00
Nicholas Nethercote
f405ce86c2 Minimize pub usage in source_map.rs.
Most notably, this commit changes the `pub use crate::*;` in that file
to `use crate::*;`. This requires a lot of `use` items in other crates
to be adjusted, because everything defined within `rustc_span::*` was
also available via `rustc_span::source_map::*`, which is bizarre.

The commit also removes `SourceMap::span_to_relative_line_string`, which
is unused.
2023-11-02 19:35:00 +11:00
Guillaume Gomez
95de91b5ce
Rollup merge of #117132 - estebank:issue-80194, r=petrochenkov
On object safety error, mention new enum as alternative

When we encounter a `dyn Trait` that isn't object safe, look for its implementors. If there's one, mention using it directly If there are less than 9, mention the possibility of creating a new enum and using that instead.

Fix #80194.
2023-10-30 17:33:15 +01:00
Esteban Küber
8c04999226 On object safety error, mention new enum as alternative
When we encounter a `dyn Trait` that isn't object safe, look for its
implementors. If there's one, mention using it directly If there are
less than 9, mention the possibility of creating a new enum and using
that instead.

Account for object unsafe `impl Trait on dyn Trait {}`.  Make a
distinction between public and sealed traits.

Fix #80194.
2023-10-29 23:55:46 +00:00
Nicholas Nethercote
8ff624a9f2 Clean up rustc_*/Cargo.toml.
- Sort dependencies and features sections.
- Add `tidy` markers to the sorted sections so they stay sorted.
- Remove empty `[lib`] sections.
- Remove "See more keys..." comments.

Excluded files:
- rustc_codegen_{cranelift,gcc}, because they're external.
- rustc_lexer, because it has external use.
- stable_mir, because it has external use.
2023-10-30 08:46:02 +11:00
bors
ec2b311914 Auto merge of #116733 - compiler-errors:alias-liveness-but-this-time-sound, r=aliemjay
Consider alias bounds when computing liveness in NLL (but this time sound hopefully)

This is a revival of #116040, except removing the changes to opaque lifetime captures check to make sure that we're not triggering any unsoundness due to the lack of general existential regions and the currently-existing `ReErased` hack we use instead.

r? `@aliemjay` -- I appreciate you pointing out the unsoundenss in the previous iteration of this PR, and I'd like to hear that you're happy with this iteration of this PR before this goes back into FCP :>

Fixes #116794 as well

---

(mostly copied from #116040 and reworked slightly)

# Background

Right now, liveness analysis in NLL is a bit simplistic. It simply walks through all of the regions of a type and marks them as being live at points. This is problematic in the case of aliases, since it requires that we mark **all** of the regions in their args[^1] as live, leading to bugs like #42940.

In reality, we may be able to deduce that fewer regions are allowed to be present in the projected type (or "hidden type" for opaques) via item bounds or where clauses, and therefore ideally, we should be able to soundly require fewer regions to be live in the alias.

For example:
```rust
trait Captures<'a> {}
impl<T> Captures<'_> for T {}

fn capture<'o>(_: &'o mut ()) -> impl Sized + Captures<'o> + 'static {}

fn test_two_mut(mut x: ()) {
    let _f1 = capture(&mut x);
    let _f2 = capture(&mut x);
    //~^ ERROR cannot borrow `x` as mutable more than once at a time
}
```

In the example above, we should be able to deduce from the `'static` bound on `capture`'s opaque that even though `'o` is a captured region, it *can never* show up in the opaque's hidden type, and can soundly be ignored for liveness purposes.

# The Fix

We apply a simple version of RFC 1214's `OutlivesProjectionEnv` and `OutlivesProjectionTraitDef` rules to NLL's `make_all_regions_live` computation.

Specifically, when we encounter an alias type, we:
1. Look for a unique outlives bound in the param-env or item bounds for that alias. If there is more than one unique region, bail, unless any of the outlives bound's regions is `'static`, and in that case, prefer `'static`. If we find such a unique region, we can mark that outlives region as live and skip walking through the args of the opaque.
2. Otherwise, walk through the alias's args recursively, as we do today.

## Limitation: Multiple choices

This approach has some limitations. Firstly, since liveness doesn't use the same type-test logic as outlives bounds do, we can't really try several options when we're faced with a choice.

If we encounter two unique outlives regions in the param-env or bounds, we simply fall back to walking the opaque via its args. I expect this to be mostly mitigated by the special treatment of `'static`, and can be fixed in a forwards-compatible by a more sophisticated analysis in the future.

## Limitation: Opaque hidden types

Secondly, we do not employ any of these rules when considering whether the regions captured by a hidden type are valid. That causes this code (cc #42940) to fail:

```rust
trait Captures<'a> {}
impl<T> Captures<'_> for T {}

fn a() -> impl Sized + 'static {
    b(&vec![])
}

fn b<'o>(_: &'o Vec<i32>) -> impl Sized + Captures<'o> + 'static {}
```

We need to have existential regions to avoid [unsoundness](https://github.com/rust-lang/rust/pull/116040#issuecomment-1751628189) when an opaque captures a region which is not represented in its own substs but which outlives a region that does.

## Read more

Context: https://github.com/rust-lang/rust/pull/115822#issuecomment-1731153952 (for the liveness case)
More context: https://github.com/rust-lang/rust/issues/42940#issuecomment-455198309 (for the opaque capture case, which this does not fix)

[^1]: except for bivariant region args in opaques, which will become less relevant when we move onto edition 2024 capture semantics for opaques.
2023-10-29 18:42:02 +00:00
Esteban Küber
7449478c2f Account for type param from other item in note_and_explain
Fix #89868.
2023-10-27 16:24:01 +00:00
Esteban Küber
3bbc70a5f7 Restrict param constraint suggestion
When encountering an associated item with a type param that could be
constrained, do not look at the parent item if the type param comes from
the associated item.

Fix #117209.
2023-10-26 18:33:03 +00:00
Oli Scherer
c601ade3ad Refactor away the need for some descr methods.
Instead we use `Display` impls and their `alternate` render scheme to
decide whether we want backticks or not.
2023-10-25 16:40:32 +00:00
Michael Goulet
a986ab4d4d Get rid of 'tcx on ConstVid, EffectVid 2023-10-24 20:13:36 +00:00
Matthias Krüger
cb651300ec
Rollup merge of #117091 - compiler-errors:debug, r=lcnr
`OptWithInfcx` naming nits, trait bound simplifications

* Use an associated type `Interner` on `InferCtxtLike` to remove a redundant interner parameter (`I: Interner, Infcx: InferCtxtLike<I>` -> `Infcx: InferCtxtLike`).
* Remove double-`Option` between `infcx: Option<Infcx>` and `fn universe_of_ty(&self, ty: ty::InferTy) -> Option<ty::UniverseIndex>`. We don't need the infcx to be optional if we can provide a "noop" (`NoInfcx`) implementation that just always returns `None` for universe index.
    * Also removes the `core::convert::Infallible` implementation which I found a bit weird...
* Some naming nits with params.
    * I found `InferCtxt` + `InfCtx` and `Infcx` to be a lot of different ways to spell "inference context", so I got rid of the `InfCtx` type parameter name in favor of `Infcx` which is a more standard name.
    * I found `OptWithInfcx` to be a bit redundant -> `WithInfcx`.

I'm making these changes because I intend to reuse the `InferCtxtLike` trait for uplifting the canonicalizer into a new trait -- conveniently, the information I need for uplifting the canonicalizer also is just the universe information of a type var, so it's super convenient 😸

r? `@BoxyUwU` or `@lcnr`
2023-10-24 17:09:00 +02:00
bors
f654229c27 Auto merge of #117103 - matthiaskrgr:rollup-96zuuom, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #107159 (rand use getrandom for freebsd (available since 12.x))
 - #116859 (Make `ty::print::Printer` take `&mut self` instead of `self`)
 - #117046 (return unfixed len if pat has reported error)
 - #117070 (rustdoc: wrap Type with Box instead of Generics)
 - #117074 (Remove smir from triage and add me to stablemir)
 - #117086 (Update .mailmap to promote my livename)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-10-23 22:18:45 +00:00
Matthias Krüger
8af4a3f9cd
Rollup merge of #116859 - Nilstrieb:more-more-funny-pretty-printers, r=oli-obk
Make `ty::print::Printer` take `&mut self` instead of `self`

based on #116815

This simplifies the code by removing all the `self` assignments and
makes the flow of data clearer - always into the printer.
Especially in v0 mangling, which already used  `&mut self` in some
places, it gets a lot more uniform.
2023-10-23 22:26:29 +02:00
Michael Goulet
269d5a322e Remove redundant type parameter 2023-10-23 16:02:05 -04:00
bohan
482275b194 use visibility to check unused imports and delete some stmts 2023-10-22 21:27:46 +08:00
Matthias Krüger
05e154fdb7
Rollup merge of #106601 - estebank:match-semi, r=cjgillot
Suggest `;` after bare `match` expression E0308

Fix #72634.
2023-10-21 13:58:33 +02:00
Nilstrieb
5acf26b97e Make ty::print::Printer take &mut self instead of self
This simplifies the code by removing all the `self` assignments and
makes the flow of data clearer - always into the printer.
Especially in v0 mangling, which already used  `&mut self` in some
places, it gets a lot more uniform.
2023-10-21 11:33:05 +02:00
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
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
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
Esteban Küber
bd8b46800d Tweak wording of type errors involving type params
Fix #78206.
2023-10-18 23:53:18 +00:00
Michael Goulet
ea73f10867 Don't ICE when encountering unresolved regions in fully_resolve 2023-10-18 20:39:29 +00: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
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
a1e274f172 revert rust-lang/rust#114586 2023-10-18 06:19:04 +00: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
Esteban Küber
dee86bff40 Suggest constraining assoc types in more cases
Fix #46969.
2023-10-17 23:50:13 +00: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
Michael Goulet
1005970485 Use a visitor that could be reused by opaque type capture check later 2023-10-17 01:26:46 +00:00
Michael Goulet
b2d2184ede Format all the let chains in compiler 2023-10-13 08:59:36 +00:00
Esteban Küber
a53f280bfc Suggest ; after bare match expression E0308
Fix #72634.
2023-10-11 18:51:56 +00: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
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
Michael Howell
c6e6ecb1af rustdoc: remove rust logo from non-Rust crates 2023-10-08 20:17:53 -07:00
Ali MJ Al-Nasrawy
a8830631b9 remove trailing dots 2023-10-08 10:06:17 +00:00
Ali MJ Al-Nasrawy
996ffcb718 always show and explain sub region 2023-10-08 09:59:51 +00:00
Ali MJ Al-Nasrawy
5be0b2283a improve the suggestion of generic_bound_failure 2023-10-08 09:56:57 +00:00
bors
94bc9c737e Auto merge of #114811 - estebank:impl-ambiguity, r=wesleywiser
Show more information when multiple `impl`s apply

- When there are `impl`s without type params, show only those (to avoid showing overly generic `impl`s).
```
error[E0283]: type annotations needed
  --> $DIR/multiple-impl-apply.rs:34:9
   |
LL |     let y = x.into();
   |         ^     ---- type must be known at this point
   |
note: multiple `impl`s satisfying `_: From<Baz>` found
  --> $DIR/multiple-impl-apply.rs:14:1
   |
LL | impl From<Baz> for Bar {
   | ^^^^^^^^^^^^^^^^^^^^^^
...
LL | impl From<Baz> for Foo {
   | ^^^^^^^^^^^^^^^^^^^^^^
   = note: required for `Baz` to implement `Into<_>`
help: consider giving `y` an explicit type
   |
LL |     let y: /* Type */ = x.into();
   |          ++++++++++++
```

- Lower the importance of `T: Sized`, `T: WellFormed` and coercion errors, to prioritize more relevant errors. The pre-existing deduplication logic deals with hiding redundant errors better that way, and we show errors with more metadata that is useful to the user.

- Show `<SelfTy as Trait>::assoc_fn` suggestion in more cases.
```
error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type
  --> $DIR/cross-return-site-inference.rs:38:16
   |
LL |     return Err(From::from("foo"));
   |                ^^^^^^^^^^ cannot call associated function of trait
   |
help: use a fully-qualified path to a specific available implementation
   |
LL |     return Err(</* self type */ as From>::from("foo"));
   |                +++++++++++++++++++     +
```

Fix #88284.
2023-10-06 18:44:32 +00:00
Michael Goulet
137b6d0b01 Point to where missing return type should go 2023-10-04 21:09:54 +00:00
Michael Goulet
be29d22eab Make it clear that args default to being related invariantly 2023-10-04 04:22:04 +00:00
Esteban Küber
7313c10774 Show suggestion for <SelfTy as Trait>::assoc_fn in more cases and fmt code 2023-10-04 02:04:14 +00:00
Matthias Krüger
12e4c780ee
Rollup merge of #116358 - compiler-errors:match, r=lcnr
Rename both of the `Match` relations

Both of these names kinda were ambiguous.

r? lcnr
2023-10-03 12:24:12 +02:00
Matthias Krüger
144862ede8
Rollup merge of #115863 - chenyukang:yukang-add-message-tidy-check, r=davidtwco
Add check_unused_messages in tidy

From https://github.com/rust-lang/rust/pull/115728#issuecomment-1715490553
The check is not 100% accurate, I guess it's enough for now.
2023-10-03 12:24:11 +02:00
Michael Goulet
2ffaeb5110 Rename both of the Match relations 2023-10-02 21:06:09 +00:00