Commit Graph

2490 Commits

Author SHA1 Message Date
Mazdak Farrokhzad
b772b5b19d
Rollup merge of #66895 - Centril:rustc_feature, r=oli-obk
Feature gating *declarations* => new crate `rustc_feature`

This PR moves the data-oriented parts of feature gating into its own crate, `rustc_feature`.
The parts consist of some data types as well as `accepted`, `active`, `removed`, and `builtin_attrs`.

Feature gate checking itself remains in `syntax::feature_gate::check`. The parts which define how to emit feature gate errors could probably be moved to `rustc_errors` or to the new `rustc_session` crate introduced in #66878. The visitor itself could probably be moved as a pass in `rustc_passes` depending on how the dependency edges work out.

The PR also contains some drive-by cleanup of feature gate checking. As such, the PR probably best read commit-by-commit.

r? @oli-obk
cc @petrochenkov
cc @Mark-Simulacrum
2019-11-30 16:56:58 +01:00
Mazdak Farrokhzad
79077f13ff move GateIssue to rustc_feature & simplify emit_feature_err 2019-11-30 07:40:28 +01:00
Mazdak Farrokhzad
70234f16df builtin_attrs.rs -> rustc_feature 2019-11-30 02:34:18 +01:00
Mazdak Farrokhzad
d04b838a44 move is_builtin_attr to syntax::attr 2019-11-30 02:20:07 +01:00
Vadim Petrochenkov
753ce4518e rustc_metadata: Merge cstore.rs into creader.rs 2019-11-28 20:59:56 +03:00
Tyler Mandry
bb6236cd74
Rollup merge of #66754 - estebank:rustdoc-capitalization, r=Dylan-DPC
Various tweaks to diagnostic output
2019-11-26 17:56:19 -06:00
Esteban Küber
5ea922aec4 Various cleanups 2019-11-25 13:30:52 -08:00
bors
4eee955502 Auto merge of #66669 - petrochenkov:tup2attr, r=matthewjasper
Fix some issues with attributes on unnamed fields

Fixes https://github.com/rust-lang/rust/issues/66487
Fixes https://github.com/rust-lang/rust/issues/66555
2019-11-25 05:41:27 +00:00
bors
412f43ac5b Auto merge of #66647 - petrochenkov:nosynt, r=Centril
rustc_plugin: Remove support for syntactic plugins

This part of the plugin interface was successfully replaced by token-based procedural macros in theory and in practice.

cc https://github.com/rust-lang/rust/issues/29597
cc https://github.com/rust-lang/rust/pull/64675
r? @Centril
2019-11-24 18:16:43 +00:00
bors
5a1d028d4c Auto merge of #66592 - estebank:raw-raw-ah-ah-ah, r=cramertj
Rework raw ident suggestions

Use heuristics to determine whethersuggesting raw identifiers is
appropriate.

Account for raw identifiers when printing a path in a `use` suggestion.

Fix #66126.
2019-11-24 14:08:08 +00:00
Vadim Petrochenkov
f89e6c8811 rustc_plugin: Remove support for syntactic plugins 2019-11-24 12:05:10 +03:00
Vadim Petrochenkov
f1359c61d3 expand: Fully preserve visibilities on unnamed fields with attributes 2019-11-24 11:47:46 +03:00
Vadim Petrochenkov
37bb0c7fa6 def_collector: Do not forget to save indices of fields with multiple attributes 2019-11-24 11:47:45 +03:00
Esteban Küber
180388670e review comments 2019-11-23 17:34:04 -08:00
Esteban Küber
4f25c618ad Rework raw ident suggestions
Use heuristics to determine whethersuggesting raw identifiers is
appropriate.

Account for raw identifiers when printing a path in a `use` suggestion.
2019-11-23 17:06:34 -08:00
Vadim Petrochenkov
bbbdbb0e44 Move def collector from rustc to rustc_resolve 2019-11-23 18:19:57 +03:00
Mazdak Farrokhzad
94b7ea97bf resolve: more declarative fresh_binding 2019-11-22 19:33:11 +01:00
bors
f50d6ea348 Auto merge of #66104 - yodaldevoid:generic-arg-disambiguation, r=petrochenkov
Generic arg disambiguation

Using the tactic suggested by @petrochenkov in https://github.com/rust-lang/rust/issues/60804#issuecomment-516769465 and on [zulip](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/generic.20argument.20disambiguation), this change checks type arguments to see if they are really incorrectly-parsed const arguments.

it should be noted that `segments.len() == 1 && segments[0].arg.is_none()` was reduced to `segments.len() == 1` as suggested by @petrochenkov in [zulip](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/generic.20argument.20disambiguation/near/177848002). This change allowed a few more existing tests to have their braces removed.

There are a couple of "problems" with these changes that I should note. First, there was a regression in the error messages found in "src/test/ui/privacy-ns1.rs" and "src/test/ui/privacy-ns1.rs". Second, some braces were unable to be removed from "src/test/ui/const-generics/fn-const-param-infer.rs". Those on line 24 caused the statement to stop equating when removed, and those on line 20 cause a statement that should not equate to produce no error when removed.

I have not looked further into any of these issues yet, though I would be willing to look into them before landing this. I simply wanted to get some other eyes on this before going further.

Fixes #60804

cc @varkor @jplatte
2019-11-20 03:07:39 +00:00
Gabriel Smith
7b4642f441 resolve: late: Check if type arg is really a const arg
A path type argument could be a generic const argument due to
limitations as to what we can determine at parsing. We double check just
to be sure by trying to resolve in the type namespace first, and if that
fails we try again in the value namespace. If resolution in the value
namespace succeeds, we have a generic const argument on our hands.
2019-11-18 17:01:48 -05:00
Gabriel Smith
041a612dad resolve: Allow idents to resolve to primitives in the type namespace 2019-11-18 17:01:33 -05:00
Vadim Petrochenkov
f74fe812fe resolve: Give derive helpers highest priority during resolution 2019-11-19 00:50:53 +03:00
Yuki Okushi
54998d1b3f
Rollup merge of #66344 - petrochenkov:noregattr, r=matthewjasper
rustc_plugin: Remove `Registry::register_attribute`

Legacy plugins cannot register inert attributes anymore.

The preferred replacement is to use `register_tool` ([tracking issue](https://github.com/rust-lang/rust/issues/66079)).
```rust
#![register_tool(servo)]

#[servo::must_root]
struct S;
```

The more direct replacement is `register_attribute` ([tracking issue](https://github.com/rust-lang/rust/issues/66080))
```rust
#![register_attr(must_root)]

#[must_root]
struct S;
```
, but it requires registering each attribute individually rather than registering the tool once, and is more likely to be removed rather than stabilized.
2019-11-17 13:36:13 +09:00
Vadim Petrochenkov
8575743793 rustc_plugin: Remove Registry::register_attribute 2019-11-16 18:50:23 +03:00
Vadim Petrochenkov
808522894b expand: Stop marking derive helper attributes as known
Pass them through name resolution instead
2019-11-16 18:31:47 +03:00
Vadim Petrochenkov
a3126a5013 resolve: Introduce a new scope for derive helpers 2019-11-16 18:20:57 +03:00
Vadim Petrochenkov
c064630e77 resolve: Scope::DeriveHelpers -> Scope::DeriveHelpersCompat
These helpers are resolved before their respective derives through a kind of look ahead into future expansions.
Some of these will migrate to proper resolution, others will be deprecated.

```
#[trait_helper] // Deprecate
#[derive(Trait)]
#[trait_helper] // Migrate to proper resolution
```
2019-11-16 18:20:39 +03:00
Tyler Mandry
c5bb2ec0dd
Rollup merge of #66197 - Centril:transparent-ast, r=varkor
Push `ast::{ItemKind, ImplItemKind}::OpaqueTy` hack down into lowering

We currently have a hack in the form of `ast::{ItemKind, ImplItemKind}::OpaqueTy` which is constructed literally when you write `type Alias = impl Trait;` but not e.g. `type Alias = Vec<impl Trait>;`. Per https://github.com/rust-lang/rfcs/pull/2515, this needs to change to allow `impl Trait` in nested positions.  This PR achieves this change for the syntactic aspect but not the semantic one, which will require changes in lowering and def collection. In the interim, `TyKind::opaque_top_hack` is introduced to avoid knock-on changes in lowering, collection, and resolve. These hacks can then be removed and fixed one by one until the desired semantics are supported.

r? @varkor
2019-11-15 14:44:47 +01:00
Yuki Okushi
43492283b4 Don't warn labels beginning with _ 2019-11-15 03:08:26 +09:00
Mazdak Farrokhzad
75aaa85f46 TAIT: adjust resolve 2019-11-14 13:40:42 +01:00
Guillaume Gomez
3302190b67 Clean some error codes diagnostics 2019-11-14 13:05:56 +01:00
Guillaume Gomez
4963116e59 Remove unused error_codes.rs files 2019-11-14 13:05:56 +01:00
Guillaume Gomez
798e389e57 Update to use new librustc_error_codes library 2019-11-14 13:05:42 +01:00
bors
3fc30d884a Auto merge of #66070 - petrochenkov:regattr, r=matthewjasper
Support registering inert attributes and attribute tools using crate-level attributes

And remove `#[feature(custom_attribute)]`.
(`rustc_plugin::Registry::register_attribute` is not removed yet, I'll do it in a follow up PR.)

```rust
#![register_attr(my_attr)]
#![register_tool(my_tool)]

#[my_attr] // OK
#[my_tool::anything] // OK
fn main() {}
```

---
Some tools (`rustfmt` and `clippy`) used in tool attributes are hardcoded in the compiler.
We need some way to introduce them without hardcoding as well.

This PR introduces a way to do it with a crate level attribute.
The previous attempt to introduce them through command line (https://github.com/rust-lang/rust/pull/57921) met some resistance.

This probably needs to go through an RFC before stabilization.
However, I'd prefer to land *this* PR without an RFC to able to remove `#[feature(custom_attribute)]` and `Registry::register_attribute` while also providing a replacement.

---
`register_attr` is a direct replacement for `#![feature(custom_attribute)]` (https://github.com/rust-lang/rust/issues/29642), except it doesn't rely on implicit fallback from unresolved attributes to custom attributes (which was always hacky and is the primary reason for the removal of `custom_attribute`) and requires registering the attribute explicitly.
It's not clear whether it should go through stabilization or not.
It's quite possible that all the uses should migrate to `#![register_tool]` (https://github.com/rust-lang/rust/issues/66079) instead.

---

Details:
- The naming is `register_attr`/`register_tool` rather than some `register_attributes` (plural, no abbreviation) for consistency with already existing attributes like `cfg_attr`, or `feature`, etc.
---
Previous attempt: https://github.com/rust-lang/rust/pull/57921
cc https://github.com/rust-lang/rust/issues/44690
Tracking issues: #66079 (`register_tool`), #66080 (`register_attr`)
Closes https://github.com/rust-lang/rust/issues/29642
2019-11-10 15:53:35 +00:00
Mark Rousskov
43a74051c7 Inline reserve_node_ids
This function was only ever called with 1 so there's little point in it;
this isn't an expensive operation (essentially a checked add) so we're
not really "reserving" anything either.
2019-11-09 11:10:13 -05:00
Mark Rousskov
516a817dbd Move next_node_id to Resolver
This doesn't migrate the pretty-printing everybody loops, which will be
done in the next few commits.
2019-11-09 11:10:13 -05:00
Vadim Petrochenkov
83f553c95c Address review comments 2019-11-09 18:19:34 +03:00
Vadim Petrochenkov
09fff50637 resolve: Factor out some common binding creation functionality 2019-11-09 17:50:51 +03:00
Vadim Petrochenkov
41a7c8be8b resolve: Remove some bits relevant only to legacy plugins
They are unstable and going to be removed anyway and the removed code would complicate the next commit
2019-11-09 17:50:51 +03:00
Vadim Petrochenkov
441e5aed25 Remove #[feature(custom_attribute)] 2019-11-09 17:50:51 +03:00
Vadim Petrochenkov
3a223a9173 Support registering attributes and attribute tools using crate-level attributes 2019-11-09 17:50:51 +03:00
Mazdak Farrokhzad
65c77bc09a
Rollup merge of #66188 - Centril:fnsig, r=davidtwco
`MethodSig` -> `FnSig` & Use it in `ItemKind::Fn`

In both AST & HIR, rename `MethodSig` to `FnSig` and then proceed to use it in `ItemKind::Fn` so that the overall structure is more regular.

r? @davidtwco
2019-11-08 16:50:41 +01:00
Mazdak Farrokhzad
7ab50e4006
Rollup merge of #65785 - Centril:compat-to-error-2, r=oli-obk
Transition future compat lints to {ERROR, DENY} - Take 2

Follow up to https://github.com/rust-lang/rust/pull/63247 implementing https://github.com/rust-lang/rust/pull/63247#issuecomment-536295992.

- `legacy_ctor_visibility` (ERROR) -- closes #39207
- `legacy_directory_ownership` (ERROR) -- closes #37872
- `safe_extern_static` (ERROR) -- closes #36247
- `parenthesized_params_in_types_and_modules` (ERROR) -- closes #42238
- `duplicate_macro_exports` (ERROR)
- `nested_impl_trait` (ERROR) -- closes #59014
- `ill_formed_attribute_input` (DENY) -- transitions #57571
- `patterns_in_fns_without_body` (DENY) -- transitions #35203

r? @varkor
cc @petrochenkov
2019-11-08 16:50:33 +01:00
Mazdak Farrokhzad
b4c6abcf9e ast::ItemKind::Fn: use ast::FnSig 2019-11-08 09:32:20 +01:00
Mazdak Farrokhzad
9d6768a478 syntax::parser::token -> syntax::token 2019-11-07 13:50:12 +01:00
Nicholas Nethercote
eea6f23a0e Make doc comments cheaper with AttrKind.
`AttrKind` is a new type with two variants, `Normal` and `DocComment`. It's a
big performance win (over 10% in some cases) because `DocComment` lets doc
comments (which are common) be represented very cheaply.

`Attribute` gets some new helper methods to ease the transition:
- `has_name()`: check if the attribute name matches a single `Symbol`; for
  `DocComment` variants it succeeds if the symbol is `sym::doc`.
- `is_doc_comment()`: check if it has a `DocComment` kind.
- `{get,unwrap}_normal_item()`: extract the item from a `Normal` variant;
  panic otherwise.

Fixes #60935.
2019-11-06 23:05:07 +11:00
Nicholas Nethercote
69bc4aba78 Remove unnecessary Deref impl for Attribute.
This kind of thing just makes the code harder to read.
2019-11-06 23:01:02 +11:00
Mazdak Farrokhzad
8e27c4f312 duplicate_macro_exports -> error 2019-11-06 11:10:37 +01:00
Mazdak Farrokhzad
c0056c04f6 legacy_ctor_visibility -> error 2019-11-06 11:08:23 +01:00
Mazdak Farrokhzad
4f9651b854
Rollup merge of #66139 - euclio:pluralize, r=nagisa
use American spelling for `pluralize!`
2019-11-06 07:03:14 +01:00
Mazdak Farrokhzad
167b8fedd6
Rollup merge of #66086 - RalfJung:smallvec, r=nagisa
bump smallvec to 1.0

This includes https://github.com/servo/rust-smallvec/pull/162, fixing an unsoundness in smallvec.

See https://github.com/servo/rust-smallvec/pull/175 for the 1.0 release announcement.

Cc @mbrubeck @emilio
2019-11-06 07:03:08 +01:00
Mazdak Farrokhzad
a0b4b4dafa
Rollup merge of #65776 - nnethercote:rename-LocalInternedString-and-more, r=estebank
Rename `LocalInternedString` and more

This PR renames `LocalInternedString` as `SymbolStr`, removes an unnecessary `impl` from it, improves comments, and cleans up some `SymbolStr` uses.

r? @estebank
2019-11-06 07:03:01 +01:00
Andy Russell
ad550b8ef3
use American spelling for pluralize! 2019-11-05 15:10:24 -05:00
Felix S. Klock II
99243616cc Review feedback: alpha-rename field from copy_derives to containers_derving_copy. 2019-11-05 14:59:29 +01:00
Felix S. Klock II
0dfe0ed8e1 Review feedback: Remove more stuff! Simplify simplify simplify! 2019-11-05 14:59:29 +01:00
Felix S. Klock II
7d7fbcb301 Remove PartialEq and Eq from the SpecialDerives. 2019-11-05 14:58:10 +01:00
Ralf Jung
90b8d34c9f bump smallvec to 1.0 2019-11-04 15:59:09 +01:00
Mark Rousskov
c68df7c503 Delete lint buffer from Session 2019-11-03 21:52:42 -05:00
Mark Rousskov
ea1ff8c07c Utilize Resolver lint buffer during HIR lowering 2019-11-03 21:52:42 -05:00
Mark Rousskov
bb0c930f82 Migrate resolver over to internal lint buffer 2019-11-03 21:52:42 -05:00
Nicholas Nethercote
b9cef6984b Simplify various Symbol use points.
Including removing a bunch of unnecessary `.as_str()` calls, and a bunch
of unnecessary sigils.
2019-11-02 09:01:02 +11:00
Guillaume Gomez
9c2f1dd377 Add long error explanation for E0578 2019-10-31 14:27:16 +01:00
Guillaume Gomez
b22a1638bf Add long error explanation for E0577 2019-10-30 14:48:45 +01:00
Tyler Mandry
0d755ff672
Rollup merge of #65539 - traxys:fix_62334, r=petrochenkov
resolve: Turn the "non-empty glob must import something" error into a lint

This fixes #62334 by changing the error to a lint warning the glob. I changed the test but I'm very unsure of what I did as I do not know how to correctly check for the warning
2019-10-29 12:01:33 -07:00
Guillaume Gomez
9869e5b969 Change E0741 into E0742 2019-10-29 13:59:40 +01:00
Guillaume Gomez
208af201ec Add long error explanation for E0740 2019-10-29 13:56:19 +01:00
Guillaume Gomez
c8420db21d Create new error code E0740 for visibility restrictions to ancestor module issues 2019-10-29 13:56:19 +01:00
Mazdak Farrokhzad
42d4e261a1
Rollup merge of #65294 - varkor:lint-inline-prototype, r=matthewjasper
Lint ignored `#[inline]` on function prototypes

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

- Adds a `unused_attribute` lint for `#[inline]` on function prototypes.
- As a consequence, foreign items, impl items and trait items now have their attributes checked, which could cause some code to no longer compile (it was previously erroneously ignored).
2019-10-29 04:08:18 +01:00
bors
8d78bf6b27 Auto merge of #65421 - estebank:variants, r=petrochenkov
Point at local similarly named element and tweak references to variants

Partially address #65386.
2019-10-28 13:41:13 +00:00
Quentin Boyer
652b1bd45d fix tidy 2019-10-28 11:22:26 +01:00
Mazdak Farrokhzad
83260d5c43
Rollup merge of #65792 - Centril:split-syntax-2, r=petrochenkov
rustc, rustc_passes: reduce deps on rustc_expand

Part of #65324.

r? @petrochenkov
2019-10-28 04:53:07 +01:00
Quentin Boyer
de9413bd34 changing non-empty glob must import something to a lint 2019-10-28 00:57:25 +01:00
Esteban Küber
b26ddb8af3 Point at local similarly named element and tweak references to variants
Point at the span for the definition of ADTs internal to the current
crate.

Look at the leading char of the ident to determine whether we're
expecting a likely fn or any of a fn, a tuple struct or a tuple variant.

Turn fn `add_typo_suggestion` into a `Resolver` method.
2019-10-27 11:50:43 -07:00
Mazdak Farrokhzad
fb12c70852 rustc, rustc_passes: don't depend on syntax_expand.
This is done by moving some data definitions to syntax::expand.
2019-10-27 17:05:57 +01:00
Esteban Küber
7ea28e761f review comment: use Default 2019-10-26 15:26:08 -07:00
Esteban Küber
93bb780e38 review comments and tweaks 2019-10-26 15:26:08 -07:00
Esteban Küber
6206a5a1b4 Use heuristics to suggest assignment
When detecting a possible `=` -> `:` typo in a `let` binding, suggest
assigning instead of setting the type.
2019-10-26 15:26:08 -07:00
varkor
b925eb5f42 Update bitflags 2019-10-25 23:26:27 +01:00
Mazdak Farrokhzad
e25720f106
Rollup merge of #65390 - GuillaumeGomez:long-err-explanation-E0576, r=matthewjasper,kinnison
Add long error explanation for E0576

Part of #61137.
2019-10-25 06:18:02 +02:00
Mazdak Farrokhzad
9c04bd1b4d
Rollup merge of #65627 - varkor:const-generics-forbid-non-structural_match, r=petrochenkov
Forbid non-`structural_match` types in const generics

Fixes https://github.com/rust-lang/rust/issues/60286.
2019-10-24 20:20:01 +02:00
Vadim Petrochenkov
3534ca8f49 Turn crate store into a resolver output 2019-10-24 20:54:16 +03:00
Vadim Petrochenkov
5fd796ad06 rustc: Combine resolver outputs into a single struct 2019-10-24 20:51:33 +03:00
Vadim Petrochenkov
fb353f050a resolve: Privatize all resolver fields 2019-10-24 20:51:33 +03:00
Mazdak Farrokhzad
ba9a9ebb25
Rollup merge of #65691 - GuillaumeGomez:2018-edition-E0659, r=Dylan-DPC
Update E0659 error code long explanation to 2018 edition

Fixes #65571

r? @Centril
2019-10-23 22:19:21 +02:00
Mazdak Farrokhzad
a649b1666c
Rollup merge of #65657 - nnethercote:rm-InternedString-properly, r=eddyb
Remove `InternedString`

This PR removes `InternedString` by converting all occurrences to `Symbol`. There are a handful of places that need to use the symbol chars instead of the symbol index, e.g. for stable sorting; local conversions `LocalInternedString` is used in those places.

r? @eddyb
2019-10-23 22:19:19 +02:00
Guillaume Gomez
aa733dacdf Add long error explanation for E0576 2019-10-23 13:07:47 +02:00
varkor
2dda8ad98a Use E0741 for structural match error 2019-10-22 12:28:23 +01:00
varkor
f0e6cd9f89 Remove "type parameter depends on const parameter" error from resolution 2019-10-22 12:26:32 +01:00
Guillaume Gomez
ed965f1b6a Update E0659 error code long explanation to 2018 edition 2019-10-22 11:52:05 +02:00
Yuki Okushi
7ea9cfc1fb
Rollup merge of #65620 - ryoqun:remove-unneeded-comment, r=varkor
Correctly note code as Ok not error for E0573

Hi, this is my first pull request to the Rust project.

The fix is very small one just to fix an oversight in a comment.

Namely, [this documentation PR](https://github.com/rust-lang/rust/pull/65234) added a longer explanation for E0573. It illustrated the error using erroneous/corrected contrasting examples. But it accidentally forgot to remove `// error` from the corrected example.

Sadly, I found the error after the PR got merged. [As suggested by the original author](https://github.com/rust-lang/rust/pull/65234/files#r336518549) of the PR, I created an PR to fix this.

Part of #61137.
2019-10-21 19:53:02 +09:00
Nicholas Nethercote
b8214e9b44 Convert fields within DefPathData from InternedString to Symbol.
It's a full conversion, except in `DefKey::compute_stable_hash()` where
a `Symbol` now is converted to an `InternedString` before being hashed.
This was necessary to avoid test failures.
2019-10-21 17:17:36 +11:00
Ryo Onodera
101e1f6f8f
Correctly note code as Ok not error for E0573 2019-10-21 09:25:57 +09:00
Yuki Okushi
2518bbd5a3
Rollup merge of #65460 - sinkuu:contains_insert, r=varkor
Clean up `contains()` `insert()` chains on HashSet

They can be merged to a single `insert()` call, which may avoid double-hashing/lookup of the value.
2019-10-21 03:10:54 +09:00
Mazdak Farrokhzad
fab74044dd
Rollup merge of #65542 - estebank:kill-static-methods, r=Centril
Refer to "associated functions" instead of "static methods"

Fix #59782.
2019-10-19 07:10:07 +02:00
Mazdak Farrokhzad
99603e99cc
Rollup merge of #65252 - petrochenkov:deriveholders2, r=matthewjasper
expand: Simplify expansion of derives

And make it more uniform with other macros.
This is done by merging placeholders for future derives' outputs into the derive container's output fragment early (addressing FIXMEs from https://github.com/rust-lang/rust/pull/63667).

Also, macros with names starting with `_` are no longer reported as unused, in accordance with the usual behavior of `unused` lints.

r? @matthewjasper or @mark-i-m
2019-10-19 07:10:04 +02:00
Vadim Petrochenkov
7ce85f2dca expand: Simplify expansion of derives
And make it more uniform with other macros.
By merging placeholders for future derives' outputs into the derive container's output fragment early.
2019-10-19 00:23:57 +03:00
Vadim Petrochenkov
2d3c17a609 resolve: Mark macros starting with an underscore as used 2019-10-19 00:23:04 +03:00
Tyler Mandry
bb53fed72f
Rollup merge of #65334 - GuillaumeGomez:long-err-explanation-E0575, r=kinnison
Add long error explanation for E0575

Part of #61137.
2019-10-18 13:48:14 -07:00
Esteban Küber
2b76c8b95f review comments 2019-10-18 13:00:14 -07:00
Esteban Küber
865c4bcff6 review comments: help wording 2019-10-18 08:36:46 -07:00
Esteban Küber
f65a492afc Point at enclosing function without self receiver 2019-10-17 20:26:21 -07:00
Esteban Küber
11011013f2 Refer to "associated functions" instead of "static methods" 2019-10-17 19:03:36 -07:00
Mazdak Farrokhzad
accc6e7e4a
Rollup merge of #65465 - Centril:split-syntax-1, r=petrochenkov
Move syntax::ext to a syntax_expand and refactor some attribute logic

Part of https://github.com/rust-lang/rust/pull/65324.

r? @petrochenkov
2019-10-17 13:46:11 +02:00
Guillaume Gomez
d1db077e06 Add long error explanation for E0575 2019-10-17 11:30:41 +02:00
Guillaume Gomez
e5d566c080 Add long error explanation for E0573 2019-10-16 13:56:14 +02:00
Mazdak Farrokhzad
d420d719c4 move syntax::ext to new crate syntax_expand 2019-10-16 10:59:53 +02:00
Shotaro Yamada
ac2f906a59 Make use of the return value of HashSet::insert 2019-10-16 13:48:20 +09:00
Tyler Mandry
42b35968fb
Rollup merge of #65308 - GuillaumeGomez:long-err-explanation-E0574, r=matthewjasper
Add long error explanation for E0574

Part of #61137.
2019-10-15 16:07:50 -07:00
Tyler Mandry
af3d9e57e7
Rollup merge of #64623 - matthewjasper:underscore-imports, r=petrochenkov
Remove last uses of gensyms

Underscore bindings now use unique `SyntaxContext`s to avoid collisions. This was the last use of gensyms in the compiler, so this PR also removes them.

closes #49300
cc #60869

r? @petrochenkov
2019-10-15 16:07:41 -07:00
Matthew Jasper
1a2597b64a Don't use gensym_if_underscore to resolve _ bindings
Instead add a disambiguator to the keys used for distinguishing
resolutions.
2019-10-15 21:12:04 +01:00
Vadim Petrochenkov
f5baad2b5e rustc_metadata: Remove resolutions for extern crate items from CStore
Use a more traditional scheme with providing them as a resolver output
2019-10-14 18:05:45 +03:00
Vadim Petrochenkov
e843d867e6 rustc_metadata: Crate loader is immutable 2019-10-14 18:05:45 +03:00
Vadim Petrochenkov
e8c28e24b9 rustc_metadata: Privatize private code and remove dead code 2019-10-14 18:05:45 +03:00
Mazdak Farrokhzad
2800bc240e
Rollup merge of #65363 - Centril:less-pprust, r=Mark-Simulacrum
Remove implicit dependencies on syntax::pprust

Part of https://github.com/rust-lang/rust/pull/65324.

The main goal here is to facilitate the eventual move of pprust out from libsyntax and because an AST definition typically should not depend on its pretty printer.

r? @estebank
2019-10-14 07:36:57 +02:00
Guillaume Gomez
6a64e9ca49 Add long error explanation for E0574 2019-10-13 22:10:03 +02:00
Mazdak Farrokhzad
540278c5ae
Rollup merge of #65250 - da-x:ctor-in-error-msgs, r=petrochenkov
resolve: fix error title regarding private constructors

One reason is that constructors can be private while their types can be
public.

Idea credit to @petrochenkov, discussed at #65153
2019-10-13 13:34:33 +02:00
Mazdak Farrokhzad
742ec4b9bf ast: remove implicit pprust dependency via Display.
Instead just use `pprust::path_to_string(..)` where needed.

This has two benefits:

a) The AST definition is now independent of printing it.
   (Therefore we get closer to extracting a data-crate.)

b) Debugging should be easier as program flow is clearer.
2019-10-13 06:58:51 +02:00
Tyler Mandry
976a57a4af
Rollup merge of #65283 - petrochenkov:softstab2, r=estebank
stability: Do not use `buffer_lint` after lowering to HIR

Fixes https://github.com/rust-lang/rust/issues/65253
2019-10-11 15:09:57 -07:00
Dan Aloni
9d11bda8dd resolve: shorten wording on private constructor error 2019-10-11 22:18:07 +03:00
Dan Aloni
7140c024c2 resolve: fix error title regarding private constructors
The constructor is private, not the type.

Idea credit to @petrochenkov, discussed at #65153
2019-10-11 18:09:23 +03:00
bors
d4f7f974b8 Auto merge of #64716 - jonhoo:stabilize-mem-take, r=SimonSapin
Stabilize mem::take (mem_take)

Tracking issue: https://github.com/rust-lang/rust/issues/61129

r? @matklad
2019-10-11 12:45:20 +00:00
Vadim Petrochenkov
ceb4c3fa30 stability: Do not use buffer_lint after lowering to HIR 2019-10-10 23:38:35 +03:00
bors
898f36c83c Auto merge of #65153 - da-x:issue-58017, r=petrochenkov
Improve message when attempting to instantiate tuple structs with private fields

Fixes #58017, fixes #39703.

```
error[E0603]: tuple struct `Error` is private
  --> main.rs:22:16
   |
2  |     pub struct Error(usize, pub usize, usize);
   |                      -----             ----- field is private
   |                      |
   |                      field is private
...
22 |     let x = a::Error(3, 1, 2);
   |                ^^^^^
   |
   = note: a tuple struct constructor is private if any of its fields is private
```
2019-10-10 19:40:48 +00:00
bors
9c588c1e23 Auto merge of #65140 - petrochenkov:disapp, r=nikomatsakis
resolve: Remove an incorrect assert

Fixes https://github.com/rust-lang/rust/issues/64803.
2019-10-10 12:02:47 +00:00
Vadim Petrochenkov
48f8beddd8 resolve: Use field spans for reporting the private constructor error 2019-10-09 18:07:22 +03:00
Vadim Petrochenkov
5d8af38329 resolve: Keep field spans for diagnostics 2019-10-09 18:07:22 +03:00
Michael Woerister
ceb1a9cfe3 self-profiling: Add events for everything except trait selection. 2019-10-09 13:40:44 +02:00
Jon Gjengset
45aca119a6
Stabilize mem::take (mem_take)
Tracking issue: https://github.com/rust-lang/rust/issues/61129
2019-10-08 18:04:18 -04:00
Mazdak Farrokhzad
9b989ea298
Rollup merge of #65133 - davidtwco:issue-65035-static-with-generic-in-foreign-mod, r=petrochenkov
typeck: prohibit foreign statics w/ generics

Fixes #65035 and fixes #65025.

This PR modifies resolve to disallow foreign statics that have
generics.

`improper_ctypes` is not written to support type parameters, as these
are normally disallowed before the lint is run. Thus, type parameters in
foreign statics must be prohibited before the lint.

The only other case where this *could* have occured is in functions,
but typeck prohibits this with a "foreign items may not have type
parameters" error - a similar error did not exist for statics, because
statics cannot have type parameters, but they can use any
type parameters that are in scope (which isn't the case for functions).
2019-10-08 23:31:22 +02:00
David Wood
ccbf2b76a6
resolve: prohibit foreign statics w/ generics
This commit modifies resolve to disallow foreign statics that use
parent generics.

`improper_ctypes` is not written to support type parameters, as these
are normally disallowed before the lint is run. Thus, type parameters in
foreign statics must be prohibited before the lint.

The only other case where this *could* have occured is in functions,
but typeck prohibits this with a "foreign items may not have type
parameters" error - a similar error did not exist for statics, because
statics cannot have type parameters, but they can use any
type parameters that are in scope (which isn't the case for functions).

Signed-off-by: David Wood <david@davidtw.co>
2019-10-08 18:46:24 +01:00
bors
0358617e3f Auto merge of #65043 - Aaron1011:fix/reexport-determinism, r=petrochenkov
Make re-export collection deterministic

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

Previously, we were using an `FxHashMap` to collect module re-exports.
However, re-exports end up getting serialized into crate metadata, which
means that metadata generation was non-deterministic. This resulted in
spurious error messages changes (e.g. PR #64906) due to pretty-printing
implicitly depending on the order of re-exports when computing the
proper path to show to the user.

See #65042 for a long-term strategy to detect this kind of issue
2019-10-06 08:40:43 +00:00
Tyler Mandry
008526340a
Rollup merge of #64708 - SimonSapin:option-deref, r=Centril
Stabilize `Option::as_deref` and `Option::as_deref_mut`

The tracking issue https://github.com/rust-lang/rust/issues/50264 still has unresolved question for the corresponding `Result` methods.
2019-10-05 21:54:47 -07:00
Vadim Petrochenkov
fcd98cf5dc resolve: Remove an incorrect assert 2019-10-05 23:46:29 +03:00
Aaron Hill
add0a42034
Remove for_each_child_stable
Now that `Resolutions` has a deterministic iteration order, it's no
longer necessary to sort its entries before iterating over them
2019-10-05 16:34:38 -04:00
Aaron Hill
dd403e4ab0
Make re-export collection deterministic
Previously, we were using an `FxHashMap` to collect module re-exports.
However, re-exports end up getting serialized into crate metadata, which
means that metadata generation was non-deterministic. This resulted in
spurious error messages changes (e.g. PR #64906) due to pretty-printing
implicitly depending on the order of re-exports when computing the
proper path to show to the user.

See #65042 for a long-term strategy to detect this kind of issue
2019-10-05 15:57:48 -04:00
Felix S. Klock II
a18d424c48 Allocate a new diagnostic for defaulted type parameters cannot use Self
(Without this commit, you still get an error (a very similar one, at
that), but it complains about use of forward declaration, which is
confusing since people do not necessarily think of `Self` as being
declared at all.)

Update: incorporate review feedback.
2019-10-03 13:54:27 +02:00
Felix S. Klock II
3a4921cde1 The crux of the bug fix.
Update: review feedback
Update: placate tidy
2019-10-03 13:54:07 +02:00
Mazdak Farrokhzad
0a2ddcc346
Rollup merge of #64691 - estebank:unexpected-variant, r=Centril
Point at definition when misusing ADT

When given `struct Foo(usize)` and using it as `Foo {}` or `Foo`, point at `Foo`'s definition in the error.
2019-09-29 20:34:12 +02:00
bors
18f00b9496 Auto merge of #64455 - GuillaumeGomez:long-error-explanation-E0531, r=Centril
Add Long error explanation for E0531

Part of #61137.
2019-09-28 12:06:44 +00:00
varkor
38121173e2 Rename MetaItem.node to MetaItem.kind 2019-09-26 18:21:48 +01:00
varkor
b474867961 Rename ForeignItem.node to ForeignItem.kind 2019-09-26 18:21:48 +01:00
varkor
7bc94cc3c2 Rename Item.node to Item.kind 2019-09-26 18:21:48 +01:00
varkor
21bf983acb Rename Stmt.node to Stmt.kind 2019-09-26 18:21:10 +01:00
varkor
c3d8791373 Rename Ty.node to Ty.kind 2019-09-26 18:21:10 +01:00
varkor
d4573c9c1e Rename TraitItem.node to TraitItem.kind 2019-09-26 18:21:09 +01:00
varkor
ce6aabbaa1 Rename ImplItem.node to ImplItem.kind 2019-09-26 18:21:09 +01:00
varkor
8bd0382134 Rename Pat.node to Pat.kind 2019-09-26 18:21:09 +01:00
varkor
95f6d72a60 Rename Expr.node to Expr.kind
For both `ast::Expr` and `hir::Expr`.
2019-09-26 18:21:09 +01:00
Guillaume Gomez
33b89a3918 Add long error explanation for E0531 2019-09-25 16:41:05 +02:00
Mazdak Farrokhzad
9e12827d56
Rollup merge of #64702 - sinkuu:deps, r=jonas-schievink
Remove unused dependencies
2019-09-24 23:45:27 +02:00
Simon Sapin
0797712e29 Stabilize Option::deref and Option::deref_mut
The tracking issue https://github.com/rust-lang/rust/issues/50264
still has unresolved question for the corresponding `Result` methods.
2019-09-23 17:14:26 +02:00
Shotaro Yamada
0423c2a7a3 Remove unused dependencies 2019-09-23 15:25:00 +09:00
Esteban Küber
2ae9016553 Point at definition when misusing ADT
When given `struct Foo(usize)` and using it as `Foo {}` or `Foo`, point at
`Foo`'s definition in the error.
2019-09-22 11:27:55 -07:00
Aleksey Kladov
645cdca9ba reduce visibility of a bunch of stuff in ext::tt 2019-09-22 20:29:31 +03:00
Mazdak Farrokhzad
7eac55518a
Rollup merge of #64660 - guanqun:unify-errors-for-tuple-struct, r=estebank
unify errors for tuple/struct variants

fix #63983
2019-09-21 21:24:20 +02:00
Guanqun Lu
e001c5f9d8 unify errors for tuple/struct variants
fix #63983
2019-09-21 23:38:35 +08:00
Mazdak Farrokhzad
176e216c8e
Rollup merge of #64632 - guanqun:patch-1, r=jonas-schievink
remove the extra comma after the match arm

This would follow the same coding style as all the other match arms in this file.
2019-09-21 16:01:31 +02:00
guanqun
c3140bae63
remove the extra comma after the match arm
This would follow the same coding style as all the other match arms in this file.
2019-09-21 00:22:43 +08:00
gaolei
1ab5593f95 factor out pluralisation remains after #64280 2019-09-20 00:25:27 +08:00
bors
60895fd1f9 Auto merge of #64483 - petrochenkov:expectattr2, r=Centril
resolve: Tweak some "cannot find" wording for macros
2019-09-15 12:24:32 +00:00
Vadim Petrochenkov
f7f8d6584b resolve: Remove ! from "cannot find" diagnostics for macros 2019-09-15 13:22:07 +03:00
Vadim Petrochenkov
42a19dde82 resolve: Tweak "cannot find" wording for attributes 2019-09-15 13:10:12 +03:00
bors
117cdf35d4 Auto merge of #64469 - matthewjasper:increase-hygiene-use, r=petrochenkov
Cleanup handling of hygiene for built-in macros

This makes most identifiers generated by built-in macros use def-site hygiene, not only the ones that previously used gensyms.

* `ExtCtxt::ident_of` now takes a `Span` and is preferred to `Ident::{from_str, from_str_and_span}`
* Remove `Span::with_legacy_ctxt`
    * `assert` now uses call-site hygiene because it needs to resolve `panic` unhygienically.
    * `concat_idents` now uses call-site hygiene because it wouldn't be very useful with def-site hygiene.
    * everything else is moved to def-site hygiene

r? @petrochenkov
2019-09-15 08:17:57 +00:00
Matthew Jasper
e8d2f62924 Prefer Symbol to Ident when there's no sensible Span 2019-09-15 09:15:37 +01:00
Vadim Petrochenkov
f6a5b29d19 resolve: Tweak some expected/found wording 2019-09-14 22:36:58 +03:00
Mazdak Farrokhzad
8926301d11
Rollup merge of #64054 - estebank:unused-import-is-to-eager, r=petrochenkov
Always emit unresolved import errors and hide unused import lint

Fix https://github.com/rust-lang/rust/issues/63724.

r? @petrochenkov
2019-09-09 22:18:10 +02:00
Caio
63a5f399ae Resolve attributes in several places
Arm, Field, FieldPat, GenericParam, Param, StructField and Variant
2019-09-09 09:27:15 -03:00
Esteban Küber
9a561872c4 Always emit unresolved import errors and hide unused import lint 2019-09-08 11:11:26 -07:00
Mazdak Farrokhzad
3a3280326e
Rollup merge of #64265 - petrochenkov:useerr, r=estebank
resolve: Mark more erroneous imports as used

Fixes https://github.com/rust-lang/rust/issues/63724
r? @estebank
2019-09-08 12:11:57 +02:00
Mazdak Farrokhzad
77e1a7c578
Rollup merge of #64177 - petrochenkov:curmod, r=matthewjasper
resolve: Do not afraid to set current module to enums and traits

After cfbb60bf6d it's ok.

This is likely required for https://github.com/rust-lang/rust/pull/63468 to work correctly, because that PR starts resolving attributes on enum variants.

r? @matthewjasper @c410-f3r
2019-09-08 00:07:33 +02:00
Mazdak Farrokhzad
4ea77975ab
Rollup merge of #64066 - petrochenkov:softstab, r=matthewjasper
Support "soft" feature-gating using a lint

Use it for feature-gating `#[bench]`.

Closes https://github.com/rust-lang/rust/issues/63798.
2019-09-08 00:07:31 +02:00
Vadim Petrochenkov
f7434aef26 Support "soft" feature-gating using a lint
Use it for feature-gating `#[bench]`
2019-09-07 21:37:51 +03:00
Vadim Petrochenkov
7dc3839b50 resolve: Mark more erroneous imports as used 2019-09-07 21:30:42 +03:00
Mazdak Farrokhzad
89a69fd76d
Rollup merge of #64139 - Mark-Simulacrum:strip-legacy-proc-macro, r=petrochenkov
Migrate internal diagnostic registration to macro_rules

Review is best done commit-by-commit.

Fixes #64132.
2019-09-07 20:01:44 +02:00
Vadim Petrochenkov
56f635304b resolve: Adjust hygienic_lexical_parent to account for enum and trait modules 2019-09-07 17:42:24 +03:00
Vadim Petrochenkov
0d084670d7 resolve: Do not afraid to set current module to enums and traits 2019-09-07 17:19:39 +03:00
Mazdak Farrokhzad
db493ef613
Rollup merge of #63919 - matthewjasper:remove-gensymmed, r=petrochenkov
Use hygiene for AST passes

AST passes are now able to have resolve consider their expansions as if they were opaque macros defined either in some module in the current crate, or a fake empty module with `#[no_implicit_prelude]`.

* Add an ExpnKind for AST passes.
* Remove gensyms in AST passes.
* Remove gensyms in`#[test]`, `#[bench]` and `#[test_case]`.
* Allow opaque macros to define tests.
* Move tests for unit tests to their own directory.
* Remove `Ident::{gensym, is_gensymed}` - `Ident::gensym_if_underscore` still exists.

cc #60869, #61019

r? @petrochenkov
2019-09-07 08:06:04 +02:00
Matthew Jasper
3f3fc52bfa Simplify std lib injection 2019-09-05 22:48:03 +01:00
Mark Rousskov
41b39fce98 Remove rustc_diagnostic_macros feature 2019-09-05 12:35:18 -04:00
Mark Rousskov
b437240cee Replace diagnostic plugins with macro_rules 2019-09-05 12:35:15 -04:00
Vadim Petrochenkov
c8cf9f5a02 Add with_{def_site,call_site,legacy}_ctxt, methods to Span
Use these to create call-site spans for AST passes when needed.
2019-09-05 15:07:17 +01:00
Matthew Jasper
beb2f5b8ff Remove Ident::{gensym, is_gensymed}
`gensym_if_underscore` still exists. The symbol interner can still
create arbitray gensyms, this is just not exposed publicly.
2019-09-05 15:07:16 +01:00
Matthew Jasper
6fcdb36ccb Make use of hygiene in AST passes 2019-09-05 15:07:16 +01:00
Matthew Jasper
4082cd95a8 Allow ast passes to create hygienic spans 2019-09-05 15:07:16 +01:00
Mazdak Farrokhzad
0341b78044 resolve: bool -> enum PatBoundCtx 2019-09-05 08:33:09 +02:00
Mazdak Farrokhzad
a7db1a4861 or-patterns: address review comments. 2019-09-05 08:33:09 +02:00
Mazdak Farrokhzad
a867c5f9cc resolve: merge resolve_pats and resolve_pattern_top. 2019-09-05 08:33:09 +02:00
Mazdak Farrokhzad
896a1c7fcd resolve: account for general or-patterns in consistency checking. 2019-09-05 08:33:09 +02:00
Mazdak Farrokhzad
166a558da6 resolve: revamp already-bound check -- fix some bugs. 2019-09-05 08:33:09 +02:00
Mazdak Farrokhzad
70cae78387 resolve: already-bound-check: account for or-patterns.
Also document `ast::Pat::walk`.
2019-09-05 08:33:09 +02:00
Mazdak Farrokhzad
dc91e229d2 resolve: move resolve_block to a better place. 2019-09-05 08:33:09 +02:00
Mazdak Farrokhzad
fd3b441846 resolve: move fresh_binding. 2019-09-05 08:33:09 +02:00
Mazdak Farrokhzad
f343e84f40 resolve: add type IdentMap<T> alias. 2019-09-05 08:33:09 +02:00
Mazdak Farrokhzad
219ddde26b resolve: extract try_resolve_as_non_binding. 2019-09-05 08:33:09 +02:00
Mazdak Farrokhzad
6d537d4020 resolve: simplify resolve_arm. 2019-09-05 08:33:09 +02:00
Mazdak Farrokhzad
f8835eeaf8 resolve: cleanup using with_rib, etc. 2019-09-05 08:33:09 +02:00
Mazdak Farrokhzad
af06bfb84c resolve: extract resolve_params. 2019-09-05 08:33:09 +02:00
Mazdak Farrokhzad
e4e6b01ca1
Rollup merge of #63867 - petrochenkov:dhelpers, r=matthewjasper
resolve: Block expansion of a derive container until all its derives are resolved

So, it turns out there's one more reason to block expansion of a `#[derive]` container until all the derives inside it are resolved, beside `Copy` (https://github.com/rust-lang/rust/pull/63248).

The set of derive helper attributes registered by derives in the container also has to be known before the derives themselves are expanded, otherwise it may be too late (see https://github.com/rust-lang/rust/pull/63468#issuecomment-524550872 and the `#[stable_hasher]`-related test failures in https://github.com/rust-lang/rust/pull/63468).

So, we stop our attempts to unblock the container earlier, as soon as the `Copy` status is known, and just block until all its derives are resolved.
After all the derives are resolved we immediately go and process their helper attributes in the item, without delaying it until expansion of the individual derives.

Unblocks https://github.com/rust-lang/rust/pull/63468
r? @matthewjasper (as a reviewer of https://github.com/rust-lang/rust/pull/63248)
cc @c410-f3r
2019-08-29 13:17:52 +02:00
Vadim Petrochenkov
2065ee9acc metadata: Eliminate FullProcMacro
Fix caching of loaded proc macros
2019-08-27 01:34:07 +03:00
Vadim Petrochenkov
ec45b87957 resolve: Block expansion of a derive container until all its derives are resolved
Also mark derive helpers as known as a part of the derive container's expansion instead of expansion of the derives themselves which may happen too late.
2019-08-27 00:31:55 +03:00
Vadim Petrochenkov
bf345dd6e3 resolve: Do not rely on default transparency when detecting proc macro derives 2019-08-23 01:44:33 +03:00