Commit Graph

732 Commits

Author SHA1 Message Date
bors
7fd331e166 Auto merge of #32328 - jseyfried:coherence, r=nikomatsakis
resolve: Improve import failure detection and lay groundwork for RFC 1422

This PR improves import failure detection and lays some groundwork for RFC 1422.
More specifically, it
 - Avoids recomputing the resolution of an import directive's module path.
 - Refactors code in `resolve_imports` that does not scale to the arbitrarily many levels of visibility that will be required by RFC 1422.
  - Replaces `ModuleS`'s fields `public_glob_count`, `private_glob_count`, and `resolved_globs` with a list of glob import directives `globs`.
  - Replaces `NameResolution`'s fields `pub_outstanding_references` and `outstanding_references` with a field `single_imports` of a newly defined type `SingleImports`.
 - Improves import failure detection by detecting cycles that include single imports (currently, only cycles of globs are detected). This fixes #32119.

r? @nikomatsakis
2016-04-04 21:50:05 -07:00
Seo Sanghyeon
a09a3acbbd Remove outdated comment 2016-04-04 20:32:42 +09:00
Benjamin Herr
d05f726eed librustc_resolve: use bug!(), span_bug!() 2016-03-31 22:06:52 +02:00
Jeffrey Seyfried
6f09deaa32 Fix suggestions 2016-03-31 05:12:10 +00:00
Jeffrey Seyfried
3d9db59566 Detect cycles that include renamed imports 2016-03-30 23:50:19 +00:00
Jeffrey Seyfried
85a1209570 Improve import failure detection 2016-03-27 22:27:21 +00:00
Jeffrey Seyfried
bfb832e7c8 Add SingleImports and use it in place of outstanding_references
and `pub_outstanding_references`.
2016-03-27 22:27:18 +00:00
Jeffrey Seyfried
5ff21f138a Refactor ModuleS fields public_glob_count, private_glob_count, and
`resolved_globs` into a single field `globs: RefCell<Vec<ImportDirective>>`.
2016-03-27 03:53:42 +00:00
Jeffrey Seyfried
0d1bc02da8 Avoid recomputing the target module for an import directive. 2016-03-27 03:53:26 +00:00
Jeffrey Seyfried
b83739af4e Add a field target_module: Cell<Option<Module>> to ImportDirective 2016-03-27 03:53:24 +00:00
Jeffrey Seyfried
fc06ea5f9c Add a type parameter to ImportDirective 2016-03-27 03:53:23 +00:00
Eduard Burtescu
5efdde0de1 rustc: move cfg, infer, traits and ty from middle to top-level. 2016-03-27 01:05:54 +02:00
Eduard Burtescu
5647586ed3 rustc: move middle::subst into middle::ty. 2016-03-27 01:05:53 +02:00
Jeffrey Seyfried
e011ae5ea9 Cleanup trait search 2016-03-26 18:23:57 +00:00
Jeffrey Seyfried
60a836fc93 Remove unnecessary pubs 2016-03-26 18:23:56 +00:00
Jeffrey Seyfried
227cc5cd26 Remove an if statement with an condition that is always false 2016-03-26 18:23:56 +00:00
Jeffrey Seyfried
3e7a22e3bc Remove outdated comment 2016-03-26 18:23:55 +00:00
Jeffrey Seyfried
4b6b506ef4 Improve the error message for paths with too many initial supers 2016-03-26 18:23:54 +00:00
Jeffrey Seyfried
8988c4538e Refactor away resolve_import_for_module 2016-03-26 18:23:53 +00:00
Jeffrey Seyfried
43dffc3294 Avoid passing around the current module as an argument in resolve_imports 2016-03-26 18:23:52 +00:00
Jeffrey Seyfried
bb09ae28c0 Refactor away resolve_name_in_lexical_scope and resolve_identifier_in_local_ribs. 2016-03-26 18:23:45 +00:00
Jeffrey Seyfried
73417853e4 Refactor out the common functionality of
`resolve_item_in_lexical_scope` and `resolve_identifier_in_local_ribs` into
a new function `resolve_ident_in_lexical_scope`.
2016-03-26 18:22:42 +00:00
Jeffrey Seyfried
07fecf8098 Replace uses of DefLike with Def (only the DlDef variant of DefLike was being used) 2016-03-26 18:22:41 +00:00
Jeffrey Seyfried
1744f55ad7 Refactor away GraphBuilder 2016-03-26 18:22:40 +00:00
Jeffrey Seyfried
0bed9aea2d Make populate_module_if_necessary a method of resolver 2016-03-26 18:22:37 +00:00
Jeffrey Seyfried
77f0f4a624 Avoid repeating parent 2016-03-26 18:22:34 +00:00
Jeffrey Seyfried
ff014a3a10 Refactor away populate_external_module 2016-03-26 18:22:33 +00:00
Jeffrey Seyfried
7bc6c75d0f Refactor away handle_external_def 2016-03-26 18:22:31 +00:00
Manish Goregaokar
b8b17a54cf Rollup merge of #32131 - petrochenkov:prim, r=eddyb
resolve: Minimize hacks in name resolution of primitive types

When resolving the first unqualified segment in a path with `n` segments and `n - 1` associated item segments, e.g. (`a` or `a::assoc` or `a::assoc::assoc` etc) try to resolve `a` without considering primitive types first. If the "normal" lookup fails or results in a module, then try to resolve `a` as a primitive type as a fallback.

This way backward compatibility is respected, but the restriction from E0317 can be lifted, i.e. primitive names mostly can be shadowed like any other names.

Furthermore, if names of primitive types are [put into prelude](https://github.com/petrochenkov/rust/tree/prim2) (now it's possible to do), then most of names will be resolved in conventional way and amount of code relying on this fallback will be greatly reduced. Although, it's not entirely convenient to put them into prelude right now due to temporary conflicts like `use prelude::v1::*; use usize;` in libcore/libstd, I'd better wait for proper glob shadowing before doing it.
I wish the `no_prelude` attribute were unstable as intended :(

cc @jseyfried @arielb1
r? @eddyb
2016-03-26 09:07:20 +05:30
Jeffrey Seyfried
54cd4d1472 Add and use resolve_name_in_lexical_scope and
exclude the prelude from `resolve_name(.., allow_private_imports = true)`.
2016-03-25 22:22:15 +00:00
Jeffrey Seyfried
de970b1dff Refactor away NameResolution::result 2016-03-25 22:22:15 +00:00
Jeffrey Seyfried
5a8845e40b Refactor away DefModifiers::PRELUDE 2016-03-25 22:22:15 +00:00
Jeffrey Seyfried
febef471e3 Refactor how the prelude is handled 2016-03-25 22:22:12 +00:00
Jeffrey Seyfried
21064d097e Refactor away resolve_imports::Shadowable and rename shadowable -> is_prelude 2016-03-25 22:18:30 +00:00
bors
64a13a4660 Auto merge of #31908 - jseyfried:disallow_shadowed_traits, r=nikomatsakis
Disallow methods from traits that are not in scope

This PR only allows a trait method to be used if the trait is in scope (fixes #31379).
This is a [breaking-change]. For example, the following would break:
```rust
mod foo {
    pub trait T { fn f(&self) {} }
    impl T for () {}
}

mod bar { pub use foo::T; }

fn main() {
    pub use bar::*;
    struct T; // This shadows the trait `T`,
    ().f() // making this an error.
}
```
r? @nikomatsakis
2016-03-25 05:03:13 -07:00
Vadim Petrochenkov
b418cd2306 Cleanup
+ Fix a comment and add a test based on it
2016-03-25 00:41:09 +03:00
Vadim Petrochenkov
77f033bac1 Lift the restriction on reusing names of primitive types 2016-03-25 00:41:09 +03:00
Vadim Petrochenkov
8d4b1d1cf3 Introduce name resolution fallback for primitive types 2016-03-25 00:41:09 +03:00
Felix S. Klock II
213d57983d Expose attached attributes to FnKind abstraction so that I can look at them in borrowck. 2016-03-21 18:36:22 +01:00
tiehuis
1138866b1f Alter E0412 help message wording
The initial wording does not make sense due to an extra 'to'.

There are two potential candidates we can change this to:
 - 'you can import it into scope'
 - 'to import it into scope'

In keeping the changes minimal, we choose the first, as this is more in line with the grammar of the extended candidates help message.
2016-03-20 16:02:31 +13:00
Jeffrey Seyfried
ae4e1082d4 Disallow methods from shadowed traits 2016-03-17 11:50:38 +00:00
Jeffrey Seyfried
65ec4dfe61 Improve diagnostics for duplicate names 2016-03-16 08:52:31 +00:00
bors
d5880fff99 Auto merge of #32227 - jseyfried:fix_import_resolution_bug, r=alexcrichton
Fix import resolution bug

This fixes #32222, which was introduced in #31726.
2016-03-13 12:24:42 -07:00
Jeffrey Seyfried
9ca3ff16ad Fixes #32222 2016-03-13 10:46:19 +00:00
Jeffrey Seyfried
fa18403a2f Refactor out methods NameResolution::increment_outstanding_references and
`NameResolution::decrement_outstanding_references`.
2016-03-13 10:45:08 +00:00
bors
06074ac004 Auto merge of #32141 - jseyfried:fix_resolution_in_lexical_scopes, r=nikomatsakis
Fix name resolution in lexical scopes

Currently, `resolve_item_in_lexical_scope` does not check the "ribs" (type parameters and local variables). This can allow items that should be shadowed by type parameters to be named.

For example,
```rust
struct T { i: i32 }
fn f<T>() {
    let t = T { i: 0 }; // This use of `T` resolves to the struct, not the type parameter
}

mod Foo {
    pub fn f() {}
}
fn g<Foo>() {
    Foo::f(); // This use of `Foo` resolves to the module, not the type parameter
}
```

This PR changes `resolve_item_in_lexical_scope` so that it fails when the item is shadowed by a rib (fixes #32120).
This is a [breaking-change], but it looks unlikely to cause breakage in practice.

r? @nikomatsakis
2016-03-12 21:55:14 -08:00
Jeffrey Seyfried
e926f281df Comment resolve_item_in_lexical_scope 2016-03-11 23:59:02 +00:00
bors
5807fbbfde Auto merge of #32134 - jseyfried:forbid_type_alias_as_module, r=nikomatsakis
Forbid glob-importing from a type alias

This PR forbids glob-importing from a type alias or trait (fixes #30560):
```rust
type Alias = ();
use Alias::*; // This is currently allowed but shouldn't be
```

This is a [breaking-change]. Since the disallowed glob imports don't actually import anything, any breakage can be fixed by removing the offending glob import.

r? @alexcrichton
2016-03-11 09:26:47 -08:00
bors
3ac4076ac0 Auto merge of #32097 - jseyfried:fix_resolution_regression, r=nikomatsakis
Fix a regression in import resolution

This fixes #32089 (caused by #31726) by deducing that name resolution has failed (as opposed to being determinate) in more cases.

r? @nikomatsakis
2016-03-09 22:41:48 -08:00
Jeffrey Seyfried
1a6092e05c Forbid use Trait::* 2016-03-09 05:18:07 +00:00
Jeffrey Seyfried
87708b7b1f Refactor away check_ribs 2016-03-08 23:28:34 +00:00
Jeffrey Seyfried
210109cf7b Include the crate root in the ribs 2016-03-08 23:28:34 +00:00
Jeffrey Seyfried
7f3491c39d Fix name resolution in lexical scopes 2016-03-08 23:28:33 +00:00
Jeffrey Seyfried
ad28c28f46 Stop treating a type alias like a module or enum (preventing use TypeAlias::*) 2016-03-08 21:50:20 +00:00
Jeffrey Seyfried
4dc4cae79a Add a comment 2016-03-07 22:43:56 +00:00
Jeffrey Seyfried
a0efd7ebdb Deduce that a name resolution fails (as opposed to being indeterminte) in more cases. 2016-03-07 11:24:23 +00:00
Jeffrey Seyfried
61f1f4d21e Add a field pub_outstanding_references to NameResolution.
Add an argument `allow_private_imports` to some methods.
2016-03-07 11:24:20 +00:00
Jeffrey Seyfried
2998564615 Refactor away ExternalExports 2016-03-06 05:46:49 +00:00
Jeffrey Seyfried
b3572ae15a Finish encapsulating the details of import resolution in resolve_imports 2016-03-04 20:48:55 +00:00
Jeffrey Seyfried
51ca449f74 Refactor away define 2016-03-04 20:48:54 +00:00
Jeffrey Seyfried
20b99d303d Start importing bindings from globs as soon as the glob path is known. 2016-03-04 20:48:51 +00:00
Jeffrey Seyfried
fb4710ce21 Add a field in Module for the ResolverArenas 2016-03-04 20:48:50 +00:00
Jeffrey Seyfried
6b94bc345c Add an arena for import directives 2016-03-04 20:48:49 +00:00
Jeffrey Seyfried
064f17c6a3 Record that an import succeeded or failed in one namespace even while it is indeterminate in the other namespace (fixes #31444) 2016-03-04 20:48:43 +00:00
bors
7cee8b9ffb Auto merge of #31824 - jseyfried:privacy_in_resolve, r=nikomatsakis
This PR privacy checks paths as they are resolved instead of in `librustc_privacy` (fixes #12334 and fixes #31779). This removes the need for the `LastPrivate` system introduced in PR #9735, the limitations of which cause #31779.

This PR also reports privacy violations in paths to intra- and inter-crate items the same way -- it always reports the first inaccessible segment of the path.

Since it fixes #31779, this is a [breaking-change]. For example, the following code would break:
```rust
mod foo {
    pub use foo::bar::S;
    mod bar { // `bar` should be private to `foo`
        pub struct S;
    }
}

impl foo::S {
    fn f() {}
}

fn main() {
    foo::bar::S::f(); // This is now a privacy error
}
```

r? @alexcrichton
2016-03-03 02:21:28 +00:00
bors
7b0b80ae21 Auto merge of #32005 - vegai:31686, r=Manishearth
Fix note for type alias in trait position

Fixes #31686
2016-03-02 22:15:51 +00:00
Vadim Petrochenkov
9047b201bf Move span into StructField
+ some cleanup in rustdoc
2016-03-02 10:32:04 +03:00
Vadim Petrochenkov
8b026a6e48 Use numeric field Names ("0", "1" etc) for positional fields 2016-03-02 10:31:19 +03:00
Vadim Petrochenkov
8b60b948d9 Get rid of hir::StructFieldKind 2016-03-02 10:31:19 +03:00
vegai
bd7e422996 Add a span note on type definition spot 2016-03-02 07:06:22 +02:00
vegai
59fafcf00c span_note => fileline_note 2016-03-01 21:33:35 +02:00
bors
9c6a0088fb Auto merge of #31857 - jseyfried:fix_scoping, r=nikomatsakis
This fixes a bug (#31845) introduced in #31105 in which lexical scopes contain items from all anonymous module ancestors, even if the path to the anonymous module includes a normal module:
```rust
fn f() {
    fn g() {}
    mod foo {
        fn h() {
           g(); // This erroneously resolves on nightly
        }
    }
}
```

This is a [breaking-change] on nightly but not on stable or beta.
r? @nikomatsakis
2016-02-26 04:38:28 +00:00
Jeffrey Seyfried
b20d567c2b Privacy check paths in resolve and typeck 2016-02-26 00:37:27 +00:00
Jeffrey Seyfried
07957ffb2e Refactor Module's field extern_crate_did: Option<DefId> to extern_crate_id: Option<NodeId> 2016-02-26 00:37:27 +00:00
Jeffrey Seyfried
8f32fdecfb Remove LastPrivate 2016-02-26 00:37:27 +00:00
Jeffrey Seyfried
2942cf7b0a Improve unused import detection 2016-02-24 13:13:46 +00:00
Jeffrey Seyfried
7ad7065c35 Uncapitalize note messages 2016-02-24 13:12:13 +00:00
Jeffrey Seyfried
197326d17b Resolve: include normal modules in the ribs 2016-02-24 06:31:55 +00:00
Jeffrey Seyfried
f8d6dcf46e Warn when reexporting a private extern crate 2016-02-24 01:34:20 +00:00
Jeffrey Seyfried
3358fb11da Fix the visibility of extern crate declarations and stop warning on pub extern crate 2016-02-24 01:34:14 +00:00
bors
e628398f34 Auto merge of #31811 - alexcrichton:clean-deps, r=sanxiyn
The standard library doesn't depend on rustc_bitflags, so move it to explicit
dependencies on all other crates. Additionally, the arena/fmt_macros deps could
be dropped from libsyntax.
2016-02-22 05:20:39 +00:00
Alex Crichton
95761417c3 rustbuild: Sync some Cargo.toml/lib.rs dependencies
The standard library doesn't depend on rustc_bitflags, so move it to explicit
dependencies on all other crates. Additionally, the arena/fmt_macros deps could
be dropped from libsyntax.
2016-02-21 09:49:13 -08:00
bors
2d14b39204 Auto merge of #31747 - jseyfried:stop_resolve_after_fail, r=nrc
Now that #31461 is merged, a failing resolution can never become indeterminate or succeed, so we no longer have to keep trying to resolve failing import directives.
r? @nrc
2016-02-20 14:33:13 +00:00
bors
cfabd17372 Auto merge of #31674 - VladUreche:issue/21221, r=nikomatsakis
This commit adds functionality that allows the name resolution pass
to search for entities (traits/types/enums/structs) by name, in
order to show recommendations along with the errors.

For now, only E0405 and E0412 have suggestions attached, as per the
request in bug #21221, but it's likely other errors can also benefit
from the ability to generate suggestions.
2016-02-20 10:40:42 +00:00
bors
28a3e8bb51 Auto merge of #31742 - frewsxcv:needless-lifetimes, r=pnkfelix
These explicit lifetimes can be ommitted because of lifetime elision
rules. Instances were found using rust-clippy.
2016-02-19 13:49:46 +00:00
bors
917db28b55 Auto merge of #31716 - jseyfried:fix_privacy_for_def_err, r=nrc
Fixes #31714
2016-02-19 02:18:25 +00:00
Jeffrey Seyfried
08b9097197 Improve dummy bindings for unresolved imports 2016-02-19 00:43:52 +00:00
Vlad Ureche
88af8fa0b1 Show candidates for names not in scope
This commit adds functionality that allows the name resolution pass
to search for entities (traits/types/enums/structs) by name, in
order to show recommendations along with the errors.

For now, only E0405 and E0412 have suggestions attached, as per the
request in bug #21221, but it's likely other errors can also benefit
from the ability to generate suggestions.
2016-02-19 01:10:36 +01:00
Corey Farwell
5850d16d52 Remove unnecessary explicit lifetime bounds.
These explicit lifetimes can be ommitted because of lifetime elision
rules. Instances were found using rust-clippy.
2016-02-18 08:37:10 -05:00
Jeffrey Seyfried
5ad84f1301 Replace the field imports in Module with unresolved_imports and refactor away resolved_import_count 2016-02-18 00:02:50 +00:00
Jeffrey Seyfried
845ad1b4ed Stop trying to resolve an import directive after the resolution fails 2016-02-17 23:55:00 +00:00
Steve Klabnik
0a88c8fb19 Rollup merge of #31679 - GuillaumeGomez:long_error_explanation, r=Manishearth
r? @Manishearth
2016-02-17 18:14:36 -05:00
bors
0d1cd9bd6a Auto merge of #31685 - petrochenkov:patrefact2, r=eddyb
And split `PatKind::Enum` into `PatKind::TupleStruct` and `PatKind::Path`.
This is the HIR part of https://github.com/rust-lang/rust/pull/31581.
This is also kind of a preparation for https://github.com/rust-lang/rfcs/pull/1492.

r? @eddyb
2016-02-17 06:01:49 +00:00
Jeffrey Seyfried
1b5d2f21d6 Don't compute LastPrivate data for Def::Err. 2016-02-16 22:22:57 +00:00
Vadim Petrochenkov
06755d90ce Split PatKind::Enum into PatKind::TupleStruct and PatKind::Path 2016-02-16 00:40:38 +03:00
ggomez
1c8766761e Global error explanations improvements 2016-02-15 17:57:21 +01:00
bors
4ce803837e Auto merge of #31648 - jseyfried:fix_diagnostics, r=nrc
This PR fixes two unrelated diagnostics bugs in resolve.

First, it reports privacy errors for an import only after the import resolution is determined, fixing #31402.

Second, it expands the per-module map from block ids to anonymous modules so that it also maps module declarations ids to modules, and it uses this map to in `with_scope` to fix #31644.

r? @nrc
2016-02-15 07:13:02 +00:00
bors
69ad91290d Auto merge of #31566 - jseyfried:fix_regression, r=nrc
This fixes a regression caused by #31461 allowing extern crates to be glob imported, and it fixes the test that was supposed to catch it.
r? @nrc
2016-02-15 05:19:29 +00:00
Vadim Petrochenkov
9b40e1e5b3 Rename hir::Pat_ and its variants 2016-02-14 15:25:12 +03:00
Jeffrey Seyfried
81d5d02c37 Rename Module field anonymous_children to module_children, expand it to include both named an anonymous modules, and fix #31644 2016-02-14 09:05:37 +00:00
Jeffrey Seyfried
4af85643b1 Rename Module field children to resolutions 2016-02-14 08:47:55 +00:00
Jeffrey Seyfried
b7889ef235 Report privacy errors at most once per import (fixes #31402) 2016-02-13 21:35:32 +00:00
bors
3548b8c273 Auto merge of #31524 - jonas-schievink:autoderef, r=steveklabnik 2016-02-13 00:16:03 +00:00
Jonas Schievink
8ac5f87db8 Autoderef in librustc_resolve 2016-02-12 19:28:42 +01:00
bors
ce4b75f256 Auto merge of #30726 - GuillaumeGomez:compile-fail, r=brson
r? @brson
cc @alexcrichton

I still need to add error code explanation test with this, but I can't figure out a way to generate the `.md` files in order to test example source codes.

Will fix #27328.
2016-02-12 18:25:08 +00:00
Alex Crichton
2581b14147 bootstrap: Add a bunch of Cargo.toml files
These describe the structure of all our crate dependencies.
2016-02-11 11:12:32 -08:00
Oliver Schneider
625e78b700 [breaking-change] don't glob export ast::{UintTy, IntTy} variants 2016-02-11 12:34:48 +01:00
Oliver Schneider
ccf48bcd40 [breaking-change] don't glob export ast::FloatTy variants 2016-02-11 12:34:48 +01:00
Jeffrey Seyfried
91894631d0 Fix regression from #31461 and fix the test that was supposed to catch it. 2016-02-11 07:27:12 +00:00
Jeffrey Seyfried
3df40c09ec Allow prelude imports to shadow eachother (needed for the [pretty] tests)
Derive the Default impl for NameResolution
2016-02-09 17:30:45 +00:00
Jeffrey Seyfried
3c62d90202 Reallow methods from traits that are shadowed by non-import items 2016-02-08 02:25:10 +00:00
Jeffrey Seyfried
d7734aebec Refactor away add_export and cleanup the end of resolve_single_import 2016-02-08 02:25:09 +00:00
Jeffrey Seyfried
7000e70825 Replace children and import_resolutions with a single NameResolution-valued map.
Refactor away resolve_name_in_module in resolve_imports.rs

Rewrite and improve the core name resolution procedure in NameResolution::result and Module::resolve_name

Refactor the duplicate checking code into NameResolution::try_define
2016-02-08 02:25:08 +00:00
Jeffrey Seyfried
d881eee608 Change try_define_child to return a Result instead of an Option 2016-02-08 02:25:07 +00:00
Jeffrey Seyfried
16e7ff1bff Write and use increment_outstanding_references_for and decrement_outstanding_references_for 2016-02-08 02:25:05 +00:00
Jeffrey Seyfried
96b4dc4b87 Refactor away the fields id and is_public of ImportResolution and rename ImportResolution to NameResolution 2016-02-08 02:25:03 +00:00
Jeffrey Seyfried
4428b1cfdf Refactor away separate tracking of used_public and used_reexport.
NameBinding now encodes these directly with binding.is_public() and (binding.is_public() && binding.is_import()) (respectively)
2016-02-08 02:25:00 +00:00
Jeffrey Seyfried
2e24c7410f Expand NameBinding to better represent bindings from imports 2016-02-08 02:24:53 +00:00
Jeffrey Seyfried
22e189ed57 Add and use an arena for NameBindings 2016-02-08 02:24:16 +00:00
Jeffrey Seyfried
7366d105cb Refactor away Target 2016-02-08 02:22:41 +00:00
Jeffrey Seyfried
661b7ce830 Make resolve_name_in_module solely responsible for tracking used crates in lib.rs 2016-02-08 02:21:36 +00:00
Guillaume Gomez
6407b9405f Update long error explanations 2016-02-07 13:03:35 +01:00
Niko Matsakis
35b6e2b0bb Instrument a bunch of tasks that employ the HIR map in one way or
another and were not previously instrumented.
2016-02-05 13:19:55 -05:00
Jeffrey Seyfried
9c166cb671 Remove unneeded borrows and slices 2016-02-03 23:40:46 +00:00
Jeffrey Seyfried
9fc71b4506 Remove unneeded use of Cell 2016-02-03 23:40:44 +00:00
Jeffrey Seyfried
79a3f22246 Refactor away resolve_item_by_name_in_lexical_scope 2016-02-03 23:40:38 +00:00
Jeffrey Seyfried
964b72b3e0 Refactor resolve_import_for_module 2016-02-03 23:39:16 +00:00
Jeffrey Seyfried
0c40621759 Refactor away resolve_module_in_lexical_scope 2016-02-03 23:39:14 +00:00
Jeffrey Seyfried
23bdbb13f4 Refactor block_needs_anonymous_module 2016-02-03 23:39:13 +00:00
Jeffrey Seyfried
2ed210d5fe Refactor more functionality into record_import_use 2016-02-03 23:39:12 +00:00
Jeffrey Seyfried
8e61ca4acc Refactor resolve_item_in_lexical_scope 2016-02-03 23:39:10 +00:00
Jeffrey Seyfried
298346dd5b Improve detection of unused imports 2016-02-03 23:39:08 +00:00
Dirk Gadsden
5ed8e98ea2 Add fake import resolutions & targets for names in bad imports 2016-02-02 20:47:34 -08:00
bors
28bed3f5e6 Auto merge of #31317 - jseyfried:remove_external_module_children, r=nrc
This PR refactors away `Module`'s `external_module_children` and instead puts `extern crate` declarations in `children` like other items, simplifying duplicate checking and name resolution.

This PR also allows values to share a name with extern crates, which are only defined in the type namespace. Other than that, it is a pure refactoring.

r? @nrc
2016-02-01 14:26:48 +00:00
bors
aaab14dd3f Auto merge of #31277 - DanielJCampbell:SpanEquality, r=nrc
r? @nrc
2016-02-01 10:25:31 +00:00
Daniel Campbell
e1be504068 Spans now derive equality 2016-02-01 10:18:50 +13:00
Jeffrey Seyfried
e768fa729f Refactor away the field Module::external_module_children in resolve 2016-01-31 03:38:41 +00:00
Jeffrey Seyfried
7a69ee0c48 Revert PR #30324, fixing a bug in which a public glob import can make preceding imports public (fixes #30159). 2016-01-31 02:21:54 +00:00
bors
9a07087bc5 Auto merge of #31288 - GuillaumeGomez:error_code_tidy, r=brson
r? @steveklabnik
2016-01-30 20:48:18 +00:00
Jeffrey Seyfried
afd42d2144 Remove resolve::dump_module 2016-01-29 21:18:23 +00:00
Jeffrey Seyfried
1ca9f03ead Nits and other local improvements in resolve 2016-01-29 21:18:15 +00:00
Jeffrey Seyfried
e13a0450d3 Clean up resolve_single_import 2016-01-29 21:18:14 +00:00
Jeffrey Seyfried
118c93ba5e Refactor away NameBindings, NsDef, ImportResolutionPerNamespace, DuplicateCheckingMode, and NamespaceDefinition. 2016-01-29 21:18:12 +00:00
ggomez
c78bf9d90c Add check for unused error codes 2016-01-29 16:37:02 +01:00
bors
ebe92e55f7 Auto merge of #31212 - jseyfried:fix_ICE_in_resolve, r=nrc
This fixes an ICE introduced by #31065 that occurs when a path cannot be resolved because of a certain class of unresolved import (`Indeterminate` imports).
For example, this currently causes an ICE:
```rust
mod foo { pub use self::*; }
fn main() { foo::f() }
```

r? @nrc
2016-01-29 13:45:03 +00:00
bors
f030d1fba1 Auto merge of #31144 - jseyfried:remove_import_ordering_restriction, r=nrc
We no longer require `use` and `extern crate` items to precede other items in modules thanks to [RFC #385](https://github.com/rust-lang/rfcs/pull/385), but we still require `use` and `extern crate` items to precede statements in blocks (other items can appear anywhere in a block).

I think that this is a needless distinction between imports and other items that contradicts the intent of the RFC.
2016-01-29 11:21:58 +00:00
Jeffrey Seyfried
d2d2144656 Refactor away NameSearchType 2016-01-28 05:07:40 +00:00
Jeffrey Seyfried
6ba35cecf6 Resolve: Fix an ICE that occurs when an identifier refers to an indeterminate import (i.e. one that is not resolved and not known to have failed) 2016-01-28 05:06:17 +00:00
bors
4b615854f0 Auto merge of #31120 - alexcrichton:attribute-deny-warnings, r=brson
This commit removes the `-D warnings` flag being passed through the makefiles to
all crates to instead be a crate attribute. We want these attributes always
applied for all our standard builds, and this is more amenable to Cargo-based
builds as well.

Note that all `deny(warnings)` attributes are gated with a `cfg(stage0)`
attribute currently to match the same semantics we have today
2016-01-26 22:10:10 +00:00
bors
43c1a173a8 Auto merge of #31105 - jseyfried:fix_lexical_scoping, r=nrc
This fixes #23880, a scoping bug in which items in a block are shadowed by local variables and type parameters that are in scope.

After this PR, an item in a block will shadow any local variables or type parameters above the item in the scope hierarchy. Items in a block will continue to be shadowed by local variables in the same block (even if the item is defined after the local variable).

This is a [breaking-change]. For example, the following code breaks:
```rust
fn foo() {
    let mut f = 1;
    {
        fn f() {}
        f += 1; // This will resolve to the function instead of the local variable
    }
}
2016-01-26 11:24:18 +00:00
Jeffrey Seyfried
faf0852fc1 Resolve: fix #23880, a scoping bug
This fixes a bug in which items in a block are shadowed by local variables and type parameters that are in scope.
It is a [breaking-change]. For example, the following code breaks:

```rust
fn foo() {
    let mut f = 1;
    {
        fn f() {}
        f += 1; // This will now resolve to the function instead of the local variable
    }
}
```

Any breakage can be fixed by renaming the item that is no longer shadowed.
2016-01-26 04:16:58 +00:00
bors
faf6d1e873 Auto merge of #31065 - nrc:ident-correct, r=pnkfelix
This PR adds some minor error correction to the parser - if there is a missing ident, we recover and carry on. It also makes compilation more robust so that non-fatal errors (which is still most of them, unfortunately) in parsing do not cause us to abort compilation. The effect is that a program with a missing or incorrect ident can get all the way to type checking.
2016-01-26 00:42:08 +00:00
Nick Cameron
43b3681588 Fix a rebasing issue and addressed reviewer comment 2016-01-26 07:00:18 +13:00
Alex Crichton
2273b52023 mk: Move from -D warnings to #![deny(warnings)]
This commit removes the `-D warnings` flag being passed through the makefiles to
all crates to instead be a crate attribute. We want these attributes always
applied for all our standard builds, and this is more amenable to Cargo-based
builds as well.

Note that all `deny(warnings)` attributes are gated with a `cfg(stage0)`
attribute currently to match the same semantics we have today
2016-01-24 20:35:55 -08:00
Steve Klabnik
82626b1ec8 Rollup merge of #31045 - Manishearth:diag-prim-shadow, r=steveklabnik
I tried to add an inline `span_suggestion()` to the error as well, but since generics don't have their own span it becomes too fragile/complicated to work.

r? @steveklabnik

fixes #19477
2016-01-23 09:38:42 -05:00
Jeffrey Seyfried
f05bc16a5d Resolve: stop requiring that use declarations precede statements in blocks 2016-01-23 08:05:57 +00:00
Vadim Petrochenkov
ff6b0aac6a resolve: Fix variant namespacing 2016-01-21 23:22:01 +03:00
Nick Cameron
585cf6fb5f Prevent missing idents from causing problems down the line 2016-01-22 08:19:27 +13:00
Nick Cameron
0ac8915875 The war on abort_if_errors 2016-01-22 08:19:27 +13:00
Vadim Petrochenkov
2084c2c33a Rename Def's variants and don't reexport them 2016-01-20 22:31:10 +03:00
Vadim Petrochenkov
d6c9aa8901 Fix associated const resolution on structs 2016-01-20 21:50:57 +03:00
Vadim Petrochenkov
ceaaa1bc33 Refactor definitions of ADTs in rustc::middle::def 2016-01-20 21:50:57 +03:00
Manish Goregaokar
a6778a2f36 Improve E0317 long diagnostics 2016-01-20 16:18:10 +05:30
Jeffrey Seyfried
a353490e6f resolve: Remove record_exports, fixes #4953 2016-01-14 22:51:58 +00:00
Jeffrey Seyfried
a8514d3ecc resolve: use arena allocation instead of reference counting for Modules to fix memory leaks from Rc cycles 2016-01-13 00:54:16 +00:00
bors
69e1f57dfb Auto merge of #30295 - jseyfried:fix_extern_crate_duplicate, r=nrc
Fix a bug allowing an item and an external crate to collide so long as the external crate is declared after the item. For example,
```rust
mod core { pub fn f() {} } // This would be an error if it followed the `extern crate`
extern crate core; // This declaration is shadowed by the preceding module

fn main() { core::f(); }
```
This is a [breaking-change], but it looks unlikely to cause breakage in practice, and any breakage can be fixed by removing colliding `extern crate` declarations, which are shadowed and hence unused.
2016-01-11 06:40:58 +00:00
Steve Klabnik
c518664ea5 Rollup merge of #30584 - GuillaumeGomez:new_handles, r=pnkfelix
Last part of #30413.

r? @pnkfelix
2016-01-08 13:02:30 -05:00
Guillaume Gomez
c07876951b Add new help messages for E0425 2016-01-08 13:33:44 +01:00
Jeffrey Seyfried
834fb17e94 Fix bug in duplicate checking for extern crates. 2016-01-06 07:04:48 +00:00
Nick Cameron
04d972906d Rebasing and review comments 2015-12-30 14:54:36 +13:00
Nick Cameron
aaa02b3ff9 Refactoring 2015-12-30 14:27:59 +13:00
Nick Cameron
95dc7efad0 use structured errors 2015-12-30 14:27:59 +13:00
Steve Klabnik
8e127ee626 Rollup merge of #30253 - Manishearth:diag-401-improve, r=steveklabnik
r? @steveklabnik
2015-12-29 15:55:08 -05:00
bors
4ce1dafd1d Auto merge of #30377 - Wafflespeanut:levenshtein, r=Manishearth
fixes part of #30197
2015-12-23 08:55:38 +00:00
Alex Crichton
cd1848a1a6 Register new snapshots
Lots of cruft to remove!
2015-12-21 09:26:21 -08:00
bors
e2834a20e7 Auto merge of #30413 - pnkfelix:fsk-span_note, r=Manishearth
Add note when item accessed from module via `m.i` rather than `m::i`.

(I tried to make this somewhat future-proofed, in that the `UnresolvedNameContext` could be expanded in the future with other cases besides paths that are known to be modules.)

This supersedes PR #30356 ; since I'm responsible for a bunch of new code here, someone else should review it. :)
2015-12-21 07:49:05 +00:00
Felix S. Klock II
04c05c7b01 Added doc comments for new UnresolvedNameContext enum. 2015-12-18 17:42:46 +01:00
Vadim Petrochenkov
8f359d5912 Prohibit public glob reexports of private variants 2015-12-18 04:14:46 +03:00
Vadim Petrochenkov
187c89a92a Address the comments 2015-12-18 04:14:46 +03:00
Vadim Petrochenkov
73307475f9 Prohibit private variant reexports 2015-12-18 04:12:31 +03:00
bors
6734dccc31 Auto merge of #30325 - jseyfried:fixes_30078, r=nrc
This fixes a bug in which unused imports can get wrongly marked as used when checking for unused qualifications in `resolve_path` (issue #30078), and it removes unused imports that were previously undetected because of the bug.
2015-12-17 18:21:25 +00:00
Jeffrey Seyfried
ba20a862d4 rustc_resolve: fix a bug in which unused imports can get wrongly marked as used when checking for unused qualifications in resolve_path (fixes #30078) 2015-12-17 05:43:44 +00:00
Jeffrey Seyfried
8364a6feef Remove unused imports 2015-12-17 05:43:27 +00:00
Guillaume Gomez
86f5275e49 Add note when item accessed from module via m.i rather than m::i. 2015-12-16 21:13:03 +01:00
Vadim Petrochenkov
0cc69f0ea3 rustc: Remove def::DefUse 2015-12-16 18:19:11 +03:00
Manish Goregaokar
ee24bddfc5 Rollup merge of #30320 - nrc:err-names, r=@nikomatsakis
We can now handle name resolution errors and get past type checking (if we're a bit lucky). This is the first step towards doing code completion for partial programs (we need error recovery in the parser and early access to save-analysis).
2015-12-16 17:46:29 +05:30
Ravi Shankar
51ff171948 Modify the Levenshtein-based suggestions to include imports 2015-12-16 16:33:24 +05:30
Manish Goregaokar
4423463465 Improve E0401 diagnostics to mention other items. 2015-12-15 10:25:29 +05:30
Jeffrey Seyfried
de0de61dd4 Partially undo the fix of issue #30159 in PR #30294 to avoid breakage. 2015-12-11 21:21:13 +00:00
Nick Cameron
18b4fe0e3e Make name resolution errors non-fatal 2015-12-11 21:00:15 +13:00
Jeffrey Seyfried
ada87fae5f Rename (Ns)ImportResolution 2015-12-11 01:38:13 +00:00
Jeffrey Seyfried
27c4f9e7b1 Fix a bug in which the visibility of a use declaration defining a name in one namespace (e.g. the value namespace) is overridden by a later use declaration defining the same name in the other namespace (e.g. the type namespace). 2015-12-10 02:55:05 +00:00
bors
462ec05764 Auto merge of #30145 - petrochenkov:hyg, r=nrc
Instead of `ast::Ident`, bindings, paths and labels in HIR now keep a new structure called `hir::Ident` containing mtwt-renamed `name` and the original not-renamed `unhygienic_name`. `name` is supposed to be used by default, `unhygienic_name` is rarely used.

This is not ideal, but better than the status quo for two reasons:
- MTWT tables can be cleared immediately after lowering to HIR
- This is less bug-prone, because it is impossible now to forget applying `mtwt::resolve` to a name. It is still possible to use `name` instead of `unhygienic_name` by mistake, but `unhygienic_name`s are used only in few very special circumstances, so it shouldn't be a problem.

Besides name resolution `unhygienic_name` is used in some lints and debuginfo. `unhygienic_name` can be very well approximated by "reverse renaming" `token::intern(name.as_str())` or even plain string `name.as_str()`, except that it would break gensyms like `iter` in desugared `for` loops. This approximation is likely good enough for lints and debuginfo, but not for name resolution, unfortunately (see https://github.com/rust-lang/rust/issues/27639), so `unhygienic_name` has to be kept.

cc https://github.com/rust-lang/rust/issues/29782

r? @nrc
2015-12-09 00:41:26 +00:00
Vadim Petrochenkov
ca88e9c536 Remove some unnecessary indirection from HIR structures 2015-12-07 17:17:41 +03:00
Vadim Petrochenkov
eb789de803 Do MTWT resolution during lowering to HIR 2015-12-05 00:40:21 +03:00
Jeffrey Seyfried
4da9694a55 Fixes #30089 2015-12-01 08:13:41 +00:00
bors
e9ac44026d Auto merge of #29383 - petrochenkov:empstr, r=pnkfelix
Fixes https://github.com/rust-lang/rust/issues/28692
Fixes https://github.com/rust-lang/rust/issues/28992
Fixes some other similar issues (see the tests)

[breaking-change], needs crater run (cc @brson or @alexcrichton )

The pattern with parens `UnitVariant(..)` for unit variants seems to be popular in rustc (see the second commit), but mostly used by one person (@nikomatsakis), according to git blame. If it causes breakage on crates.io I'll add an exceptional case for it.
2015-11-28 00:45:34 +00:00
bors
5dc91a74b1 Auto merge of #30064 - fhartwig:macro-suggestions, r=sanxiyn
Fixes #13677
This does the same sort of suggestion for misspelt macros that we already do for misspelt identifiers.
Example. Compiling this program:

```rust
macro_rules! foo {
    ($e:expr) => ( $e )
}

fn main() {
    fob!("hello!");
}
```

gives the following error message:

```
/Users/mcp/temp/test.rs:7:5: 7:8 error: macro undefined: 'fob!'
/Users/mcp/temp/test.rs:7     fob!("hello!");
                              ^~~
/Users/mcp/temp/test.rs:7:5: 7:8 help: did you mean `foo`?
/Users/mcp/temp/test.rs:7     fob!("hello!");
```

I had to move the levenshtein distance function into libsyntax for this. Maybe this should live somewhere else (some utility crate?), but I couldn't find a crate to put it in that is imported by libsyntax and the other rustc crates.
2015-11-27 18:41:53 +00:00
Florian Hartwig
4bb7cf11dc Introduce max_suggestion_distance function to avoid duplicating the heuristic 2015-11-27 17:52:29 +01:00
Ariel Ben-Yehuda
0a8bb4c509 split the metadata code into rustc_metadata
tests & rustdoc still broken
2015-11-26 18:22:40 +02:00