Commit Graph

19480 Commits

Author SHA1 Message Date
Oli Scherer
d7f5d784d7 Simplify and document range layout computation 2022-11-25 08:39:11 +00:00
Oli Scherer
fcb1f1874f Don't show fields from other crates 2022-11-25 08:12:16 +00:00
Oli Scherer
2e79f5f9f8 Move a comment to the right place 2022-11-25 08:11:53 +00:00
Oli Scherer
98c550ecc8 Reinstate the previous compact form of "in this field" errors 2022-11-25 08:11:29 +00:00
Oli Scherer
ccaa28bf69 Don't try to compute the layout of generic types. 2022-11-25 08:10:52 +00:00
Oli Scherer
2bed079103 Compute layout instead of manually procesisng the layout restriction attributes 2022-11-25 08:10:29 +00:00
Oli Scherer
5cbf172909 Print a trace through types to show how to get to the problematic type 2022-11-25 08:09:52 +00:00
Oli Scherer
9909cb902f Make the ICEs in the mir typechecker have more spans helpful 2022-11-25 08:01:12 +00:00
Oli Scherer
6773e7ee56 More manual formatting 2022-11-25 08:00:49 +00:00
Oli Scherer
c3eb8f2778 rustc_layout_scalar_valid_range can be applied to scalar pairs and affects teh first scalar 2022-11-25 08:00:26 +00:00
Oli Scherer
2b8963a94c Some manual formatting of let..else statements 2022-11-25 08:00:02 +00:00
Oli Scherer
2a94a2d385 Prefer not accessing the private field of newtype_index types 2022-11-25 07:51:56 +00:00
Oli Scherer
b5554722ff Add helper method to ScalarInt 2022-11-25 07:47:56 +00:00
bors
41e0363055 Auto merge of #104602 - petrochenkov:effvisperf5, r=oli-obk
privacy: Fix more (potential) issues with effective visibilities

Continuation of https://github.com/rust-lang/rust/pull/103965.
See individual commits for more detailed description of the changes.

The shortcuts removed in 4eb63f618e and c7c7d16727 could actually be correct (or correct after some tweaks), but they used global reasoning like "we can skip this update because if the code compiles then some other update should do the same thing eventually".
I have some expertise in this area, but I still have doubt whether such global reasoning was correct or not, especially in presence of all possible exotic cases with imports.
After this PR all table changes should be "locally correct" after every update, even if it may be overcautious.
If similar optimizations are introduced again they will need detailed comments explaining why it's legal to do what they do and providing proofs.

Fixes https://github.com/rust-lang/rust/issues/104249.
Fixes https://github.com/rust-lang/rust/issues/104539.
2022-11-25 06:14:42 +00:00
Santiago Pastorino
974e2837bb
Introduce PredicateKind::Clause 2022-11-25 00:04:54 -03:00
Oli Scherer
42cc8e8f4e
Simplify a bunch of trait ref obligation creations 2022-11-25 00:04:54 -03:00
Oli Scherer
08afabddac
get rid of to_poly_trait_predicate 2022-11-25 00:04:52 -03:00
bors
65a6e22668 Auto merge of #104845 - matthiaskrgr:rollup-tckj956, r=matthiaskrgr
Rollup of 11 pull requests

Successful merges:

 - #104514 (Use node_ty_opt to avoid ICE in visit_ty)
 - #104704 (Allow power10-vector feature in PowerPC)
 - #104747 (resolve: Don't use constructor def ids in the map for field names)
 - #104773 (OpaqueCast projections are always overlapping, they can't possibly be disjoint)
 - #104774 (Document split{_ascii,}_whitespace() for empty strings)
 - #104780 (make `error_reported` check for delayed bugs)
 - #104782 (Bump the const eval step limit)
 - #104792 (rustdoc: simplify `.search-results-title` CSS)
 - #104796 (lint: do not warn unused parens around higher-ranked function pointers)
 - #104820 (Remove normalize_projection_type)
 - #104822 (with_query_mode -> new)

Failed merges:

 - #104716 (move 2 candidates into builtin candidate)
 - #104841 (Assert that we don't capture escaping bound vars in `Fn` trait selection)

r? `@ghost`
`@rustbot` modify labels: rollup
2022-11-24 23:45:32 +00:00
Nicholas Nethercote
2c5d3705ec Clarify SyntaxExtensionKind::LegacyDerive. 2022-11-25 09:13:27 +11:00
Michael Goulet
d945967779 Remove comment, simplify since we asserted fn ptr Self type has no bound vars 2022-11-24 21:50:04 +00:00
Michael Goulet
c7330c9fe8 Also check that fn pointer candidates don't have escaping bound vars 2022-11-24 21:50:04 +00:00
Michael Goulet
8927135274 Assert that we don't capture escaping bound vars in Fn trait selection 2022-11-24 21:50:04 +00:00
Matthias Krüger
1048a85dbe
Rollup merge of #104822 - spastorino:selctx-new-instead-of-with_query_mode, r=lcnr
with_query_mode -> new

r? ```@lcnr```
2022-11-24 21:34:57 +01:00
Matthias Krüger
73f01ffd46
Rollup merge of #104820 - spastorino:remove-normalize_projection_type, r=jackh726
Remove normalize_projection_type

r? ``@lcnr``
2022-11-24 21:34:56 +01:00
Matthias Krüger
83d1aab9ff
Rollup merge of #104796 - notriddle:notriddle/unused-issue-104397, r=oli-obk
lint: do not warn unused parens around higher-ranked function pointers

Fixes #104397
2022-11-24 21:34:56 +01:00
Matthias Krüger
679f1b7892
Rollup merge of #104782 - oli-obk:const_eval_limit_bump, r=pnkfelix
Bump the const eval step limit

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

https://github.com/rust-lang/rust/pull/103877 has too much of an impact to beta backport. So let's just increase the limit, avoiding the immediate breakage.

r? ``@pnkfelix``
2022-11-24 21:34:55 +01:00
Matthias Krüger
4843946a10
Rollup merge of #104780 - BoxyUwU:error_reported_not_be_bad, r=oli-obk
make `error_reported` check for delayed bugs

Fixes #104768

`error_reported()` was only checking if there were errors emitted, not for `delay_bug`s which can also be a source of `ErrorGuaranteed`. I assume the same is true of `lint_err_count` but i dont know
2022-11-24 21:34:54 +01:00
Matthias Krüger
9a558b68e1
Rollup merge of #104773 - oli-obk:overlap, r=lcnr
OpaqueCast projections are always overlapping, they can't possibly be disjoint

r? ``@lcnr``
2022-11-24 21:34:53 +01:00
Matthias Krüger
0e4eb0da33
Rollup merge of #104747 - petrochenkov:ctorfields, r=cjgillot
resolve: Don't use constructor def ids in the map for field names

Also do some minor cleanup to insertion of those field names.

Addresses a FIXME left in https://github.com/rust-lang/rust/pull/103578.
2022-11-24 21:34:53 +01:00
Matthias Krüger
7a17d61d3d
Rollup merge of #104704 - ecnelises:p10vec, r=jackh726
Allow power10-vector feature in PowerPC

Note that we don't have `power10-altivec`:

57fd7ffeff/llvm/lib/Target/PowerPC/PPC.td (L277-L280)
2022-11-24 21:34:52 +01:00
Matthias Krüger
80dc91c6c3
Rollup merge of #104514 - chenyukang:yukang/fix-104513-ice, r=petrochenkov
Use node_ty_opt to avoid ICE in visit_ty

Fixes #104513
2022-11-24 21:34:51 +01:00
bors
b3bc6bf312 Auto merge of #103693 - HKalbasi:master, r=oli-obk
Make rustc_target usable outside of rustc

I'm working on showing type size in rust-analyzer (https://github.com/rust-lang/rust-analyzer/pull/13490) and I currently copied rustc code inside rust-analyzer, which works, but is bad. With this change, I would become able to use `rustc_target` and `rustc_index` directly in r-a, reducing the amount of copy needed.

This PR contains some feature flag to put nightly features behind them to make crates buildable on the stable compiler + makes layout related types generic over index type + removes interning of nested layouts.
2022-11-24 20:29:13 +00:00
Maybe Waffle
e143fa2156 nested-match mutability (proposed by the reviewer) 2022-11-24 18:18:45 +00:00
Camille GILLOT
5de9c84140 Fix rustc_pass_by_value. 2022-11-24 17:49:42 +00:00
Camille GILLOT
1c737d6997 Use kw::Empty for elided lifetimes in path. 2022-11-24 17:48:59 +00:00
Camille GILLOT
41090346d8 Change how suggested lifetime args are computed. 2022-11-24 17:48:42 +00:00
Camille GILLOT
5f5e7a8eec Record in HIR whether lifetime elision was succesful. 2022-11-24 17:48:27 +00:00
Santiago Pastorino
3dee3aac78
Use infcx.partially_normalize_associated_types_in 2022-11-24 14:16:40 -03:00
bors
5dfb4b0afa Auto merge of #104321 - Swatinem:async-gen, r=oli-obk
Avoid `GenFuture` shim when compiling async constructs

Previously, async constructs would be lowered to "normal" generators, with an additional `from_generator` / `GenFuture` shim in between to convert from `Generator` to `Future`.

The compiler will now special-case these generators internally so that async constructs will *directly* implement `Future` without the need to go through the `from_generator` / `GenFuture` shim.

The primary motivation for this change was hiding this implementation detail in stack traces and debuginfo, but it can in theory also help the optimizer as there is less abstractions to see through.

---

Given this demo code:

```rust
pub async fn a(arg: u32) -> Backtrace {
    let bt = b().await;
    let _arg = arg;
    bt
}

pub async fn b() -> Backtrace {
    Backtrace::force_capture()
}
```

I would get the following with the latest stable compiler (on Windows):

```
   4: async_codegen:🅱️:async_fn$0
             at .\src\lib.rs:10
   5: core::future::from_generator::impl$1::poll<enum2$<async_codegen:🅱️:async_fn_env$0> >
             at /rustc/897e37553bba8b42751c67658967889d11ecd120\library\core\src\future\mod.rs:91
   6: async_codegen:🅰️:async_fn$0
             at .\src\lib.rs:4
   7: core::future::from_generator::impl$1::poll<enum2$<async_codegen:🅰️:async_fn_env$0> >
             at /rustc/897e37553bba8b42751c67658967889d11ecd120\library\core\src\future\mod.rs:91
```

whereas now I get a much cleaner stack trace:

```
   3: async_codegen:🅱️:async_fn$0
             at .\src\lib.rs:10
   4: async_codegen:🅰️:async_fn$0
             at .\src\lib.rs:4
```
2022-11-24 17:14:42 +00:00
Sarthak Singh
1767f9f9bf Unsupported query error now specifies if its unsupported for local or external crate 2022-11-24 19:05:17 +05:30
hkalbasi
390a637e29 move things from rustc_target::abi to rustc_abi 2022-11-24 16:26:13 +03:30
hkalbasi
27fb904d68 move some layout logic to rustc_target::abi::layout 2022-11-24 16:26:12 +03:30
hkalbasi
09a384643e make rustc_target usable outside of rustc 2022-11-24 16:26:12 +03:30
Santiago Pastorino
66b4b8b907
with_query_mode -> new 2022-11-24 09:36:17 -03:00
Santiago Pastorino
1930c77de1
Remove normalize_projection_type 2022-11-24 09:02:55 -03:00
Boxy
72d8879c29 make error_reported check for delayed bugs 2022-11-24 11:12:46 +00:00
bors
1dda298ad3 Auto merge of #104809 - matthiaskrgr:rollup-8abjdwh, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #103908 (Suggest `.clone()` or `ref binding` on E0382)
 - #104517 (Throw error on failure in loading llvm-plugin)
 - #104594 (Properly handle `Pin<&mut dyn* Trait>` receiver in codegen)
 - #104742 (Make `deref_into_dyn_supertrait` lint the impl and not the usage)
 - #104753 (Pass `InferCtxt` to `DropRangeVisitor` so we can resolve vars)
 - #104771 (Add regression test for issue #99938)
 - #104772 (Small accessibility improvements)
 - #104775 (Use ObligationCtxt::normalize)
 - #104778 (⬆️ rust-analyzer)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-11-24 09:44:46 +00:00
Arpad Borsos
9f36f988ad
Avoid GenFuture shim when compiling async constructs
Previously, async constructs would be lowered to "normal" generators,
with an additional `from_generator` / `GenFuture` shim in between to
convert from `Generator` to `Future`.

The compiler will now special-case these generators internally so that
async constructs will *directly* implement `Future` without the need
to go through the `from_generator` / `GenFuture` shim.

The primary motivation for this change was hiding this implementation
detail in stack traces and debuginfo, but it can in theory also help
the optimizer as there is less abstractions to see through.
2022-11-24 10:04:27 +01:00
Matthias Krüger
2190b163a3
Rollup merge of #104775 - spastorino:use-obligation-ctxt-normalize, r=lcnr
Use ObligationCtxt::normalize

r? ```@lcnr```
2022-11-24 08:42:37 +01:00
Matthias Krüger
6938717ca5
Rollup merge of #104753 - compiler-errors:drop-tracking-var-ice, r=oli-obk
Pass `InferCtxt` to `DropRangeVisitor` so we can resolve vars

The types that we encounter in the  `TypeckResults` that we pass to the `DropRangeVisitor` are not yet fully resolved, since that only happens in writeback after type checking is complete.

Instead, pass down the whole `InferCtxt` so that we can resolve any inference vars that have been constrained since they were written into the results. This is similar to how the `MemCategorizationContext` in the `ExprUseVisitor` also needs to pass down both typeck results _and_ the inference context.

Fixes an ICE mentioned in this comment: https://github.com/rust-lang/rust/issues/104382#issuecomment-1324410781
2022-11-24 08:42:35 +01:00
Matthias Krüger
c08c57e856
Rollup merge of #104742 - WaffleLapkin:forbidden-SUPER-deref, r=compiler-errors
Make `deref_into_dyn_supertrait` lint the impl and not the usage

Proposed by ``@compiler-errors`` in https://github.com/rust-lang/rust/issues/89460#issuecomment-1320806785
r? ``@crlf0710``
2022-11-24 08:42:34 +01:00
Matthias Krüger
b43c2e7cd9
Rollup merge of #104594 - compiler-errors:dyn-star-rcvr, r=eholk,estebank
Properly handle `Pin<&mut dyn* Trait>` receiver in codegen

This ensures we can actually await a `dyn* Future`, which seems important for async fn in dyn trait.

Also, disable `dyn*` trait upcasting. It's not exactly complete right now, and can cause strange ICEs for no reason -- nobody's using it either. I thought it was cute to implement when I did it, but I didn't think about how it interacts structurally with `CoerceUnsized` correctly.

Fixes #104794, presumably removing `dyn*` upcasting and its `CoerceUnsized` issues does the trick.
2022-11-24 08:42:34 +01:00
Matthias Krüger
1e0df8827b
Rollup merge of #104517 - dfordivam:patch-1, r=cuviper
Throw error on failure in loading llvm-plugin

The following code silently ignores the error as the `LLVMRustSetLastError` only tracks one error at a time. At all other places where `LLVMRustSetLastError` is used the code immediately returns.

251831ece9/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp (L801-L804)
2022-11-24 08:42:33 +01:00
Matthias Krüger
5197ef66b7
Rollup merge of #103908 - estebank:consider-cloning, r=compiler-errors
Suggest `.clone()` or `ref binding` on E0382
2022-11-24 08:42:33 +01:00
bors
341d8b8a2c Auto merge of #103808 - cjgillot:vec-cache, r=TaKO8Ki
Use an IndexVec to cache queries with index-like key

Revival of an old idea. Let's see if it has more effect.

r? `@ghost`
2022-11-24 06:32:23 +00:00
yukang
ecea94e6a4 fix #104513, Use node_ty_opt to avoid ICE in visit_ty 2022-11-24 13:02:00 +08:00
bors
fd815a5091 Auto merge of #104610 - ouz-a:revert-overflow, r=compiler-errors
Reverts check done by #100757

As my `fix` caused more issues than it resolved it's better to revert it.
( #103274 #104322 https://github.com/rust-lang/rust/issues/104606)

r? `@compiler-errors`

Reopens #95134
2022-11-24 03:29:04 +00:00
Michael Goulet
8f79fc24e3 Properly handle Pin<&mut dyn* Trait> receiver in codegen 2022-11-24 01:10:25 +00:00
Michael Goulet
c620a972f3 Disable dyn* upcasting 2022-11-24 01:10:24 +00:00
Weihang Lo
433d471a1a
rustc_codegen_ssa: write .dwp in a streaming fashion 2022-11-24 00:59:04 +00:00
Michael Howell
97d95d48e2 lint: do not warn unused parens around higher-ranked function pointers
Fixes #104397
2022-11-23 17:57:11 -07:00
bors
872631d0f0 Auto merge of #104507 - WaffleLapkin:asderefsyou, r=wesleywiser
Use `as_deref` in compiler (but only where it makes sense)

This simplifies some code :3

(there are some changes that are not exacly `as_deref`, but more like "clever `Option`/`Result` method use")
2022-11-24 00:17:35 +00:00
Vadim Petrochenkov
47cd844468 effective visibility: Stop recalculating current private visibility
It becomes relatively expensive if done often and shows up during perf profiling.
2022-11-24 01:30:58 +03:00
Vadim Petrochenkov
7e76d94a22 effective visibility: Always add table entries for nodes used as parents
Previously if the parent was not in the table, and there was nothing to inherit from, the child's private visibility was used, but that's not correct - the parent may have a larger visibility so we should set it to at least the parent's private visibility.
That parent's private visibility is also inserted into the table for caching, so it's not recalculated later if used again.
2022-11-24 01:28:41 +03:00
Esteban Küber
78b8d126db Fix rebase 2022-11-23 13:06:27 -08:00
Vadim Petrochenkov
a45a302be5 effective visibility: Fix private visibility calculation for modules
Optimizations removed in the previous commit required this function to behave incorrectly, but now those optimizations are gone so we can fix the bug.

Fixes https://github.com/rust-lang/rust/issues/104249
2022-11-24 00:03:51 +03:00
Vadim Petrochenkov
f0843b89d1 effective visibility: Remove questionable optimizations
First, they require eagerly calculating private visibility (current normal module), which is somewhat expensive.
Private visibilities are also lost once calculated, instead of being cached in the table.

Second, I cannot prove that the optimizations are correct.
Maybe they can be partially reinstated in the future in cases when it's cheap and provably correct to do them.
They will also probably be merged into `fn update` in that case.

Partially fixes https://github.com/rust-lang/rust/issues/104249
Fixes https://github.com/rust-lang/rust/issues/104539
2022-11-24 00:03:51 +03:00
Vadim Petrochenkov
3f20f4ac42 effective visibility: Satisfy borrow checker to use resolver lazily from a closure 2022-11-24 00:03:51 +03:00
Maybe Waffle
550319059d Simplify mutability assert!s 2022-11-23 20:39:16 +00:00
Maybe Waffle
f9a332a48c Simplify creation of AutoBorrowMutability 2022-11-23 20:39:16 +00:00
Maybe Waffle
6486ba94a3 random::<Improve<Mutability>>() 2022-11-23 20:39:16 +00:00
Maybe Waffle
4439f1f6a6 Add Mutability::mutably_str 2022-11-23 20:39:16 +00:00
Maybe Waffle
e51cd6e822 Don't accept Mutability by ref 2022-11-23 20:26:31 +00:00
Maybe Waffle
da40965300 Add Mutability::{is_mut,is_not} 2022-11-23 20:26:31 +00:00
Maybe Waffle
9b9c7d0ecc Depend on Mutability ordering 2022-11-23 20:26:31 +00:00
Esteban Küber
0da4c44190 Account for closures 2022-11-23 12:17:48 -08:00
Esteban Küber
3a471b5fd8 Account for x @ y and suggest ref x @ ref y 2022-11-23 12:17:48 -08:00
Esteban Küber
3c905d4ccd review comments: inline bindings and fix typo 2022-11-23 12:17:48 -08:00
Esteban Küber
5993f5d0f8 Tweak output to account for alternative bindings in the same pattern 2022-11-23 12:17:47 -08:00
Esteban Küber
e6e7a6db28 Fix wording 2022-11-23 12:17:47 -08:00
Esteban Küber
d687d46f68 Tweak output in for loops
Do not suggest `.clone()` as we already suggest borrowing the iterated
value.
2022-11-23 12:17:47 -08:00
Esteban Küber
c0e481731b Remove logic duplication 2022-11-23 12:17:47 -08:00
Esteban Küber
42d7174bbc Extract suggestion logic to its own method 2022-11-23 12:17:47 -08:00
Esteban Küber
14a3d572e6 Use type_implements_trait 2022-11-23 12:17:47 -08:00
Esteban Küber
4a51f37bcb Do not suggest ref multiple times for the same binding 2022-11-23 12:17:47 -08:00
Esteban Küber
9e72e35ceb Suggest .clone() or ref binding on E0382 2022-11-23 12:17:47 -08:00
bors
70f8737b2f Auto merge of #104410 - WaffleLapkin:unregress, r=estebank
Fix perf regression by correctly matching keywords

This should (hopefully) fix regression from #99918

r? `@estebank`
2022-11-23 19:52:43 +00:00
Maybe Waffle
8195e12dd9 Add Mutability::ref_prefix_str, order Mutability, simplify code 2022-11-23 19:36:27 +00:00
Camille GILLOT
fb7d25e978 Separate lifetime ident from resolution in HIR. 2022-11-23 19:33:06 +00:00
Oli Scherer
6c2719a6d6 Bump the const eval step limit 2022-11-23 16:55:57 +00:00
bors
d121aa3b55 Auto merge of #104776 - Dylan-DPC:rollup-rf4c2u0, r=Dylan-DPC
Rollup of 6 pull requests

Successful merges:

 - #104269 (Fix hang in where-clause suggestion with `predicate_can_apply`)
 - #104286 (copy doc output files by format)
 - #104509 (Use obligation ctxt instead of dyn TraitEngine)
 - #104721 (Remove more `ref` patterns from the compiler)
 - #104744 (rustdoc: give struct fields CSS `display: block`)
 - #104751 (Fix an ICE parsing a malformed attribute.)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-11-23 16:29:17 +00:00
Maybe Waffle
20f3de5ab1 Use nicer spans for deref_into_dyn_supertrait 2022-11-23 16:12:51 +00:00
Maybe Waffle
0d4a5c725a Make deref_into_dyn_supertrait lint the impl and not the usage 2022-11-23 15:40:27 +00:00
Maybe Waffle
11a5386256 Move get_associated_type from clippy to rustc_lint 2022-11-23 15:40:27 +00:00
Dylan DPC
5d7b68c82b
Rollup merge of #104751 - nnethercote:fix-104620, r=petrochenkov
Fix an ICE parsing a malformed attribute.

Fixes #104620.

r? `@petrochenkov`
2022-11-23 20:32:38 +05:30
Dylan DPC
c03026a7c6
Rollup merge of #104721 - WaffleLapkin:deref-harder, r=oli-obk
Remove more `ref` patterns from the compiler

r? `@oli-obk`
Previous PR: https://github.com/rust-lang/rust/pull/104500
2022-11-23 20:32:37 +05:30
Dylan DPC
0a791381c3
Rollup merge of #104509 - spastorino:use-obligation-ctxt, r=lcnr
Use obligation ctxt instead of dyn TraitEngine

r? `@lcnr`
2022-11-23 20:32:36 +05:30
Dylan DPC
bd91c94a5d
Rollup merge of #104269 - compiler-errors:hang-in-where-clause-sugg, r=lcnr
Fix hang in where-clause suggestion with `predicate_can_apply`

Using `predicate_may_hold` during error reporting causes an evaluation overflow, which (because we use `evaluate_obligation_no_overflow`) then causes the predicate to need to be re-evaluated locally, which results in a hang.

... but since the "add a where clause" suggestion is best-effort, just throw any overflow errors. No need for 100% accuracy.

r? `@lcnr` who has been thinking about overflows... Let me know if you want more context about this issue, and as always, feel free to reassign.

Fixes #104225
2022-11-23 20:32:35 +05:30
Oli Scherer
46b37e20af OpaqueCast projections are always overlapping, they can't possibly be disjoint 2022-11-23 14:37:13 +00:00
Santiago Pastorino
409203a315
Use ObligationCtxt::normalize 2022-11-23 11:32:49 -03:00
bors
80b3c6dbde Auto merge of #103947 - camsteffen:place-clones, r=cjgillot
Reduce `PlaceBuilder` cloning

Some API tweaks with an eye towards reducing clones.
2022-11-23 13:13:50 +00:00
Santiago Pastorino
859b147d4f
Pass ObligationCtxt from enter_canonical_trait_query and use ObligationCtxt API 2022-11-23 09:36:03 -03:00
Santiago Pastorino
5b3a06a3c2
Call fully_solve_obligations instead of repeating code 2022-11-23 09:36:00 -03:00
Santiago Pastorino
ad094cdceb
Use ObligationCtxt intead of dyn TraitEngine 2022-11-23 09:24:42 -03:00
bors
4e0d0d757e Auto merge of #102750 - the8472:opt-field-order, r=wesleywiser
optimize field ordering by grouping m*2^n-sized fields with equivalently aligned ones

```rust
use std::ptr::addr_of;
use std::mem;

struct Foo {
    word: u32,
    byte: u8,
    ary: [u8; 4]
}

fn main() {
    let foo: Foo = unsafe { mem::zeroed() };

    println!("base: {:p}\nword: {:p}\nbyte: {:p}\nary:  {:p}", &foo, addr_of!(foo.word), addr_of!(foo.byte), addr_of!(foo.ary));
}
```

prints

```
base: 0x7fffc1a8a668
word: 0x7fffc1a8a668
byte: 0x7fffc1a8a66c
ary:  0x7fffc1a8a66d
```

I.e. the `u8` in the middle causes the array to sit at an odd offset, which might prevent optimizations, especially on architectures where unaligned loads are costly.

Note that this will make field ordering niche-dependent, i.e. a `Bar<T>` with `T=char` and `T=u32` may result in different field order, this may break some code that makes invalid assumptions about `repr(Rust)` types.
2022-11-23 10:01:48 +00:00
Michael Goulet
a884a9e634 Drive-by: Don't manually call evaluate_obligation_no_overflow 2022-11-23 04:42:38 +00:00
Michael Goulet
cbe9328018 Do not need to account for overflow in predicate_can_apply 2022-11-23 04:42:38 +00:00
Manish Goregaokar
54b6292855
Rollup merge of #104621 - YC:master, r=davidtwco
Fix --extern library finding errors

- `crate_name` is not specified/passed to `metadata_crate_location_unknown_type`
c493bae0d8/compiler/rustc_error_messages/locales/en-US/metadata.ftl (L274-L275)
- `metadata_lib_filename_form` is missing `$`
- Add additional check to ensure that library is file

Testing
1. Create file `a.rs`
```rust
extern crate t;
fn main() {}
```
1. Create empty file `x`
1. Create empty directory `y`
1. Run
```sh
$ rustc -o a a.rs --extern t=x
$ rustc -o a a.rs --extern t=y
```
Both currently panic with stable.
2022-11-22 22:54:40 -05:00
Manish Goregaokar
36815c6e3b
Rollup merge of #104612 - Swatinem:async-ret-y, r=estebank
Lower return type outside async block creation

This allows feeding a different output type to async blocks with a different `ImplTraitContext`. Spotted this while working on #104321
2022-11-22 22:54:39 -05:00
Manish Goregaokar
a673364c54
Rollup merge of #104359 - Nilstrieb:plus-one, r=fee1-dead
Refactor must_use lint into two parts

Before, the lint did the checking for `must_use` and pretty printing the types in a special format in one pass, causing quite complex and untranslatable code.
Now the collection and printing is split in two. That should also make it easier to translate or extract the type pretty printing in the future.

Also fixes an integer overflow in the array length pluralization
calculation.

fixes #104352
2022-11-22 22:54:39 -05:00
Manish Goregaokar
53eab246db
Rollup merge of #103488 - oli-obk:impl_trait_for_tait, r=lcnr
Allow opaque types in trait impl headers and rely on coherence to reject unsound cases

r? ````@lcnr````

fixes #99840
2022-11-22 22:54:38 -05:00
Michael Goulet
024bb8c7fb Pass ParamEnv down instead of using ParamEnv of a module 2022-11-23 02:06:03 +00:00
Michael Goulet
1e7f6a7e0d Pass InferCtxt to DropRangeVisitor so we can resolve vars 2022-11-23 01:48:03 +00:00
Nicholas Nethercote
7c3f631ddf Fix an ICE parsing a malformed attribute.
Fixes #104620.
2022-11-23 12:11:14 +11:00
The 8472
a9128d8927 fix tests, update size asserts 2022-11-22 23:12:26 +01:00
The 8472
97d8a9bdd3 also sort fields by niche sizes to retain optimizations 2022-11-22 23:12:26 +01:00
The 8472
a3450d060d group fields based on largest power of two dividing its size 2022-11-22 23:12:26 +01:00
The 8472
9f0cb566ea optimize field ordering by grouping power-of-two arrays with larger types 2022-11-22 23:12:26 +01:00
Vadim Petrochenkov
5fc359f1ef resolve: Don't use constructor def ids in the map for field names
Also do some minor cleanup to insertion of those field names
2022-11-23 00:53:50 +03:00
Yuki Okushi
3ec1ca0516
Rollup merge of #104728 - WaffleLapkin:require-lang-items-politely, r=compiler-errors
Use `tcx.require_lang_item` instead of unwrapping lang items

I clearly remember esteban telling me that there is `require_lang_item` but he was from a phone atm and I couldn't find it, so I didn't use it. Stumbled on it today, so here we are :)
2022-11-23 06:40:24 +09:00
Yuki Okushi
dcbfb9776d
Rollup merge of #104724 - WaffleLapkin:to_def_idn't, r=compiler-errors
Fix `ClosureKind::to_def_id`

`Fn` and `FnOnce` were mixed up in https://github.com/rust-lang/rust/pull/99131.
2022-11-23 06:40:24 +09:00
Yuki Okushi
b162bb4270
Rollup merge of #102293 - ecnelises:aix.initial, r=davidtwco
Add powerpc64-ibm-aix as Tier-3 target

This is part of the effort mentioned in https://github.com/rust-lang/compiler-team/issues/553.

A reference to these options are definitions from [clang](ad6fe32032/clang/lib/Basic/Targets/PPC.h (L414-L448)) and [llvm](https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp).

AIX has a system `ld` but [its options and behaviors](https://www.ibm.com/docs/en/aix/7.3?topic=l-ld-command) are different from GNU ld. Thanks to ``@bzEq`` for contributing the linking args.
2022-11-23 06:40:22 +09:00
Maybe Waffle
b97ec3924d rustc_ast_lowering: remove ref patterns 2022-11-22 18:49:29 +00:00
Maybe Waffle
a603635670 rustc_arena: remove a couple of ref patterns 2022-11-22 18:49:29 +00:00
Maybe Waffle
616df0f03b rustc_parse: remove ref patterns 2022-11-22 18:49:16 +00:00
Michael Goulet
0ba5e7416f Add size hints to early binder iterator adapters 2022-11-22 18:35:49 +00:00
Vadim Petrochenkov
24f2ee1efd rustc_metadata: Cleanup to get_module_children
to unify proc-macro and non-proc-macro cases in particular.
2022-11-22 20:43:48 +03:00
Vadim Petrochenkov
6a233b5e2a rustc_metadata: Switch module children decoding to an iterator 2022-11-22 20:43:48 +03:00
Vadim Petrochenkov
f3b5791a47 rustc_metadata: Do not encode empty reexport lists
This is more a cleanup than optimization
2022-11-22 20:43:48 +03:00
Maybe Waffle
b80356a5ab Use tcx.require_lang_item instead of unwrapping 2022-11-22 17:19:19 +00:00
Maybe Waffle
04610ad129 Fix ClosureKind::to_def_id 2022-11-22 16:45:06 +00:00
bors
66ccf36f16 Auto merge of #104711 - Dylan-DPC:rollup-gkw1qr8, r=Dylan-DPC
Rollup of 6 pull requests

Successful merges:

 - #104295 (Check generics parity before collecting return-position `impl Trait`s in trait)
 - #104464 (Reduce exceptions overallocation on non Windows x86_64)
 - #104615 (Create def_id for async fns during lowering)
 - #104669 (Only declare bindings for if-let guards once per arm)
 - #104701 (Remove a lifetime resolution hack from `compare_predicate_entailment`)
 - #104710 (disable strict-provenance-violating doctests in Miri)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-11-22 13:18:45 +00:00
Dylan DPC
b12d31f166
Rollup merge of #104701 - compiler-errors:rpitit-remove-reempty-hack, r=TaKO8Ki
Remove a lifetime resolution hack from `compare_predicate_entailment`

This is not needed anymore, probably due to #102334 equating the function signatures fully in `collect_trait_impl_trait_tys`. Also, the assertion in in #102903 makes sure that this is actually fixed, so I'm pretty confident this isn't needed.
2022-11-22 16:36:38 +05:30
Dylan DPC
d29491aba0
Rollup merge of #104669 - LeSeulArtichaut:88015-if-let-guard-bindings, r=cjgillot
Only declare bindings for if-let guards once per arm

Currently, each candidate for a match arm uses separate locals for the bindings in the if-let guard, causing problems (#88015) when those branches converge in the arm body.

Fixes #88015 (🤞)
2022-11-22 16:36:38 +05:30
Dylan DPC
88542a3150
Rollup merge of #104615 - spastorino:create-async-def-id-in-lowering, r=compiler-errors
Create def_id for async fns during lowering

r? `@compiler-errors`
2022-11-22 16:36:37 +05:30
Dylan DPC
680ba90f96
Rollup merge of #104295 - compiler-errors:rpitit-generics-parity, r=eholk
Check generics parity before collecting return-position `impl Trait`s in trait

The only thing is that this duplicates the error message for number of generics mismatch, but we already deduplicate that error message in Cargo. I could add a flag to delay the error if the reviewer cares.

Fixes #104281

Also drive-by adds a few comments to the `collect_trait_impl_trait_tys` method, and removes an unused argument from `compare_number_of_generics`.
2022-11-22 16:36:36 +05:30
bors
b7463e8bdb Auto merge of #103578 - petrochenkov:nofict, r=nagisa
Unreserve braced enum variants in value namespace

With this PR braced enum variants (`enum E { V { /*...*/ } }`) no longer take a slot in value namespace, so the special case mentioned in the note in https://github.com/rust-lang/rfcs/blob/master/text/1506-adt-kinds.md#braced-structs is removed.

Report - https://github.com/rust-lang/rust/pull/103578#issuecomment-1292594900.
2022-11-22 10:17:09 +00:00
Qiu Chaofan
85c99855c4 Allow power10-vector feature in PowerPC 2022-11-22 14:45:56 +08:00
Steven Tang
7169c7d105
Tests for bad --extern library path and file 2022-11-22 17:44:38 +11:00
Manish Goregaokar
9043dfd946
Rollup merge of #104638 - Nilstrieb:macro-diagnostics, r=compiler-errors
Move macro_rules diagnostics to diagnostics module

This will make it easier to add more diagnostics in the future in a centralized place.
2022-11-22 01:26:08 -05:00
Steven Tang
395f2b84e6
Remove extra . in metadata_lib_filename_form 2022-11-22 17:07:19 +11:00
Michael Goulet
1c1778da25 Remove a hack from compare_predicate_entailment 2022-11-22 03:41:13 +00:00
Michael Goulet
df5f247a5c Delay bug to deduplicate diagnostics 2022-11-22 01:36:41 +00:00
Michael Goulet
0a95878972 drive-by: style nits 2022-11-22 01:36:41 +00:00
Michael Goulet
94e047ba3b Check generics parity between impl and trait before collecting RPITITs 2022-11-22 01:36:41 +00:00
bors
0f7d81754d Auto merge of #104696 - matthiaskrgr:rollup-gi1pdb0, r=matthiaskrgr
Rollup of 11 pull requests

Successful merges:

 - #103396 (Pin::new_unchecked: discuss pinning closure captures)
 - #104416 (Fix using `include_bytes` in pattern position)
 - #104557 (Add a test case for async dyn* traits)
 - #104559 (Split `MacArgs` in two.)
 - #104597 (Probe + better error messsage for `need_migrate_deref_output_trait_object`)
 - #104656 (Move tests)
 - #104657 (Do not check transmute if has non region infer)
 - #104663 (rustdoc: factor out common button CSS)
 - #104666 (Migrate alias search result to CSS variables)
 - #104674 (Make negative_impl and negative_impl_exists take the right types)
 - #104692 (Update test's cfg-if dependency to 1.0)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-11-22 01:35:57 +00:00
Matthias Krüger
816a31fc66
Rollup merge of #104674 - spastorino:negative-impl-tcx, r=lcnr
Make negative_impl and negative_impl_exists take the right types

r? `@lcnr`
2022-11-22 00:01:12 +01:00
Matthias Krüger
9cefd9dd29
Rollup merge of #104657 - hi-rustin:rustin-patch-check-transmute, r=compiler-errors
Do not check transmute if has non region infer

close https://github.com/rust-lang/rust/issues/104609

See: https://github.com/rust-lang/rust/issues/104609#issuecomment-1320956351

r? `@compiler-errors`
2022-11-22 00:01:10 +01:00
Matthias Krüger
118ee14dd1
Rollup merge of #104597 - compiler-errors:need_migrate_deref_output_trait_object-msg, r=eholk
Probe + better error messsage for `need_migrate_deref_output_trait_object`

1. Use `InferCtxt::probe` in `need_migrate_deref_output_trait_object` -- that normalization *could* technically do type inference as a side-effect, and this is a lint, so it should have no side-effects.
2. Return the trait-ref so we format the error message correctly. See the UI test change -- `(dyn A + 'static)` is not a trait.
2022-11-22 00:01:09 +01:00
Matthias Krüger
589d843bd0
Rollup merge of #104559 - nnethercote:split-MacArgs, r=petrochenkov
Split `MacArgs` in two.

`MacArgs` is an enum with three variants: `Empty`, `Delimited`, and `Eq`. It's used in two ways:
- For representing attribute macro arguments (e.g. in `AttrItem`), where all three variants are used.
- For representing function-like macros (e.g. in `MacCall` and `MacroDef`), where only the `Delimited` variant is used.

In other words, `MacArgs` is used in two quite different places due to them having partial overlap. I find this makes the code hard to read. It also leads to various unreachable code paths, and allows invalid values (such as accidentally using `MacArgs::Empty` in a `MacCall`).

This commit splits `MacArgs` in two:
- `DelimArgs` is a new struct just for the "delimited arguments" case. It is now used in `MacCall` and `MacroDef`.
- `AttrArgs` is a renaming of the old `MacArgs` enum for the attribute macro case. Its `Delimited` variant now contains a `DelimArgs`.

Various other related things are renamed as well.

These changes make the code clearer, avoids several unreachable paths, and disallows the invalid values.

r? `@petrochenkov`
2022-11-22 00:01:09 +01:00