Commit graph

1104 commits

Author SHA1 Message Date
bors
d488de82f3 Auto merge of #87587 - oli-obk:lazy_tait, r=spastorino
Various refactorings of the TAIT infrastructure

Before this PR we used to store the opaque type knowledge outside the `InferCtxt`, so it got recomputed on every opaque type instantiation.

I also removed a feature gate check that makes no sense in the planned lazy TAIT resolution scheme

Each commit passes all tests, so this PR is best reviewed commit by commit.

r? `@spastorino`
2021-08-11 05:14:45 +00:00
Yuki Okushi
4be63b2b5c
Rollup merge of #87895 - TheWastl:issue-87872, r=estebank
typeck: don't suggest inaccessible fields in struct literals and suggest ignoring inaccessible fields in struct patterns

Fixes #87872.

This PR adjusts the missing field diagnostic logic in typeck so that when any of the missing fields in a struct literal or pattern is inaccessible then the error is less confusing, even if some of the missing fields are accessible.

See also #76524.
2021-08-11 04:18:47 +09:00
Yuki Okushi
4d4915ae48
Rollup merge of #87889 - estebank:method-call-disambiguate, r=oli-obk
Use smaller spans when suggesting method call disambiguation

Use smaller spans when suggesting method call disambiguation.
2021-08-11 04:18:46 +09:00
Yuki Okushi
6c92656624
Rollup merge of #87854 - BoxyUwU:var-None, r=oli-obk
correctly handle enum variants in `opt_const_param_of`

Fixes #87542

`opt_const_param_of` was returning `None` for args on an enum variant `Enum::Variant::<10>` because we called `generics_of` on the enum variant which has no generics.

r? `@oli-obk`
2021-08-11 04:18:39 +09:00
TheWastl
cda6ecfc3d typeck: better diagnostics for missing inaccessible fields in struct literals/patterns
- typeck/expr: don't suggest adding fields in struct literals with inaccessible fields
- typeck/pat: suggest ignoring inaccessible fields in struct patterns
2021-08-10 16:18:37 +02:00
Esteban Kuber
f3021b3561 Use smaller spans when suggesting method call disambiguation 2021-08-09 16:47:09 +00:00
bors
d3928b183d Auto merge of #87465 - audunhalland:refactor_typeck_primary_body_of, r=eddyb
Simplify typeck/primary_body_of, fix comment to match return signature

Hi, new contributor here! I'm carefully reading through the various modules just to learn. I noticed this function, `primary_body_of`, which has gone through a couple of refactors over time, adding new `Option`s to its returned tuple. Observations:

1. the `fn`'s documentation was not all up to date with the the current return signature.
2. `FnHeader` and `FnDecl` are always both `Some` or `None`. So I figured it might just return a reference to the full `hir::FnSig`, for simplicity and more precise typing. It's a pure refactor.

I'm learning better by working with code than just reading it, so here goes! If you want to avoid pure refactor PRs that don't really fix anything, I can revert the code change to only update the comment instead.
2021-08-09 01:08:52 +00:00
bors
442e627bee Auto merge of #87697 - GuillaumeGomez:add-e0784, r=nagisa
Assign E0784 error code for union expression errors
2021-08-08 16:40:14 +00:00
Ellen
5f61271e38 fmt 2021-08-07 20:55:37 +01:00
Ellen
d777cb84e2 less opt in const param of 2021-08-07 18:44:36 +01: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
20371b94f6 Immediately register new opaque types in the global list.
Previously each opaque type instantiation would create new inference vars, even for the same opaque type/substs combination. Now there is a global map in InferCtxt that gets filled whenever we encounter an opaque type.
2021-08-06 10:39:08 +00:00
Oli Scherer
c091b5c84c Remove a useless feature gateing
With the planned lazy TAIT system, this will not really make sense anymore anyway.
2021-08-06 10:25:18 +00:00
Oli Scherer
d99805982b Move opaque type cache into InferCtxt 2021-08-06 10:12:31 +00:00
bors
1f94abcda6 Auto merge of #87808 - JohnTitor:rollup-qqp79xs, r=JohnTitor
Rollup of 9 pull requests

Successful merges:

 - #87561 (thread set_name haiku implementation.)
 - #87715 (Add long error explanation for E0625)
 - #87727 (explicit_generic_args_with_impl_trait: fix min expected number of generics)
 - #87742 (Validate FFI-safety warnings on naked functions)
 - #87756 (Add back -Zno-profiler-runtime)
 - #87759 (Re-use std::sealed::Sealed in os/linux/process.)
 - #87760 (Promote `aarch64-apple-ios-sim` to Tier 2)
 - #87770 (permit drop impls with generic constants in where clauses)
 - #87780 (alloc: Use intra doc links for the reserve function)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-08-06 05:02:35 +00:00
Yuki Okushi
8bad35095b
Rollup merge of #87770 - BoxyUwU:cec-drop-impl, r=lcnr
permit drop impls with generic constants in where clauses

Fixes #79248

`==` is not sufficient to check for equality between unevaluated consts which causes the above issue because the const in `[(); N - 1]:` on the impl and the const in `[(); N - 1]:` on the struct def are not seen as equal. Any predicate that can contain an unevaluated const cant use `==` here as it will cause us to incorrectly emit an error.

I dont know much about chalk but it seems like we ought to be relating the `TypeWellFormedFromEnv` instead of `==` as it contains a `Ty` so I added that too...

r? ``````@lcnr``````
2021-08-06 11:21:35 +09:00
Yuki Okushi
5b43960687
Rollup merge of #87727 - SkiFire13:fix-87718, r=jackh726
explicit_generic_args_with_impl_trait: fix min expected number of generics

Fixes #87718

The problem was that `synth_type_param_count` was already subtracted from `named_type_param_count`, so this ended up being subtracted again. This caused `expected_min` to overflow, and ultimately resulting in weird and wrong behaviour.

I've also added another test not present in the original issue but caused by the same bug.
2021-08-06 11:21:30 +09:00
bors
7129033b42 Auto merge of #87462 - ibraheemdev:tidy-file-length-ignore-comment, r=Mark-Simulacrum
Ignore comments in tidy-filelength

Ref https://github.com/rust-lang/rust/issues/60302#issuecomment-652402127
2021-08-06 02:07:01 +00:00
Ellen
fa46715002 remove tywf relation 2021-08-05 03:09:01 +01:00
bors
25b7648496 Auto merge of #86155 - alexcrichton:abort-on-unwind, r=nikomatsakis
rustc: Fill out remaining parts of C-unwind ABI

This commit intends to fill out some of the remaining pieces of the
C-unwind ABI. This has a number of other changes with it though to move
this design space forward a bit. Notably contained within here is:

* On `panic=unwind`, the `extern "C"` ABI is now considered as "may
  unwind". This fixes a longstanding soundness issue where if you
  `panic!()` in an `extern "C"` function defined in Rust that's actually
  UB because the LLVM representation for the function has the `nounwind`
  attribute, but then you unwind.

* Whether or not a function unwinds now mainly considers the ABI of the
  function instead of first checking the panic strategy. This fixes a
  miscompile of `extern "C-unwind"` with `panic=abort` because that ABI
  can still unwind.

* The aborting stub for non-unwinding ABIs with `panic=unwind` has been
  reimplemented. Previously this was done as a small tweak during MIR
  generation, but this has been moved to a separate and dedicated MIR
  pass. This new pass will, for appropriate functions and function
  calls, insert a `cleanup` landing pad for any function call that may
  unwind within a function that is itself not allowed to unwind. Note
  that this subtly changes some behavior from before where previously on
  an unwind which was caught-to-abort it would run active destructors in
  the function, and now it simply immediately aborts the process.

* The `#[unwind]` attribute has been removed and all users in tests and
  such are now using `C-unwind` and `#![feature(c_unwind)]`.

I think this is largely the last piece of the RFC to implement.
Unfortunately I believe this is still not stabilizable as-is because
activating the feature gate changes the behavior of the existing `extern
"C"` ABI in a way that has no replacement. My thinking for how to enable
this is that we add support for the `C-unwind` ABI on stable Rust first,
and then after it hits stable we change the behavior of the `C` ABI.
That way anyone straddling stable/beta/nightly can switch to `C-unwind`
safely.
2021-08-04 21:09:53 +00:00
Ellen
b1d14ef08f dropck 2021-08-04 18:30:54 +01:00
Alex Crichton
1c07096a45 rustc: Fill out remaining parts of C-unwind ABI
This commit intends to fill out some of the remaining pieces of the
C-unwind ABI. This has a number of other changes with it though to move
this design space forward a bit. Notably contained within here is:

* On `panic=unwind`, the `extern "C"` ABI is now considered as "may
  unwind". This fixes a longstanding soundness issue where if you
  `panic!()` in an `extern "C"` function defined in Rust that's actually
  UB because the LLVM representation for the function has the `nounwind`
  attribute, but then you unwind.

* Whether or not a function unwinds now mainly considers the ABI of the
  function instead of first checking the panic strategy. This fixes a
  miscompile of `extern "C-unwind"` with `panic=abort` because that ABI
  can still unwind.

* The aborting stub for non-unwinding ABIs with `panic=unwind` has been
  reimplemented. Previously this was done as a small tweak during MIR
  generation, but this has been moved to a separate and dedicated MIR
  pass. This new pass will, for appropriate functions and function
  calls, insert a `cleanup` landing pad for any function call that may
  unwind within a function that is itself not allowed to unwind. Note
  that this subtly changes some behavior from before where previously on
  an unwind which was caught-to-abort it would run active destructors in
  the function, and now it simply immediately aborts the process.

* The `#[unwind]` attribute has been removed and all users in tests and
  such are now using `C-unwind` and `#![feature(c_unwind)]`.

I think this is largely the last piece of the RFC to implement.
Unfortunately I believe this is still not stabilizable as-is because
activating the feature gate changes the behavior of the existing `extern
"C"` ABI in a way that has no replacement. My thinking for how to enable
this is that we add support for the `C-unwind` ABI on stable Rust first,
and then after it hits stable we change the behavior of the `C` ABI.
That way anyone straddling stable/beta/nightly can switch to `C-unwind`
safely.
2021-08-03 07:06:19 -07:00
bors
d5fd37f00f Auto merge of #86338 - JohnTitor:issue-86162, r=estebank
Do not suggest impl traits as type arguments

Fixes #86162
2021-08-03 13:23:31 +00:00
Giacomo Stevanato
2fd874d0d5 Fix overflow when calculating expected_min in generics diagnostics 2021-08-03 13:18:06 +02:00
Yuki Okushi
b84d08d1e4
Use has_impl_trait where possible 2021-08-03 20:08:16 +09:00
bors
2939249f29 Auto merge of #87725 - JohnTitor:rollup-2ywcpuk, r=JohnTitor
Rollup of 8 pull requests

Successful merges:

 - #87645 (Properly find owner of closure in THIR unsafeck)
 - #87646 (Fix a parser ICE on invalid `fn` body)
 - #87652 (Validate that naked functions are never inlined)
 - #87685 (Write docs for SyncOnceCell From and Default impl)
 - #87693 (Add `aarch64-apple-ios-sim` as a possible target to the manifest)
 - #87708 (Add convenience method for handling ipv4-mapped addresses by canonicalizing them)
 - #87711 (Correct typo)
 - #87716 (Allow generic SIMD array element type)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-08-03 10:42:30 +00:00
bors
3354a44d2f Auto merge of #87033 - FabianWolff:issue-87017, r=estebank
Provide a suggestion when trying to destructure a `Vec` as a slice

Fixes #87017.

r? `@estebank`
2021-08-03 08:00:30 +00:00
Caleb Zulawski
b23de51dcb Allow generic SIMD array element type 2021-08-03 03:33:09 +00:00
Guillaume Gomez
c364a4e30f Assign E0784 to union expression error 2021-08-02 16:51:39 +02:00
Cameron Steffen
87a99c5949
Rollup merge of #87687 - camsteffen:inline-macros, r=oli-obk
Inline some macros

I factored out some macros that are not really necessary.
2021-08-02 09:36:54 -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
bors
b53a93db2d Auto merge of #87535 - lf-:authors, r=Mark-Simulacrum
rfc3052 followup: Remove authors field from Cargo manifests

Since RFC 3052 soft deprecated the authors field, 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 for contributors, we may as well
remove it from crates in this repo.
2021-08-02 05:49:17 +00: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
Cameron Steffen
8746b79a38 Inline create_maybe_get_coercion_reason macro 2021-08-01 17:46:23 -05:00
bors
aadd6189ad Auto merge of #87449 - matthiaskrgr:clippyy_v2, r=nagisa
more clippy::complexity fixes

(also a couple of clippy::perf fixes)
2021-08-01 09:15:15 +00:00
Fabian Wolff
c29aadd9cf Provide a suggestion when trying to destructure a Vec as a slice 2021-07-31 21:47:36 +02:00
bors
7069a8c2b7 Auto merge of #86264 - crlf0710:trait_upcasting_part1, r=nikomatsakis
Trait upcasting coercion (part1)

This revives the first part of earlier PR #60900 .

It's not very clear to me which parts of that pr was design decisions, so i decide to cut it into pieces and land them incrementally. This allows more eyes on the details.

This is the first part, it adds feature gates, adds feature gates tests, and implemented the unsize conversion part.
(I hope i have dealt with the `ExistentialTraitRef` values correctly...)

The next part will be implementing the pointer casting.
2021-07-31 07:46:14 +00:00
bors
199d1aebe4 Auto merge of #86754 - estebank:use-multispans-more, r=varkor
Use `multipart_suggestions` more

Built on top of #86532
2021-07-30 23:18:12 +00:00
bors
1f0a591b3a Auto merge of #87640 - JohnTitor:rollup-yq24nq5, r=JohnTitor
Rollup of 9 pull requests

Successful merges:

 - #86072 (Cross compiling rustc_llvm on Darwin requires zlib.)
 - #87385 (Make `SEMICOLON_IN_EXPRESSIONS_FROM_MACROS` warn by default)
 - #87547 (Add missing examples for NonNull)
 - #87557 (Fix issue with autofix for ambiguous associated function from Rust 2021 prelude when struct is generic)
 - #87559 (Tweak borrowing suggestion in `for` loop)
 - #87596 (Add warning when whitespace is not skipped after an escaped newline)
 - #87606 (Add some TAIT-related regression tests)
 - #87609 (Add docs about performance and `Iterator::map` to `[T; N]::map`)
 - #87616 (Fix missing word in rustdoc book)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-07-30 19:45:55 +00:00
Yuki Okushi
fb27c4cc70
Rollup merge of #87557 - rylev:fix-invalid-prelude-collision-error, r=nikomatsakis
Fix issue with autofix for ambiguous associated function from Rust 2021 prelude when struct is generic

Fixes #86940

The test cases and associated issue should make it clear what specifically this is meant to fix. The fix is slightly hacky in that we check against the literal source code of the call site for the presence of `<` in order to determine if the user has included the generics for the struct (meaning we don't need to include them for them).

r? ``@nikomatsakis``
2021-07-31 04:09:29 +09:00
bors
ef9549b6c0 Auto merge of #87421 - estebank:perf-run, r=oli-obk
Do not discard `?Sized` type params and suggest their removal
2021-07-30 17:18:50 +00:00
Charles Lew
fb4e0a0972 Implement trait upcasting coercion type-checking. 2021-07-31 00:51:39 +08:00
Esteban Küber
0b8f192cfe Use multispan suggestions more often
* Use more accurate span for `async move` suggestion
* Use more accurate span for deref suggestion
* Use `multipart_suggestion` more often
2021-07-30 09:26:31 -07:00
Esteban Küber
15a40c7ee8 Do not discard ?Sized type params and suggest their removal 2021-07-30 08:44:31 -07:00
Ryan Levick
578fcbdb3c Fix error with suggestion for how to disambiguate associated function when struct is generic 2021-07-30 17:18:43 +02:00
bors
f3f8e758f2 Auto merge of #85971 - FabianWolff:issue-85586, r=davidtwco
Use more precise span for E0282 in cast expressions

This pull request fixes #85586. The example code given there:
```rust
fn main() {
    let a = [1, 2, 3].iter().sum();
    let b = (a + 1) as usize;
}
```
currently produces
```
error[E0282]: type annotations needed
 --> issue-85586.rs:3:13
  |
3 |     let b = (a + 1) as usize;
  |             ^^^^^^^^^^^^^^^^ cannot infer type
  |
  = note: type must be known at this point

error: aborting due to previous error
```
even though the type of the entire cast expression quite clearly should be `usize`. The error is in the cast's left-hand side, which is made explicit by the changes in this PR:
```
error[E0282]: type annotations needed
 --> issue-85586.rs:3:13
  |
3 |     let b = (a + 1) as usize;
  |             ^^^^^^^ cannot infer type
  |
  = note: type must be known at this point

error: aborting due to previous error
```
2021-07-30 14:38:00 +00:00
Yuki Okushi
aaef1a1649
Rollup merge of #87554 - sexxi-goose:fix-issue-87426, r=nikomatsakis
2229: Discr should be read when PatKind is Range

This PR fixes an issue related to pattern matching in closures when Edition 2021 is enabled.

- If any of the patterns the discr is being matched on is `PatKind::Range` then the discr should be read

r? ```@nikomatsakis```

Closes https://github.com/rust-lang/rust/issues/87426
2021-07-30 16:26:55 +09: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
Roxane
d380ed1304 fix nit 2021-07-28 12:27:57 -04:00
Roxane
9829efb892 Range PatKind implies discr should be read 2021-07-28 10:52:39 -04:00