Commit graph

415 commits

Author SHA1 Message Date
jackh726 890de33e4f Fix duplicate error 2021-09-07 18:51:24 -04:00
jackh726 af9de99f12 Detect stricter constraints on gats where clauses in impls vs trait 2021-09-07 18:30:58 -04:00
Mark Rousskov 2eac09d258 Use index newtyping for TyVid 2021-09-06 22:38:06 -04:00
bors 97f2698484 Auto merge of #88363 - michaelwoerister:remapped-diagnostics, r=estebank
Path remapping: Make behavior of diagnostics output dependent on presence of --remap-path-prefix.

This PR fixes a regression (#87745) with `--remap-path-prefix` where the flag stopped causing diagnostic messages to be remapped as well. The regression was introduced in https://github.com/rust-lang/rust/pull/83813 where we erroneously assumed that remapping of diagnostic messages was not desired anymore (because #70642 partially undid that functionality with nobody objecting).

The issue is fixed by making `--remap-path-prefix` remap diagnostic messages again, including for paths that have been remapped in upstream crates (e.g. the standard library). This means that "sysroot-localization" (implemented in #70642) is also disabled if `rustc` is invoked with `--remap-path-prefix`. The assumption is that once someone starts explicitly remapping paths they also don't want paths to their local Rust installation in their build output.

In the future we might want to give more fine-grained control over this behavior via compiler flags (see https://github.com/rust-lang/rfcs/pull/3127 for a related RFC). For now this PR is intended as a regression fix.

This PR is an alternative to https://github.com/rust-lang/rust/pull/88191, which makes diagnostic messages be remapped unconditionally. That approach, however, would effectively revert #70642.

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

cc `@cbeuw`
r? `@ghost`
2021-09-03 00:23:10 +00:00
Cameron Steffen 2f4e86b9ef Enforce diverging let...else 2021-08-30 20:18:42 -05:00
lcnr 0c28e028b6 feature(const_generics) -> feature(const_param_types) 2021-08-30 11:00:21 +02:00
Ellen c0e853f274 remove lazy_normalization_consts 2021-08-30 11:00:21 +02:00
Michael Woerister af1b65cb18 Path remapping: Make behavior of diagnostics output dependent on presence of --remap-path-prefix. 2021-08-27 11:50:44 +02:00
lcnr f3996f6a88 review 2021-08-26 11:14:31 +02:00
lcnr bc0156bace shrink ty::PredicateKind again 2021-08-26 11:00:30 +02:00
lcnr caa975c89e use ty::Unevaluated instead of def substs pair 2021-08-26 11:00:30 +02:00
lcnr 2140016d6c don't just compare ty::Const 2021-08-26 11:00:30 +02:00
lcnr ab9108b70f update TypeFlags to deal with missing ct substs 2021-08-26 11:00:30 +02:00
lcnr cc47998e28 add tcx to fn walk 2021-08-26 11:00:30 +02:00
lcnr bfaf13af4e make unevaluated const substs optional 2021-08-26 11:00:30 +02:00
lcnr f4b606fd17 require a tcx for TypeVisitor 2021-08-26 10:54:01 +02:00
Léo Lanteri Thauvin f2cbbb93a2
Rollup merge of #88218 - Aaron1011:missing-method-dyn, r=nagisa
Remove `Session.trait_methods_not_found`

Instead, avoid registering the problematic well-formed obligation
to begin with. This removes global untracked mutable state,
and avoids potential issues with incremental compilation.
2021-08-25 15:48:51 +02:00
Mara Bos 5cf025f076
Rollup merge of #88230 - steffahn:a_an, r=oli-obk
Fix typos “a”→“an”

Fix typos in comments; found using a regex to find some easy instance of incorrect usage of a vs. an.

While automation was used to find these, every change was checked manually.

Changes in submodules get separate PRs:
* https://github.com/rust-lang/stdarch/pull/1201
* https://github.com/rust-lang/cargo/pull/9821
* https://github.com/rust-lang/miri/pull/1874
* https://github.com/rust-lang/rls/pull/1746
* https://github.com/rust-analyzer/rust-analyzer/pull/9984
  _folks @ rust-analyzer are fast at merging…_
  * https://github.com/rust-analyzer/rust-analyzer/pull/9985
  * https://github.com/rust-analyzer/rust-analyzer/pull/9987
  * https://github.com/rust-analyzer/rust-analyzer/pull/9989

_For `clippy`, I don’t know if the changes should better better be moved to a PR to the original repo._

<hr>

This has some overlap with #88226, but neither is a strict superset of the other.

If you want multiple commits, I can split it up; in that case, make sure to suggest a criterion for splitting.
2021-08-23 20:45:49 +02:00
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
Frank Steffahn 2396fad095 Fix more “a”/“an” typos 2021-08-22 17:27:18 +02:00
Frank Steffahn bf88b113ea Fix typos “a”→“an” 2021-08-22 15:35:11 +02:00
Aaron Hill 41f9f38d6e
Remove Session.trait_methods_not_found
Instead, avoid registering the problematic well-formed obligation
to begin with. This removes global untracked mutable state,
and avoids potential issues with incremental compilation.
2021-08-21 20:45:11 -05: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
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
Jack Huey 6d5efa9f04 Add var to BoundRegion. Add query to get bound vars for applicable items. 2021-03-31 10:16:37 -04:00
Jack Huey 666859a6f8 Make late and late_anon regions track the bound var position 2021-03-31 10:15:56 -04:00
Jack Huey 62a49c3bb8 Add tcx lifetime to Binder 2021-03-31 10:13:57 -04:00
Jack Huey 4955d755d3 Some rebinds and dummys 2021-03-31 10:05:32 -04:00
Oli Scherer dbacfbc368 Add a new normalization query just for mir constants 2021-03-31 10:40:42 +00:00
Dylan DPC 7d888d100f
Rollup merge of #83654 - JohnTitor:issue-83606, r=estebank
Do not emit a suggestion that causes the E0632 error

Fixes #83606
2021-03-31 01:14:46 +02:00
JohnTitor 7e6fd40614 Do not emit a suggestion that causes the E0632 error 2021-03-30 03:00:25 +09:00
Joshua Nelson de0fda9558 Address review comments
- Add back `HirIdVec`, with a comment that it will soon be used.
- Add back `*_region` functions, with a comment they may soon be used.
- Remove `-Z borrowck_stats` completely. It didn't do anything.
- Remove `make_nop` completely.
- Add back `current_loc`, which is used by an out-of-tree tool.
- Fix style nits
- Remove `AtomicCell` with `cfg(parallel_compiler)` for consistency.
2021-03-27 22:16:34 -04:00
Joshua Nelson 441dc3640a Remove (lots of) dead code
Found with https://github.com/est31/warnalyzer.

Dubious changes:
- Is anyone else using rustc_apfloat? I feel weird completely deleting
  x87 support.
- Maybe some of the dead code in rustc_data_structures, in case someone
  wants to use it in the future?
- Don't change rustc_serialize

  I plan to scrap most of the json module in the near future (see
  https://github.com/rust-lang/compiler-team/issues/418) and fixing the
  tests needed more work than I expected.

TODO: check if any of the comments on the deleted code should be kept.
2021-03-27 22:16:33 -04:00
Dylan DPC b2e254318d
Rollup merge of #82917 - cuviper:iter-zip, r=m-ou-se
Add function core::iter::zip

This makes it a little easier to `zip` iterators:

```rust
for (x, y) in zip(xs, ys) {}
// vs.
for (x, y) in xs.into_iter().zip(ys) {}
```

You can `zip(&mut xs, &ys)` for the conventional `iter_mut()` and
`iter()`, respectively. This can also support arbitrary nesting, where
it's easier to see the item layout than with arbitrary `zip` chains:

```rust
for ((x, y), z) in zip(zip(xs, ys), zs) {}
for (x, (y, z)) in zip(xs, zip(ys, zs)) {}
// vs.
for ((x, y), z) in xs.into_iter().zip(ys).zip(xz) {}
for (x, (y, z)) in xs.into_iter().zip((ys.into_iter().zip(xz)) {}
```

It may also format more nicely, especially when the first iterator is a
longer chain of methods -- for example:

```rust
    iter::zip(
        trait_ref.substs.types().skip(1),
        impl_trait_ref.substs.types().skip(1),
    )
    // vs.
    trait_ref
        .substs
        .types()
        .skip(1)
        .zip(impl_trait_ref.substs.types().skip(1))
```

This replaces the tuple-pair `IntoIterator` in #78204.
There is prior art for the utility of this in [`itertools::zip`].

[`itertools::zip`]: https://docs.rs/itertools/0.10.0/itertools/fn.zip.html
2021-03-27 20:37:07 +01:00
Bastian Kauschke 42150fb8a1 combine: stop eagerly evaluating consts 2021-03-27 16:38:23 +01:00
Josh Stone 72ebebe474 Use iter::zip in compiler/ 2021-03-26 09:32:31 -07:00
kadmin 33370fd982 Update to not have extra match 2021-03-23 20:01:40 +00:00
kadmin 7116bb5c33 Update with comments 2021-03-23 17:16:20 +00:00
kadmin ea2af70466 Update with comments
A bunch of nits fixed, and a new test for pretty printing the AST.
2021-03-23 17:16:20 +00:00
varkor 8ef81388e2 Some refactoring 2021-03-23 17:16:20 +00:00
kadmin e4e5db4e42 Add has_default to GenericParamDefKind::Const
This currently creates a field which is always false on GenericParamDefKind for future use when
consts are permitted to have defaults

Update const_generics:default locations

Previously just ignored them, now actually do something about them.

Fix using type check instead of value

Add parsing

This adds all the necessary changes to lower const-generics defaults from parsing.

Change P<Expr> to AnonConst

This matches the arguments passed to instantiations of const generics, and makes it specific to
just anonymous constants.

Attempt to fix lowering bugs
2021-03-23 17:16:20 +00:00
bors 5d04957a4b Auto merge of #79278 - mark-i-m:stabilize-or-pattern, r=nikomatsakis
Stabilize or_patterns (RFC 2535, 2530, 2175)

closes #54883

This PR stabilizes the or_patterns feature in Rust 1.53.

This is blocked on the following (in order):
- [x] The crater run in https://github.com/rust-lang/rust/pull/78935#issuecomment-731564021
- [x] The resolution of the unresolved questions and a second crater run (https://github.com/rust-lang/rust/pull/78935#issuecomment-735412705)
    - It looks like we will need to pursue some sort of edition-based transition for `:pat`.
- [x] Nomination and discussion by T-lang
- [x] Implement new behavior for `:pat` based on consensus (https://github.com/rust-lang/rust/pull/80100).
- [ ] An FCP on stabilization

EDIT: Stabilization report is in https://github.com/rust-lang/rust/pull/79278#issuecomment-772815177
2021-03-22 19:48:27 +00:00
lcnr 7c9b5b4ce0 update const_eval_resolve 2021-03-20 17:22:24 +01:00
mark db5629adcb stabilize or_patterns 2021-03-19 19:45:32 -05:00
Vadim Petrochenkov 38ed36bba4 hir: Preserve used syntax in TyKind::TraitObject 2021-03-18 03:02:32 +03:00
Vadim Petrochenkov 7e66e9d6b0 More precise spans for HIR paths 2021-03-15 22:13:45 +03:00
Harald van Dijk 95e096d623
Change x64 size checks to not apply to x32.
Rust contains various size checks conditional on target_arch = "x86_64",
but these checks were never intended to apply to
x86_64-unknown-linux-gnux32. Add target_pointer_width = "64" to the
conditions.
2021-03-06 16:02:48 +00:00
Joshua Nelson 6873831139
Rollup merge of #82635 - pierwill:edit-infer, r=oli-obk
Fix typos in rustc_infer::infer::nll_relate
2021-03-01 11:25:10 -05:00
pierwill ebe798e31e Fix typos in rustc_infer::infer::nll_relate 2021-02-28 10:10:58 -08:00
Yuki Okushi 5091209750 Fix a typo in the find_anon_type doc 2021-02-28 23:10:55 +09:00
Dylan DPC f0c98b15cc
Rollup merge of #82370 - 0yoyoyo:update-issue-81650-point-anonymous-lifetime, r=estebank
Improve anonymous lifetime note to indicate the target span

Improvement for  #81650
Cc #81995

Message after this improvement:
(Improve note in the middle)

```
error[E0311]: the parameter type `T` may not live long enough
  --> src/main.rs:25:11
   |
24 | fn play_with<T: Animal + Send>(scope: &Scope, animal: T) {
   |              -- help: consider adding an explicit lifetime bound...: `T: 'a +`
25 |     scope.spawn(move |_| {
   |           ^^^^^
   |
note: the parameter type `T` must be valid for the anonymous lifetime defined on the function body at 24:40...
  --> src/main.rs:24:40
   |
24 | fn play_with<T: Animal + Send>(scope: &Scope, animal: T) {
   |                                        ^^^^^
note: ...so that the type `[closure@src/main.rs:25:17: 27:6]` will meet its required lifetime bounds
  --> src/main.rs:25:11
   |
25 |     scope.spawn(move |_| {
   |           ^^^^^
```

r? ``````@estebank``````
2021-02-27 02:34:22 +01:00
Nell Shamrell 356beb3084 clarifies error when finding mismatched returned types for async functions
Signed-off-by: Nell Shamrell <nellshamrell@gmail.com>
2021-02-24 18:46:54 -08:00
0yoyoyo ce1a521012 Apply tidy check 2021-02-21 22:51:49 +09:00
0yoyoyo 17176ccd78 Add indication of anonymous lifetime position 2021-02-21 18:38:20 +09:00
0yoyoyo fece59b56c Change find_anon_type method to function 2021-02-21 18:29:14 +09:00
Dylan DPC f468fd1d23
Rollup merge of #81496 - guswynn:expected_async_block, r=oli-obk
name async generators something more human friendly in type error diagnostic

fixes #81457

Some details:

1. I opted to load the generator kind from the hir in TyCategory. I also use 1 impl in the hir for the descr
2. I named both the source of the future, in addition to the general type (`future`), not sure what is preferred
3. I am not sure what is required to make sure "generator" is not referred to anywhere. A brief `rg "\"generator\"" showed me that most diagnostics correctly distinguish from generators and async generator, but the `descr` of `DefKind` is pretty general (not sure how thats used)
4. should the descr impl of AsyncGeneratorKind use its display impl instead of copying the string?
2021-02-19 02:49:00 +01:00
Dylan DPC 66211f6657
Rollup merge of #82066 - matthewjasper:trait-ref-fix, r=jackh726
Ensure valid TraitRefs are created for GATs

This fixes `ProjectionTy::trait_ref` to use the correct substs. Places that need all of the substs have been updated to not use `trait_ref`.

r? ````@jackh726````
2021-02-18 16:57:34 +01:00
Yuki Okushi ce6367f479
Rollup merge of #82240 - matthiaskrgr:qmark, r=Dylan-DPC
remove useless ?s (clippy::needless_question_marks)

Example code:
```rust
fn opts() -> Option<String> {
    let s: Option<String> = Some(String::new());
    Some(s?) // this can just be "s"
}
```
2021-02-18 15:57:33 +09:00
Dylan DPC cdd93fd3e2
Rollup merge of #81972 - matthewjasper:hrtb-error-cleanup, r=nikomatsakis
Placeholder lifetime error cleanup

- Remove note of trait definition
- Avoid repeating the same self type
- Use original region names when possible
- Use this error kind more often
- Print closure signatures when they are suppose to implement `Fn*` traits

Works towards #57374

r? ```@nikomatsakis```
2021-02-17 23:51:18 +01:00
Matthias Krüger f7b834831f remove useless ?s (clippy::needless_question_marks)
Example code:
```
fn opts() -> Option<String> {
    let s: Option<String> = Some(String::new());
    Some(s?) // this can just be "s"
}
```
2021-02-17 23:23:57 +01:00
bors 8fe989dd76 Auto merge of #81611 - cjgillot:meowner, r=estebank
Only store a LocalDefId in some HIR nodes

Some HIR nodes are guaranteed to be HIR owners: Item, TraitItem, ImplItem, ForeignItem and MacroDef.
As a consequence, we do not need to store the `HirId`'s `local_id`, and we can directly store a `LocalDefId`.

This allows to avoid a bit of the dance with `tcx.hir().local_def_id` and `tcx.hir().local_def_id_to_hir_id` mappings.
2021-02-16 22:14:32 +00:00
Guillaume Gomez 46b93b2e44
Rollup merge of #82163 - matthiaskrgr:slice, r=jyn514
avoid full-slicing slices

If we already have a slice, there is no need to get another full-range slice from that, just use the original.
clippy::redundant_slicing
2021-02-16 19:21:20 +01:00
Guillaume Gomez 73d6b603a7
Rollup merge of #82160 - pierwill:patch-2, r=lcnr
Fix typo in rustc_infer::infer::UndoLog

Also use double quotes.
2021-02-16 19:21:18 +01:00
Matthias Krüger 4390a61b64 avoid full-slicing slices
If we already have a slice, there is no need to get another full-range slice from that, just use the original.
clippy::redundant_slicing
2021-02-16 00:31:11 +01:00
Camille GILLOT 7dd1e8cfdf Trait impls are Items, therefore HIR owners. 2021-02-15 19:36:13 +01:00
Camille GILLOT 786a80e9ea Only store a LocalDefId in hir::ImplItem. 2021-02-15 19:32:29 +01:00
Camille GILLOT a871a0f111 Only store a LocalDefId in hir::TraitItem. 2021-02-15 19:32:28 +01:00
Camille GILLOT c676e358a5 Use ItemId as a strongly typed index. 2021-02-15 19:24:58 +01:00
pierwill f2f7ffecd7
Fix typo in rustc_infer::infer::UndoLog
Also use double quotes.
2021-02-15 10:02:03 -08:00
Gus Wynn c28d86c53b name async generators something more human friendly in type error diagnostics 2021-02-15 08:51:08 -08:00
Jonas Schievink 665bf9e35f
Rollup merge of #82067 - BoxyUwU:hahaicantthinkofabadpun, r=oli-obk
const_generics: Fix incorrect ty::ParamEnv::empty() usage

Fixes #80561

Not sure if I should keep the `debug!(..)`s or not but its the second time I've needed them so they sure seem useful lol

cc ``@lcnr``
r? ``@oli-obk``
2021-02-15 16:06:59 +01:00
klensy 93c8ebe022 bumped smallvec deps 2021-02-14 18:03:11 +03:00
Ellen 7bd71262f8 param_env debugs are instrumental to rustc's success 2021-02-14 11:18:40 +00:00
Matthew Jasper 0bf1d73d22 Don't go through TraitRef to relate projections 2021-02-13 19:30:07 +00:00
Ellen b6144e7a20 yeet ya fixme into the void 2021-02-13 19:10:08 +00:00
Ellen 68405fdc2e debug!("paramenv={}paramenv={}paramenv={}paramenv={}") 2021-02-13 19:10:08 +00:00
0yoyoyo 788e4bb4e5 Fix suggestion to introduce explicit lifetime 2021-02-12 00:48:44 +09:00