Commit graph

1677 commits

Author SHA1 Message Date
Vadim Petrochenkov
90e371027e rustc_metadata: Encode list of all crate's traits into metadata 2021-12-28 19:31:51 +08:00
Matthias Krüger
bd77fbfef1
Rollup merge of #92112 - SparrowLii:issue92010, r=cjgillot
Fix the error of checking `base_expr` twice in type_changing_struct_update

Fixes #92010
2021-12-27 21:42:25 +01:00
Matthias Krüger
d8bf974df5
Rollup merge of #91544 - rukai:91492, r=wesleywiser
Fix duplicate derive clone suggestion

closes https://github.com/rust-lang/rust/issues/91492

The addition of:
```rust
derives.sort();
derives.dedup();
```
is what actually solves the problem.
The rest is just cleanup.

I want to improve the diagnostic message to provide the suggestion as a proper diff but ran into some problems, so I'll attempt that again in a follow up PR.
2021-12-23 00:28:51 +01:00
Michael Goulet
f83508592b Suggest glob-import if we need to import a trait, but it has no visible name 2021-12-20 19:50:15 -08:00
SparrowLii
5b2a7606ae Fix the error of checking base_expr twice in type_changing_struct_update 2021-12-20 10:21:07 +08:00
Nicholas Nethercote
f09b1facd0 Eliminate ObligationCauseData.
This makes `Obligation` two words bigger, but avoids allocating a lot of
the time.

I previously tried this in #73983 and it didn't help much, but local
timings look more promising now.
2021-12-20 09:29:20 +11:00
bors
a41a6925ba Auto merge of #91957 - nnethercote:rm-SymbolStr, r=oli-obk
Remove `SymbolStr`

This was originally proposed in https://github.com/rust-lang/rust/pull/74554#discussion_r466203544. As well as removing the icky `SymbolStr` type, it allows the removal of a lot of `&` and `*` occurrences.

Best reviewed one commit at a time.

r? `@oli-obk`
2021-12-19 09:31:37 +00:00
Matthias Krüger
a391d545cf
Rollup merge of #92022 - woodenarrow:br_expected_bool, r=estebank
Eliminate duplicate codes of expected_found_bool

The function expected_found_bool is the same as ExpectedFound::new. So use ExpectedFound::new to replace expected_found_bool to eliminate duplicate codes.

![image](https://user-images.githubusercontent.com/95843988/146486722-c910eccd-a36c-4dc5-8b36-214aab058e38.png)
2021-12-18 11:28:06 +01:00
Matthias Krüger
7a626cf7ce
Rollup merge of #89090 - cjgillot:bare-dyn, r=jackh726
Lint bare traits in AstConv.

Removing the lint from lowering allows to:
- make lowering querification easier;
- have the lint implementation in only one place.

r? `@estebank`
2021-12-18 08:16:26 +01:00
bors
dde825db46 Auto merge of #89841 - cormacrelf:let-else-typed, r=nagisa
Implement let-else type annotations natively

Tracking issue: #87335

Fixes #89688, fixes #89807, edit: fixes  #89960 as well

As explained in https://github.com/rust-lang/rust/issues/89688#issuecomment-940405082, the previous desugaring moved the let-else scrutinee into a dummy variable, which meant if you wanted to refer to it again in the else block, it had moved.

This introduces a new hir type, ~~`hir::LetExpr`~~ `hir::Let`, which takes over all the fields of `hir::ExprKind::Let(...)` and adds an optional type annotation. The `hir::Let` is then treated like a `hir::Local` when type checking a function body, specifically:

* `GatherLocalsVisitor` overrides a new `Visitor::visit_let_expr` and does pretty much exactly what it does for `visit_local`, assigning a local type to the `hir::Let` ~~(they could be deduplicated but they are right next to each other, so at least we know they're the same)~~
* It reuses the code in `check_decl_local` to typecheck the `hir::Let`, simply returning 'bool' for the expression type after doing that.

* ~~`FnCtxt::check_expr_let` passes this local type in to `demand_scrutinee_type`, and then imitates check_decl_local's pattern checking~~
* ~~`demand_scrutinee_type` (the blindest change for me, please give this extra scrutiny) uses this local type instead of of creating a new one~~
    * ~~Just realised the `check_expr_with_needs` was passing NoExpectation further down, need to pass the type there too. And apparently this Expectation API already exists.~~

Some other misc notes:

* ~~Is the clippy code supposed to be autoformatted? I tried not to give huge diffs but maybe some rustfmt changes simply haven't hit it yet.~~
* in `rustc_ast_lowering/src/block.rs`, I noticed some existing `self.alias_attrs()` calls in `LoweringContext::lower_stmts` seem to be copying attributes from the lowered locals/etc to the statements. Is that right? I'm new at this, I don't know.
2021-12-17 22:12:34 +00:00
lzh
a995462f9a Eliminate duplicate codes of expected_found_bool 2021-12-17 11:17:43 +08:00
bors
69ac533527 Auto merge of #86986 - lcnr:simplify_type, r=nikomatsakis,oli-obk
extend `simplify_type`

might cause a slight perf inprovement and imo more accurately represents what types there are.

considering that I was going to use this in #85048 it seems like we might need this in the future anyways 🤷
2021-12-15 22:32:56 +00:00
Matthias Krüger
d258e92900
Rollup merge of #90521 - jhpratt:stabilize-destructuring_assignment, r=jackh726,pnkfelix
Stabilize `destructuring_assignment`

Closes #71126

- [Stabilization report](https://github.com/rust-lang/rust/issues/71126#issuecomment-941148058)
- [Completed FCP](https://github.com/rust-lang/rust/issues/71126#issuecomment-954914819)

`@rustbot` label +F-destructuring-assignment +T-lang
Also needs +relnotes but I don't have permission to add that tag.
2021-12-15 08:36:19 +01:00
Nicholas Nethercote
b1c934ebb8 Remove unnecessary sigils around Ident::as_str() calls. 2021-12-15 17:32:42 +11:00
Nicholas Nethercote
056d48a2c9 Remove unnecessary sigils around Symbol::as_str() calls. 2021-12-15 17:32:14 +11:00
Jacob Pratt
d95f749f14
Stabilize destructuring_assignment 2021-12-14 22:38:51 -05:00
Nicholas Nethercote
8cddcd39ba Remove SymbolStr.
By changing `as_str()` to take `&self` instead of `self`, we can just
return `&str`. We're still lying about lifetimes, but it's a smaller lie
than before, where `SymbolStr` contained a (fake) `&'static str`!
2021-12-15 13:30:26 +11:00
Matthias Krüger
6abad4c438
Rollup merge of #91882 - Patrick-Poitras:remove-in-band-lifetimes-from-rustc-typeck, r=jackh726
Remove `in_band_lifetimes` from `rustc_typeck`

Joining in on the effort to remove the `in_band_lifetimes` features, as described in issue #91867.
2021-12-15 01:28:09 +01:00
Matthias Krüger
4e7497bda0
Rollup merge of #91881 - Patrick-Poitras:stabilize-iter-zip, r=scottmcm
Stabilize `iter::zip`

Hello all!

As the tracking issue (#83574) for `iter::zip` completed the final commenting period without any concerns being raised, I hereby submit this stabilization PR on the issue.

As the pull request that introduced the feature (#82917) states, the `iter::zip` function is a shorter way to zip two iterators. As it's generally a quality-of-life/ergonomic improvement, it has been integrated into the codebase without any trouble, and has been
used in many places across the rust compiler and standard library since March without any issues.

For more details, I would refer to `@cuviper's` original PR, or the [function's documentation](https://doc.rust-lang.org/std/iter/fn.zip.html).
2021-12-15 01:28:08 +01:00
Matthias Krüger
272188eecd
Rollup merge of #90939 - estebank:wg-af-polish, r=tmandry
Tweak errors coming from `for`-loop, `?` and `.await` desugaring

 * Suggest removal of `.await` on non-`Future` expression
 * Keep track of obligations introduced by desugaring
 * Remove span pointing at method for obligation errors coming from desugaring
 * Point at called local sync `fn` and suggest making it `async`

```
error[E0277]: `()` is not a future
  --> $DIR/unnecessary-await.rs:9:10
   |
LL |     boo().await;
   |     -----^^^^^^ `()` is not a future
   |     |
   |     this call returns `()`
   |
   = help: the trait `Future` is not implemented for `()`
help: do not `.await` the expression
   |
LL -     boo().await;
LL +     boo();
   |
help: alternatively, consider making `fn boo` asynchronous
   |
LL | async fn boo () {}
   | +++++
```

Fix #66731.
2021-12-15 01:28:04 +01:00
PFPoitras
304ede6bcc Stabilize iter::zip. 2021-12-14 18:50:31 -04:00
PFPoitras
a586e7d857 Make suggestions from @jackh726; run fmt 2021-12-14 09:26:57 -04:00
lcnr
dcd716fee2 extend simplify_type 2021-12-14 13:32:42 +01:00
PFPoitras
ae21dd00ac Remove in_band_lifetimes 2021-12-13 21:45:08 -04:00
Matthias Krüger
84878336b0
Rollup merge of #91849 - jackh726:gats-outlives-lint-part2, r=nikomatsakis
GATs outlives lint: Try to prove bounds

Fixes #91036
Fixes #90888
Fixes #91348 (better error + documentation to be added to linked issue)

Instead of checking for bounds directly, try to prove them in the associated type environment.

Also, add a bit of extra information to the error, including a link to the relevant discussion issue (#87479). That should be edited to include a brief summary of the current state of the outlives lint, including a brief background. It also might or might not be worth it to bump this to a full error code at some point.

r? ``@nikomatsakis``
2021-12-13 18:15:16 +01:00
Matthias Krüger
f8de2f56e8
Rollup merge of #91847 - BoxyUwU:generic_arg_infer_fixme, r=lcnr
Fix FIXME for `generic_arg_infer` in `create_substs_for_ast_path`

Fixes a FIXME, does some general refactoring of this fn, and also fixes a bug where we would use a const params defaults instead of an inference var ([playground](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=19456f65ea5dc3fcaa9b696f842ab380))
(lot of stuff in one PR but it was all so close together...)

r? `@lcnr`

Fixes #91614
2021-12-13 18:15:15 +01:00
Esteban Kuber
b825b0fe63 Fix rebase and clippy tests 2021-12-13 17:09:16 +00:00
Esteban Kuber
f640438b40 Keep info on pre-desugaring expression for better "incorrect .await" suggestion
Keep the `HirId` of `.await`ed expressions so in the case of a `fn` call
on on a sync `fn`, we can suggest maybe turning it into an `async fn`.
2021-12-13 17:09:16 +00:00
Esteban Kuber
d45e030c04 Fix mistake 2021-12-13 17:09:15 +00:00
Esteban Kuber
79749d64fa Remove yet more output from for-loop and ? errors 2021-12-13 17:09:15 +00:00
Esteban Kuber
81a3b90afd Further silence ? errors 2021-12-13 17:09:15 +00:00
Esteban Kuber
caf0c1bb1c Reduce verbosity for ? on non-Try expressions 2021-12-13 17:09:15 +00:00
Esteban Kuber
75b62757e4 Reduce verbosity when calling for-loop on non-Iterator expression 2021-12-13 17:09:15 +00:00
Esteban Kuber
7227a87371 When .await is called on a non-Future expression, suggest removal
Keep track of the origin of a `T: Future` obligation when caused by an
`.await` expression.

Address #66731.
2021-12-13 17:09:15 +00:00
Jack Huey
48974158f1 Adjust wording for review 2021-12-13 10:06:57 -05:00
Jack Huey
7cbd0dcf93 I wrote these functions, I should use them dang it 2021-12-13 01:10:39 -05:00
Jack Huey
8a28c172a1 Instead of checking for exact bounds, try to prove them 2021-12-13 00:48:46 -05:00
Ellen
5ab1329b58 hurray for portable simd finding a nice test for this FIXME 2021-12-13 03:16:00 +00:00
Cormac Relf
af2f0e6b7c let-else: add hir::Let and type check it like a hir::Local
unify typeck of hir::Local and hir::Let
remove extraneous pub(crate/super)
2021-12-13 14:02:19 +11:00
bors
22f8bde876 Auto merge of #91549 - fee1-dead:const_env, r=spastorino
Eliminate ConstnessAnd again

Closes #91489.
Closes #89432.

Reverts #91491.
Reverts #89450.

r? `@spastorino`
2021-12-12 22:15:32 +00:00
bors
753e569c9c Auto merge of #90207 - BoxyUwU:stabilise_cg_defaults, r=lcnr
Stabilise `feature(const_generics_defaults)`

`feature(const_generics_defaults)` is complete implementation wise and has a pretty extensive test suite so I think is ready for stabilisation.

needs stabilisation report and maybe an RFC 😅

r? `@lcnr`
cc `@rust-lang/project-const-generics`
2021-12-12 14:24:23 +00:00
Deadbeef
83587e8d30
Small performance tweaks 2021-12-12 12:35:01 +08:00
Deadbeef
84b1d859c8
Revert "Auto merge of #91491 - spastorino:revert-91354, r=oli-obk"
This reverts commit ff2439b7b9, reversing
changes made to 2a9e0831d6.
2021-12-12 12:34:46 +08:00
Deadbeef
5166f68754
Fix #91489 2021-12-12 12:09:27 +08:00
bors
229d0a9412 Auto merge of #91769 - estebank:type-trait-bound-span-2, r=oli-obk
Tweak assoc type obligation spans

* Point at RHS of associated type in obligation span
* Point at `impl` assoc type on projection error
* Reduce verbosity of recursive obligations
* Point at source of binding lifetime obligation
* Tweak "required bound" note
* Tweak "expected... found opaque (return) type" labels
* Point at set type in impl assoc type WF errors

r? `@oli-obk`

This is a(n uncontroversial) subset of #85799.
2021-12-11 21:57:19 +00:00
Matthias Krüger
7083f8edfd
Rollup merge of #91640 - cjgillot:in-band-collect, r=oli-obk
Simplify collection of in-band lifetimes

Split from https://github.com/rust-lang/rust/pull/91403

r? ````@oli-obk````
2021-12-11 16:02:46 +01:00
Esteban Kuber
5e1972eba7 Tweak assoc type obligation spans
* Point at RHS of associated type in obligation span
* Point at `impl` assoc type on projection error
* Reduce verbosity of recursive obligations
* Point at source of binding lifetime obligation
* Tweak "required bound" note
* Tweak "expected... found opaque (return) type" labels
* Point at set type in impl assoc type WF errors
2021-12-11 02:32:15 +00:00
Matthias Krüger
40988591ec
Rollup merge of #91625 - est31:remove_indexes, r=oli-obk
Remove redundant [..]s
2021-12-10 22:40:36 +01:00
Ellen
69d2d735bc remove feature gate and cleanup code 2021-12-10 19:20:31 +00:00
bors
e250777041 Auto merge of #91691 - matthiaskrgr:rollup-wfommdr, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #91042 (Use Vec extend instead of repeated pushes on several places)
 - #91476 (Improve 'cannot contain emoji' error.)
 - #91568 (Pretty print break and continue without redundant space)
 - #91645 (Implement `core::future::join!`)
 - #91666 (update Miri)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-12-09 04:04:01 +00:00