Commit graph

1469 commits

Author SHA1 Message Date
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
ef212e7fb3 Point at overlapping impls when type annotations are needed 2021-10-24 18:33:04 +00:00
Matthias Krüger
d576393e34
Rollup merge of #90221 - JakobDegen:issue-90213, r=cjgillot
Fix ICE when forgetting to `Box` a parameter to a `Self::func` call

Closes #90213 .

Assuming we can get the `DefId` of the receiver causes an ICE if the receiver is `Self`. We can just avoid doing this though.
2021-10-24 15:48:45 +02: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
Jakob Degen
4b970231fd Fix ICE when forgetting to Box a parameter to a Self::func call 2021-10-24 00:33:29 -04:00
bors
91b931926f Auto merge of #90203 - matthiaskrgr:rollup-v215wew, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #85833 (Scrape code examples from examples/ directory for Rustdoc)
 - #88041 (Make all proc-macro back-compat lints deny-by-default)
 - #89829 (Consider types appearing in const expressions to be invariant)
 - #90168 (Reset qualifs when a storage of a local ends)
 - #90198 (Add caveat about changing parallelism and function call overhead)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-10-23 15:53:50 +00:00
Matthias Krüger
2b874f0242
Rollup merge of #89829 - voidc:assoc-const-variance, r=lcnr
Consider types appearing in const expressions to be invariant

This is an approach to fix #80977.
Currently, a type parameter which is only used in a constant expression is considered bivariant and will trigger error E0392 *"parameter T is never used"*.
Here is a short example:

```rust
pub trait Foo {
    const N: usize;
}

struct Bar<T: Foo>([u8; T::N])
where [(); T::N]:;
```
([playgound](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2015&gist=b51a272853f75925e72efc1597478aa5))

While it is possible to silence this error by adding a `PhantomData<T>` field, I think the better solution would be to make `T` invariant.
This would be analogous to the invariance constraints added for associated types.
However, I'm quite new to the compiler and unsure whether this is the right approach.

r? ``@varkor`` (since you authored #60058)
2021-10-23 14:58:41 +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
Yuki Okushi
371fd4f1c0
Rollup merge of #90074 - klensy:upvar-all, r=wesleywiser
2229 migrations small cleanup

This removes needless `format!`'ing of empty string and replaces `vec!` with const strings with const array.
2021-10-21 14:11:09 +09:00
Santiago Pastorino
6975afd141
Add polarity to TraitPredicate 2021-10-20 12:10:41 -03:00
klensy
f3fb821f3b use array explicitly instead of vec for const content (even if optimizer smart enought to remove allocation) 2021-10-20 03:24:07 +03:00
klensy
aad48f71b3 replace format!("") with String::new()
use array explicitly instead of vec for const content (even if optimizer smart enought to remove allocation)
2021-10-20 03:23:24 +03:00
Yuki Okushi
d8b3764bd2
Rollup merge of #90025 - JohnTitor:revert-86011, r=estebank
Revert #86011 to fix an incorrect bound check

This reverts commit 36a1076d24, reversing
changes made to e1e9319d93.

Fixes #89935
r? ``@estebank``
2021-10-20 04:35:17 +09: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
Yuki Okushi
e2453dc2ff
Revert "Rollup merge of #86011 - tlyu:correct-sized-bound-spans, r=estebank"
This reverts commit 36a1076d24, reversing
changes made to e1e9319d93.
2021-10-19 02:33:38 +09:00
Matthias Krüger
e0e2b3cc43
Rollup merge of #89963 - r00ster91:parenthesisparentheses, r=nagisa
Some "parenthesis" and "parentheses" fixes

"Parenthesis" is the singular (e.g. one `(` or one `)`) and "parentheses" is the plural (multiple `(` or `)`s) and this is not hard to mix up so here are some fixes for that.

Inspired by #89958
2021-10-17 18:18:59 +02:00
r00ster91
3c1d55422a Some "parenthesis" and "parentheses" fixes 2021-10-17 12:04:01 +02:00
bors
4e89811b46 Auto merge of #89860 - camsteffen:macro-semi, r=petrochenkov
Remove trailing semicolon from macro call span

Macro call site spans are now less surprising/more consistent since they no longer contain a semicolon after the macro call.

The downside is that we need to do a little guesswork to get the semicolon in diagnostics. But this should not be noticeable since it is rare for the semicolon to not immediately follow the macro call.
2021-10-16 18:20:20 +00:00
est31
ef018be5c4 Update the syn crate and adopt let_else in three more places
The syn crate has gained support for let_else syntax in version 1.0.76,
see https://github.com/dtolnay/syn/pull/1057 .

In the three instances that use let_else, we've sent code through an
attr macro, which would create compile errors when there was no
let_else support in syn. To avoid this, we ran
`cargo +nightly update -p syn` for updating the syn crate.
2021-10-16 07:18:15 +02:00
est31
1418df5888 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.
2021-10-16 07:18:05 +02:00
Niko Matsakis
094a9c743e simplify constrain_opaque_types 2021-10-15 17:50:33 +00:00
jackh726
2b5b456e23 Move some outlives bounds things from rustc_trait_selection to rustc_typeck 2021-10-15 12:14:19 -04:00
jackh726
d3fa07c72e Use LocalDefId directly in more places in wfcheck 2021-10-15 12:14:02 -04:00
jackh726
a7c132de55 Move push_outlives_components to rustc_infer 2021-10-15 12:13:35 -04:00
lcnr
00e5abe9b6 allow potential_query_instability everywhere 2021-10-15 10:58:18 +02:00
lcnr
7f7915347d write substs for lang item paths 2021-10-15 10:58:18 +02:00
Cameron Steffen
f005e9fe96 Guess semicolon span for macro statements 2021-10-15 02:24:48 -05:00
bors
72d66064e7 Auto merge of #89903 - matthiaskrgr:rollup-s0c69xl, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #86011 (move implicit `Sized` predicate to end of list)
 - #89821 (Add a strange test for `unsafe_code` lint.)
 - #89859 (add dedicated error variant for writing the discriminant of an uninhabited enum variant)
 - #89870 (Suggest Box::pin when Pin::new is used instead)
 - #89880 (Use non-checking TLS relocation in aarch64 asm! sym test.)
 - #89885 (add long explanation for E0183)
 - #89894 (Remove unused dependencies from rustc_const_eval)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-10-15 05:59:49 +00:00
Matthias Krüger
e2c28ad1e7
Rollup merge of #89870 - tmandry:box-pin, r=estebank
Suggest Box::pin when Pin::new is used instead

This fixes an incorrect diagnostic.

**Based on #89390**; only the last commit is specific to this PR. "Ignore whitespace changes" also helps here.
2021-10-15 07:44:47 +02:00
Matthias Krüger
36a1076d24
Rollup merge of #86011 - tlyu:correct-sized-bound-spans, r=estebank
move implicit `Sized` predicate to end of list

In `Bounds::predicates()`, move the implicit `Sized` predicate to the
end of the generated list. This means that if there is an explicit
`Sized` bound, it will be checked first, and any resulting
diagnostics will have a more useful span.

Fixes #85998, at least partially. ~~Based on #85979, but only the last 2 commits are new for this pull request.~~ (edit: rebased) A full fix would need to deal with where-clauses, and that seems difficult. Basically, predicates are being collected in multiple stages, and there are two places where implicit `Sized` predicates can be inserted: once for generic parameters, and once for where-clauses. I think this insertion is happening too early, and we should actually do it only at points where we collect all of the relevant trait bounds for a type parameter.

I could use some help interpreting the changes to the stderr output. It looks like reordering the predicates changed some diagnostics that don't obviously have anything to do with `Sized` bounds. Possibly some error reporting code is making assumptions about ordering of predicates? The diagnostics for src/test/ui/derives/derives-span-Hash-*.rs seem to have improved, no longer pointing at the type parameter identifier, but src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.rs became less verbose for some reason.

I also ran into an instance of #84970 while working on this, but I kind of expected that could happen, because I'm reordering predicates. I can open a separate issue on that if it would be helpful.

``@estebank`` this seems likely to conflict (slightly?) with your work on #85947; how would you like to resolve that?
2021-10-15 07:44:44 +02:00
bors
313e71a253 Auto merge of #89884 - Mark-Simulacrum:revert-enum-discr, r=wesleywiser
Revert enum discriminants

Reverts stabilization of arbitrary enum discriminants per https://github.com/rust-lang/rust/issues/88621#issuecomment-929482371.

Reopens #60553.
2021-10-15 02:55:58 +00:00
Mark Rousskov
8485e6fdec Revert "Stabilize arbitrary_enum_discriminant"
This reverts commit 7a62f29f31.
2021-10-14 10:57:56 -04:00
Matthias Krüger
f9c9774aea
Rollup merge of #89390 - tmandry:issue-72117, r=estebank
Fix incorrect Box::pin suggestion

The suggestion checked if `Pin<Box<T>>` could be coeerced to the expected
type, but did not check predicates created by the coercion. We now
look for predicates that definitely cannot be satisfied before giving
the suggestion.

The suggestion is still marked MaybeIncorrect because we allow predicates that
are still ambiguous and can't be proven.

Fixes #72117.
2021-10-14 16:06:43 +02:00
bors
c34ac8747c Auto merge of #89247 - fee1-dead:const-eval-select, r=oli-obk
Add `const_eval_select` intrinsic

Adds an intrinsic that calls a given function when evaluated at compiler time, but generates a call to another function when called at runtime.

See https://github.com/rust-lang/const-eval/issues/7 for previous discussion.

r? `@oli-obk.`
2021-10-14 10:06:30 +00:00
Tyler Mandry
d18502d6b3 Suggest Box::pin when Pin::new is used instead 2021-10-14 01:06:25 +00:00
Tyler Mandry
a8558e9efa Exit early if expected type is not an adt 2021-10-13 23:26:01 +00:00
Tyler Mandry
485ae9f2c0 Always check predicates in can_coerce
This only changed two tests and I consider both changes an improvement.
2021-10-13 23:26:00 +00:00
Tyler Mandry
5c14433c00 Fix incorrect Box::pin suggestion
The suggestion checked if Pin<Box<T>> could be coeerced to the expected
type, but did not check predicates created by the coercion. We now
look for predicates that definitely cannot be satisfied before giving
the suggestion.

The suggestion is marked MaybeIncorrect because we allow predicates that
are still ambiguous and can't be proven.
2021-10-13 23:26:00 +00:00
Tyler Mandry
2c31c31bb8 Fix line length 2021-10-13 23:26:00 +00:00
Tomasz Miąsko
8aaf4ab59a Deduplicate regions ids before merging them
The merging code does not expect to see any duplicates.
2021-10-13 00:00:00 +00:00
Deadbeef
5387b6542f
Add const_eval_select intrinsic 2021-10-12 05:42:23 +00:00
bors
97e3b30285 Auto merge of #89791 - matthiaskrgr:rollup-1lhxh5b, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #89471 (Use Ancestory to check default fn in const impl instead of comparing idents)
 - #89643 (Fix inherent impl overlap check.)
 - #89651 (Add `Poll::ready` and revert stabilization of `task::ready!`)
 - #89675 (Re-use TypeChecker instead of passing around some of its fields )
 - #89710 (Add long explanation for error E0482)
 - #89756 (Greatly reduce amount of debuginfo compiled for bootstrap itself)
 - #89760 (Remove hack ignoring unused attributes for stage 0 std)
 - #89772 (Fix function-names test for GDB 10.1)
 - #89785 (Fix ICE when compiling nightly std/rustc on beta compiler)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-10-12 00:20:34 +00:00
Matthias Krüger
b80dd9e445
Rollup merge of #89643 - cjgillot:overlap, r=matthewjasper
Fix inherent impl overlap check.

The current implementation of the overlap check was slightly buggy, and unified the wrong connected component in the `ids.len() <= 1` case. This became visible in another PR which changed the iteration order of items.

r? ``@matthewjasper`` since you reviewed the other PR.
2021-10-11 23:45:46 +02:00
bors
7cc8c44871 Auto merge of #89648 - nbdd0121:issue-89606, r=nikomatsakis
Ignore type of projections for upvar capturing

Fix #89606

Ignore type of projections for upvar capturing. Originally HashMap is used, and the hash/eq implementation of Place takes the type of projections into account. These types may differ by lifetime which causes #89606 to ICE.

I originally considered erasing regions but `place.ty()` is used when creating upvar tuple type, more than just serving as a key type, so I switched to a linear comparison with custom eq (`compare_place_ignore_ty`) instead.

r? `@wesleywiser`

`@rustbot` label +T-compiler
2021-10-11 21:39:11 +00:00
Gary Guo
7275cfa47c Explicit PlaceAncestryRelation::SamePlace and handle like Descendant 2021-10-09 06:49:47 +01:00
Guillaume Gomez
836597a881
Rollup merge of #89649 - matthiaskrgr:clippycompl, r=jyn514
clippy::complexity fixes
2021-10-08 22:30:40 +02:00
Guillaume Gomez
32502404e5
Rollup merge of #86506 - b-naber:gen_trait_impl_inconsistent, r=jackh726
Don't normalize xform_ret_ty during method candidate assembly

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

Normalizing the return type of a method candidate together with the expected receiver type of the method can lead to valid method candidates being rejected during probing. Specifically in the example of the fixed issue we have a `self_ty` of the form `&A<&[Coef]>` whereas the `impl_ty` of the method would be `&A<_>`, if we normalize the projection in the return type we unify the inference variable with `Cont`, which will lead us to reject the candidate in the sup type check in `consider_probe`. Since we don't actually need the normalized return type during candidate assembly, we postpone the normalization until we consider candidates in `consider_probe`.
2021-10-08 22:30:38 +02:00
Matthias Krüger
e6f77a1787 clippy::complexity fixes 2021-10-08 20:07:44 +02:00
bors
87df4dd70f Auto merge of #89644 - matthiaskrgr:clippy_perf_okt, r=jyn514
some clippy::perf fixes
2021-10-08 14:35:00 +00:00