Commit graph

294 commits

Author SHA1 Message Date
bors 91f9806208 Auto merge of #88166 - BoxyUwU:const-equate-canon, r=lcnr
canonicalize consts before calling try_unify_abstract_consts query

Fixes #88022
Fixes #86953
Fixes #77708
Fixes #82034
Fixes #85031

these ICEs were all caused by calling the `try_unify_abstract_consts` query with inference vars in substs

r? `@lcnr`
2021-08-22 18:00:22 +00:00
Niko Matsakis 60cc00f540 move fallback_if_possible and friends to fallback.rs
Along the way, simplify and document the logic more clearly.
2021-08-20 17:27:50 -04:00
Niko Matsakis 020655b90d move the sub-unify check and extend the documentation a bit
I didn't like the sub-unify code executing when a predicate was
ENQUEUED, that felt fragile. I would have preferred to move the
sub-unify code so that it only occurred during generalization, but
that impacted diagnostics, so having it also occur when we process
subtype predicates felt pretty reasonable. (I guess we only need one
or the other, but I kind of prefer both, since the generalizer
ultimately feels like the *right* place to guarantee the properties we
want.)
2021-08-20 17:27:50 -04:00
Niko Matsakis 947c0de028 introduce a Coerce predicate 2021-08-19 17:28:24 -04:00
Niko Matsakis 7e0ae7d89b introduce a Diverging enum instead of a bool 2021-08-19 17:28:24 -04:00
Ellen c2b61fbafe move code to InferCtxt method 2021-08-19 21:04:09 +01:00
bors 3d0774d0dc Auto merge of #86700 - lqd:matthews-nll-hrtb-errors, r=nikomatsakis
Matthew's work on improving NLL's "higher-ranked subtype error"s

This PR rebases `@matthewjasper's` [branch](https://github.com/matthewjasper/rust/tree/nll-hrtb-errors) which has great work to fix the obscure higher-ranked subtype errors that are tracked in #57374.

These are a blocker to turning full NLLs on, and doing some internal cleanups to remove some of the old region code.

The goal is so `@nikomatsakis` can take a look at this early, and I'll then do my best to help do the changes and followup work to land this work, and move closer to turning off the migration mode.

I've only updated the branch and made it compile, removed a warning or two.

r? `@nikomatsakis`

(Here's the [zulip topic to discuss this](https://rust-lang.zulipchat.com/#narrow/stream/122657-t-compiler.2Fwg-nll/topic/.2357374.3A.20improving.20higher-ranked.20subtype.20errors.20via.20.2386700) that Niko wanted)
2021-08-18 15:54:59 +00:00
est31 15672dc695 Remove box syntax from rustc_infer 2021-08-18 09:25:26 +02:00
Mara Bos fa4edcc851
Rollup merge of #88030 - fee1-dead:fixme, r=oli-obk
Assign FIXMEs to me and remove obsolete ones

Also fixed capitalization of documentation

We also don't need to transform predicates to be non-const since we basically ignore const predicates in non-const contexts.

r? `````@oli-obk`````
2021-08-16 23:37:30 +02:00
Caio 6aa9937a76 Introduce hir::ExprKind::Let - Take 2 2021-08-15 16:18:26 -03:00
Matthew Jasper d563a63788 Report nicer errors for HRTB NLL errors from queries 2021-08-15 09:11:01 +02:00
Matthew Jasper 5e6027c6bf Track causes for universes created during borrowck 2021-08-15 09:10:46 +02:00
Matthew Jasper 842f0590db Show bound lifetimes when comparing types in diagnostics 2021-08-15 08:44:35 +02:00
Deadbeef f25d2bd53b
Assign FIXMEs to me and remove obsolete ones
Also fixed capitalization of documentation
2021-08-14 16:48:01 +00:00
bors 136eaa1b25 Auto merge of #87375 - fee1-dead:move-constness-to-traitpred, r=oli-obk
Try filtering out non-const impls when we expect const impls

**TL;DR**: Associated types on const impls are now bounded; we now disallow calling a const function with bounds when the specified type param only has a non-const impl.

r? `@oli-obk`
2021-08-14 12:06:34 +00:00
jackh726 22fc7d6e5a Point to where clause for GATs 2021-08-13 17:07:56 -04:00
Deadbeef 01bb3710b5
Pass constness to SelectionContext 2021-08-13 09:28:50 +00:00
Deadbeef 32390a0df6
move Constness into TraitPredicate 2021-08-13 09:26:33 +00:00
Oli Scherer 238d974fc6 Document with_opaque_type_inference's use cases. 2021-08-06 10:49:35 +00:00
Oli Scherer 1b9ad13941 Use existing type alias instead of manually writing it 2021-08-06 10:44:16 +00:00
Oli Scherer b2c1919a3d Store the DefId of the currently typechecked item in InferCtxt
This allows opaque type inference to check for defining uses without having to pass down that def id via function arguments to every method that could possibly cause an opaque type to be compared with a concrete type
2021-08-06 10:39:23 +00:00
Oli Scherer 14021feea9 Remove a field that is computed later anyway 2021-08-06 10:18:31 +00:00
Oli Scherer d99805982b Move opaque type cache into InferCtxt 2021-08-06 10:12:31 +00:00
Yuki Okushi 14e92d7116
Do not suggest impl traits as type arguments 2021-08-03 20:05:50 +09:00
bors f63ab6cfa2 Auto merge of #87628 - estebank:unmet-explicit-lifetime-bound, r=oli-obk
Point at unmet explicit lifetime obligation bound

r? `@oli-obk`

Split off of #85799.
2021-08-02 23:16:40 +00:00
Cameron Steffen 1b48f4d1ea
Rollup merge of #87673 - estebank:opaque-ty-mismatch, r=davidtwco
Tweak opaque type mismatch error
2021-08-02 09:36:52 -05:00
Cameron Steffen 14f3418f79
Rollup merge of #86176 - nbdd0121:explicit-generic-args, r=jackh726
Implement a `explicit_generic_args_with_impl_trait` feature gate

Implements #83701

When this gate is enabled, explicit generic arguments can be specified even if `impl Trait` is used in argument position. Generic arguments can only be specified for explicit generic parameters but not for the synthetic type parameters from  `impl Trait`

So code like this will be accepted:
```rust
#![feature(explicit_generic_args_with_impl_trait)]

fn foo<T: ?Sized>(_f: impl AsRef<T>) {}
fn main() {
    foo::<str>("".to_string());
}
```
2021-08-02 09:36:49 -05:00
Gary Guo 9b90e7e980 Implement a explicit_generic_args_with_impl_trait feature gate
When this gate is enabled, explicit generic arguments can be specified even
if `impl Trait` is used in argument position. Generic arguments can only be
specified for explicit generic parameters but not for the synthetic type
parameters from  `impl Trait`
2021-08-02 04:17:01 +01:00
Esteban Küber 052084af13 Tweak opaque type mismatch error 2021-07-31 12:20:00 -07:00
Esteban Küber e5d42af6ba Point at unmet explicit lifetime obligation bound 2021-07-31 07:56:01 -07:00
Jade 3cf820e17d rfc3052: Remove authors field from Cargo manifests
Since RFC 3052 soft deprecated the authors field anyway, hiding it from
crates.io, docs.rs, and making Cargo not add it by default, and it is
not generally up to date/useful information, we should remove it from
crates in this repo.
2021-07-29 14:56:05 -07:00
bors f9b95f92c8 Auto merge of #86461 - crlf0710:rich_vtable, r=nikomatsakis
Refactor vtable format for upcoming trait_upcasting feature.

This modifies vtable format:
1. reordering occurrence order of methods coming from different traits
2. include `VPtr`s for supertraits where this vtable cannot be directly reused during trait upcasting.
Also, during codegen, the vtables corresponding to these newly included `VPtr` will be requested and generated.

For the cases where this vtable can directly used, now the super trait vtable has exactly the same content to some prefix of this one.

r? `@bjorn3`
cc `@RalfJung`
cc `@rust-lang/wg-traits`
2021-07-24 10:21:23 +00:00
Guillaume Gomez e16d023a5e
Rollup merge of #87281 - rust-lang:issue-81487, r=nikomatsakis
Normalize generic_ty before checking if bound is met

Fixes #81487

r? `@nikomatsakis`
2021-07-22 13:39:21 +02:00
bors 8024983ea7 Auto merge of #87246 - rust-lang:placeholder-pretty, r=nikomatsakis
When pretty printing, name placeholders as bound regions

Split from #85499

When we see a placeholder that we are going to print, treat it as a bound var (and add it to a `for<...>`
2021-07-22 02:22:02 +00:00
Aaron Hill 3291218f47
Improve caching during trait evaluation
Previously, we would 'forget' that we had `'static` regions in some
place during trait evaluation. This lead to us producing
`EvaluatedToOkModuloRegions` when we could have produced
`EvaluatedToOk`, causing us to perform unnecessary work.

This PR preserves `'static` regions when we canonicalize a predicate for
`evaluate_obligation`, and when we 'freshen' a predicate during trait
evaluation. Thie ensures that evaluating a predicate containing
`'static` regions can produce `EvaluatedToOk` (assuming that we
don't end up introducing any region dependencies during evaluation).

Building off of this improved caching, we use
`predicate_must_hold_considering_regions` during fulfillment of
projection predicates to see if we can skip performing additional work.
We already do this for trait predicates, but doing this for projection
predicates lead to mixed performance results without the above caching
improvements.
2021-07-21 17:54:05 -05:00
Guillaume Gomez 358b2cc0b9
Rollup merge of #87206 - matthiaskrgr:clippy_collect, r=davidtwco
avoid temporary vectors/reuse iterators

Avoid collecting an interator just to re-iterate immediately.
Rather reuse the previous iterator. (clippy::needless_collect)
2021-07-21 15:52:45 +02:00
Charles Lew d2dc4276fd Refactor vtable format. 2021-07-20 22:14:42 +08:00
bors da7d405357 Auto merge of #87244 - jackh726:issue-71883, r=estebank
Better diagnostics with mismatched types due to implicit static lifetime

Fixes #78113

I think this is my first diagnostics PR...definitely happy to hear thoughts on the direction/implementation here.

I was originally just trying to solve the error above, where the lifetime on a GAT was causing a cryptic "mismatched types" error. But as I was writing this, I realized that this (unintentionally) also applied to a different case: `wf-in-foreign-fn-decls-issue-80468.rs`. I'm not sure if this diagnostic should get a new error code, or even reuse an existing one. And, there might be some ways to make this even more generalized. Also, the error is a bit more lengthy and verbose than probably needed. So thoughts there are welcome too.

This PR essentially ended up adding a new nice region error pass that triggers if a type doesn't match the self type of an impl which is selected because of a predicate because of an implicit static bound on that self type.

r? `@estebank`
2021-07-20 10:56:08 +00:00
jackh726 ae02491984 Better errors when we don't have implicit statics in trait objects 2021-07-19 23:46:11 -04:00
jackh726 3cd5ad5cd7 Better diagnostics when mismatched types due to implict static lifetime 2021-07-19 18:20:21 -04:00
jackh726 3d464947d4 Normalize generic_ty before checking if bound is met 2021-07-19 10:25:20 -04:00
Santiago Pastorino 962ac8183d
Remove impl_trait_in_bindings handling on inference error reporting 2021-07-18 09:30:09 -03:00
jackh726 b9ee2fb6d8 When pretty printing, name placeholders as bound regions 2021-07-18 03:35:54 -04:00
jackh726 d954a8ee8e Some perf optimizations and logging 2021-07-17 16:09:17 -04:00
Matthias Krüger 8462a378f3 avoid temporary vectors
Avoid collecting an interator just to re-iterate immediately.
Rather reuse the previous iterator. (clippy::needless_collect)
2021-07-17 01:20:10 +02:00
Aaron Hill a765333738
Add initial implementation of HIR-based WF checking for diagnostics
During well-formed checking, we walk through all types 'nested' in
generic arguments. For example, WF-checking `Option<MyStruct<u8>>`
will cause us to check `MyStruct<u8>` and `u8`. However, this is done
on a `rustc_middle::ty::Ty`, which has no span information. As a result,
any errors that occur will have a very general span (e.g. the
definintion of an associated item).

This becomes a problem when macros are involved. In general, an
associated type like `type MyType = Option<MyStruct<u8>>;` may
have completely different spans for each nested type in the HIR. Using
the span of the entire associated item might end up pointing to a macro
invocation, even though a user-provided span is available in one of the
nested types.

This PR adds a framework for HIR-based well formed checking. This check
is only run during error reporting, and is used to obtain a more precise
span for an existing error. This is accomplished by individually
checking each 'nested' type in the HIR for the type, allowing us to
find the most-specific type (and span) that produces a given error.

The majority of the changes are to the error-reporting code. However,
some of the general trait code is modified to pass through more
information.

Since this has no soundness implications, I've implemented a minimal
version to begin with, which can be extended over time. In particular,
this only works for HIR items with a corresponding `DefId` (e.g. it will
not work for WF-checking performed within function bodies).
2021-07-16 16:29:02 -05:00
Niko Matsakis 26f7030b16 remove unused Option 2021-07-04 11:09:32 -04:00
Josh Triplett 40cc27849a rustc_infer: Remove unused dependency rustc_ast
Unused since commit 50e1ae15e9
("Use ty::{IntTy,UintTy,FloatTy} in rustc").
2021-06-25 01:12:59 -07:00
Josh Triplett b060ba93b9 rustc_infer: Remove unused dependency rustc_graphviz
Unused since commit 7d73e4cc47
("Remove ReScope").
2021-06-25 01:12:59 -07:00
bors cb3c4ee718 Auto merge of #86164 - FabianWolff:issue-86053, r=davidtwco
Handle C-variadic arguments properly when reporting region errors

This pull request fixes #86053. The issue is that for a C-variadic function
```rust
#![feature(c_variadic)]
unsafe extern "C" fn foo(_: (), ...) {}
```
`foo`'s signature will contain only the first parameter (and have `c_variadic` set to `true`), whereas its body has a second argument (a `hir::Pat` for the `...`).

The code for reporting region errors iterates over the body's parameters and tries to fetch the corresponding parameter from the signature; this causes an out-of-bounds ICE for the `...` (though not in the example above, because there are no region errors to report).

I have simply restricted the iteration over the body parameters to exclude `...`, which is fine because `...` cannot cause a region error.
2021-06-17 06:34:12 +00:00