Commit Graph

3895 Commits

Author SHA1 Message Date
bors
a4ab2e0643 Auto merge of #103975 - oli-obk:tracing, r=jackh726
Some tracing and comment cleanups

Pulled out of https://github.com/rust-lang/rust/pull/101900 to see if that is the perf impact
2022-11-06 02:21:34 +00:00
clubby789
02025b54ea Use FmtPrinter instead of creating Instance 2022-11-05 22:56:20 +00:00
Michael Goulet
99b3454d37 Enforce rust-check ABI in signatures, calls 2022-11-05 18:05:25 +00:00
Nilstrieb
27e0f03d41
Add internal descriptions to a few queries 2022-11-05 17:54:15 +01:00
Vadim Petrochenkov
43bea6cf69 resolve: Fill effective visibilities for import def ids in a separate pass
This should result in less update calls than doing it repeatedly during the fix point iteration.
2022-11-05 17:55:20 +04:00
Vadim Petrochenkov
448261a78a privacy: Check effective visibility invariants 2022-11-05 16:25:41 +04:00
Vadim Petrochenkov
24093fc6bd resolve: More detailed effective visibility tracking for imports
Also drop `extern` blocks from the effective visibility table, they are nominally private and it doesn't make sense to keep them there.
2022-11-05 15:46:22 +04:00
Matthias Krüger
b101f3a865
Rollup merge of #103984 - V0ldek:103974-refactor-mk_const, r=BoxyUwU
Refactor tcx mk_const parameters.

Unroll the `ty::ConstS` parameter to `TyCtxt::mk_const` into separate `ty::ConstKind` and `Ty` parameters.

Signature change is in:

c97fd8183a/compiler/rustc_middle/src/ty/context.rs (L2234)

and

c97fd8183a/compiler/rustc_middle/src/ty/context.rs (L2572-L2575)

the rest is callsites.

Closes #103974

r? `@oli-obk`
2022-11-05 00:02:06 +01:00
Mateusz
c97fd8183a
Refactor tcx mk_const parameters. 2022-11-04 20:33:32 +00:00
Matthias Krüger
f7ed72de40
Rollup merge of #103937 - BoxyUwU:misc_cleanups, r=compiler-errors
minor changes to make method lookup diagnostic code easier to read

The end result of around 4 days of trying to understand this 1000+ line long function- a bunch of tiny nitpicks

r? `@compiler-errors`
2022-11-04 18:52:28 +01:00
Oli Scherer
44d1936d00 Some tracing and comment cleanups 2022-11-04 17:10:07 +00:00
bors
2efb0cd4b2 Auto merge of #103954 - matthiaskrgr:rollup-tskpxnj, r=matthiaskrgr
Rollup of 10 pull requests

Successful merges:

 - #103825 (Remove let_underscore_must_use from list of uplifted lints)
 - #103884 (Add visit_fn_ret_ty to hir intravisit)
 - #103892 (Properly render asyncness for trait fns without default body)
 - #103905 (rustdoc: remove redundant mobile CSS `.sidebar-elems { background }`)
 - #103912 (Add howto for adding new targets)
 - #103915 (Improve use of ErrorGuaranteed and code cleanup)
 - #103930 (Move some tests from `src/test/ui` to more reasonable places)
 - #103931 (Add note to RELEASES.md regarding issue 102754.)
 - #103938 (rustdoc: clean up hardcoded CSS border color on search results)
 - #103940 (rustdoc: remove no-op CSS `#main-content > .item-info { margin-top: 0 }`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-11-04 07:26:56 +00:00
Matthias Krüger
61c6cdb5f4
Rollup merge of #103915 - chenyukang:yukang/fix-103874, r=lcnr
Improve use of ErrorGuaranteed and code cleanup

Part of #103874
2022-11-04 06:40:32 +01:00
Boxy
3583f2758b Cleanups 2022-11-03 18:52:16 +00:00
Michael Howell
03968a802c rustdoc: use ThinVec for cleaned generics 2022-11-02 16:17:22 -07:00
yukang
ab22f5521b change error_reported to use Result instead of an option 2022-11-03 04:57:44 +08:00
yukang
7df9d818ab deprecate DelaySpanBugEmitted and use ErrorGuaranteed directly 2022-11-02 23:15:49 +08:00
Michael Goulet
e24df2778f Format dyn Trait better in type_name intrinsic 2022-11-01 20:41:47 +00:00
Camille GILLOT
bc9a202a22 Use Key impl to select cache. 2022-11-01 17:07:55 +00:00
Camille GILLOT
ade5cffc2b Move keys module. 2022-11-01 17:02:51 +00:00
Camille GILLOT
15d2f62bd2 Use VecCache for LocalDefId. 2022-11-01 17:02:51 +00:00
Camille GILLOT
aee4d132e7 Remove CacheSelector. 2022-11-01 17:02:51 +00:00
Dylan DPC
43634675f6
Rollup merge of #103061 - Amanieu:rewrite_alloc_error_handler, r=bjorn3
Rewrite implementation of `#[alloc_error_handler]`

The new implementation doesn't use weak lang items and instead changes `#[alloc_error_handler]` to an attribute macro just like `#[global_allocator]`.

The attribute will generate the `__rg_oom` function which is called by the compiler-generated `__rust_alloc_error_handler`. If no `__rg_oom` function is defined in any crate then the compiler shim will call `__rdl_oom` in the alloc crate which will simply panic.

This also fixes link errors with `-C link-dead-code` with `default_alloc_error_handler`: `__rg_oom` was previously defined in the alloc crate and would attempt to reference the `oom` lang item, even if it didn't exist. This worked as long as `__rg_oom` was excluded from linking since it was not called.

This is a prerequisite for the stabilization of `default_alloc_error_handler` (#102318).
2022-11-01 14:12:25 +05:30
Yuki Okushi
5bf9d617cb
Rollup merge of #103772 - compiler-errors:better-strict-coherence-err, r=davidtwco
better error for `rustc_strict_coherence` misuse

Fixes #103753
2022-11-01 12:03:42 +09:00
Michael Goulet
0f632c8f78 Fix ICE in default impl error reporting 2022-11-01 02:27:26 +00:00
Amanieu d'Antras
56074b5231 Rewrite implementation of #[alloc_error_handler]
The new implementation doesn't use weak lang items and instead changes
`#[alloc_error_handler]` to an attribute macro just like
`#[global_allocator]`.

The attribute will generate the `__rg_oom` function which is called by
the compiler-generated `__rust_alloc_error_handler`. If no `__rg_oom`
function is defined in any crate then the compiler shim will call
`__rdl_oom` in the alloc crate which will simply panic.

This also fixes link errors with `-C link-dead-code` with
`default_alloc_error_handler`: `__rg_oom` was previously defined in the
alloc crate and would attempt to reference the `oom` lang item, even if
it didn't exist. This worked as long as `__rg_oom` was excluded from
linking since it was not called.

This is a prerequisite for the stabilization of
`default_alloc_error_handler` (#102318).
2022-10-31 16:32:57 +00:00
Dylan DPC
c1c2922aa1
Rollup merge of #103603 - camsteffen:refactor-lang, r=oli-obk
Lang item cleanups

Various cleanups related to lang items.
2022-10-31 14:52:56 +05:30
bors
4596f4f8b5 Auto merge of #103787 - notriddle:rollup-q1vmxsb, r=notriddle
Rollup of 8 pull requests

Successful merges:

 - #97971 (Enable varargs support for calling conventions other than C or cdecl )
 - #101428 (Add mir building test directory)
 - #101944 (rustdoc: clean up `#toggle-all-docs`)
 - #102101 (check lld version to choose correct option to disable multi-threading in tests)
 - #102689 (Add a tier 3 target for the Sony PlayStation 1)
 - #103746 (rustdoc: add support for incoherent impls on structs and traits)
 - #103758 (Add regression test for reexports in search results)
 - #103764 (All verbosity checks in `PrettyPrinter` now go through `PrettyPrinter::should_print_verbose`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-10-31 03:40:22 +00:00
Michael Howell
e6ffd96e41
Rollup merge of #103764 - SarthakSingh31:issue-94187-2, r=compiler-errors
All verbosity checks in `PrettyPrinter` now go through `PrettyPrinter::should_print_verbose`

Follow-up to #103428. That pr only partially fixed #94187. In some cases (like closures) `std::any::type_name` was still producing a different output when `-Zverbose` was enabled.

This pr fixes those cases and adds a new function `PrettyPrinter::should_print_verbose`. This function should always be used over `self.tcx().sess.verbose()` inside a `impl PrettyPrinter`.

Maybe closes #94187 now.

r? ``@compiler-errors``
2022-10-30 19:31:40 -07:00
Nicholas Nethercote
003a3f8cd3 Use br instead of switch in more cases.
`codegen_switchint_terminator` already uses `br` instead of `switch`
when there is one normal target plus the `otherwise` target. But there's
another common case with two normal targets and an `otherwise` target
that points to an empty unreachable BB. This comes up a lot when
switching on the tags of enums that use niches.

The pattern looks like this:
```
bb1:                                              ; preds = %bb6
  %3 = load i8, ptr %_2, align 1, !range !9, !noundef !4
  %4 = sub i8 %3, 2
  %5 = icmp eq i8 %4, 0
  %_6 = select i1 %5, i64 0, i64 1
  switch i64 %_6, label %bb3 [
    i64 0, label %bb4
    i64 1, label %bb2
  ]

bb3:                                              ; preds = %bb1
  unreachable
```
This commit adds code to convert the `switch` to a `br`:
```
bb1:                                              ; preds = %bb6
  %3 = load i8, ptr %_2, align 1, !range !9, !noundef !4
  %4 = sub i8 %3, 2
  %5 = icmp eq i8 %4, 0
  %_6 = select i1 %5, i64 0, i64 1
  %6 = icmp eq i64 %_6, 0
  br i1 %6, label %bb4, label %bb2

bb3:                                              ; No predecessors!
  unreachable
```
This has a surprisingly large effect on compile times, with reductions
of 5% on debug builds of some crates. The reduction is all due to LLVM
taking less time. Maybe LLVM is just much better at handling `br` than
`switch`.

The resulting code is still suboptimal.
- The `icmp`, `select`, `icmp` sequence is silly, converting an `i1` to an `i64`
  and back to an `i1`. But with the current code structure it's hard to avoid,
  and LLVM will easily clean it up, in opt builds at least.
- `bb3` is usually now truly dead code (though not always, so it can't
  be removed universally).
2022-10-31 10:16:39 +11:00
Michael Goulet
953727f574 better error for rustc_strict_coherence misuse 2022-10-30 19:11:55 +00:00
Sarthak Singh
8609364480 All verbosity checks in PrettyPrinter now go through PrettyPrinter::should_print_verbose 2022-10-30 20:37:43 +05:30
Cameron Steffen
1c8e658820 Use LanguageItems::require less 2022-10-29 16:04:10 -05:00
Cameron Steffen
6621279a75 Cleanup weak lang items 2022-10-29 16:04:10 -05:00
Cameron Steffen
ebfa1f0185 Encode LangItem directly 2022-10-29 16:04:10 -05:00
Vadim Petrochenkov
f1850d4c9b rustc_middle: Remove unnecessary type parameter from AccessLevels 2022-10-29 23:36:56 +04:00
Guillaume Gomez
2414a4c31a
Rollup merge of #103625 - WaffleLapkin:no_tyctxt_dogs_allowed, r=compiler-errors
Accept `TyCtxt` instead of `TyCtxtAt` in `Ty::is_*` functions

Functions in answer:

- `Ty::is_freeze`
- `Ty::is_sized`
- `Ty::is_unpin`
- `Ty::is_copy_modulo_regions`

This allows to remove a lot of useless `.at(DUMMY_SP)`, making the code a bit nicer :3

r? `@compiler-errors`
2022-10-29 14:18:03 +02:00
Guillaume Gomez
692a22e735
Rollup merge of #103618 - nnethercote:rename-OwnerId-fields, r=compiler-errors
Rename some `OwnerId` fields.

`@spastorino` noticed some silly expressions like `item_id.def_id.def_id`.

This commit renames several `def_id: OwnerId` fields as `owner_id`, so those expressions become `item_id.owner_id.def_id`.

`item_id.owner_id.local_def_id` would be even clearer, but the use of `def_id` for values of type `LocalDefId` is *very* widespread, so I left that alone.

r? `@compiler-errors`
2022-10-29 14:18:03 +02:00
Charles Lew
3b6b6047b6 Lint against usages of struct_span_lint_hir. 2022-10-29 18:03:47 +08:00
Nicholas Nethercote
c8c25ce5a1 Rename some OwnerId fields.
spastorino noticed some silly expressions like `item_id.def_id.def_id`.

This commit renames several `def_id: OwnerId` fields as `owner_id`, so
those expressions become `item_id.owner_id.def_id`.

`item_id.owner_id.local_def_id` would be even clearer, but the use of
`def_id` for values of type `LocalDefId` is *very* widespread, so I left
that alone.
2022-10-29 20:28:38 +11:00
bors
607878d069 Auto merge of #102698 - michaelwoerister:unord-collections, r=lncr
Introduce UnordMap, UnordSet, and UnordBag (MCP 533)

This is the start of implementing [MCP 533](https://github.com/rust-lang/compiler-team/issues/533).

I followed `@eddyb's` suggestion of naming the collection types `Unord(Map/Set/Bag)` which is a bit easier to type than `Unordered(Map/Set/Bag)`

r? `@eddyb`
2022-10-29 06:20:48 +00:00
bors
33b55ac39f Auto merge of #102233 - petrochenkov:effvis, r=jackh726
privacy: Rename "accessibility levels" to "effective visibilities"

And a couple of other naming and comment tweaks.

Related to https://github.com/rust-lang/rust/issues/48054

For `enum Level` I initially used naming `enum EffectiveVisibilityLevel`, but it was too long and inconvenient because it's used pretty often.
So I shortened it to just `Level`, if it needs to be used from some context where this name would be ambiguous, then it can be imported with renaming like `use rustc_middle::privacy::Level as EffVisLevel` or something.
2022-10-29 03:08:59 +00:00
bors
77e7b74ad5 Auto merge of #103071 - wesleywiser:fix_inlined_line_numbers, r=davidtwco
Fix line numbers for MIR inlined code

`should_collapse_debuginfo` detects if the specified span is part of a
macro expansion however it does this by checking if the span is anything
other than a normal (non-expanded) kind, then the span sequence is
walked backwards to the root span.

This doesn't work when the MIR inliner inlines code as it creates spans
with expansion information set to `ExprKind::Inlined` and results in the
line number being attributed to the inline callsite rather than the
normal line number of the inlined code.

Fixes #103068
2022-10-28 16:27:56 +00:00
Michael Goulet
dce44faf5b Revert "Make ClosureOutlivesRequirement not rely on an unresolved type"
This reverts commit a6b5f95fb0.
2022-10-27 16:15:11 +00:00
Michael Woerister
9117ea9758 Introduce UnordMap, UnordSet, and UnordBag (see MCP 533)
MCP 533: https://github.com/rust-lang/compiler-team/issues/533

Also, as an example, substitute UnordMap for FxHashMap in
used_trait_imports query result.
2022-10-27 13:23:26 +00:00
Maybe Waffle
a17ccfa621 Accept TyCtxt instead of TyCtxtAt in Ty::is_* functions
Functions in answer:

- `Ty::is_freeze`
- `Ty::is_sized`
- `Ty::is_unpin`
- `Ty::is_copy_modulo_regions`
2022-10-27 15:06:08 +04:00
Vadim Petrochenkov
34eb73c72d privacy: Rename "accessibility levels" to "effective visibilities"
And a couple of other naming tweaks

Related to https://github.com/rust-lang/rust/issues/48054
2022-10-26 16:34:53 +04:00
Dylan DPC
ffde0f722e
Rollup merge of #103428 - SarthakSingh31:issue-94187, r=compiler-errors
Removed verbose printing from the `PrettyPrinter` when printing constants

Partially solves #94187 by completing the first step described in [this comment](https://github.com/rust-lang/rust/issues/94187#issuecomment-1282339909).
2022-10-26 17:32:54 +05:30
bors
629a414d7b Auto merge of #103562 - Dylan-DPC:rollup-sheepp5, r=Dylan-DPC
Rollup of 10 pull requests

Successful merges:

 - #102951 (suggest type annotation for local statement initialed by ref expression)
 - #103209 (Diagnostic derives: allow specifying multiple alternative suggestions)
 - #103287 (Use a faster allocation size check in slice::from_raw_parts)
 - #103416 (Name the `impl Trait` in region bound suggestions)
 - #103430 (Workaround unstable stmt_expr_attributes for method receiver expressions)
 - #103444 (Remove extra type error after missing semicolon error)
 - #103520 (rustc_middle: Rearrange resolver outputs structures slightly)
 - #103533 (Use &self instead of &mut self for cast methods)
 - #103536 (Remove `rustc_driver::set_sigpipe_handler()`)
 - #103542 (Pinning tests for some `macro_rules!` errors discussed in the lang meeting)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-10-26 07:58:28 +00:00
Dylan DPC
c956351f97
Rollup merge of #103520 - petrochenkov:resout, r=cjgillot
rustc_middle: Rearrange resolver outputs structures slightly

Addresses https://github.com/rust-lang/rust/pull/98106#discussion_r898427061.
I also haven't seen the motivation for moving `cstore` from its old place, so I moved it back in this PR.
r? ```@cjgillot```
2022-10-26 11:29:56 +05:30
bors
d49e7e7fa1 Auto merge of #103279 - compiler-errors:normalize-hack-back, r=lcnr
Add eval hack in `super_relate_consts` back

Partially reverts 01adb7e98d.

This extra eval call *still* needs to happen, for example, in `normalize_param_env_or_error` when a param-env predicate has an unnormalized constant, since the param-env candidates never get normalized during candidate assembly (everywhere else we can assume that they are normalized fully).

r? `@lcnr,` though I feel like I've assigned quite a few PRs to you in the last few days, so feel free to reassign to someone else familiar with this code if you're busy!

cc #103243 (fixes the issue, but don't want to auto-close that until a backport is performed).
2022-10-26 05:17:46 +00:00
bors
a5406feb1c Auto merge of #103158 - Bryanskiy:resolve_perf, r=petrochenkov
Perf improvements for effective visibility calculating

related to https://github.com/rust-lang/rust/pull/102026
r? `@petrochenkov`
2022-10-26 02:30:18 +00:00
bors
bed4ad65bf Auto merge of #102340 - JakobDegen:pass-manager-simplification, r=oli-obk
Split phase change from `MirPass`

The main goal here is to simplify the pass manager logic. `MirPass` no longer contains the `phase_change` method, and `run_passes` instead accepts an `Option<PhaseChange>`. The hope is that this addresses the comments (and maybe perf regression) from #99102 .

r? `@oli-obk` cc `@RalfJung`
2022-10-25 15:55:39 +00:00
Bryanskiy
a9447bb9d0 Perf improvements for effective visibility calculating 2022-10-25 15:15:18 +03:00
Vadim Petrochenkov
919673ea03 rustc_middle: Rearrange resolver outputs structures slightly 2022-10-25 15:42:29 +04:00
Sarthak Singh
5e46d8675c Added helper to prevent verbose printing from the PrettyPrinter when printing constants 2022-10-25 13:05:34 +05:30
Michael Howell
039e9b6b94
Rollup merge of #103414 - compiler-errors:rpit-print-lt, r=cjgillot
Pretty print lifetimes captured by RPIT

This specifically makes the output in #103409 change from:

```diff
  error: `impl` item signature doesn't match `trait` item signature
    --> $DIR/signature-mismatch.rs:15:5
     |
  LL |     fn async_fn(&self, buff: &[u8]) -> impl Future<Output = Vec<u8>>;
     |     ----------------------------------------------------------------- expected `fn(&'1 Struct, &'2 [u8]) -> impl Future<Output = Vec<u8>>`
  ...
  LL |     fn async_fn<'a>(&self, buff: &'a [u8]) -> impl Future<Output = Vec<u8>> + 'a {
-  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found `fn(&'1 Struct, &'2 [u8]) -> impl Future<Output = Vec<u8>>`
+  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found `fn(&'1 Struct, &'2 [u8]) -> impl Future<Output = Vec<u8>> + '2`
     |
     = note: expected `fn(&'1 Struct, &'2 [u8]) -> impl Future<Output = Vec<u8>>`
-               found `fn(&'1 Struct, &'2 [u8]) -> impl Future<Output = Vec<u8>>`
+               found `fn(&'1 Struct, &'2 [u8]) -> impl Future<Output = Vec<u8>> + '2`
     = help: the lifetime requirements from the `impl` do not correspond to the requirements in the `trait`
     = help: verify the lifetime relationships in the `trait` and `impl` between the `self` argument, the other inputs and its output

  error: aborting due to previous error
```

Along with the UI tests in this PR, which I think are all improvements!

r? `@oli-obk` though feel free to re-roll
2022-10-23 14:48:17 -07:00
Jakob Degen
be2401b8bf Split phase change from MirPass 2022-10-23 14:18:09 -07:00
Michael Goulet
dd51b36fb2 Add normalize hack back 2022-10-23 17:23:35 +00:00
Michael Goulet
c5df620419 Annotate static lifetimes too 2022-10-23 17:21:43 +00:00
bors
e64f1110c0 Auto merge of #103345 - Nilstrieb:diag-flat, r=compiler-errors
Flatten diagnostic slug modules

This makes it easier to grep for the slugs in the code.

See https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Localization.20infra.20interferes.20with.20grepping.20for.20error for more discussion about it.

This was mostly done with a few regexes and a bunch of manual work. This also exposes a pretty annoying inconsistency for the extra labels. Some of the extra labels are defined as additional properties in the fluent message (which makes them not prefixed with the crate name) and some of them are new fluent messages themselves (which makes them prefixed with the crate name). I don't know whether we want to clean this up at some point but it's useful to know.

r? `@davidtwco`
2022-10-23 09:06:39 +00:00
Nilstrieb
c65ebae221
Migrate all diagnostics 2022-10-23 10:09:44 +02:00
bors
faab68eb29 Auto merge of #103426 - matthiaskrgr:rollup-n6dqdy8, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #103123 (Introduce `subst_iter` and `subst_iter_copied` on `EarlyBinder` )
 - #103328 (Do not suggest trivially false const predicates)
 - #103354 (Escape string literals when fixing overlong char literal)
 - #103355 (Handle return-position `impl Trait` in traits properly in `register_hidden_type`)
 - #103368 (Delay ambiguity span bug in normalize query iff not rustdoc)
 - #103388 (rustdoc: remove unused CSS class `.result-description`)
 - #103399 (Change `unknown_lint` applicability to `MaybeIncorrect`)
 - #103401 (Use functions for headings rustdoc GUI test)
 - #103412 (Fix typo in docs of `String::leak`.)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-10-23 06:20:24 +00:00
Matthias Krüger
5290d5e321
Rollup merge of #103123 - compiler-errors:early-binder-iter, r=cjgillot
Introduce `subst_iter` and `subst_iter_copied` on `EarlyBinder`

Makes working with bounds lists a bit easier, which I seem to do a lot.

Specifically, means that we don't need to do `.transpose_iter().map(|(pred, _)| *pred)` every time we want to iterate through an `EarlyBinder<&'tcx [(Predicate, Span)]>` (and even then, still have to call `subst` later), which was a very awkward idiom imo.
2022-10-23 08:14:30 +02:00
bors
6c9c2d862d Auto merge of #102660 - camsteffen:uninhabited-perf, r=oli-obk
Remove ParamEnv from uninhabited query
2022-10-23 03:39:43 +00:00
Michael Goulet
c0cda2b278 Pretty print lifetimes captured by RPIT 2022-10-22 20:29:40 +00:00
Cameron Steffen
2928e9ef2c Introduce InhabitedPredicate 2022-10-22 13:20:06 -05:00
bors
26c96e3416 Auto merge of #103227 - lcnr:bye-bye-unevaluated-const, r=oli-obk
stop using `ty::UnevaluatedConst` directly

best reviewed commit by commit.

simplifies #99798 because we now don't have to expand `ty::UnevaluatedConst` to `ty::Const`.
I also remember some other places where using `ty::UnevaluatedConst` directly was annoying and caused issues, though I don't quite remember what they were rn '^^

r? `@oli-obk` cc `@JulianKnodt`
2022-10-22 07:49:33 +00:00
Michael Goulet
aa8931c612 Introduce subst_iter and subst_iter_copied on EarlyBinder 2022-10-22 06:52:12 +00:00
bors
3022afe3d1 Auto merge of #103196 - Nilstrieb:no-meta-query, r=cjgillot
Get rid of native_library projection queries

They don't seem particularly useful as I don't expect native libraries to change frequently.

Maybe they do provide significant value of keeping incremental compilation green though, I'm not sure.
2022-10-22 05:08:51 +00:00
bors
eecde5850c Auto merge of #103172 - pcwalton:deduced-param-attrs, r=oli-obk
Introduce deduced parameter attributes, and use them for deducing `readonly` on indirect immutable freeze by-value function parameters.

Introduce deduced parameter attributes, and use them for deducing `readonly` on
indirect immutable freeze by-value function parameters.

Right now, `rustc` only examines function signatures and the platform ABI when
determining the LLVM attributes to apply to parameters. This results in missed
optimizations, because there are some attributes that can be determined via
analysis of the MIR making up the function body. In particular, `readonly`
could be applied to most indirectly-passed by-value function arguments
(specifically, those that are freeze and are observed not to be mutated), but
it currently is not.

This patch introduces the machinery that allows `rustc` to determine those
attributes. It consists of a query, `deduced_param_attrs`, that, when
evaluated, analyzes the MIR of the function to determine supplementary
attributes. The results of this query for each function are written into the
crate metadata so that the deduced parameter attributes can be applied to
cross-crate functions. In this patch, we simply check the parameter for
mutations to determine whether the `readonly` attribute should be applied to
parameters that are indirect immutable freeze by-value.  More attributes could
conceivably be deduced in the future: `nocapture` and `noalias` come to mind.

Adding `readonly` to indirect function parameters where applicable enables some
potential optimizations in LLVM that are discussed in [issue 103103] and [PR
103070] around avoiding stack-to-stack memory copies that appear in functions
like `core::fmt::Write::write_fmt` and `core::panicking::assert_failed`. These
functions pass a large structure unchanged by value to a subfunction that also
doesn't mutate it. Since the structure in this case is passed as an indirect
parameter, it's a pointer from LLVM's perspective. As a result, the
intermediate copy of the structure that our codegen emits could be optimized
away by LLVM's MemCpyOptimizer if it knew that the pointer is `readonly
nocapture noalias` in both the caller and callee. We already pass `nocapture
noalias`, but we're missing `readonly`, as we can't determine whether a
by-value parameter is mutated by examining the signature in Rust. I didn't have
much success with having LLVM infer the `readonly` attribute, even with fat
LTO; it seems that deducing it at the MIR level is necessary.

No large benefits should be expected from this optimization *now*; LLVM needs
some changes (discussed in [PR 103070]) to more aggressively use the `noalias
nocapture readonly` combination in its alias analysis. I have some LLVM patches
for these optimizations and have had them looked over. With all the patches
applied locally, I enabled LLVM to remove all the `memcpy`s from the following
code:

```rust
fn main() {
    println!("Hello {}", 3);
}
```

which is a significant codegen improvement over the status quo. I expect that if this optimization kicks in in multiple places even for such a simple program, then it will apply to Rust code all over the place.

[issue 103103]: https://github.com/rust-lang/rust/issues/103103

[PR 103070]: https://github.com/rust-lang/rust/pull/103070
2022-10-22 02:28:05 +00:00
Rageking8
62a2a1d257 fix some typos 2022-10-21 18:04:00 +08:00
Patrick Walton
da630ac79d Introduce deduced parameter attributes, and use them for deducing readonly on
indirect immutable freeze by-value function parameters.

Right now, `rustc` only examines function signatures and the platform ABI when
determining the LLVM attributes to apply to parameters. This results in missed
optimizations, because there are some attributes that can be determined via
analysis of the MIR making up the function body. In particular, `readonly`
could be applied to most indirectly-passed by-value function arguments
(specifically, those that are freeze and are observed not to be mutated), but
it currently is not.

This patch introduces the machinery that allows `rustc` to determine those
attributes. It consists of a query, `deduced_param_attrs`, that, when
evaluated, analyzes the MIR of the function to determine supplementary
attributes. The results of this query for each function are written into the
crate metadata so that the deduced parameter attributes can be applied to
cross-crate functions. In this patch, we simply check the parameter for
mutations to determine whether the `readonly` attribute should be applied to
parameters that are indirect immutable freeze by-value.  More attributes could
conceivably be deduced in the future: `nocapture` and `noalias` come to mind.

Adding `readonly` to indirect function parameters where applicable enables some
potential optimizations in LLVM that are discussed in [issue 103103] and [PR
103070] around avoiding stack-to-stack memory copies that appear in functions
like `core::fmt::Write::write_fmt` and `core::panicking::assert_failed`. These
functions pass a large structure unchanged by value to a subfunction that also
doesn't mutate it. Since the structure in this case is passed as an indirect
parameter, it's a pointer from LLVM's perspective. As a result, the
intermediate copy of the structure that our codegen emits could be optimized
away by LLVM's MemCpyOptimizer if it knew that the pointer is `readonly
nocapture noalias` in both the caller and callee. We already pass `nocapture
noalias`, but we're missing `readonly`, as we can't determine whether a
by-value parameter is mutated by examining the signature in Rust. I didn't have
much success with having LLVM infer the `readonly` attribute, even with fat
LTO; it seems that deducing it at the MIR level is necessary.

No large benefits should be expected from this optimization *now*; LLVM needs
some changes (discussed in [PR 103070]) to more aggressively use the `noalias
nocapture readonly` combination in its alias analysis. I have some LLVM patches
for these optimizations and have had them looked over. With all the patches
applied locally, I enabled LLVM to remove all the `memcpy`s from the following
code:

```rust
fn main() {
    println!("Hello {}", 3);
}
```

which is a significant codegen improvement over the status quo. I expect that
if this optimization kicks in in multiple places even for such a simple
program, then it will apply to Rust code all over the place.

[issue 103103]: https://github.com/rust-lang/rust/issues/103103

[PR 103070]: https://github.com/rust-lang/rust/pull/103070
2022-10-21 02:33:15 -07:00
bors
4b3b731b55 Auto merge of #103220 - compiler-errors:deny-infers, r=lcnr
Deny hashing ty/re/ct inference variables

cc `@cjgillot` and https://github.com/rust-lang/rust/pull/102695#issuecomment-1275706528
r? `@lcnr`

best reviewed one commit at a time, mostly because the second commit that fixes `ClosureOutlivesRequirement` is mostly noise because of losing its `<'tcx>` lifetime parameter.
2022-10-20 05:56:56 +00:00
bors
cb9467515b Auto merge of #102417 - oli-obk:opaque_lifetimes2, r=jackh726
Require lifetime bounds for opaque types in order to allow hidden types to capture said lifetimes

fixes #96996

cc `@aliemjay`
2022-10-20 00:22:17 +00:00
Michael Goulet
6b0ef9c810 Deny const variables as well 2022-10-19 17:11:40 +00:00
Michael Goulet
1e2eb97c6e Don't call own_existential_vtable_entries on unresolved trait ref 2022-10-19 17:11:40 +00:00
Michael Goulet
a6b5f95fb0 Make ClosureOutlivesRequirement not rely on an unresolved type 2022-10-19 17:10:59 +00:00
Michael Goulet
91af4f5d0b Don't hash non-fresh Ty::Infer or RegionKind::Infer 2022-10-19 17:10:58 +00:00
nils
ccc54613c3
Get rid of native_library projection queries
They don't seem particularly useful as I don't expect
native libraries to change frequently.
2022-10-19 16:21:21 +02:00
lcnr
c5c6ef7029 stop folding UnevaluatedConst 2022-10-19 10:15:46 +02:00
nils
4ed834523e
Clean up query descriptions
Use the same tense everywhere and prefer display over debug, as these
descriptions are user facing.
2022-10-18 17:29:42 +02:00
lcnr
116d35d401 const_evaluatable_unchecked to const eval 2022-10-18 16:31:56 +02:00
lcnr
660ca48041 change ConstEvaluatable to use ty::Const 2022-10-18 16:09:04 +02:00
bors
a9d1cafa87 Auto merge of #102355 - lcnr:bye-bye-type-traversal, r=oli-obk
remove type traversal for mir constants

r? `@oli-obk` cc `@b-naber`
2022-10-17 14:19:28 +00:00
lcnr
d04bff6583 add inline to TrivialTypeTraversalImpls 2022-10-17 10:54:03 +02:00
lcnr
face090ef1 rm try_normalize_mir_const_after_erasing_regions 2022-10-17 10:54:03 +02:00
lcnr
e8150fa60c mir constants: type traversing bye bye 2022-10-17 10:54:01 +02:00
Samuel Moelius
bf3a29f590
Duplicate comment in mod.rs 2022-10-17 03:54:56 -04:00
bors
b8b5caee04 Auto merge of #102026 - Bryanskiy:resolve_update, r=petrochenkov
Populate effective visibilities in 'rustc_resolve'

Next part of RFC https://github.com/rust-lang/rust/issues/48054.
previous: https://github.com/rust-lang/rust/pull/101713

`@rustbot` author
r? `@petrochenkov`
2022-10-16 20:34:38 +00:00
Bryanskiy
496ccd982c Populate effective visibilities in 'rustc_resolve' 2022-10-16 21:47:14 +03:00
Matthias Krüger
d6506cc0be
Rollup merge of #102953 - WaffleLapkin:better_docs_for_decorate_param, r=RalfJung
Improve docs for `struct_lint_level` function.

r? ``@RalfJung``

Does this answer your questions?
2022-10-16 17:51:31 +02:00
Ralf Jung
39375e14d7
fix typo 2022-10-16 16:47:55 +02:00
Michael Goulet
c1aa9bf849 Fix subst issues with RPITIT 2022-10-15 17:46:03 +00:00
bors
b8c35ca26b Auto merge of #102895 - Nilstrieb:query-cleanups, r=cjgillot
Get rid of `rustc_query_description!`

**I am not entirely sure whether this is an improvement and would like to get your feedback on it.**

Helps with #96524.

Queries can provide an arbitrary expression for their description and their caching behavior. Before, these expressions where stored in a `rustc_query_description` macro emitted by the `rustc_queries` macro, and then used in `rustc_query_impl` to fill out the methods for the `QueryDescription` trait.

Instead, we now emit two new modules from `rustc_queries` containing the functions with the expressions. `rustc_query_impl` calls these functions now instead of invoking the macro.

Since we are now defining some of the functions in `rustc_middle::query`, we now need all the imports for the key types mthere as well.

r? `@cjgillot`
2022-10-15 13:30:15 +00:00
bors
b15e2c129e Auto merge of #101832 - compiler-errors:dyn-star-plus, r=eholk
Make `dyn*` casts into a coercion, allow `dyn*` upcasting

I know that `dyn*` is likely not going to be a feature exposed to surface Rust, but this makes it slightly more ergonomic to write tests for these types anyways. ... and this was just fun to implement anyways.

1. Make `dyn*` into a coercion instead of a cast
2. Enable `dyn*` upcasting since we basically get it for free
3. Simplify some of the cast checking code since we're using the coercion path now

r? `@eholk` but feel free to reassign
cc `@nikomatsakis` and `@tmandry` who might care about making `dyn*` casts into a coercion
2022-10-15 07:36:38 +00:00
Wesley Wiser
34d90a46da Fix line numbers for MIR inlined code
`should_collapse_debuginfo` detects if the specified span is part of a
macro expansion however it does this by checking if the span is anything
other than a normal (non-expanded) kind, then the span sequence is
walked backwards to the root span.

This doesn't work when the MIR inliner inlines code as it creates spans
with expansion information set to `ExprKind::Inlined` and results in the
line number being attributed to the inline callsite rather than the
normal line number of the inlined code.
2022-10-14 18:44:30 -04:00
Nilstrieb
167b3bd3b2
Get rid of rustc_query_description!
Queries can provide an arbitrary expression for their description and
their caching behavior. Before, these expressions where stored in a
`rustc_query_description` macro emitted by the `rustc_queries` macro,
and then used in `rustc_query_impl` to fill out the methods for the
`QueryDescription` trait.

Instead, we now emit two new modules from `rustc_queries` containing the
functions with the expressions. `rustc_query_impl` calls these functions
now instead of invoking the macro.

Since we are now defining some of the functions in
`rustc_middle::query`, we now need all the imports for the key types
there as well.
2022-10-14 22:35:56 +02:00
Dylan DPC
77064b7f0a
Rollup merge of #103018 - Rageking8:more-dupe-word-typos, r=TaKO8Ki
More dupe word typos

I only picked those changes (from the regex search) that I am pretty certain doesn't change meaning and is just a typo fix. Do correct me if any fix is undesirable and I can revert those. Thanks.
2022-10-14 16:19:15 +05:30
Oli Scherer
1dc2119c03 Require lifetime bounds for opaque types in order to allow hidden types to capture said lifetimes 2022-10-14 08:15:51 +00:00
bors
32717603f6 Auto merge of #102695 - compiler-errors:int-and-float-trivial-copy, r=lcnr
Int and float inference variables are trivially copy

Fixes #102645
2022-10-14 07:41:55 +00:00
Michael Goulet
a010df9389 float and int vars are trivially copy 2022-10-14 05:26:32 +00:00
Rageking8
7122abaddf more dupe word typos 2022-10-14 12:57:56 +08:00
bors
1755c85302 Auto merge of #102684 - JhonnyBillM:delete-target-data-layout-errors-wrapper, r=davidtwco
Move `IntoDiagnostic` conformance for `TargetDataLayoutErrors` into `rustc_errors`

Addressed this suggestion https://github.com/rust-lang/rust/pull/101558#issuecomment-1243830009.

This way we comply with the Coherence rule given that `IntoDiagnostic` trait is defined in `rustc_errors`, and almost all other crates depend on it.
2022-10-14 04:35:22 +00:00
Michael Goulet
76386bd65e Make dyn* cast into a coercion 2022-10-14 04:27:01 +00:00
bors
60bd3f9677 Auto merge of #102700 - oli-obk:0xDEAD_TAIT, r=compiler-errors
Check hidden types in dead code

fixes #99490

r? `@compiler-errors`

best reviewed commit by commit
2022-10-13 22:39:05 +00:00
Michael Goulet
61f097308b Print RPITIT verbosely if -Zverbose 2022-10-13 02:31:43 +00:00
bors
0938e1680d Auto merge of #101679 - compiler-errors:rpitit-default-body, r=nikomatsakis
Support default-body trait functions with return-position `impl Trait` in traits

Introduce a new `Trait` candidate kind for the `ImplTraitInTrait` projection candidate, which just projects an RPITIT down to its opaque type form.

This is a hack until we lower RPITITs to regular associated types, after which we will need to rework how these default bodies are type-checked, so comments are left in a few places for us to clean up later.

Fixes #101665
2022-10-12 21:03:47 +00:00
Jhonny Bill Mena
5645cd5b09 ADD - IntoDiagnostic conformance for TargetDataLayoutErrors in rustc_errors
This way we comply with the Coherence rule given that IntoDiagnostic trait is defined in rustc_errors, and almost all other crates depend on it.
2022-10-12 16:54:25 -04:00
Maybe Waffle
c5de3ecec3 link lint function with decorate function param to struct_lint_level 2022-10-12 14:16:24 +00:00
Waffle Maybe
b1c3e78661
Apply suggestions from code review
Co-authored-by: Ralf Jung <post@ralfj.de>
2022-10-12 16:39:11 +04:00
Nilstrieb
7bfef19844 Use tidy-alphabetical in the compiler 2022-10-12 17:49:10 +05:30
Maybe Waffle
f1ac7b5a65 Improve docs for struct_lint_level function. 2022-10-12 09:28:11 +00:00
Dylan DPC
c8a8e7d116
Rollup merge of #102890 - camsteffen:adt-sized-representability, r=cjgillot
Check representability in adt_sized_constraint

Now that representability is a query, we can use it to preemptively avoid a cycle in `adt_sized_constraint`.

I moved the representability check into `check_mod_type_wf` to avoid a scenario where rustc quits before checking all the types for representability. This also removes the check from rustdoc, which is alright AFAIK.

r? ``@cjgillot``
2022-10-12 11:11:26 +05:30
Dylan DPC
32471a7035
Rollup merge of #102110 - CleanCut:migrate_rustc_passes_diagnostics, r=davidtwco
Migrate rustc_passes diagnostics

Picks up abandoned work from https://github.com/rust-lang/rust/pull/100870

I would like to do this collaboratively, as there is a lot of work! Here's the process:

- Comment below that you are willing to help and I will add you as a collaborator to my `rust` fork (that gives you write access)
- Indicate which file/task you would like to work on (so we don't duplicate work) from the list below
- Do the work, push up a commit, comment that you're done with that file/task
- Repeat until done 😄

### Files to Migrate (in `compiler/rustc_passes/src/`)

- [x] check_attr.rs ``@CleanCut``
- [x] check_const.rs ``@CleanCut``
- [x] dead.rs ``@CleanCut``
- [x] debugger_visualizer.rs ``@CleanCut``
- [x] diagnostic_items.rs ``@CleanCut``
- [x] entry.rs ``@CleanCut``
- [x] lang_items.rs ``@CleanCut``
- [x] layout_test.rs ``@CleanCut``
- [x] lib_features.rs ``@CleanCut``
- [x] ~liveness.rs~ ``@CleanCut`` Nothing to do
- [x] loops.rs ``@CleanCut``
- [x] naked_functions.rs ``@CleanCut``
- [x] stability.rs ``@CleanCut``
- [x] weak_lang_items.rs ``@CleanCut``

### Tasks

- [x] Rebase on current `master` ``@CleanCut``
- [x] Review work from [the earlier PR](https://github.com/rust-lang/rust/pull/100870) and make sure it all looks good
  - [x] compiler/rustc_error_messages/locales/en-US/passes.ftl ``@CleanCut``
  - [x] compiler/rustc_passes/src/check_attr.rs ``@CleanCut``
  - [x] compiler/rustc_passes/src/errors.rs ``@CleanCut``
  - [x] compiler/rustc_passes/src/lang_items.rs ``@CleanCut``
  - [x] compiler/rustc_passes/src/lib.rs ``@CleanCut``
  - [x] compiler/rustc_passes/src/weak_lang_items.rs ``@CleanCut``
2022-10-12 11:11:23 +05:30
Matthias Krüger
cadb37a8c7
Rollup merge of #101727 - est31:stabilize_map_first_last, r=m-ou-se
Stabilize map_first_last

Stabilizes the following functions:

```Rust
impl<T> BTreeSet<T> {
    pub fn first(&self) -> Option<&T> where T: Ord;
    pub fn last(&self) -> Option<&T> where T: Ord;
    pub fn pop_first(&mut self) -> Option<T> where T: Ord;
    pub fn pop_last(&mut self) -> Option<T> where T: Ord;
}

impl<K, V> BTreeMap<K, V> {
    pub fn first_key_value(&self) -> Option<(&K, &V)> where K: Ord;
    pub fn last_key_value(&self) -> Option<(&K, &V)> where K: Ord;
    pub fn first_entry(&mut self) -> Option<OccupiedEntry<'_, K, V>> where K: Ord;
    pub fn last_entry(&mut self) -> Option<OccupiedEntry<'_, K, V>> where K: Ord;
    pub fn pop_first(&mut self) -> Option<(K, V)> where K: Ord;
    pub fn pop_last(&mut self) -> Option<(K, V)> where K: Ord;
}
```

Closes #62924

~~Blocked on the [FCP](https://github.com/rust-lang/rust/issues/62924#issuecomment-1179489929) finishing.~~ Edit: It finished!
2022-10-11 18:59:46 +02:00
Cameron Steffen
d933092dc5 Check representability in adt_sized_constraint 2022-10-10 14:36:12 -05:00
Guillaume Gomez
adc24d1b5e Fix compiler docs 2022-10-10 18:28:29 +02:00
Dylan DPC
58d533dfc1
Rollup merge of #102786 - compiler-errors:no-tuple-candidate, r=lcnr
Remove tuple candidate, nothing special about it

r? `@lcnr` you mentioned this during the talk you gave i think
2022-10-10 13:43:41 +05:30
Yuki Okushi
c50e64d872
Rollup merge of #102275 - Urgau:stabilize-half_open_range_patterns, r=cjgillot
Stabilize `half_open_range_patterns`

This PR stabilize `feature(half_open_range_patterns)`:
```
Allows using `..=X` as a pattern.
```

And adds a new `feature(half_open_range_patterns_in_slices)` for the slice part, https://github.com/rust-lang/rust/pull/102275#issuecomment-1267422806.

The FCP was completed in https://github.com/rust-lang/rust/issues/67264.
2022-10-10 10:23:03 +09:00
Yuki Okushi
24424d0acb
Rollup merge of #102829 - compiler-errors:rename-impl-item-kind, r=TaKO8Ki
rename `ImplItemKind::TyAlias` to `ImplItemKind::Type`

The naming of this variant seems inconsistent given that this is not really a "type alias", and the associated type variant for `TraitItemKind` is just called `Type`.
2022-10-10 00:09:42 +09:00
Michael Goulet
70f3c79c50 ImplItemKind::TyAlias => ImplItemKind::Type 2022-10-09 07:09:57 +00:00
Michael Howell
5ba30a680c
Rollup merge of #102514 - b-naber:binder-print-fixes, r=jackh726
Don't repeat lifetime names from outer binder in print

Fixes https://github.com/rust-lang/rust/issues/102392
Fixes https://github.com/rust-lang/rust/issues/102414

r? ```@lcnr```
2022-10-08 18:14:59 -07:00
b-naber
048e637e9e handle late-bound vars from inner binders correctly and add test 2022-10-08 17:48:02 +02:00
bors
c27948d255 Auto merge of #102809 - matthiaskrgr:rollup-qq62vuv, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #101520 (Allow transmutes between the same types after erasing lifetimes)
 - #102675 (Remove `mir::CastKind::Misc`)
 - #102778 (Fix MIR inlining of asm_unwind)
 - #102785 (Remove `DefId` from some `SelectionCandidate` variants)
 - #102788 (Update rustc-dev-guide)
 - #102789 (Update browser UI test version)
 - #102797 (rustdoc: remove no-op CSS `.rightside { position: initial }`)
 - #102798 (rustdoc: add main-heading and example-wrap link CSS to big selector)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-10-08 14:58:11 +00:00
Matthias Krüger
f1a03b6e4a
Rollup merge of #102785 - fee1-dead-contrib:rm_autoimpl_defid, r=compiler-errors
Remove `DefId` from some `SelectionCandidate` variants

They are both from `obligation.predicate.def_id()`, which do not need to be on the `SelectionCandidate`.

cc ````@lcnr```` ````@compiler-errors````
2022-10-08 14:38:19 +02:00
Matthias Krüger
c731646d6a
Rollup merge of #102675 - ouz-a:mir-technical-debt, r=oli-obk
Remove `mir::CastKind::Misc`

As discussed in #97649 `mir::CastKind::Misc` is not clear, this PR addresses that by creating a new enum variant for every valid cast.

r? ````@oli-obk````
2022-10-08 14:38:18 +02:00
bors
bba9785dd7 Auto merge of #100720 - camsteffen:representable, r=cjgillot
Rewrite representability

 * Improve placement of `Box` in the suggestion
 * Multiple items in a cycle emit 1 error instead of an error for each item in the cycle
 * Introduce `representability` query to avoid traversing an item every time it is used.
 * Also introduce `params_in_repr` query to avoid traversing generic items every time it is used.
2022-10-08 11:53:25 +00:00
Urgau
5ae73634dc Stabilize half_open_range_patterns 2022-10-08 11:00:13 +02:00
Oli Scherer
f85d3a7e33 Check hidden types in dead code 2022-10-07 19:43:46 +00:00
Oli Scherer
70d39abbc2 Remap hidden types from typeck before storing them in the TypeckResult 2022-10-07 19:43:46 +00:00
Oli Scherer
9eb69e82e0 Move ReverseMapper logic onto OpaqueHiddenType 2022-10-07 19:43:46 +00:00
Oli Scherer
5d15beb591 Unconditionally encode hidden types in typeck results 2022-10-07 19:36:32 +00:00
Nathan Stocks
965dbf6c28 First batch of review feedback changes from #102110 2022-10-07 13:19:28 -06:00
Michael Goulet
8b9a1f1f4e Remove tuple candidate, nothing special about it 2022-10-07 16:19:21 +00:00
Ralf Jung
fd59d44f58 make const_err a hard error 2022-10-07 18:08:49 +02:00
Deadbeef
e8a2aee50d Remove DefId from some SelectionCandidate variants 2022-10-07 15:14:22 +00:00
Cameron Steffen
ff940db666 Rewrite representability 2022-10-07 09:33:46 -05:00
Matthias Krüger
dd0fa6f871
Rollup merge of #98496 - BoxyUwU:instancers_bad_equality, r=lcnr
make `compare_const_impl` a query and use it in `instance.rs`

Fixes #88365

the bug in #88365 was caused by some `instance.rs` code using the `PartialEq` impl on `Ty` to check that the type of the associated const in an impl is the same as the type of the associated const in the trait definition. This was wrong for two reasons:
- the check typeck does is that the impl type is a subtype of the trait definition's type (see `mismatched_impl_ty_2.rs` which [was ICEing](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=f6d60ebe6745011f0d52ab2bc712025d) before this PR on stable)
- it assumes that if two types are equal then the `PartialEq` impl will reflect that which isnt true for higher ranked types or type level constants when `feature(generic_const_exprs)` is enabled (see `mismatched_impl_ty_3.rs` for higher ranked types which was [ICEing on stable](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=d7af131a655ed515b035624626c62c71))

r? `@lcnr`
2022-10-06 16:29:43 +02:00
ouz-a
d59c7ff000 Remove mir::CastKind::Misc 2022-10-06 15:32:41 +03:00
Michael Goulet
9a5936b814 Validate opaques in default trait bodies, don't normalize unless a body is provided 2022-10-05 04:16:09 +00:00
Michael Goulet
79450360d2 Fix test for default body with impl 2022-10-05 04:16:05 +00:00
Matthias Krüger
0dd0c6c1e6
Rollup merge of #102651 - oli-obk:non_region_things, r=lcnr
It's not about types or consts, but the lack of regions

pulled out of https://github.com/rust-lang/rust/pull/101900 which adds a fourth kind of non-lifetime generic parameter, and the naming of these methods would get ridiculous.
2022-10-04 18:26:41 +02:00
Oli Scherer
c7b6ebdf7c It's not about types or consts, but the lack of regions 2022-10-04 14:10:44 +00:00
bors
02cd79afb8 Auto merge of #102652 - Dylan-DPC:rollup-6ff8ct8, r=Dylan-DPC
Rollup of 6 pull requests

Successful merges:

 - #101189 (Implement `Ready::into_inner()`)
 - #101642 (Fix in-place collection leak when remaining element destructor panic)
 - #102489 (Normalize substs before resolving instance in `NoopMethodCall` lint)
 - #102559 (Don't ICE when trying to copy unsized value in const prop)
 - #102568 (Lint against nested opaque types that don't satisfy associated type bounds)
 - #102633 (Fix rustdoc ICE in invalid_rust_codeblocks lint)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-10-04 13:04:57 +00:00
Dylan DPC
35f92ed1bf
Rollup merge of #102568 - compiler-errors:lint-unsatisfied-opaques, r=oli-obk
Lint against nested opaque types that don't satisfy associated type bounds

See the test failures for examples of places where this lint would fire.

r? `@oli-obk`
2022-10-04 16:11:02 +05:30
bors
ead49f0beb Auto merge of #102622 - camsteffen:move-layout, r=fee1-dead
Move layout_of and friends from rustc_middle to rustc_ty_utils

Breaks up the very large module that is `rustc_middle::ty::layout` by fork-lifting some queries into `rustc_ty_utils::{abi, layout}`.

This does set back `rustc_ty_utils` to having untranslatable diagnostics. I'd like to leave this as a separate task.
2022-10-04 09:29:07 +00:00
Matthias Krüger
8a0fda2ec1
Rollup merge of #102567 - compiler-errors:issue-102561, r=davidtwco
Delay evaluating lint primary message until after it would be suppressed

Fixes #102561
Fixes #102572
2022-10-04 06:14:11 +02:00
bors
f83e0266cf Auto merge of #102632 - matthiaskrgr:rollup-h8s3zmo, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #98218 (Document the conditional existence of `alloc::sync` and `alloc::task`.)
 - #99216 (docs: be less harsh in wording for Vec::from_raw_parts)
 - #99460 (docs: Improve AsRef / AsMut docs on blanket impls)
 - #100470 (Tweak `FpCategory` example order.)
 - #101040 (Fix `#[derive(Default)]` on a generic `#[default]` enum adding unnecessary `Default` bounds)
 - #101308 (introduce `{char, u8}::is_ascii_octdigit`)
 - #102486 (Add diagnostic struct for const eval error in `rustc_middle`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-10-03 20:22:18 +00:00
pierwill
b9c0467e0c Add diagnostic struct for const eval error in rustc_middle
Co-authored-by: Michael Goulet <michael@errs.io>
2022-10-03 12:29:49 -05:00
Matthias Krüger
8ede2340b7
Rollup merge of #102597 - compiler-errors:issue-102571, r=davidtwco
Avoid ICE in printing RPITIT type

Fixes #102571
2022-10-03 19:12:18 +02:00
b-naber
e83dcf4ecd re-name params + add comments 2022-10-03 17:37:22 +02:00
Cameron Steffen
95b689b1d5 Move utils from rustc_middle to rustc_ty_utils 2022-10-03 09:12:03 -05:00
Matthias Krüger
d5fb8d2aef
Rollup merge of #102592 - WaffleLapkin:less_lifetimes, r=cjgillot
Remove a couple lifetimes that can be infered

From the review: https://github.com/rust-lang/rust/pull/101986#discussion_r974497497

r? `@cjgillot`
2022-10-03 08:00:48 +02:00
Michael Goulet
90a8d67491 Avoid ICE in printing RPITIT type 2022-10-02 20:43:13 +00:00
Michael Goulet
d0d6af9146 Lint for unsatisfied nested opaques 2022-10-02 19:50:19 +00:00
Maybe Waffle
8cc8140775 Remove a couple lifetimes that could be infered 2022-10-02 15:40:20 +00:00
Dylan DPC
f3ab5a66a9
Rollup merge of #102538 - cjgillot:def-span-ctxt, r=fee1-dead
Give `def_span` the same SyntaxContext as `span_with_body`.

https://github.com/rust-lang/rust/issues/102217

I'm not sure how to add a test, since the erroneous span was crafted using a proc macro.
The debug assertion in `def_span` will ensure we have the correct behaviour.
2022-10-02 20:42:21 +05:30
Michael Goulet
f088e543cb Delay evaluating lint primary message until after it would be suppressed 2022-10-02 06:32:40 +00:00
Camille GILLOT
9f2ab5b9ad Use a SortedMap instead of a VecMap. 2022-10-01 16:24:30 +02:00
Camille GILLOT
d08669c4fa Compute by owner instead of HirId. 2022-10-01 16:22:40 +02:00
Camille GILLOT
26e5fe9e85 Do not fetch HIR node when iterating to find lint. 2022-10-01 16:20:21 +02:00
Camille GILLOT
34bc5c8824 Move lint level computation to rustc_middle::lint. 2022-10-01 16:18:54 +02:00
Camille GILLOT
41db9b152f Move code to rustc_lint. 2022-10-01 16:18:13 +02:00
Camille GILLOT
107170b9c3 Remove unused tool_name. 2022-10-01 16:12:54 +02:00
Deadbeef
3cb1811e45 Compute lint_levels by definition 2022-10-01 16:12:50 +02:00
Camille GILLOT
6019cbbfd3 Allow query system to recover a HirId. 2022-10-01 15:58:42 +02:00
bors
744e397d88 Auto merge of #101986 - WaffleLapkin:move_lint_note_to_the_bottom, r=estebank
Move lint level source explanation to the bottom

So, uhhhhh

r? `@estebank`

## User-facing change

"note: `#[warn(...)]` on by default" and such are moved to the bottom of the diagnostic:
```diff
-   = note: `#[warn(unsupported_calling_conventions)]` on by default
   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
   = note: for more information, see issue #87678 <https://github.com/rust-lang/rust/issues/87678>
+   = note: `#[warn(unsupported_calling_conventions)]` on by default
```

Why warning is enabled is the least important thing, so it shouldn't be the first note the user reads, IMO.

## Developer-facing change

`struct_span_lint` and similar methods have a different signature.

Before: `..., impl for<'a> FnOnce(LintDiagnosticBuilder<'a, ()>)`
After: `..., impl Into<DiagnosticMessage>, impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>) -> &'b mut DiagnosticBuilder<'a, ()>`

The reason for this is that `struct_span_lint` needs to edit the diagnostic _after_ `decorate` closure is called. This also makes lint code a little bit nicer in my opinion.

Another option is to use `impl for<'a> FnOnce(LintDiagnosticBuilder<'a, ()>) -> DiagnosticBuilder<'a, ()>` altough I don't _really_ see reasons to do `let lint = lint.build(message)` everywhere.

## Subtle problem

By moving the message outside of the closure (that may not be called if the lint is disabled) `format!(...)` is executed earlier, possibly formatting `Ty` which may call a query that trims paths that crashes the compiler if there were no warnings...

I don't think it's that big of a deal, considering that we move from `format!(...)` to `fluent` (which is lazy by-default) anyway, however this required adding a workaround which is unfortunate.

## P.S.

I'm sorry, I do not how to make this PR smaller/easier to review. Changes to the lint API affect SO MUCH 😢
2022-10-01 10:44:25 +00:00
Maybe Waffle
ad3d1fc9d5 Move lint level source explanation to the bottom 2022-10-01 10:03:06 +00:00
Maybe Waffle
a8f7e244b7 Refactor rustc lint API 2022-10-01 10:03:06 +00:00
Camille GILLOT
c321933e22 Give def_span the same SyntaxContext as span_with_body. 2022-10-01 11:38:59 +02:00
Matthias Krüger
05b9f0e360
Rollup merge of #102483 - spastorino:create-defs-on-lowering, r=cjgillot
create def ids for impl traits during ast lowering

r? `@cjgillot`
2022-09-30 23:38:25 +02:00
Santiago Pastorino
b2bef02bcd
create def ids for impl traits during ast lowering 2022-09-30 15:12:01 -03:00
Boxy
c1a9cf42b4 make query take (LocalDefId, DefId) 2022-09-30 18:53:32 +01:00
Boxy
86a8a3beb4 make compare_const_impl a query and use it in instance.rs 2022-09-30 17:47:44 +01:00
est31
2c72ea7748 Stabilize map_first_last 2022-09-30 17:00:07 +02:00
b-naber
e1f735a5d1 don't repeat lifetime names from outer binder in print 2022-09-30 15:44:38 +02:00
Matthias Krüger
25017f8bce
Rollup merge of #101075 - ellishg:rustc_codegen_gcc_diagnostics, r=davidtwco
Migrate rustc_codegen_gcc to SessionDiagnostics

As part of #100717 this pr migrates diagnostics to `SessionDiagnostics` for the `rustc_codegen_gcc` crate.

``@rustbot`` label +A-translation
2022-09-30 10:22:36 +02:00
bors
b3aa4997d4 Auto merge of #102164 - compiler-errors:rpitit-foreign, r=TaKO8Ki
Serialize return-position `impl Trait` in trait hidden values in foreign libraries

Fixes #101630
2022-09-30 04:24:14 +00:00
bors
1bb8d276c9 Auto merge of #101887 - nnethercote:shrink-Res, r=spastorino
Shrink `hir::def::Res`

r? `@spastorino`
2022-09-29 22:45:24 +00:00
bors
9f1a21ae2b Auto merge of #101893 - oli-obk:lift_derive, r=lcnr
Fix perf regression from TypeVisitor changes

Regression occurred in https://github.com/rust-lang/rust/pull/101858#issuecomment-1248732579

Instead of just reverting, we only fixed part of the regression. The main regression was due to actually correctly visiting a type that contains types and consts and should therefor be visited. This is not actually observable (yet?), but we should still do it correctly instead of risking major bugs in the future.
2022-09-29 17:05:00 +00:00
Yuki Okushi
039e9e2160
Rollup merge of #102399 - b-naber:binder-print-ice, r=lcnr
Account for use of index-based lifetime names in print of binder

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

r? ```@lcnr```

cc ```@steffahn```
2022-09-29 11:42:06 +09:00
Nicholas Nethercote
f07d4efc45 Shrink hir::def::Res.
`Res::SelfTy` currently has two `Option`s. When the second one is `Some`
the first one is never consulted. So we can split it into two variants,
`Res::SelfTyParam` and `Res::SelfTyAlias`, reducing the size of `Res`
from 24 bytes to 12. This then shrinks `hir::Path` and
`hir::PathSegment`, which are the HIR types that take up the most space.
2022-09-29 08:44:52 +10:00
b-naber
4fdc78e6bf account for use of index-based lifetime names in print of binder 2022-09-28 12:31:08 +02:00
Noah Lev
4bf789fba7 rustdoc: Queryify is_notable_trait
This might help with #102375.
2022-09-27 17:44:54 -07:00
lcnr
1fc86a63f4 rustc_typeck to rustc_hir_analysis 2022-09-27 10:37:23 +02:00
Matthias Krüger
b02062e886
Rollup merge of #101996 - b-naber:binder-print, r=lcnr
Don't duplicate region names for late-bound regions in print of Binder

Fixes https://github.com/rust-lang/rust/issues/101280
2022-09-26 19:19:20 +02:00
b-naber
6118ee343f address review 2022-09-26 14:21:39 +02:00
b-naber
456f4e8d22 don't duplicate late-bound region names in print of Binder 2022-09-26 13:10:55 +02:00
Pietro Albini
3975d55d98
remove cfg(bootstrap) 2022-09-26 10:14:45 +02:00
fee1-dead
39c6bdc30d
Rollup merge of #102270 - Nilstrieb:delete-useless-benches, r=TaKO8Ki
Remove benches from `rustc_middle`

These benches benchmark rust langauge features and not the compiler, so they seem to be in the wrong place here. They also all take <1ns, making them pretty useless. Looking at their git history, they just seem to have been carried around for many, many years. This commit ends their journey.
2022-09-26 13:09:43 +08:00
bors
ff40f2ec95 Auto merge of #101710 - jyn514:move-dep-kind-node, r=cjgillot
Move DepKindStruct from rustc_middle to rustc_query_system

Helps with https://github.com/rust-lang/rust/issues/96524. cc https://rust-lang.zulipchat.com/#narrow/stream/241847-t-compiler.2Fwg-incr-comp/topic/Moving.20.60DepKindStruct.60.20to.20rustc_query_system.20.2396524

r? `@cjgillot`
2022-09-25 21:37:10 +00:00
bors
f5193a9fcc Auto merge of #95474 - oli-obk:tait_ub, r=jackh726
Neither require nor imply lifetime bounds on opaque type for well formedness

The actual hidden type can live arbitrarily longer than any individual lifetime and arbitrarily shorter than all but one of the lifetimes.

fixes #86218
fixes #84305

This is a **breaking change** but it is a necessary soundness fix
2022-09-25 19:15:26 +00:00
Joshua Nelson
00cde6d4b9 Move the codegen_unit debug assert from rustc_query_system to query_impl
This allows removing a function from the `DepKind` trait.
2022-09-25 12:08:36 -05:00
Joshua Nelson
ccc8d000f2 Move some more code from rustc_middle to rustc_query_system 2022-09-25 12:08:36 -05:00
Joshua Nelson
f3f91bb514 Move functions on DepKindStruct from rustc_middle to rustc_query_system 2022-09-25 12:07:17 -05:00
Joshua Nelson
93a0fb190e Move DepKindStruct from rustc_middle to rustc_query_system 2022-09-25 11:56:23 -05:00
Nilstrieb
ddf7982741 Remove benches from rustc_middle
These benches benchmark rust langauge features and not the compiler,
so they seem to be in the wrong place here. They also all take <1ns,
making them pretty useless. Looking at their git history, they just
seem to have been carried around for many, many years. This commit
ends their journey.
2022-09-25 18:35:43 +02:00
bors
d0ece44cfa Auto merge of #102040 - TaKO8Ki:separate-definitions-and-hir-owners, r=cjgillot
Separate definitions and HIR owners in the type system

Fixes #83158

r? `@cjgillot`
2022-09-24 22:42:07 +00:00
Ellis Hoag
ac97487645 fix lifetime error 2022-09-24 11:36:16 -07:00