Commit Graph

24879 Commits

Author SHA1 Message Date
Michael Goulet
97c11ffb22 Strongly prefer alias and param-env bounds 2023-05-25 03:35:14 +00:00
Michael Goulet
a2d806d56d Pre-populate MIR with opaques, prefer subst-relate candidate 2023-05-25 03:35:14 +00:00
Michael Goulet
e3f8beaed6 Check that opaque is a defining use, prefer pre-defined opaques 2023-05-25 03:21:22 +00:00
Michael Goulet
f3c9c21658 Prepopulate opaques in canonical input 2023-05-25 03:21:22 +00:00
Michael Goulet
a2d7ffc635 Move DefiningAnchor 2023-05-25 03:21:21 +00:00
Michael Goulet
4d80b8090c Pull out logic from #111131, plus some new logic in EvalCtxt::normalize_opaque_type
Co-authored-by: lcnr <rust@lcnr.de>
2023-05-25 03:19:15 +00:00
bors
7664dfe433 Auto merge of #111925 - Manishearth:rollup-z6z6l2v, r=Manishearth
Rollup of 5 pull requests

Successful merges:

 - #111741 (Use `ObligationCtxt` in custom type ops)
 - #111840 (Expose more information in `get_body_with_borrowck_facts`)
 - #111876 (Roll compiler_builtins to 0.1.92)
 - #111912 (Use `Option::is_some_and` and `Result::is_ok_and` in the compiler  )
 - #111915 (libtest: Improve error when missing `-Zunstable-options`)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-05-25 00:33:43 +00:00
Manish Goregaokar
d0b3ebee66
Rollup merge of #111912 - WaffleLapkin:is_some_and_in_the_compiler, r=petrochenkov
Use `Option::is_some_and` and `Result::is_ok_and` in the compiler

`.is_some_and(..)`/`.is_ok_and(..)` replace `.map_or(false, ..)` and `.map(..).unwrap_or(false)`, making the code more readable.

This PR is a sibling of https://github.com/rust-lang/rust/pull/111873#issuecomment-1561316515
2023-05-24 15:05:05 -07:00
Manish Goregaokar
b84ab57f90
Rollup merge of #111840 - voidc:borrowck-consumers, r=oli-obk
Expose more information in `get_body_with_borrowck_facts`

Verification tools for Rust such as, for example, Creusot or Prusti would benefit from having access to more information computed by the borrow checker.
As a first step in that direction, #86977 added the `get_body_with_borrowck_facts` API, allowing compiler consumers to obtain a `mir::Body` with accompanying borrow checker information.
At RustVerify 2023, multiple people working on verification tools expressed their need for a more comprehensive API.
While eventually borrow information could be part of Stable MIR, in the meantime, this PR proposes a more limited approach, extending the existing `get_body_with_borrowck_facts` API.
In summary, we propose the following changes:

- Permit obtaining the borrow-checked body without necessarily running Polonius
- Return the `BorrowSet` and the `RegionInferenceContext` in `BodyWithBorrowckFacts`
- Provide a way to compute the `borrows_out_of_scope_at_location` map
- Make some helper methods public

This is similar to #108328 but smaller in scope.
`@smoelius` Do you think these changes would also be sufficient for your needs?

r? `@oli-obk`
cc `@JonasAlaif`
2023-05-24 15:05:04 -07:00
Manish Goregaokar
a9a4c9b3db
Rollup merge of #111741 - compiler-errors:custom-type-op, r=lcnr
Use `ObligationCtxt` in custom type ops

We already make one when evaluating the `CustomTypeOp`, so it's simpler to just pass it to the user. Removes a redundant `ObligationCtxt::new_in_snapshot` usage and simplifies some other code.

This makes several refactorings related to opaque types in the new solver simpler, but those are not included in this PR.
2023-05-24 15:05:03 -07:00
bors
096309e6dc Auto merge of #111919 - matthiaskrgr:rollup-8qcdp0q, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #111121 (Work around `rust-analyzer` false-positive type errors)
 - #111759 (Leverage the interval property to precompute borrow kill points.)
 - #111841 (Run AST validation on match guards correctly)
 - #111862 (Split out opaque collection from from `type_of`)
 - #111863 (Don't skip mir typeck if body has errors)
 - #111903 (Migrate GUI colors test to original CSS color format)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-05-24 21:56:17 +00:00
Matthias Krüger
680f8b8efe
Rollup merge of #111863 - compiler-errors:check-more-mir, r=b-naber
Don't skip mir typeck if body has errors

Comment says:

```
// if verifier failed, don't do further checks to avoid ICEs
```

But there are no ICEs to be found. The comment is quite old, so perhaps something fixed it... maybe because the MIR typechecker is delaying span bugs rather than panicking via eager bugs? IDK

I'm generally inclined to fix the ICEs themselves that were to arise from this, rather than just totally skipping large parts of the compiler that have impacts on downstream logic (namely, our opaque type results are affected). Anyways, this happens on the error path, so it shouldn't really matter.

Fixes this hack: https://github.com/rust-lang/rust/pull/111853/files#r1201501540
2023-05-24 21:36:58 +02:00
Matthias Krüger
d09ee575ee
Rollup merge of #111862 - compiler-errors:opq, r=lcnr
Split out opaque collection from from `type_of`

requested by lcnr

r? `@lcnr`
2023-05-24 21:36:57 +02:00
Matthias Krüger
092352f6fd
Rollup merge of #111841 - matthewjasper:validate-match-guards, r=compiler-errors
Run AST validation on match guards correctly

AST validation was being skipped on match guards other than `if let` guards.
2023-05-24 21:36:57 +02:00
Matthias Krüger
52890cc719
Rollup merge of #111759 - cjgillot:interval-kill, r=b-naber
Leverage the interval property to precompute borrow kill points.
2023-05-24 21:36:56 +02:00
Matthias Krüger
09489b9137
Rollup merge of #111121 - Zalathar:ra-false-positive, r=jackh726
Work around `rust-analyzer` false-positive type errors

rust-analyzer incorrectly reports two type errors in `debug.rs`:

> expected &dyn Display, found &i32
> expected &dyn Display, found &i32

This is due to a known bug in r-a: (https://github.com/rust-lang/rust-analyzer/issues/11847).

In these particular cases, changing `&0` to `&0i32` seems to be enough to avoid the bug.
2023-05-24 21:36:56 +02:00
bors
c373194cb6 Auto merge of #111260 - petrochenkov:effvisperf7, r=cjgillot
rustc_privacy: Cleanups and perf improvements to `EmbargoVisitor`

Continuation of https://github.com/rust-lang/rust/pull/110907.
2023-05-24 19:02:19 +00:00
Michael Goulet
d7ccbdd696 Split out opaque from type_of 2023-05-24 17:23:58 +00:00
Michael Goulet
b1387e776c Don't skip mir typeck if body has errors 2023-05-24 17:12:46 +00:00
bors
97d328012b Auto merge of #111673 - cjgillot:dominator-preprocess, r=cjgillot,tmiasko
Preprocess and cache dominator tree

Preprocessing dominators has a very strong effect for https://github.com/rust-lang/rust/pull/111344.
That pass checks that assignments dominate their uses repeatedly. Using the unprocessed dominator tree caused a quadratic runtime (number of bbs x depth of the dominator tree).

This PR also caches the dominator tree and the pre-processed dominators in the MIR cfg cache.

Rebase of https://github.com/rust-lang/rust/pull/107157
cc `@tmiasko`
2023-05-24 16:18:21 +00:00
Michael Goulet
521a0bcd1f Use ObligationCtxt in custom type ops 2023-05-24 16:06:32 +00:00
Maybe Waffle
307799a711 Use is_some_and/is_ok_and in less obvious spots 2023-05-24 14:33:43 +00:00
Maybe Waffle
fb0f74a8c9 Use Option::is_some_and and Result::is_ok_and in the compiler 2023-05-24 14:20:41 +00:00
bors
b3cbf7c835 Auto merge of #111694 - Amanieu:no-assume-bdynamic, r=petrochenkov
Don't assume that `-Bdynamic` is the default linker mode

In particular this is false when passing `-static` or `-static-pie` to the linker, which changes the default to `-Bstatic`. This PR ensures we explicitly initialize the correct mode when we first need it.
2023-05-24 13:35:30 +00:00
bors
d69787f098 Auto merge of #111195 - GuillaumeGomez:fix-ice-intra-doc-link, r=petrochenkov
Prevent crash when a path is not resolved in intra-doc link

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

cc `@petrochenkov`
r? `@notriddle`
2023-05-24 07:49:53 +00:00
Matthias Krüger
8227c4fd6e
Rollup merge of #111880 - compiler-errors:pointer-like-param-env, r=jackh726
Don't ICE when computing PointerLike trait when region vars are in param-env

Fixes #111877
2023-05-24 06:05:39 +02:00
Matthias Krüger
783bea940b
Rollup merge of #111870 - WaffleLapkin:just_🌟traits🌟_query, r=compiler-errors
Rename `traits_in_crate` query to `traits`

> NOTE: Not named just `traits` due to a naming conflict.

This can, in fact, be easily avoided.
2023-05-24 06:05:38 +02:00
Matthias Krüger
efea88ae08
Rollup merge of #111864 - Jules-Bertholet:sized-closures, r=compiler-errors
Always require closure parameters to be `Sized`

The `rust-call` ABI isn't compatible with `#![feature(unsized_fn_params)]`, so trying to use that feature with closures leads to an ICE (#67981). This turns that ICE into a type-check error.

`@rustbot` label A-closures F-unsized_fn_params
2023-05-24 06:05:38 +02:00
Matthias Krüger
224b6511b1
Rollup merge of #111861 - compiler-errors:rtn-in-super, r=jackh726
Don't ICE on return-type notation when promoting trait preds to associated type bounds

Fixes #111846
2023-05-24 06:05:37 +02:00
Maybe Waffle
cc1ec49a14 Rename traits_in_crate query to traits 2023-05-23 21:26:37 +00:00
bors
d5699874dc Auto merge of #111882 - matthiaskrgr:rollup-1xyv5mq, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #111427 ([rustdoc][JSON] Use exclusively externally tagged enums in the JSON representation)
 - #111486 (Pretty-print inherent projections correctly)
 - #111722 (Document stack-protector option)
 - #111761 (fix(resolve): not defined `extern crate shadow_name`)
 - #111845 (Update books)
 - #111851 (CFI: Fix encode_region: unexpected ReEarlyBound(0, 'a))
 - #111871 (Migrate GUI colors test to original CSS color format)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-05-23 18:13:36 +00:00
Matthias Krüger
20b6e5a1d8
Rollup merge of #111851 - rcvalle:rust-cfi-fix-111515, r=bjorn3
CFI: Fix encode_region: unexpected ReEarlyBound(0, 'a)

Fixes #111515 and complements #106547 by adding support for encoding early bound regions and also excluding projections when transforming trait objects' traits into their identities before emitting type checks.
2023-05-23 19:53:43 +02:00
Matthias Krüger
37c9478b1a
Rollup merge of #111761 - bvanjoi:fix-109148, r=petrochenkov
fix(resolve): not defined `extern crate shadow_name`

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

## Why does #109148 panic?

When resolving `use std::xx` it enters `visit_scopes` from `early_resolve_ident_in_lexical_scope`, and iters twice during the loop:

|iter| `scope` | `break_result` | result |
|-|-|-|-|
| 0 | `Module` pointed to root | binding pointed to `Undetermined`, so result is `None` | scope changed to `ExternPrelude` |
| 1 | `ExternPrelude` | binding pointed to `std` | - |

Then, the result of `maybe_resolve_path` is `Module(std)`, so `import.imported_module.set` is executed.

Finally, during the `finalize_import` of `use std::xx`, `resolve_path` returns `NonModule` because `Binding(Ident(std), Module(root)`'s binding points to `extern crate blah as std`, which causes the assertion to fail at `assert!(import.imported_module.get().is_none());`.

## Investigation

The question is why `#[a] extern crate blah as std` is not defined as a binding of `std::xxx`, which causes the iteration twice during `visit_scopes` when resolving `std::xxx`. Ideally, the value of `break_result.is_some()` should have been valid in the first iteration.

After debugging, I found that because `#[a] extern crate blah as std` had been dummied by `placeholder` during `collect_invocations`, so it had lost its attrs, span, etc..., so it will not be defined. However, `expand_invoc` added them back, then the next `build_reduced_graph`, `#[a] extern crate blah as std` would have been defined, so it makes the result of `resolved_path` unexpected, and the program panics.

## Try to solve

I think there has two-way to solve this issue:

- Expand invocations before the first `resolve_imports` during `fully_expand_fragment`. However, I do not think this is a good idea because it would mess up the current design.
- As my PR described: do not define to `extern crate blah as std` during the second `build_reduced_graph`, which is very easy and more reasonable.

r? `@petrochenkov`
2023-05-23 19:53:42 +02:00
Matthias Krüger
221039b416
Rollup merge of #111486 - fmease:pp-inh-proj, r=petrochenkov
Pretty-print inherent projections correctly

Previously, we were trying to pretty-print inherent projections with `Printer::print_def_path` which is incorrect since
it expects the substitutions to be of a certain format (parents substs followed by own substs) which doesn't hold for
inherent projections (self type subst followed by own substs).
Now we print inherent projections manually.

Fixes #111390.
Fixes #111397.

Lacking tests! Is there a test suite / compiletest flags for the pretty-printer? In most if not all cases,
inherent projections are normalized away before they get the chance to appear in diagnostics.

If I were to create regression tests for linked issues, they would need to be `mir-opt` tests to exercise
`-Zdump-mir=all` (right?) which doesn't feel quite adequate to me.

`@rustbot` label F-inherent_associated_types
2023-05-23 19:53:41 +02:00
Michael Goulet
3a2710cdb6 Don't ICE when computing PointerLike trait when region vars are in param-env 2023-05-23 17:23:30 +00:00
Jules Bertholet
5cd02eaece
Always require closure parameters to be Sized
The `rust-call` ABI isn't compatible with
`#![feature(unsized_fn_params)]`, so trying to use that feature with
closures leads to an ICE (#67981). This turns that ICE into a
type-check error.
2023-05-23 12:46:25 -04:00
Ramon de C Valle
9bbdfea23c CFI: Fix encode_region: unexpected ReEarlyBound(0, 'a)
Fixes #111515 and complements #106547 by adding support for encoding
early bound regions and also excluding projections when transforming
trait objects' traits into their identities before emitting type checks.
2023-05-23 16:44:03 +00:00
Dominik Stolz
8dac074087 Add RegionInferenceContext::outlives_constraints 2023-05-23 17:33:55 +02:00
bors
52dd1cde59 Auto merge of #107294 - JamieCunliffe:neon-fp, r=Amanieu
Fix some issues with folded AArch64 features

In #91608 the `fp` feature was removed for AArch64 and folded into the `neon` feature, however disabling the `neon` feature doesn't actually disable the `fp` feature. If my understanding on that thread is correct it should do.

While doing this, I also noticed that disabling some features would disable features that it shouldn't. For instance enabling `sve` will enable `neon`, however, when disabling `sve` it would then also disable `neon`, I wouldn't expect disabling `sve` to also disable `neon`.

cc `@workingjubilee`
2023-05-23 15:30:37 +00:00
Guillaume Gomez
234927e098 Ignore "non-real" type Res in rustdoc intra doc link resolution 2023-05-23 15:33:34 +02:00
bors
b08148f6a7 Auto merge of #111869 - Dylan-DPC:rollup-9pydw08, r=Dylan-DPC
Rollup of 6 pull requests

Successful merges:

 - #111461 (Fix symbol conflict diagnostic mistakenly being shown instead of missing crate diagnostic)
 - #111579 (Also assume wrap-around discriminants in `as` MIR building)
 - #111704 (Remove return type sized check hack from hir typeck)
 - #111853 (Check opaques for mismatch during writeback)
 - #111854 (rustdoc: clean up `settings.css`)
 - #111860 (Don't ICE if method receiver fails to unify with `arbitrary_self_types`)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-05-23 12:47:51 +00:00
Dominik Stolz
c6e3f27864 Move BodyWithBorrowckFacts to consumers 2023-05-23 14:36:36 +02:00
Dylan DPC
c4f2a62182
Rollup merge of #111860 - compiler-errors:issue-111838, r=WaffleLapkin
Don't ICE if method receiver fails to unify with `arbitrary_self_types`

Consider:

```rust
struct Foo(u32);
impl Foo {
    fn get<R: Deref<Target=Self>>(self: R) -> u32 {
        self.0
    }
}

fn main() {
    let mut foo = Foo(1);
    foo.get::<&Foo>();
}
```

The problem here is that with `arbitrary_self_types`, we're allowed to have a method receiver that mentions generics from the method itself (`fn get<R: Deref<Target=Self>>(self: R)`). Since we don't actually take into account the user-written turbofish generics when doing method lookup (nor do we check that method predicates hold), method probing will happily infer `R = Foo` during the probe. When we later confirm the method, we do use the turbofish'd subst and instead now have that `R = &Foo`. This doesn't unify with the self type we chose during the probe, causing an ICE.

Getting this to work correctly will be difficult. Specifically, we'll need to actually pass in the turbofish generics for the method being probed for and check that the self type unifies considering those generics. This seems like a lot of work, and I'm not actually familiar with the restrictions originally called out for `#![feature(arbitrary_self_types)]`, but I think we should probably instead just deny having receivers that mention (type/const) generics that come from the method itself.

But I mostly just want to turn this ICE into an error, so I'll leave that up for later PRs.

Fixes #111838
2023-05-23 16:44:29 +05:30
Dylan DPC
6583025c93
Rollup merge of #111853 - compiler-errors:opaque-check, r=oli-obk
Check opaques for mismatch during writeback

Revive #111705.

I realized that we don't need to put any substs in the writeback results since all of the hidden types have already been remapped. See the comment in `compiler/rustc_middle/src/ty/typeck_results.rs`, which should make that clear for other explorers of the codebase.

Additionally, we need to do some diagnostic stashing because the diagnostics we produce during HIR typeck is very poor and we should prefer the diagnostic that comes from MIR, if we have one.

r? `@oli-obk`
2023-05-23 16:44:28 +05:30
Dylan DPC
4b26b80dd5
Rollup merge of #111704 - compiler-errors:sized-return-cleanup, r=oli-obk
Remove return type sized check hack from hir typeck

Remove a bunch of special-cased suggestions when someone returns `-> dyn Trait` that checks for type equality, etc.

This was a pretty complex piece of code that also relied on a hack in hir typeck (see changes to `compiler/rustc_hir_typeck/src/check.rs`), and I'm not convinced that it's necessary to maintain, when all we really need to tell the user is that they should return `-> impl Trait` or `-> Box<dyn Trait>`, depending on their specific use-case.

This is necessary because we may need to move the "return type is sized" check from hir typeck to wfcheck, which does not have access to typeck results. This is a prerequisite for that, and I'm fairly confident that the diagnostics "regressions" here are not a big deal.
2023-05-23 16:44:27 +05:30
Dylan DPC
00185bec7c
Rollup merge of #111579 - scottmcm:enum-as-signed, r=oli-obk
Also assume wrap-around discriminants in `as` MIR building

Resolves this FIXME:

8d18c32b61/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs (L231)

r? `@oli-obk`
2023-05-23 16:44:27 +05:30
Dylan DPC
731c1a5592
Rollup merge of #111461 - oli-obk:crate_collision, r=petrochenkov
Fix symbol conflict diagnostic mistakenly being shown instead of missing crate diagnostic

This was a refactoring mistake in https://github.com/rust-lang/rust/pull/109213

fixes #111284
2023-05-23 16:44:26 +05:30
Dominik Stolz
ab9e7037d1 Make place helpers accessible 2023-05-23 13:11:23 +02:00
Dominik Stolz
0e44a38892 Return promoteds in BodyWithBorrowckFacts 2023-05-23 13:11:23 +02:00
Jonáš Fiala
388071a2cb Allow consumers to retrieve borrowck output 2023-05-23 13:11:23 +02:00