Commit graph

1397 commits

Author SHA1 Message Date
Esteban Kuber
e8fc076f23 Consider unfulfilled obligations in binop errors
When encountering a binop where the types would have been accepted, if
all the predicates had been fulfilled, include information about the
predicates and suggest appropriate `#[derive]`s if possible.

Point at trait(s) that needs to be `impl`emented.
2021-10-05 23:34:13 +00:00
Manish Goregaokar
04314a6061
Rollup merge of #89482 - hkmatsumoto:patch-diagnostics, r=joshtriplett
Follow the diagnostic output style guide

Detected by #89455.
2021-10-04 23:56:23 -07:00
Manish Goregaokar
87f782ede6
Rollup merge of #89423 - DevinR528:reachable-fields, r=Nadrieril
Fix ICE caused by non_exaustive_omitted_patterns struct lint

fixes #89382

Add check that a list of `Pat`s is non empty to prevent ICE in `FnCtxt::lint_non_exhaustive_omitted_patterns`.

Is related to #89374 and #89105
2021-10-04 23:56:20 -07:00
Jubilee
05b4cd6789
Rollup merge of #89413 - matthewjasper:spec-marker-fix, r=nikomatsakis
Correctly handle supertraits for min_specialization

Supertraits of specialization markers could circumvent checks for
min_specialization. Elaborating predicates prevents this.

r? ````@nikomatsakis````
2021-10-04 21:12:35 -07:00
Jubilee
4f6afee4e5
Rollup merge of #88090 - nbdd0121:inference, r=nikomatsakis
Perform type inference in range pattern

Fix #88074
2021-10-04 21:12:33 -07:00
Jubilee
2bc89ce0bf
Rollup merge of #89453 - waywardmonkeys:consistent-supertrait-usage, r=nagisa
Consistently use 'supertrait'.

A subset of places referred to 'super-trait', so this changes them
to all use 'supertrait'. This matches 'supertype' and some other
usages. An exception is 'auto-trait' which is consistently used
in that manner.
2021-10-04 13:58:14 -07:00
Jubilee
a2c6075dff
Rollup merge of #88451 - theo-lw:issue-87771, r=jackh726
Fix an ICE caused by type mismatch errors being ignored

This PR fixes #87771. It turns out that the check on `compiler/rustc_typeck/src/check/demand.rs:148` leads to the ICE. I removed it because the early return in [`check_expr_assign`](dec7fc3ced/compiler/rustc_typeck/src/check/expr.rs (L928)) already prevents unnecessary error messages from the call to `check_expr_coercable_to_type`.
2021-10-04 13:58:07 -07:00
bors
e737694a4d Auto merge of #88175 - camsteffen:let-desugar-span, r=Manishearth
Add expansion to while desugar spans

In the same vein as #88163, this reverts a change in Clippy behavior as a result of #80357 (and reverts some `#[allow]`s): This changes `clippy::blocks_in_if_conditions` to not fire on `while` loops. Though we might actually want Clippy to lint those cases, we should introduce the change purposefully, with tests, and possibly under a different lint name.

The actual change here is to add a desugaring expansion to the spans when lowering a `while` loop.

r? `@Manishearth`
2021-10-03 21:44:10 +00:00
Hirochika Matsumoto
fb0b1a5466 Follow the diagnostic output style guide 2021-10-03 14:28:39 +09:00
Cameron Steffen
eec856bfbc Make diangostic item names consistent 2021-10-02 19:38:19 -05:00
Cameron Steffen
67ea84d97a Add desugaring mark to while loop 2021-10-02 17:41:14 -05:00
Devin Ragotzy
b06409ebcd Rename etc -> has_rest_pat 2021-10-02 17:51:31 -04:00
Devin Ragotzy
f7a8980347 Reorder etc check for non_exhaustive_omitted_patterns 2021-10-02 17:50:53 -04:00
Devin Ragotzy
8cbcc893a6 Fix ICE caused by non_exaustive_omitted_patterns struct lint 2021-10-02 17:50:53 -04:00
bors
b27661eb33 Auto merge of #89405 - GuillaumeGomez:fix-clippy-lints, r=cjgillot
Fix clippy lints

I'm currently working on allowing clippy to run on librustdoc after a discussion I had with `@Mark-Simulacrum.` So in the meantime, I fixed a few lints on the compiler crates.
2021-10-02 10:52:09 +00:00
Bruce Mitchener
058a21d5cf Consistently use 'supertrait'.
A subset of places referred to 'super-trait', so this changes them
to all use 'supertrait'. This matches 'supertype' and some other
usages. An exception is 'auto-trait' which is consistently used
in that manner.
2021-10-02 08:05:44 +07:00
Guillaume Gomez
759eba0a08 Fix clippy lints 2021-10-01 23:17:19 +02:00
bors
c02371c442 Auto merge of #88880 - cjgillot:no-krate, r=oli-obk
Rework HIR API to make invocations of the hir_crate query harder.

`hir_crate` forces the recomputation of queries that depend on it.

This PR aims at avoiding useless invocations of `hir_crate` by making dependent code go through `tcx.hir()`.
2021-10-01 20:06:34 +00:00
Manish Goregaokar
1708219940
Rollup merge of #89029 - notriddle:notriddle/issue-89013, r=estebank
feat(rustc_parse): recover from pre-RFC-2000 const generics syntax

Fixes #89013
2021-10-01 09:18:17 -07:00
Manish Goregaokar
e77d163e82
Rollup merge of #89251 - estebank:negative-index-literals, r=davidtwco
Detect when negative literal indices are used and suggest appropriate code
2021-09-30 23:41:06 -07:00
Manish Goregaokar
b437be45ea
Rollup merge of #89202 - estebank:infer-call-type, r=oli-obk
Resolve infered types when complaining about unexpected call type

```
error[E0618]: expected function, found `{integer}`
  --> $DIR/call-block.rs:2:13
   |
LL |     let _ = {42}();
   |             ^^^^--
   |             |
   |             call expression requires function
```
instead of
```
error[E0618]: expected function, found `_`
  --> $DIR/call-block.rs:2:13
   |
LL |     let _ = {42}();
   |             ^^^^--
   |             |
   |             call expression requires function
```
2021-09-30 18:05:21 -07:00
Matthew Jasper
c8f86cad2d Elaborate predicates in min_specialization checks
Supertraits of specialization markers could circumvent checks for
min_specialization. Elaborating predicates prevents this.
2021-09-30 21:42:09 +01:00
bors
aa7aca3b95 Auto merge of #89282 - sexxi-goose:fix-88118, r=nikomatsakis
2229: Consume IfLet expr

When using the IfLet guard feature, we can ICE when attempting to resolve PlaceBuilders.
For pattern matching, we currently don't consume the IfLet expression when "visiting" the arms leading us to not "read" all variables and hence not being able to resolve them.

r? `@nikomatsakis`
Closes https://github.com/rust-lang/rust/issues/88118
2021-09-30 20:23:47 +00:00
bors
69c1c6a173 Auto merge of #89250 - Aaron1011:keep-bound-region-names, r=estebank
Don't anonymize bound region names during typeck

Once this anonymization has performed, we have no
way of recovering the original names during NLL
borrow checking. Keeping the original names allows
error messages in full NLL mode to contain the original
bound region names.

As a result, the typeck results may contain types that
differ only in the names used for their bound regions. However,
anonimization of bound regions does not guarantee that
all distinct types are unqual (e.g. not subtypes of each other).
For example, `for<'a> fn(&'a u32, &'a u32)` and
`for<'b, 'c> fn(&'b u32, &'c u32)` are subtypes of each other,
as explained here:

63cc2bb3d0/compiler/rustc_infer/src/infer/nll_relate/mod.rs (L682-L690)

Therefore, any code handling types with higher-ranked regions already
needs to handle the case where two distinct `Ty`s are 'actually'
equal.
2021-09-30 07:33:59 +00:00
Camille GILLOT
abc57f63ad Move body_owners to tcx.hir(). 2021-09-29 23:16:48 +02:00
Camille GILLOT
db9fea508a Avoid more invocations of hir_crate query. 2021-09-29 23:16:47 +02:00
bors
50f9f7810c Auto merge of #89331 - GuillaumeGomez:rollup-b10unye, r=GuillaumeGomez
Rollup of 8 pull requests

Successful merges:

 - #87260 (Libgccjit codegen)
 - #89212 (x.py: run `rustup toolchain link` in setup)
 - #89233 (Hide `<...> defined here` note if the source is not available)
 - #89235 (make junit output more consistent with default format)
 - #89255 (Fix incorrect disambiguation suggestion for associated items)
 - #89276 (Fix the population of the `union.impls` field)
 - #89283 (Add regression test for issue #83564)
 - #89318 (rustc_session: Remove lint store from `Session`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-09-29 10:39:41 +00:00
Michael Howell
105b60f250 feat(rustc_typeck): avoid erroring with "wrong number of generics" if there's other problems
As shown in the two test requirements that got updated, if there's other problems,
then those other problems are probably the root cause of the incorrect generics count.
2021-09-28 15:56:45 -07:00
Guillaume Gomez
48b5d110ae
Rollup merge of #89255 - FabianWolff:issue-88806, r=cjgillot
Fix incorrect disambiguation suggestion for associated items

Fixes #88806. I have not added a new test case, because the erroneous behavior is already present in existing test cases.
2021-09-28 20:00:16 +02:00
Guillaume Gomez
3c60e040b2
Rollup merge of #89233 - FabianWolff:issue-89159, r=estebank
Hide `<...> defined here` note if the source is not available

Fixes #89159. Similar to #87088.

r? ``@estebank``
2021-09-28 20:00:14 +02:00
Esteban Kuber
e19d82f1bf review comments 2021-09-28 16:13:39 +00:00
Oli Scherer
9b5aa063d8 More tracing instrumentation 2021-09-28 12:28:22 +00:00
Roxane
87010206ad 2229: Consume IfLet expr 2021-09-26 15:52:02 -04:00
Esteban Kuber
5c70f25f8c Detect when negative literal indices are used and suggest appropriate code 2021-09-26 16:52:10 +00:00
Fabian Wolff
3d08ff1c19 Fix incorrect disambiguation suggestion for associated items 2021-09-25 21:47:33 +02:00
Aaron Hill
78013f296a
Don't anonymize bound region names during typeck
Once this anonymization has performed, we have no
way of recovering the original names during NLL
borrow checking. Keeping the original names allows
error messages in full NLL mode to contain the original
bound region names.

As a result, the typeck results may contain types that
differ only in the names used for their bound regions. However,
anonimization of bound regions does not guarantee that
all distinct types are unqual (e.g. not subtypes of each other).
For example, `for<'a> fn(&'a u32, &'a u32)` and
`for<'b, 'c> fn(&'b u32, &'c u32)` are subtypes of each other,
as explained here:

63cc2bb3d0/compiler/rustc_infer/src/infer/nll_relate/mod.rs (L682-L690)

Therefore, any code handling types with higher-ranked regions already
needs to handle the case where two distinct `Ty`s are 'actually'
equal.
2021-09-25 13:04:00 -05:00
bors
6867dd2c01 Auto merge of #89230 - workingjubilee:rollup-1swktdq, r=workingjubilee
Rollup of 8 pull requests

Successful merges:

 - #88893 (Add 1.56.0 release notes)
 - #89001 (Be explicit about using Binder::dummy)
 - #89072 (Avoid a couple of Symbol::as_str calls in cg_llvm )
 - #89104 (Simplify scoped_thread)
 - #89208 ([rfc 2229] Drop fully captured upvars in the same order as the regular drop code)
 - #89210 (Add missing time complexities to linked_list.rs)
 - #89217 (Enable "generate-link-to-definition" option on rust tools docs as well)
 - #89221 (Give better error for `macro_rules! name!`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-09-25 00:20:28 +00:00
Fabian Wolff
911ced003a Hide <...> defined here note if the source is not available 2021-09-24 22:42:05 +02:00
Jubilee
7ade6ed48e
Rollup merge of #89208 - wesleywiser:rfc_2229_droporder, r=nikomatsakis
[rfc 2229] Drop fully captured upvars in the same order as the regular drop code

Currently, with the new 2021 edition, if a closure captures all of the
fields of an upvar, we'll drop those fields in the order they are used
within the closure instead of the normal drop order (the definition
order of the fields in the type).

This changes that so we sort the captured fields by the definition order
which causes them to drop in that same order as well.

Fixes rust-lang/project-rfc-2229#42

r? `@nikomatsakis`
2021-09-24 11:40:14 -07:00
Jubilee
ee2e97c416
Rollup merge of #89001 - jackh726:binder-cleanup, r=nikomatsakis
Be explicit about using Binder::dummy

This is somewhat of a late followup to the binder refactor PR. It removes `ToPredicate` and `ToPolyTraitImpls` that hide the use of `Binder::dummy`. While this does make code a bit more verbose, it allows us be more careful about where we create binders.

Another alternative here might be to add a new trait `ToBinder` or something with a `dummy()` fn. Which could still allow grepping but allows doing something like `trait_ref.dummy()` (but I also wonder if longer-term, it would be better to be even more explicit with a `bind_with_vars(ty::List::empty())` *but* that's not clear yet.

r? ``@nikomatsakis``
2021-09-24 11:40:11 -07:00
Fabian Wolff
cb6c13977a Make error message for malformed fn/fn_mut lang item more specific 2021-09-24 20:15:19 +02:00
Fabian Wolff
4337089098 Add basic checks for well-formedness of fn/fn_mut lang items 2021-09-24 18:26:27 +02:00
Wesley Wiser
389365631d Fix tidy and respond to some feedback 2021-09-23 22:15:12 -04:00
bors
293b8f2c11 Auto merge of #89211 - workingjubilee:rollup-fj4eduk, r=workingjubilee
Rollup of 7 pull requests

Successful merges:

 - #88612 (Add a better error message for #39364)
 - #89023 (Resolve issue : Somewhat confusing error with extended_key_value_attributes)
 - #89148 (Suggest `_` in turbofish if param will be inferred from fn argument)
 - #89171 (Run `no_core` rustdoc tests only on Linux)
 - #89176 (Change singular to plural)
 - #89184 (Temporarily rename int_roundings functions to avoid conflicts)
 - #89200 (Fix typo)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-09-24 01:48:02 +00:00
Jubilee
9e11d1cca4
Rollup merge of #89148 - estebank:used-type-param, r=oli-obk
Suggest `_` in turbofish if param will be inferred from fn argument
2021-09-23 17:31:43 -07:00
bors
900cf5e890 Auto merge of #88804 - Mark-Simulacrum:never-algo-v2, r=nikomatsakis,jackh726
Revise never type fallback algorithm

This is a rebase of https://github.com/rust-lang/rust/pull/84573, but dropping the stabilization of never type (and the accompanying large test diff).

Each commit builds & has tests updated alongside it, and could be reviewed in a more or less standalone fashion. But it may make more sense to review the PR as a whole, I'm not sure. It should be noted that tests being updated isn't really a good indicator of final behavior -- never_type_fallback is not enabled by default in this PR, so we can't really see the full effects of the commits here.

This combines the work by Niko, which is [documented in this gist](https://gist.github.com/nikomatsakis/7a07b265dc12f5c3b3bd0422018fa660), with some additional rules largely derived to target specific known patterns that regress with the algorithm solely derived by Niko. We build these from an intuition that:

* In general, fallback to `()` is *sound* in all cases
* But, in general, we *prefer* fallback to `!` as it accepts more code, particularly that written to intentionally use `!` (e.g., Result's with a Infallible/! variant).

When evaluating Niko's proposed algorithm, we find that there are certain cases where fallback to `!` leads to compilation failures in real-world code, and fallback to `()` fixes those errors. In order to allow for stabilization, we need to fix a good portion of these patterns.

The final rule set this PR proposes is that, by default, we fallback from `?T` to `!`, with the following exceptions:

1. `?T: Foo` and `Bar::Baz = ?T` and `(): Foo`, then fallback to `()`
2. Per [Niko's algorithm](https://gist.github.com/nikomatsakis/7a07b265dc12f5c3b3bd0422018fa660#proposal-fallback-chooses-between--and--based-on-the-coercion-graph), the "live" `?T` also fallback to `()`.

The first rule is necessary to address a fairly common pattern which boils down to something like the snippet below. Without rule 1, we do not see the closure's return type as needing a () fallback, which leads to compilation failure.

```rust
#![feature(never_type_fallback)]

trait Bar { }
impl Bar for () {  }
impl Bar for u32 {  }

fn foo<R: Bar>(_: impl Fn() -> R) {}

fn main() {
    foo(|| panic!());
}
```

r? `@jackh726`
2021-09-23 22:45:22 +00:00
Wesley Wiser
ab8aef40b1 Drop fully captured upvars in the same order as the regular drop code
Currently, with the new 2021 edition, if a closure captures all of the
fields of an upvar, we'll drop those fields in the order they are used
within the closure instead of the normal drop order (the definition
order of the fields in the type).

This changes that so we sort the captured fields by the definition order
which causes them to drop in that same order as well.

Fixes https://github.com/rust-lang/project-rfc-2229/issues/42
2021-09-23 18:01:32 -04:00
bors
2b862bed98 Auto merge of #89024 - oli-obk:lazy_tait_is_not_limited_to_being_used_in_return_position, r=nikomatsakis
Lazy TAIT preparation cleanups

Check that TAIT generics are fully generic in mir typeck instead of wf-check, as wf-check can by definition only check TAIT in return position and not account for TAITs defined in the body of the function

r? `@spastorino` `@nikomatsakis`
2021-09-23 19:38:30 +00:00
Esteban Kuber
affea730e9 Suggest _ in turbofish if param will be inferred from fn argument 2021-09-23 14:08:47 +00:00
Oli Scherer
6067eadb65 Check that TAIT generics are fully generic in mir typeck instead of wf-check, as wf-check can by definition only check TAIT in return position and not account for TAITs defined in the body of the function 2021-09-23 13:35:16 +00:00