Commit graph

198 commits

Author SHA1 Message Date
surechen 0f5bfc2242 Correct fmt 2021-07-21 12:01:03 +08:00
surechen 7af840f62e Simplify the collecting of ? Trait bounds in where clause 2021-07-21 11:35:06 +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
Santiago Pastorino 3e857f5743
Improve impl trait disallowed context error text 2021-07-19 10:19:58 -03:00
Santiago Pastorino e8c04b4386
Remove impl_trait_in_bindings feature flag 2021-07-18 09:30:11 -03:00
Santiago Pastorino c34fb5167e
Remove origin field from TypeAliasesOpaqueTy 2021-07-18 09:30:10 -03:00
Santiago Pastorino 000b945cea
Remove OpaqueTyOrigin::Misc, use TyAlias instead 2021-07-18 09:30:10 -03:00
Santiago Pastorino 4d2d90307d
Remove impl trait bindings handling on const AST lowering 2021-07-18 09:30:07 -03:00
Santiago Pastorino bc106ebb5a
Remove impl traits bindings error message handling on AST lowering 2021-07-17 23:14:23 -03:00
Santiago Pastorino ac3a43b316
Fix TypeAliasesOpaqueTy origin docs 2021-07-17 23:14:23 -03:00
Santiago Pastorino 13287d8dd2
Rename OtherOpaqueTy to TypeAliasesOpaqueTy 2021-07-17 23:14:22 -03:00
Santiago Pastorino 66c9cd9e66
Remove OpaqueTyOrigin::Binding 2021-07-17 23:14:22 -03:00
Cameron Steffen 1537cd4fb1 Remove refs from pat slices 2021-07-15 16:09:57 -05:00
Camille GILLOT 616ce3c5c0 Cache expansion hash. 2021-07-13 23:10:56 +02:00
bors 99f8efec46 Auto merge of #86416 - Amanieu:asm_clobber_only, r=nagisa
Add clobber-only register classes for asm!

These are needed to properly express a function call ABI using a clobber
list, even though we don't support passing actual values into/out of
these registers.
2021-07-11 01:06:58 +00:00
Amanieu d'Antras e1c3f5e017 Add clobber-only register classes for asm!
These are needed to properly express a function call ABI using a clobber
list, even though we don't support passing actual values into/out of
these registers.
2021-07-10 17:29:00 +02:00
Scott McMurray 099a357e5c Update the comment on lower_expr_try
I'd updated the ones inside the method, but not its doc comment.
2021-07-09 00:13:44 -07:00
Camille GILLOT c520cf2253 Arena-allocate Crate during lowering. 2021-06-30 20:31:56 +02:00
bors 607d6b00d4 Auto merge of #86321 - JohnTitor:rollup-q61c8q4, r=JohnTitor
Rollup of 10 pull requests

Successful merges:

 - #80269 (Explain non-dropped sender recv in docs)
 - #82179 (Add functions `Duration::try_from_secs_{f32, f64}`)
 - #85608 (Stabilize `ops::ControlFlow` (just the type))
 - #85792 (Refactor windows sockets impl methods)
 - #86220 (Improve maybe_uninit_extra docs)
 - #86277 (Remove must_use from ALLOWED_ATTRIBUTES)
 - #86285 (⬆️ rust-analyzer)
 - #86294 (Stabilize {std, core}::prelude::rust_*.)
 - #86306 (Add mailmap entries for myself)
 - #86314 (Remove trailing triple backticks in `mut_keyword` docs)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-06-15 20:15:23 +00:00
Yuki Okushi 5936ecc24f
Rollup merge of #85608 - scottmcm:stabilize-control-flow-enum-basics, r=m-ou-se
Stabilize `ops::ControlFlow` (just the type)

Tracking issue: https://github.com/rust-lang/rust/issues/75744 (which also tracks items *not* closed by this PR).

With the new `?` desugar implemented, [it's no longer possible to mix `Result` and `ControlFlow`](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=13feec97f5c96a9d791d97f7de2d49a6).  (At the time of making this PR, godbolt was still on the 2021-05-01 nightly, where you can see that [the mixing example compiled](https://rust.godbolt.org/z/13Ke54j16).)  That resolves the only blocker I know of, so I'd like to propose that `ControlFlow` be considered for stabilization.

Its basic existence was part of https://github.com/rust-lang/rfcs/pull/3058, where it got a bunch of positive comments (examples [1](https://github.com/rust-lang/rfcs/pull/3058#issuecomment-758277325) [2](https://github.com/rust-lang/rfcs/pull/3058#pullrequestreview-592106494) [3](https://github.com/rust-lang/rfcs/pull/3058#issuecomment-784444155) [4](https://github.com/rust-lang/rfcs/pull/3058#issuecomment-797031584)).  Its use in the compiler has been well received (https://github.com/rust-lang/rust/pull/78182#issuecomment-713695594), and there are ecosystem updates interested in using it (https://github.com/rust-itertools/itertools/issues/469#issuecomment-677729589, https://github.com/jonhoo/rust-imap/issues/194).

As this will need an FCP, picking a libs member manually:
r? `@m-ou-se`

## Stabilized APIs

```rust
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum ControlFlow<B, C = ()> {
    /// Exit the operation without running subsequent phases.
    Break(B),
    /// Move on to the next phase of the operation as normal.
    Continue(C),
}
```

As well as using `?` on a `ControlFlow<B, _>` in a function returning `ControlFlow<B, _>`.  (Note, in particular, that there's no `From::from`-conversion on the `Break` value, the way there is for `Err`s.)

## Existing APIs *not* stabilized here

All the associated methods and constants: `break_value`, `is_continue`, `map_break`, [`CONTINUE`](https://doc.rust-lang.org/nightly/std/ops/enum.ControlFlow.html#associatedconstant.CONTINUE), etc.

Some of the existing methods in nightly seem reasonable, some seem like they should be removed, and some need more discussion to decide.  But none of them are *essential*, so [as in the RFC](https://rust-lang.github.io/rfcs/3058-try-trait-v2.html#methods-on-controlflow), they're all omitted from this PR.

They can be considered separately later, as further usage demonstrates which are important.
2021-06-15 17:40:08 +09:00
LeSeulArtichaut e3ca81fd5a Use the now available implementation of IntoIterator for arrays 2021-06-14 23:40:09 +02:00
Ryan Levick 6936349233 Add support for using qualified paths with structs in expression and pattern
position.
2021-06-10 13:18:41 +02:00
Camille GILLOT 0839cd5e9a Rename take_trait_map. 2021-06-01 20:53:04 +02:00
Camille GILLOT 273778086c Remove StableVec. 2021-06-01 20:53:04 +02:00
Camille GILLOT e291be3649 Only compute the trait_map once. 2021-06-01 20:43:50 +02:00
Camille Gillot 0f0f3138cb
Revert "Reduce the amount of untracked state in TyCtxt" 2021-06-01 09:05:22 +02:00
Camille GILLOT 2b6daf9e14 Rename take_trait_map. 2021-05-30 20:07:25 +02:00
Camille GILLOT ee567fe1b1 Remove StableVec. 2021-05-30 19:54:21 +02:00
Camille GILLOT 139f7ad637 Only compute the trait_map once. 2021-05-30 19:37:53 +02:00
Pietro Albini 9e22b844dd remove cfg(bootstrap) 2021-05-24 11:07:48 -04:00
Scott McMurray 65a0a8b386 Stabilize ops::ControlFlow (just the type) 2021-05-23 13:20:05 -07:00
bors 4e3e6db011 Auto merge of #84767 - scottmcm:try_trait_actual, r=lcnr
Implement the new desugaring from `try_trait_v2`

~~Currently blocked on https://github.com/rust-lang/rust/issues/84782, which has a PR in https://github.com/rust-lang/rust/pull/84811~~ Rebased atop that fix.

`try_trait_v2` tracking issue: https://github.com/rust-lang/rust/issues/84277

Unfortunately this is already touching a ton of things, so if you have suggestions for good ways to split it up, I'd be happy to hear them.  (The combination between the use in the library, the compiler changes, the corresponding diagnostic differences, even MIR tests mean that I don't really have a great plan for it other than trying to have decently-readable commits.

r? `@ghost`

~~(This probably shouldn't go in during the last week before the fork anyway.)~~ Fork happened.
2021-05-18 20:50:01 +00:00
jedel1043 059b68dd67 Implement Anonymous{Struct, Union} in the AST
Add unnamed_fields feature gate and gate unnamed fields on parsing
2021-05-16 09:49:16 -05:00
Amanieu d'Antras bb6bec1d55 Clarify error message when both asm! and global_asm! are unsupported 2021-05-13 22:31:58 +01:00
Amanieu d'Antras 5918ee4317 Add support for const operands and options to global_asm!
On x86, the default syntax is also switched to Intel to match asm!
2021-05-13 22:31:57 +01:00
Giacomo Stevanato b1c8835a0f Add more precise span informations to generic types 2021-05-12 11:36:07 +02:00
b-naber e4d9bc66f6 improve diagnosts for GATs 2021-05-11 14:09:46 +02:00
Joshua Nelson 96509b4835 Make Diagnostic::span_fatal unconditionally raise an error
It had no callers which didn't immediately call `raise()`, and this
unifies the behavior with `Session`.
2021-05-08 23:12:04 -04:00
Scott McMurray ca92b5a23a Actually implement the feature in the compiler
Including all the bootstrapping tweaks in the library.
2021-05-06 11:37:45 -07:00
bors 7a0f1781d0 Auto merge of #83213 - rylev:update-lints-to-errors, r=nikomatsakis
Update BARE_TRAIT_OBJECT and ELLIPSIS_INCLUSIVE_RANGE_PATTERNS to errors in Rust 2021

This addresses https://github.com/rust-lang/rust/pull/81244 by updating two lints to errors in the Rust 2021 edition.

r? `@estebank`
2021-05-04 08:09:23 +00:00
Camille GILLOT 553004539e Make current_hir_id_owner a simple tuple. 2021-04-29 21:26:15 +02:00
Camille GILLOT 22f6448bed Lower async fn in traits.
An error is already created by AST validation.
2021-04-13 20:57:44 +02:00
Aaron Hill a93c4f05de
Implement token-based handling of attributes during expansion
This PR modifies the macro expansion infrastructure to handle attributes
in a fully token-based manner. As a result:

* Derives macros no longer lose spans when their input is modified
  by eager cfg-expansion. This is accomplished by performing eager
  cfg-expansion on the token stream that we pass to the derive
  proc-macro
* Inner attributes now preserve spans in all cases, including when we
  have multiple inner attributes in a row.

This is accomplished through the following changes:

* New structs `AttrAnnotatedTokenStream` and `AttrAnnotatedTokenTree` are introduced.
  These are very similar to a normal `TokenTree`, but they also track
  the position of attributes and attribute targets within the stream.
  They are built when we collect tokens during parsing.
  An `AttrAnnotatedTokenStream` is converted to a regular `TokenStream` when
  we invoke a macro.
* Token capturing and `LazyTokenStream` are modified to work with
  `AttrAnnotatedTokenStream`. A new `ReplaceRange` type is introduced, which
  is created during the parsing of a nested AST node to make the 'outer'
  AST node aware of the attributes and attribute target stored deeper in the token stream.
* When we need to perform eager cfg-expansion (either due to `#[derive]` or `#[cfg_eval]`),
we tokenize and reparse our target, capturing additional information about the locations of
`#[cfg]` and `#[cfg_attr]` attributes at any depth within the target.
This is a performance optimization, allowing us to perform less work
in the typical case where captured tokens never have eager cfg-expansion run.
2021-04-11 01:31:36 -04:00
Dylan DPC 74b23f9d11
Rollup merge of #83980 - pierwill:fix-compiler-librustc-names, r=davidtwco
Fix outdated crate names in compiler docs

Changes `librustc_X` to `rustc_X`, only in documentation comments.
Plain code comments are left unchanged.
2021-04-08 20:29:58 +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
Ryan Levick d7b226398e Change how edition is determined 2021-04-08 15:36:29 +02:00
Ryan Levick a2b1347bbb Improve error 2021-04-08 15:36:29 +02:00
Ryan Levick c2d0f1457a Update BARE_TRAIT_OBJECT and ELLIPSIS_INCLUSIVE_RANGE_PATTERNS to errors in Rust 2021 2021-04-08 15:36:27 +02:00
Dylan DPC d554385bbf
Rollup merge of #83935 - SNCPlay42:param-default-impl-trait, r=varkor
forbid `impl Trait` in generic param defaults

Fixes #83929

Forbid using `impl Trait` in the default types of generic parameters, e.g. `struct Foo<T = impl Trait>`. I assume this was never supposed to be allowed - it seems no UI test used it.

Note that using `impl Trait` in this position did not hit a feature gate error; however, this *shouldn't* be a breaking change as any attempt to use it should have hit the ICE in #83929 and/or failed to provide a defining use of the `impl Trait`.
2021-04-07 13:07:15 +02:00