Commit graph

268 commits

Author SHA1 Message Date
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
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
LeSeulArtichaut e3ca81fd5a Use the now available implementation of IntoIterator for arrays 2021-06-14 23:40:09 +02:00
Fabian Wolff 7dccce0706 Handle C-variadic arguments properly when reporting region errors 2021-06-09 17:02:39 +02:00
Fabian Wolff 6206247335 Suggest a trailing comma if a 1-tuple is expected 2021-06-07 23:16:03 +02:00
Aaron Hill fad2242ff7
Add variance-related information to lifetime error messages 2021-06-06 12:37:42 -05:00
Yuki Okushi 36f1ed6de2
Rollup merge of #85850 - bjorn3:less_feature_gates, r=jyn514
Remove unused feature gates

The first commit removes a usage of a feature gate, but I don't expect it to be controversial as the feature gate was only used to workaround a limitation of rust in the past. (closures never being `Clone`)

The second commit uses `#[allow_internal_unstable]` to avoid leaking the `trusted_step` feature gate usage from inside the index newtype macro. It didn't work for the `min_specialization` feature gate though.

The third commit removes (almost) all feature gates from the compiler that weren't used anyway.
2021-06-04 13:42:54 +09:00
Camille GILLOT 0e71283495 Restrict access to crate_name.
Also remove original_crate_name, which had the exact same implementation
2021-06-02 18:35:32 +02:00
Camille Gillot 0f0f3138cb
Revert "Reduce the amount of untracked state in TyCtxt" 2021-06-01 09:05:22 +02:00
bjorn3 312f964478 Remove unused feature gates 2021-05-31 13:55:43 +02:00
Camille GILLOT 10fb4b2fe5 Restrict access to crate_name.
Also remove original_crate_name, which had the exact same implementation
2021-05-30 19:54:04 +02:00
Jacob Pratt bc2f0fb5a9
Specialize implementations
Implementations in stdlib are now optimized as they were before.
2021-05-26 18:07:09 -04:00
Pietro Albini 9e22b844dd remove cfg(bootstrap) 2021-05-24 11:07:48 -04:00
Jack Huey c6e4284f8b Add comments to opportunistic resolve functions 2021-05-15 23:36:10 -04:00
Jack Huey 909d0e83d6 Missed a couple things 2021-05-15 12:26:50 -04:00
Jack Huey fb6cec440a Revert to only using opportunistic_resolve_vars for existing places 2021-05-15 12:10:56 -04:00
Jack Huey 61157b341e Store Option<Region> as value for RegionVid 2021-05-14 21:48:32 -04:00
Jack Huey e8c284ff28 Make the UnifyValue for RegionVid () 2021-05-14 18:17:13 -04:00
Aaron Hill bc6330d47a
Don't suggest adding 'static lifetime to arguments
Fixes #69350

This is almost always the wrong this to do
2021-05-12 21:43:09 -04:00
bors e1ff91f439 Auto merge of #83813 - cbeuw:remap-std, r=michaelwoerister
Fix `--remap-path-prefix` not correctly remapping `rust-src` component paths and unify handling of path mapping with virtualized paths

This PR fixes #73167 ("Binaries end up containing path to the rust-src component despite `--remap-path-prefix`") by preventing real local filesystem paths from reaching compilation output if the path is supposed to be remapped.

`RealFileName::Named` introduced in #72767 is now renamed as `LocalPath`, because this variant wraps a (most likely) valid local filesystem path.

`RealFileName::Devirtualized` is renamed as `Remapped` to be used for remapped path from a real path via `--remap-path-prefix` argument, as well as real path inferred from a virtualized (during compiler bootstrapping) `/rustc/...` path. The `local_path` field is now an `Option<PathBuf>`, as it will be set to `None` before serialisation, so it never reaches any build output. Attempting to serialise a non-`None` `local_path` will cause an assertion faliure.

When a path is remapped, a `RealFileName::Remapped` variant is created. The original path is preserved in `local_path` field and the remapped path is saved in `virtual_name` field. Previously, the `local_path` is directly modified which goes against its purpose of "suitable for reading from the file system on the local host".

`rustc_span::SourceFile`'s fields `unmapped_path` (introduced by #44940) and `name_was_remapped` (introduced by #41508 when `--remap-path-prefix` feature originally added) are removed, as these two pieces of information can be inferred from the `name` field: if it's anything other than a `FileName::Real(_)`, or if it is a `FileName::Real(RealFileName::LocalPath(_))`, then clearly `name_was_remapped` would've been false and `unmapped_path` would've been `None`. If it is a `FileName::Real(RealFileName::Remapped{local_path, virtual_name})`, then `name_was_remapped` would've been true and `unmapped_path` would've been `Some(local_path)`.

cc `@eddyb` who implemented `/rustc/...` path devirtualisation
2021-05-12 11:05:56 +00:00
lcnr 513c56a611 remove unused variant 2021-05-06 14:59:53 +02:00
Andy Wang 5417b45c26
Use local and remapped paths where appropriate 2021-05-05 15:31:28 +01:00
Jack Huey 5f82e22ba4 Don't rebind in transitive_bounds_that_define_assoc_type 2021-04-28 18:10:44 -04:00
bors b56b175c6c Auto merge of #84310 - RalfJung:const-fn-feature-flags, r=oli-obk
further split up const_fn feature flag

This continues the work on splitting up `const_fn` into separate feature flags:
* `const_fn_trait_bound` for `const fn` with trait bounds
* `const_fn_unsize` for unsizing coercions in `const fn` (looks like only `dyn` unsizing is still guarded here)

I don't know if there are even any things left that `const_fn` guards... at least libcore and liballoc do not need it any more.

`@oli-obk` are you currently able to do reviews?
2021-04-24 23:16:03 +00:00
klensy f43ee8ebf6 fix few typos 2021-04-19 15:57:08 +03:00
Ralf Jung bd9556956a fix feature use in rustc libs 2021-04-18 22:05:45 +02:00
pierwill 0019ca9141 Fix outdated crate names in compiler docs
Changes `librustc_X` to `rustc_X`, only in documentation comments.
Plain code comments are left unchanged.

Also fix incorrect file paths.
2021-04-08 11:12:14 -05:00
bors 0978a9eb99 Auto merge of #83207 - oli-obk:valtree2, r=lcnr
normalize mir::Constant differently from ty::Const in preparation for valtrees

Valtrees are unable to represent many kind of constant values (this is on purpose). For constants that are used at runtime, we do not need a valtree representation and can thus use a different form of evaluation. In order to make this explicit and less fragile, I added a `fold_constant` method to `TypeFolder` and implemented it for normalization. Normalization can now, when it wants to eagerly evaluate a constant, normalize `mir::Constant` directly into a `mir::ConstantKind::Val` instead of relying on the `ty::Const` evaluation.

In the future we can get rid of the `ty::Const` in there entirely and add our own `Unevaluated` variant to `mir::ConstantKind`. This would allow us to remove the `promoted` field from `ty::ConstKind::Unevaluated`, as promoteds can never occur in the type system.

cc `@rust-lang/wg-const-eval`

r? `@lcnr`
2021-04-02 10:28:12 +00:00