Commit Graph

432 Commits

Author SHA1 Message Date
varkor
befc4b1100 Rename hir::map::Node to hir::map::NodeKind 2018-08-27 21:45:46 +01:00
bors
70a21e89f1 Auto merge of #53441 - toidiu:ak-fix53419, r=nikomatsakis
fix for late-bound regions

Fix for https://github.com/rust-lang/rust/issues/53419

r? @nikomatsakis
2018-08-27 17:42:45 +00:00
Ariel Ben-Yehuda
993e7e2622 fix is_non_exhaustive confusion between structs and enums
Structs and enums can both be non-exhaustive, with a very different
meaning. This PR splits `is_non_exhaustive` to 2 separate functions - 1
for structs, and another for enums, and fixes the places that got the
usage confused.

Fixes #53549.
2018-08-26 18:24:51 +03:00
Niko Matsakis
73fb1622b3 check that adding infer-outlives requirement to all crates works 2018-08-24 17:10:50 -04:00
kennytm
a1ec2f76bb
Rollup merge of #53545 - FelixMcFelix:fix-50865-beta, r=petrochenkov
Fix #50865: ICE on impl-trait returning functions reaching private items

Adds a test case as suggested in #50865, and implements @petrochenkov's suggestion. Fixes #50865.

Impl-trait-returning functions are marked under a new (low) access level, which they propagate rather than `AccessLevels::Reachable`. `AccessLevels::is_reachable` returns false for such items (leaving stability analysis unaffected), these items may still be visible to the lints phase however.
2018-08-24 23:27:16 +08:00
Kyle Simpson
85a05d1815 Light restructuring. 2018-08-23 13:12:53 +01:00
varkor
04fa5d3adb Remove Ty prefix from Ty{Foreign|Param} 2018-08-22 16:07:55 +01:00
varkor
6f637da50c Remove Ty prefix from Ty{Adt|Array|Slice|RawPtr|Ref|FnDef|FnPtr|Dynamic|Closure|Generator|GeneratorWitness|Never|Tuple|Projection|Anon|Infer|Error} 2018-08-22 16:07:44 +01:00
Kyle Simpson
3536359ad8 Further fixes. 2018-08-21 01:50:20 +01:00
Kyle Simpson
81684bf1aa New AccessLevel and accompanying propagation. 2018-08-21 00:11:59 +01:00
Kyle Simpson
00b260691f Mark impl Trait Functions as reachable. (Fixes #50865) 2018-08-20 22:39:47 +01:00
varkor
11adc1300c Address minor comments 2018-08-19 20:02:32 +01:00
Kyle Simpson
f285876b43 Logging for rustc_privacy. 2018-08-10 10:32:52 +01:00
memoryruins
87fb6fc6ef [nll] librustc_privacy: enable feature(nll) for bootstrap 2018-08-09 04:09:50 -04:00
Mark Rousskov
3baec3cdd7 Add HirId to VisibilityKind::Restricted 2018-08-07 10:13:17 -06:00
kennytm
d028b3ea33
Rollup merge of #53001 - petrochenkov:master, r=estebank
privacy: Fix an ICE in `path_is_private_type`

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

(Untested.)
2018-08-04 14:35:55 +08:00
Vadim Petrochenkov
6a3dfa4dba
privacy: Fix an ICE in path_is_private_type
Fixes https://github.com/rust-lang/rust/issues/52879

(Untested.)
2018-08-03 00:43:49 +03:00
Tatsuyuki Ishi
e098985939 Deny bare_trait_objects globally 2018-07-25 10:25:29 +09:00
Oliver Schneider
53d2ebb0ad Implement existential types 2018-07-18 10:53:08 +02:00
csmoe
19730cc996 Fix tidy 2018-07-16 15:09:17 +02:00
csmoe
5b0cf56f32 ItemKind 2018-07-16 15:09:17 +02:00
csmoe
f12eca47e0 TyKind 2018-07-16 15:09:17 +02:00
csmoe
6a16b38198 ExprKind 2018-07-16 15:09:16 +02:00
bors
cc903c64eb Auto merge of #52348 - oli-obk:bugfix, r=petrochenkov
Reach the body of functions returning `impl Trait` but don't treat it as public

fixes #52128

r? @pnkfelix

cc @eddyb
2018-07-15 04:01:43 +00:00
Oliver Schneider
61414fd6c1 Use the correct visibility 2018-07-13 20:45:23 +02:00
ljedrz
5058af7003 Deny bare trait objects in the rest of rust 2018-07-12 13:50:22 +02:00
Oliver Schneider
6e5b9c1472 Get rid of TyImplTraitExistential 2018-07-02 09:17:38 +02:00
bors
45935640f0 Auto merge of #51866 - zackmdavis:hir_making_each_day_of_the_year, r=petrochenkov
add modifier keyword spans to hir::Visibility; improve unreachable-pub, private-no-mangle lint suggestions

#50455 pointed out that the unreachable-pub suggestion for brace-grouped `use`s was bogus; #50476 partially ameliorated this by marking the suggestion as `Applicability::MaybeIncorrect`, but this is the actual fix.

Meanwhile, another application of having spans available in `hir::Visibility` is found in the private-no-mangle lints, where we can now issue a suggestion to use `pub` if the item has a more restricted visibility marker (this seems much less likely to come up in practice than not having any visibility keyword at all, but thoroughness is a virtue). While we're there, we can also add a helpful note if the item does have a `pub` (but triggered the lint presumably because enclosing modules were private).

![hir_vis](https://user-images.githubusercontent.com/1076988/42018064-ca830290-7a65-11e8-9c4c-48bc846f861f.png)

r? @nrc
cc @Manishearth
2018-07-02 03:18:49 +00:00
Zack M. Davis
43a0a65fa2 call it hir::VisibilityKind instead of hir::Visibility_:*
It was pointed out in review that the glob-exported
underscore-suffixed convention for `Spanned` HIR nodes is no longer
preferred: see February 2016's #31487 for AST's migration away from
this style towards properly namespaced NodeKind enums.

This concerns #51968.
2018-07-01 11:05:10 -07:00
bors
d94b804863 Auto merge of #51882 - varkor:check-type_dependent_defs, r=estebank
Always check type_dependent_defs

Directly indexing into `type_dependent_defs` has caused multiple ICEs in the past (https://github.com/rust-lang/rust/issues/46771, https://github.com/rust-lang/rust/issues/49241, etc.) and is almost certainly responsible for #51798 too. This PR ensures we always check `type_dependent_defs` first, which should prevent any more of these (or at least make them easier to track down).
2018-07-01 08:41:50 +00:00
Zack M. Davis
c2d44b2286 in which the private/restricted-in-public error messaging gets specific
April 2016's Issue #33174 called out the E0446 diagnostics as
confusing. While adding the name of the restricted type to the message
(548e681f) clarified matters somewhat, Esteban Küber pointed out that we
could stand to place a secondary span on the restricted type.

Here, we differentiate between crate-visible, truly private, and
otherwise restricted types, and place a secondary span specifically on
the visibility modifier of the restricted type's declaration (which we
can do now that HIR visibilities have spans!).

At long last, this resolves #33174.
2018-06-30 22:48:05 -07:00
Zack M. Davis
4ae89129e1 in which hir::Visibility recalls whence it came (i.e., becomes Spanned)
There are at least a couple (and plausibly even three) diagnostics that
could use the spans of visibility modifiers in order to be reliably
correct (rather than hacking and munging surrounding spans to try to
infer where the visibility keyword must have been).

We follow the naming convention established by the other `Spanned` HIR
nodes: the "outer" type alias gets the "prime" node-type name, the
"inner" enum gets the name suffixed with an underscore, and the variant
names are prefixed with the prime name and `pub use` exported from here
(from HIR).

Thanks to veteran reviewer Vadim Petrochenkov for suggesting this
uniform approach. (A previous draft, based on the reasoning that
`Visibility::Inherited` should not have a span, tried to hack in a named
`span` field on `Visibility::Restricted` and a positional field on
`Public` and `Crate`. This was ... not so uniform.)
2018-06-30 22:41:01 -07:00
varkor
4071adfcb5 Always check type_dependent_defs 2018-06-28 22:52:44 +01:00
Vadim Petrochenkov
e8215a4f6f Use Idents for path segments in HIR 2018-06-28 11:04:50 +03:00
varkor
7a829273bf Rename ty_param_bound to generic_bound 2018-06-20 12:23:46 +01:00
varkor
37204027b6 Rename ty_param_bound to trait_bound 2018-06-20 12:23:46 +01:00
varkor
c5f16e0e18 Rename ParamBound(s) to GenericBound(s) 2018-06-20 12:23:46 +01:00
varkor
7de6ed06a5 Rename TraitTyParamBound to ParamBound::Trait 2018-06-20 12:23:23 +01:00
varkor
aed530a457 Lift bounds into GenericParam 2018-06-20 12:22:46 +01:00
varkor
f457b3d10a Refactor generic parameters in rustdoc/clean 2018-06-20 12:21:52 +01:00
varkor
82dba3d419 Refactor hir::GenericParam as a struct 2018-06-20 12:21:07 +01:00
bors
862703e05e Auto merge of #51414 - oli-obk:impl_trait_type_def, r=pnkfelix
Add existential type definitions

Note: this does not allow creating named existential types, it just desugars `impl Trait` to a less (but still very) hacky version of actual `existential type` items.

r? @nikomatsakis
2018-06-18 14:34:52 +00:00
Eduard-Mihai Burtescu
5a5c7ded0d rustc: rename ty::maps to ty::query. 2018-06-14 18:05:12 +03:00
Oliver Schneider
9b1bd94e37 Add existential type definitons 2018-06-07 17:33:53 +02:00
John Kåre Alsaker
b7aabaa3fc Update recursion limits 2018-06-01 14:56:01 +02:00
Vadim Petrochenkov
189c0a1297 Use Idents for fields in HIR 2018-05-26 14:41:58 +03:00
Eduard-Mihai Burtescu
73f62106ad rustc: move TypeParamDef's fields into GenericParamDefKind::Type. 2018-05-21 12:13:19 +03:00
varkor
007de2f896 Lift pure_wrt_drop to GenericParamDef 2018-05-15 14:21:32 +01:00
varkor
9200bdee26 Refactor generic params loops 2018-05-15 14:21:32 +01:00
varkor
4bed895cab Pull common parameters into GenericParamDef
This leads to a lot of simplifications, as most code doesn't actually need to know about the specific lifetime/type data; rather, it's concerned with properties like name, index and def_id.
2018-05-15 14:21:32 +01:00
varkor
b75f421ee9 Generalise more cases of explicit iteration of specific kinds 2018-05-15 14:21:03 +01:00
varkor
e5825c29c3 Prefer iterator to vec 2018-05-15 14:20:19 +01:00
varkor
fe0c119e7d Consolidate ty::Generics 2018-05-15 14:20:19 +01:00
leonardo.yvens
56bc4c2490 Fix self referential impl Trait substitutions
A high impact bug because a lot of common traits use a `Self`
substitution by default. Should be backported to beta.

There was a check for this which wasn't catching all cases, it was made
more robust.

Fixes #49376
Fixes #50626

r? @petrochenkov
2018-05-12 16:43:42 -03:00
Vadim Petrochenkov
4f69b7fb85 Avoid comparing fields by name when possible
Resolve them into field indices once and then use those resolutions

+ Fix rebase
2018-04-12 23:06:03 +03:00
Mark Simulacrum
c115cc655c Move deny(warnings) into rustbuild
This permits easier iteration without having to worry about warnings
being denied.

Fixes #49517
2018-04-08 16:59:14 -06:00
Vadim Petrochenkov
baae274fb7 Use Span instead of SyntaxContext in Ident 2018-04-06 11:46:26 +03:00
John Kåre Alsaker
b74e97cf42 Replace Rc with Lrc for shared data 2018-03-02 10:48:52 +01:00
bors
4a70e27219 Auto merge of #48082 - jseyfried:improve_struct_field_hygiene, r=petrochenkov
macros: improve struct constructor field hygiene, fix span bug

Fixes #47311.
r? @nrc
2018-02-26 09:41:33 +00:00
Mark Simulacrum
33f5ceee1f stage0 cfg cleanup 2018-02-20 08:52:33 -07:00
Jeffrey Seyfried
4294528b5d Improve hygiene when privacy-checking struct expression or struct constructor fields. 2018-02-17 21:48:35 -08:00
Matthias Krüger
4452446292 fix more typos found by codespell. 2018-02-17 17:38:49 +01:00
Carol (Nichols || Goulding)
e168aa385b
Reexport -> re-export in prose and documentation comments 2018-01-15 13:36:53 -05:00
leonardo.yvens
f93183adb4 Remove impl Foo for .. in favor of auto trait Foo
No longer parse it.
Remove AutoTrait variant from AST and HIR.
Remove backwards compatibility lint.
Remove coherence checks, they make no sense for the new syntax.
Remove from rustdoc.
2018-01-13 18:48:00 +03:00
Alex Crichton
8c9bf663d4 rustc: Don't use relative paths for extended errors
These no longer work now that Cargo changes the cwd of rustc while it's running.
Instead use an absolute path that's set by rustbuild.
2018-01-04 07:21:22 -08:00
Jonas Platte
78493ed21a Add GenericParam, refactor Generics in ast, hir, rustdoc
The Generics now contain one Vec of an enum for the generic parameters,
rather than two separate Vec's for lifetime and type parameters.

Additionally, places that previously used Vec<LifetimeDef> now use
Vec<GenericParam> instead.
2017-12-21 13:38:10 +01:00
Vadim Petrochenkov
c6209a36bb Always report private-in-public in associated types as hard errors
according to RFC 2145.

Fix a silly label message.
2017-12-21 03:19:05 +03:00
Vadim Petrochenkov
020961d880 Prohibit access to private statics from other crates through macros 2.0 2017-12-21 03:17:19 +03:00
Vadim Petrochenkov
190adc0e19 Properly check traits in type privacy 2017-12-21 03:17:19 +03:00
Alex Burka
2eefc9db15 add trait aliases to HIR 2017-12-14 12:56:26 -05:00
Jeffrey Seyfried
58e80400b2 Include non-pub use and extern crate items in the crate metadata for macros 2.0. 2017-12-05 17:23:01 -08:00
Christopher Vittal
8fd48e7d59 Split hir::TyImplTrait, move checks to HIR lowering
Replace hir::TyImplTrait with TyImplTraitUniversal and
TyImplTraitExistential.

Add an ImplTraitContext enum to rustc::hir::lowering to track the kind
and allowedness of an impl Trait.

Significantly alter lowering to thread ImplTraitContext and one other
boolean parameter described below throughought much of lowering.

The other parameter is for tracking if lowering a function is in a trait
impl, as there is not enough information to otherwise know this
information during lowering otherwise.

This change also removes the checks from ast_ty_to_ty for impl trait
allowedness as they are now all taking place in HIR lowering.
2017-11-15 15:46:01 -05:00
bors
d762b1d6c6 Auto merge of #45394 - davidtwco:rfc-2008, r=petrochenkov
RFC 2008: Future-proofing enums/structs with #[non_exhaustive] attribute

This work-in-progress pull request contains my changes to implement [RFC 2008](https://github.com/rust-lang/rfcs/pull/2008). The related tracking issue is #44109.

As of writing, enum-related functionality is not included and there are some issues related to tuple/unit structs. Enum related tests are currently ignored.

WIP PR requested by @nikomatsakis [in Gitter](https://gitter.im/rust-impl-period/WG-compiler-middle?at=59e90e6297cedeb0482ade3e).
2017-11-04 18:07:07 +00:00
David Wood
059eccb07f
Implemented RFC 2008 for enums (not including variants) and structs. 2017-11-03 19:36:18 +00:00
leonardo.yvens
06506bb751 [Syntax Breaking] Rename DefaultImpl to AutoImpl
DefaultImpl is a highly confusing name for what we now call auto impls,
as in `impl Send for ..`. The name auto impl is not formally decided
but for sanity anything is better than `DefaultImpl` which refers
neither to `default impl` nor to `impl Default`.
2017-11-03 16:13:20 -02:00
Paul Lietar
77f7e85d7f Implement RFC 1861: Extern types 2017-10-27 23:01:34 +02:00
Wesley Wiser
8281e883dd Switch several crate-wide queries to use eval_always
Closes #45238
2017-10-26 18:47:47 -04:00
Vadim Petrochenkov
419069d984 Use recorded types in rustc_privacy 2017-09-23 00:50:46 +03:00
Alex Crichton
caaf365a9d rustc: Remove HirId from queries
This'll allow us to reconstruct query parameters purely from the `DepNode`
they're associated with. Some queries could move straight to `HirId` but others
that don't always have a correspondance between `HirId` and `DefId` moved to
two-level maps where the query operates over a `DefIndex`, returning a map,
which is then keyed off `ItemLocalId`.

Closes #44414
2017-09-11 07:53:48 -07:00
Alex Crichton
43ae380191 rustc: Flag some CrateStore methods as "untracked"
The main use of `CrateStore` *before* the `TyCtxt` is created is during
resolution, but we want to be sure that any methods used before resolution are
not used after the `TyCtxt` is created. This commit starts moving the methods
used by resolve to all be named `{name}_untracked` where the rest of the
compiler uses just `{name}` as a query.

During this transition a number of new queries were added to account for
post-resolve usage of these methods.
2017-09-05 07:37:39 -07:00
Mark Simulacrum
f3b7197384 Rollup merge of #44202 - alexcrichton:xcrate-generators, r=arielb1
rustc: Fix reachability with cross-crate generators

Same solution as in f2df1857

Closes #44181
2017-08-31 18:07:42 -06:00
Alex Crichton
41d3e83183 rustc: Fix reachability with cross-crate generators
Same solution as in f2df1857

Closes #44181
2017-08-30 17:32:21 -07:00
Alex Crichton
5c279a40ae Merge branch 'hide-trait-map' into rollup 2017-08-30 13:17:40 -07:00
Alex Crichton
942c8dcf19 rustc: Make the export_map of TyCtxt private
This map, like `trait_map`, is calculated in resolve, but we want to be sure to
track it for incremental compliation. Hide it behind a query to get more
refactorings later.
2017-08-29 22:00:40 -07:00
Vadim Petrochenkov
3da868dcb6 Make fields of Span private 2017-08-30 01:38:54 +03:00
Tamir Duberstein
b3f50caee0
*: remove crate_{name,type} attributes
Fixes #41701.
2017-08-25 16:18:21 -04:00
Vadim Petrochenkov
de4dbe5789 rustc: Remove some dead code 2017-08-19 13:27:16 +03:00
Zack M. Davis
1b6c9605e4 use field init shorthand EVERYWHERE
Like #43008 (f668999), but _much more aggressive_.
2017-08-15 15:29:17 -07:00
bors
0d12553320 Auto merge of #43740 - michaelwoerister:local-id-in-typecktables, r=arielb1
Use hir::ItemLocalId as keys in TypeckTables.

This PR makes `TypeckTables` use `ItemLocalId` instead of `NodeId` as key. This is needed for incremental compilation -- for stable hashing and for being able to persist and reload these tables. The PR implements the most important part of https://github.com/rust-lang/rust/issues/40303.

Some notes on the implementation:
* The PR adds the `HirId` to HIR nodes where needed (`Expr`, `Local`, `Block`, `Pat`) which obviates the need to store a `NodeId -> HirId` mapping in crate metadata. Thanks @eddyb for the suggestion! In the future the `HirId` should completely replace the `NodeId` in HIR nodes.
* Before something is read or stored in one of the various `TypeckTables` subtables, the entry's key is validated via the new `TypeckTables::validate_hir_id()` method. This makes sure that we are not mixing information from different items in a single table.

That last part could be made a bit nicer by either (a) new-typing the table-key and making `validate_hir_id()` the only way to convert a `HirId` to the new-typed key, or (b) just encapsulate sub-table access a little better. This PR, however, contents itself with not making things significantly worse.

Also, there's quite a bit of switching around between `NodeId`, `HirId`, and `DefIndex`. These conversions are cheap except for `HirId -> NodeId`, so if the valued reviewer finds such an instance in a performance critical place, please let me know.

Ideally we convert more and more code from `NodeId` to `HirId` in the future so that there are no more `NodeId`s after HIR lowering anywhere. Then the amount of switching should be minimal again.

r? @eddyb, maybe?
2017-08-14 14:15:06 +00:00
Michael Woerister
f2df18579b Mark closures return via impl-trait as reachable. 2017-08-14 12:04:52 +02:00
Michael Woerister
6fd7d8586c Fix some merge fallout. 2017-08-14 11:21:34 +02:00
Michael Woerister
a69eaf62c5 Improve validation of TypeckTables keys. 2017-08-11 12:17:07 +02:00
Michael Woerister
1f54df1101 Encapsulate sub-table access in TypeckTables and validate keys on each access. 2017-08-11 12:17:07 +02:00
Michael Woerister
7f2423eede Use ItemLocalId as key for node_types, node_substs, and adjustments in TypeckTables. 2017-08-11 12:11:38 +02:00
Michael Woerister
783ccc443b Make TypeckTables::type_dependent_defs use ItemLocalId instead of NodeId. 2017-08-11 12:11:38 +02:00
bors
2400ebfe76 Auto merge of #43522 - alexcrichton:rewrite-lints, r=michaelwoerister
rustc: Rearchitect lints to be emitted more eagerly

In preparation for incremental compilation this commit refactors the lint
handling infrastructure in the compiler to be more "eager" and overall more
incremental-friendly. Many passes of the compiler can emit lints at various
points but before this commit all lints were buffered in a table to be emitted
at the very end of compilation. This commit changes these lints to be emitted
immediately during compilation using pre-calculated lint level-related data
structures.

Linting today is split into two phases, one set of "early" lints run on the
`syntax::ast` and a "late" set of lints run on the HIR. This commit moves the
"early" lints to running as late as possible in compilation, just before HIR
lowering. This notably means that we're catching resolve-related lints just
before HIR lowering. The early linting remains a pass very similar to how it was
before, maintaining context of the current lint level as it walks the tree.

Post-HIR, however, linting is structured as a method on the `TyCtxt` which
transitively executes a query to calculate lint levels. Each request to lint on
a `TyCtxt` will query the entire crate's 'lint level data structure' and then go
from there about whether the lint should be emitted or not.

The query depends on the entire HIR crate but should be very quick to calculate
(just a quick walk of the HIR) and the red-green system should notice that the
lint level data structure rarely changes, and should hopefully preserve
incrementality.

Overall this resulted in a pretty big change to the test suite now that lints
are emitted much earlier in compilation (on-demand vs only at the end). This in
turn necessitated the addition of many `#![allow(warnings)]` directives
throughout the compile-fail test suite and a number of updates to the UI test
suite.

Closes https://github.com/rust-lang/rust/issues/42511
2017-08-10 11:20:15 +00:00
Alex Crichton
0374e6aab7 rustc: Rearchitect lints to be emitted more eagerly
In preparation for incremental compilation this commit refactors the lint
handling infrastructure in the compiler to be more "eager" and overall more
incremental-friendly. Many passes of the compiler can emit lints at various
points but before this commit all lints were buffered in a table to be emitted
at the very end of compilation. This commit changes these lints to be emitted
immediately during compilation using pre-calculated lint level-related data
structures.

Linting today is split into two phases, one set of "early" lints run on the
`syntax::ast` and a "late" set of lints run on the HIR. This commit moves the
"early" lints to running as late as possible in compilation, just before HIR
lowering. This notably means that we're catching resolve-related lints just
before HIR lowering. The early linting remains a pass very similar to how it was
before, maintaining context of the current lint level as it walks the tree.

Post-HIR, however, linting is structured as a method on the `TyCtxt` which
transitively executes a query to calculate lint levels. Each request to lint on
a `TyCtxt` will query the entire crate's 'lint level data structure' and then go
from there about whether the lint should be emitted or not.

The query depends on the entire HIR crate but should be very quick to calculate
(just a quick walk of the HIR) and the red-green system should notice that the
lint level data structure rarely changes, and should hopefully preserve
incrementality.

Overall this resulted in a pretty big change to the test suite now that lints
are emitted much earlier in compilation (on-demand vs only at the end). This in
turn necessitated the addition of many `#![allow(warnings)]` directives
throughout the compile-fail test suite and a number of updates to the UI test
suite.
2017-08-09 09:13:51 -07:00
Isaac van Bakel
400075d9d9 Fixed all unnecessary muts in language core 2017-08-01 23:01:24 +01:00
Tobias Schottdorf
687ee7fee4 Downgrade ProjectionTy's TraitRef to its substs
Addresses the second part of #42171 by removing the `TraitRef` from
`ProjectionTy`, and directly storing its `Substs`.

Closes #42171.
2017-07-11 10:33:09 -04:00
Vadim Petrochenkov
8c44a9dca7 Store all generic arguments for method calls in HIR 2017-07-10 00:20:25 +03:00