Commit graph

677 commits

Author SHA1 Message Date
Gary Guo
02c1774cd3 Give inline const separate DefKind 2021-11-07 03:59:06 +00:00
Matthias Krüger
0a5640b55f use matches!() macro in more places 2021-11-06 16:13:14 +01:00
bors
18cae2680f Auto merge of #88441 - jackh726:closure_norm, r=nikomatsakis
Normalize obligations for closure confirmation

Based on #90017

Fixes #74261
Fixes #71955
Fixes #88459

r? `@nikomatsakis`
2021-11-06 01:12:39 +00:00
bors
489ec310d2 Auto merge of #90577 - matthiaskrgr:clippy_perf_nov, r=petrochenkov
clippy::perf fixes
2021-11-05 09:17:39 +00:00
Matthias Krüger
28ef4169cc clippy::perf fixes 2021-11-04 21:07:56 +01:00
Charles Lew
8841204cc6 Erase regions within vtable_trait_first_method_offset. 2021-11-04 00:53:54 +08:00
Matthias Krüger
bc487f7dd2
Rollup merge of #90417 - lcnr:stabilize-relaxed-struct-unsizing, r=wesleywiser
stabilize `relaxed_struct_unsize`

closes #81793

the fcp is already complete.
2021-11-02 23:48:47 +01:00
Guillaume Gomez
06bb1ff1b5
Rollup merge of #90375 - yanok:master, r=lcnr
Use `is_global` in `candidate_should_be_dropped_in_favor_of`

This manifistated in #90195 with compiler being unable to keep
one candidate for a trait impl, if where is a global impl and more
than one trait bound in the where clause.

Before #87280 `candidate_should_be_dropped_in_favor_of` was using
`TypeFoldable::is_global()` that was enough to discard the two
`ParamCandidate`s. But #87280 changed it to use
`TypeFoldable::is_known_global()` instead, which is pessimistic, so
now the compiler drops the global impl instead (because
`is_known_global` is not sure) and then can't decide between the
two `ParamCandidate`s.

Switching it to use `is_global` again solves the issue.

Fixes #90195.
2021-10-30 20:30:27 +02:00
lcnr
b40aa64e48 stabilize relaxed_struct_unsize 2021-10-30 15:56:02 +02:00
bors
88a5a984fe Auto merge of #90380 - Mark-Simulacrum:revert-89558-query-stable-lint, r=lcnr
Revert "Add rustc lint, warning when iterating over hashmaps"

Fixes perf regressions introduced in https://github.com/rust-lang/rust/pull/90235 by temporarily reverting the relevant PR.
2021-10-29 04:55:51 +00:00
Mark Rousskov
3215eeb99f
Revert "Add rustc lint, warning when iterating over hashmaps" 2021-10-28 11:01:42 -04:00
Oli Scherer
bc552fc417 Move instantiate_opaque_types to rustc_infer.
It does not depend on anything from rustc_trait_selection anymore.
2021-10-28 14:12:24 +00:00
Oli Scherer
a8f06b249b Move some functions into rustc_infer.
They don't depend on trait selection anymore, so there is no need for an extension trait.
2021-10-28 13:54:11 +00:00
Oli Scherer
849b73b8d9 Manually inline a function that is only ever called at the end of another function 2021-10-28 13:42:16 +00:00
Oli Scherer
f1a2f2098f Remove dead code.
We don't do member constraint checks in regionck anymore.
All member constraint checks are done in mir borrowck.
2021-10-28 13:38:41 +00:00
Ilya Yanok
6f942a2f4a Reformat the changed line to make tidy happy 2021-10-28 13:23:49 +00:00
Ilya Yanok
6c61db4407 Use is_global in candidate_should_be_dropped_in_favor_of
This manifistated in #90195 with compiler being unable to keep
one candidate for a trait impl, if where is a global impl and more
than one trait bound in the where clause.

Before #87280 `candidate_should_be_dropped_in_favor_of` was using
`TypeFoldable::is_global()` that was enough to discard the two
`ParamCandidate`s. But #87280 changed it to use
`TypeFoldable::is_known_global()` instead, which is pessimistic, so
now the compiler drops the global impl instead (because
`is_known_global` is not sure) and then can't decide between the
two `ParamCandidate`s.

Switching it to use `is_global` again solves the issue.

Fixes #90195.
2021-10-28 12:49:46 +00:00
Michael Howell
8520105464 fix(rustc_typeck): report function argument errors on matching type
Fixes #90101
2021-10-25 12:23:52 -07:00
Matthias Krüger
b25172b504
Rollup merge of #89889 - estebank:unmet-send-bound-on-foreign-future, r=tmandry
Use the "nice E0277 errors"[1] for `!Send` `impl Future` from foreign crate

Partly address #78543 by making the error quieter.

We don't have access to the `typeck` tables from foreign crates, so we
used to completely skip the new code when checking foreign crates. Now,
we carry on and don't provide as nice output (we don't clarify *what* is
making the `Future: !Send`), but at least we no longer emit a sea of
derived obligations in the output.

[1]: https://blog.rust-lang.org/inside-rust/2019/10/11/AsyncAwait-Not-Send-Error-Improvements.html

r? `@tmandry`
2021-10-25 07:54:12 +02:00
bors
41d8c94d45 Auto merge of #89427 - estebank:collect-overlapping-impls, r=jackh726
Point at overlapping impls when type annotations are needed

Address https://github.com/rust-lang/rust/issues/89254.
2021-10-24 22:26:41 +00:00
Esteban Kuber
6dcff4e9f6 Use the "nice E0277 errors"[1] for !Send impl Future from foreign crate
Partly address #78543 by making the error quieter.

We don't have access to the `typeck` tables from foreign crates, so we
used to completely skip the new code when checking foreign crates. Now,
we carry on and don't provide as nice output (we don't clarify *what* is
making the `Future: !Send`), but at least we no longer emit a sea of
derived obligations in the output.

[1]: https://blog.rust-lang.org/inside-rust/2019/10/11/AsyncAwait-Not-Send-Error-Improvements.html
2021-10-24 20:45:33 +00:00
Esteban Kuber
ef212e7fb3 Point at overlapping impls when type annotations are needed 2021-10-24 18:33:04 +00:00
Matthias Krüger
87822b27ee
Rollup merge of #89558 - lcnr:query-stable-lint, r=estebank
Add rustc lint, warning when iterating over hashmaps

r? rust-lang/wg-incr-comp
2021-10-24 15:48:42 +02:00
bors
aa5740c715 Auto merge of #90104 - spastorino:coherence-for-negative-trait, r=nikomatsakis
Implement coherence checks for negative trait impls

The main purpose of this PR is to be able to [move Error trait to core](https://github.com/rust-lang/project-error-handling/issues/3).

This feature is necessary to handle the following from impl on box.

```rust
impl From<&str> for Box<dyn Error> { ... }
```

Without having negative traits affect coherence moving the error trait into `core` and moving that `From` impl to `alloc` will cause the from impl to no longer compiler because of a potential future incompatibility. The compiler indicates that `&str` _could_ introduce an `Error` impl in the future, and thus prevents the `From` impl in `alloc` that would cause overlap with `From<E: Error> for Box<dyn Error>`. Adding `impl !Error for &str {}` with the negative trait coherence feature will disable this error by encoding a stability guarantee that `&str` will never implement `Error`, making the `From` impl compile.

We would have this in `alloc`:

```rust
impl From<&str> for Box<dyn Error> {} // A
impl<E> From<E> for Box<dyn Error> where E: Error {} // B
```

and this in `core`:

```rust
trait Error {}
impl !Error for &str {}
```

r? `@nikomatsakis`

This PR was built on top of `@yaahc` PR #85764.

Language team proposal: to https://github.com/rust-lang/lang-team/issues/96
2021-10-23 12:51:15 +00:00
Santiago Pastorino
3287f72d39
Avoid code duplication by extracting checks into fns 2021-10-23 08:55:48 -03:00
Santiago Pastorino
9534186857
Hide negative coherence checks under negative_impls feature flag 2021-10-22 17:54:20 -03:00
Santiago Pastorino
132409f0c6
Assemple trait alias candidates for negative polarity
This doesn't work properly yet, we would probably need to implement an
`assembly_neg_candidates` and consider things like `T: !AB` as `T: !A`
|| `T: !B`
2021-10-22 15:49:54 -03:00
Santiago Pastorino
da79fa964c
Add rustc_strict_coherence attribute and use it to check overlap 2021-10-22 15:49:46 -03:00
Santiago Pastorino
74454c4888
Add comment about the only way to prove NotImplemented here 2021-10-22 11:04:30 -03:00
Santiago Pastorino
2e9fb8b68b
Fix filter_impls comment 2021-10-22 10:58:38 -03:00
Santiago Pastorino
b03a0df737
Fix debug method name 2021-10-22 10:57:10 -03:00
Santiago Pastorino
5b5a2e600e
Move const filter to filter_impls 2021-10-22 10:56:32 -03:00
Santiago Pastorino
7829d9dde3
Document overlap check filter 2021-10-22 09:22:19 -03:00
Yuki Okushi
9ed9025ea9
Rollup merge of #90028 - tmiasko:structural-match-closure, r=spastorino
Reject closures in patterns

Fixes #90013.
2021-10-22 19:42:48 +09:00
Yuki Okushi
6f0acbcbd0
Rollup merge of #88644 - eopb:abstractconst_leaf_subst, r=lcnr
`AbstractConst` private fields

Calls `subst` in `AbstractConst::root` when `Node` is `Leaf`.

r? ``@lcnr``
2021-10-21 14:11:03 +09:00
Santiago Pastorino
5a727538f8
Fix allow_negative_impls logic 2021-10-20 18:05:06 -03:00
Santiago Pastorino
68d444ffa1
Add TraitObligation::polarity() for better encapsulation 2021-10-20 14:45:10 -03:00
Santiago Pastorino
7568632513
Filter candidates when goal and impl polarity doesn't match 2021-10-20 12:10:46 -03:00
Santiago Pastorino
6ae1d68e16
Use predicate_must_hold_modulo_regions 2021-10-20 12:10:46 -03:00
Santiago Pastorino
89a419cf7d
Filter out Negative impls on intercrate mode's ambiguous reasoning 2021-10-20 12:10:46 -03:00
Santiago Pastorino
85c8fd9c94
Make EvaluationCache consider polarity as cache's key 2021-10-20 12:10:46 -03:00
Santiago Pastorino
da8873e343
Only assemble_candidates_from_impls for polarity Negative 2021-10-20 12:10:46 -03:00
Santiago Pastorino
ab17068662
Consider negative polarity on trait selection 2021-10-20 12:10:45 -03:00
Santiago Pastorino
8b0bfb0dcb
Consider negative polarity on overlap check 2021-10-20 12:10:45 -03:00
Santiago Pastorino
6975afd141
Add polarity to TraitPredicate 2021-10-20 12:10:41 -03:00
Ethan Brierley
be30e60296 remove duplicate subst 2021-10-20 10:21:06 +01:00
Ethan Brierley
99b8c016ce Address lcnr review 2021-10-19 22:18:13 +01:00
Tomasz Miąsko
c97cf7fed7 Reject closures in patterns 2021-10-19 20:45:43 +02:00
bors
1af55d19c7 Auto merge of #89933 - est31:let_else, r=michaelwoerister
Adopt let_else across the compiler

This performs a substitution of code following the pattern:

```
let <id> = if let <pat> = ... { identity } else { ... : ! };
```

To simplify it to:

```
let <pat> = ... { identity } else { ... : ! };
```

By adopting the `let_else` feature (cc #87335).

The PR also updates the syn crate because the currently used version of the crate doesn't support `let_else` syntax yet.

Note: Generally I'm the person who *removes* usages of unstable features from the compiler, not adds more usages of them, but in this instance I think it hopefully helps the feature get stabilized sooner and in a better state. I have written a [comment](https://github.com/rust-lang/rust/issues/87335#issuecomment-944846205) on the tracking issue about my experience and what I feel could be improved before stabilization of `let_else`.
2021-10-19 14:41:39 +00:00
bors
ec724ac075 Auto merge of #89229 - oli-obk:i_love_inferctxt, r=jackh726
Remove redundant member-constraint check

impl trait will, for each lifetime in the hidden type, register a "member constraint" that says the lifetime must be equal or outlive one of the lifetimes of the impl trait. These member constraints will be solved by borrowck

But, as you can see in the big red block of removed code, there was an ad-hoc check for member constraints happening at the site where they get registered. This check had some minor effects on diagnostics, but will fall down on its feet with my big type alias impl trait refactor. So we removed it and I pulled the removal out into a (hopefully) reviewable PR that works on master directly.
2021-10-18 23:02:53 +00:00