summary refs log tree commit diff
path: root/src/librustc_resolve
AgeCommit message (Collapse)AuthorLines
2018-10-18resolve: Do not skip extern prelude during speculative resolutionVadim Petrochenkov-3/+9
2018-10-18resolve: Scale back hard-coded extern prelude additionsVadim Petrochenkov-7/+9
2018-10-18Copy extern prelude from resolver to global contextVadim Petrochenkov-1/+1
2018-10-18Revert "rustc_resolve: move extern_prelude from Resolver to Session."Vadim Petrochenkov-7/+21
This reverts commit e90985acdec9928da9f6d157cfeb64f0ee98bffe.
2018-10-07Revert "Auto merge of #53793 - toidiu:ak-stabalize, r=nikomatsakis"Ariel Ben-Yehuda-0/+1
This reverts commit 6810f5286b6b91daab06fc3dccb27d8c46f14349, reversing changes made to 8586ec6980462c99a8926646201b2444d8938d29.
2018-10-04resolve: Prefer `macro_rules` definitions to in-module macro definitions in ↵Vadim Petrochenkov-4/+45
some cases
2018-10-02resolve: Do not block derive helper resolutions on single import resolutionsVadim Petrochenkov-10/+10
Derive helpers conflict currently conflict with anything else, so if some resolution from a single import appears later, it will result in error anyway
2018-10-02rustc_resolve: move extern_prelude from Resolver to Session.Eduard-Mihai Burtescu-21/+7
2018-09-21Stabilize crate_in_paths, extern_absolute_paths and extern_prelude on all ↵Eduard-Mihai Burtescu-28/+1
editions.
2018-09-17Auto merge of #54277 - petrochenkov:afterder, r=alexcrichtonbors-6/+15
Temporarily prohibit proc macro attributes placed after derives ... and also proc macro attributes used together with `#[test]`/`#[bench]`. Addresses item 6 from https://github.com/rust-lang/rust/pull/50911#issuecomment-411605393. The end goal is straightforward predictable left-to-right expansion order for attributes. Right now derives are expanded last regardless of their relative ordering with macro attributes and right now it's simpler to temporarily prohibit macro attributes placed after derives than changing the expansion order. I'm not sure whether the new beta is already released or not, but if it's released, then this patch needs to be backported, so the solution needs to be minimal. How to fix broken code (derives): - Move macro attributes above derives. This won't change expansion order, they are expanded before derives anyway. Using attribute macros on same items with `#[test]` and `#[bench]` is prohibited for similar expansion order reasons, but this one is going to be reverted much sooner than restrictions on derives. How to fix broken code (test/bench): - Enable `#![feature(plugin)]` (don't ask why). r? @ghost
2018-09-16resolve: Do not error on access to proc macros imported with `#[macro_use]`Vadim Petrochenkov-81/+0
2018-09-16Temporarily prohibit proc macro attributes placed after derivesVadim Petrochenkov-6/+15
... and also proc macro attributes used together with test/bench.
2018-09-15rustc_resolve: use `continue` instead of `return` to "exit" a loop iteration.Eduard-Mihai Burtescu-2/+2
2018-09-15rustc_resolve: always include core, std and meta in the extern prelude.Eduard-Mihai Burtescu-23/+28
2018-09-15rustc_resolve: don't allow `::crate_name` to bypass `extern_prelude`.Eduard-Mihai Burtescu-2/+10
2018-09-14Auto merge of #54069 - petrochenkov:subns, r=aturonbors-11/+18
resolve: Introduce two sub-namespaces in macro namespace Two sub-namespaces are introduced in the macro namespace - one for bang macros and one for attribute-like macros (attributes, derives). "Sub-namespace" means this is not a newly introduced full namespace, the single macro namespace is still in place. I.e. you still can't define/import two macros with the same name in a single module, `use` imports still import only one name in macro namespace (from any sub-namespace) and not possibly two. However, when we are searching for a name used in a `!` macro call context (`my_macro!()`) we skip attribute names in scope, and when we are searching for a name used in attribute context (`#[my_macro]`/`#[derive(my_macro)]`) we are skipping bang macro names in scope. In other words, bang macros cannot shadow attribute macros and vice versa. For a non-macro analogy, we could e.g. skip non-traits when searching for `MyTrait` in `impl MyTrait for Type { ... }`. However we do not do it in non-macro namespaces because we don't have practical issues with e.g. non-traits shadowing traits with the same name, but with macros we do, especially after macro modularization. For `#[test]` and `#[bench]` we have a hack in the compiler right now preventing their shadowing by `macro_rules! test` and similar things. This hack was introduced after making `#[test]`/`#[bench]` built-in macros instead of built-in attributes (https://github.com/rust-lang/rust/pull/53410), something that needed to be done from the start since they are "active" attributes transforming their inputs. Now they are passed through normal name resolution and can be shadowed, but that's a breaking change, so we have a special hack basically applying this PR for `#[test]` and `#[bench]` only. Soon all potentially built-in attributes will be passed through normal name resolution (https://github.com/rust-lang/rust/pull/53913) and that uncovers even more cases where the strict "macro namespace is a single namespace" rule needs to be broken. For example, with strict rules, built-in macro `cfg!(...)` would shadow built-in attribute `#[cfg]` (they are different things), standard library macro `thread_local!(...)` would shadow built-in attribute `#[thread_local]` - both of these cases are covered by special hacks in https://github.com/rust-lang/rust/pull/53913 as well. Crater run uncovered more cases of attributes being shadowed by user-defined macros (`warn`, `doc`, `main`, even `deprecated`), we cannot add exceptions in the compiler for all of them. Regressions with user-defined attributes like https://github.com/rust-lang/rust/issues/53583 and https://github.com/rust-lang/rust/issues/53898 also appeared after enabling macro modularization. People are also usually confused (https://github.com/rust-lang/rust/issues/53205#issuecomment-411552763, https://github.com/rust-lang/rust/issues/53583#issuecomment-415447800) when they see conflicts between attributes and non-attribute macros for the first time. So my proposed solution is to solve this issue by introducing two sub-namespaces and thus skipping resolutions of the wrong kind and preventing more error-causing cases of shadowing. Fixes https://github.com/rust-lang/rust/issues/53583
2018-09-14Auto merge of #54201 - eddyb:reflexive-disambiguation, r=petrochenkovbors-73/+73
rustc_resolve: don't treat uniform_paths canaries as ambiguities unless they resolve to distinct Def's. In particular, this allows this pattern that @cramertj mentioned in https://github.com/rust-lang/rust/issues/53130#issuecomment-420848814: ```rust use log::{debug, log}; fn main() { use log::{debug, log}; debug!(...); } ``` The canaries for the inner `use log::...;`, *in the macro namespace*, see the `log` macro imported at the module scope, and the (same) `log` macro, imported in the block scope inside `main`. Previously, these two possible (macro namspace) `log` resolutions would be considered ambiguous (from a forwards-compat standpoint, where we might make imports aware of block scopes). With this PR, such a case is allowed *if and only if* all the possible resolutions refer to the same definition (more specifically, because the *same* `log` macro is being imported twice). This condition subsumes previous (weaker) checks like #54005 and the second commit of #54011. Only the last commit is the main change, the other two are cleanups. r? @petrochenkov cc @Centril @joshtriplett
2018-09-14Auto merge of #54032 - oli-obk:layout_scalar_ranges, r=eddybbors-7/+7
Add forever unstable attribute to allow specifying arbitrary scalar ranges r? @eddyb for the first commit and @nikomatsakis for the second one
2018-09-14Auto merge of #53751 - F001:tuple-struct-self-ctor, r=petrochenkov,varkorbors-68/+89
Implement RFC 2302: tuple_struct_self_ctor Tracking issue: https://github.com/rust-lang/rust/issues/51994
2018-09-13rustc_resolve: don't treat uniform_paths canaries as ambiguities unless they ↵Eduard-Mihai Burtescu-26/+16
resolve to distinct Def's.
2018-09-13rustc_resolve: ignore uniform_paths canaries with no module scopes.Eduard-Mihai Burtescu-0/+6
2018-09-13rustc_resolve: only process uniform_paths canaries in namespaces they're ↵Eduard-Mihai Burtescu-75/+79
present in.
2018-09-13resolve: Introduce two sub-namespaces in macro namespaceVadim Petrochenkov-11/+18
2018-09-13introduce SelfCtorF001-102/+71
2018-09-13implement feature tuple_struct_self_ctorF001-13/+65
2018-09-13resolve: Future proof derive helper attributesVadim Petrochenkov-38/+36
2018-09-13resolve: Put different parent scopes into a single structureVadim Petrochenkov-66/+102
2018-09-12Auto merge of #53793 - toidiu:ak-stabalize, r=nikomatsakisbors-1/+0
stabilize outlives requirements https://github.com/rust-lang/rust/issues/44493 r? @nikomatsakis
2018-09-11stabalize infer outlives requirements (RFC 2093).toidiu-1/+0
Co-authored-by: nikomatsakis
2018-09-11Split `CrateNum` into an enum instead of having magic constantsOliver Schneider-7/+7
2018-09-11resolve: Reserve a few very special names in macro namespaceVadim Petrochenkov-0/+14
2018-09-11resolve: Skip bang macros when resolving potentially built-in attributesVadim Petrochenkov-32/+29
2018-09-11resolve: Future proof resolutions for potentially built-in attributesVadim Petrochenkov-0/+32
2018-09-11resolve: Support resolving identifier macros without their own IDVadim Petrochenkov-42/+44
Invocation/expansion ID (aka `Mark`) is not really necessary for resolving a macro path. What is really necessary is its parent module, parent expansion and parent legacy scope. This is required for validation resolutions of built-in attributes, which don't get their own `Mark`s
2018-09-10Auto merge of #54011 - eddyb:anchored-in-the-future, r=petrochenkovbors-47/+57
rustc_resolve: inject `uniform_paths` canaries regardless of the feature-gate, on Rust 2018. This PR is an attempt at future-proofing "anchored paths" by emitting the same ambiguity errors that `#![feature(uniform_paths)]` would, with slightly changed phrasing (see added UI tests). Also, on top of #54005, this PR allows this as well: ```rust use crate_name; use crate_name::foo; ``` In that any ambiguity between an extern crate and an import *of that same crate* is ignored. r? @petrochenkov cc @aturon @Centril @joshtriplett
2018-09-10rustc_resolve: ignore uniform_paths canaries that resolve to an import of ↵Eduard-Mihai Burtescu-43/+39
the same crate.
2018-09-10rustc_resolve: inject `uniform_paths` canaries regardless of the ↵Eduard-Mihai Burtescu-6/+20
feature-gate, on Rust 2018.
2018-09-10Auto merge of #53565 - PramodBisht:issue/53359_b, r=estebankbors-19/+44
#53359: putting multiple unresolved import on single line r? @estebank Here is WIP implementation of #53359 this PR have clubbed multiple unresolved imports into a single line. I think still two things need to improve like giving specific `label message` for each span of multi_span(how we can do this?) and second we are getting a warning while compiling, stating something like `E0432` have been passed before.
2018-09-10resolve: Remove `unshadowable_attrs`Vadim Petrochenkov-29/+24
2018-09-10resolve: Split macro prelude into built-in and user-defined partsVadim Petrochenkov-33/+48
2018-09-09Auto merge of #53778 - petrochenkov:shadrelax2, r=nikomatsakisbors-203/+246
resolve: Relax shadowing restrictions on macro-expanded macros Previously any macro-expanded macros weren't allowed to shadow macros from outer scopes. Now only "more macro-expanded" macros cannot shadow "less macro-expanded" macros. See comments to `fn may_appear_after` and added tests for more details and examples. The functional changes are a21f6f588fc28c97533130ae44a6957b579ab58c and 46dd365ce9ca0a6b8653849b80267763c542842a, other commits are refactorings.
2018-09-09Auto merge of #53902 - dtolnay:group, r=petrochenkovbors-2/+3
proc_macro::Group::span_open and span_close Before this addition, every delimited group like `(`...`)` `[`...`]` `{`...`}` has only a single Span that covers the full source location from opening delimiter to closing delimiter. This makes it impossible for a procedural macro to trigger an error pointing to just the opening or closing delimiter. The Rust compiler does not seem to have the same limitation: ```rust mod m { type T = } ``` ```console error: expected type, found `}` --> src/main.rs:3:1 | 3 | } | ^ ``` On that same input, a procedural macro would be forced to trigger the error on the last token inside the block, on the entire block, or on the next token after the block, none of which is really what you want for an error like above. This commit adds `group.span_open()` and `group.span_close()` which access the Span associated with just the opening delimiter and just the closing delimiter of the group. Relevant to Syn as we implement real error messages for when parsing fails in a procedural macro: https://github.com/dtolnay/syn/issues/476. ```diff impl Group { fn span(&self) -> Span; + fn span_open(&self) -> Span; + fn span_close(&self) -> Span; } ``` Fixes #48187 r? @alexcrichton
2018-09-09Auto merge of #53988 - eddyb:issue-53770, r=petrochenkovbors-41/+37
rustc_resolve: only prepend CrateRoot to a non-keyword segment. Fixes #53770 by treating `use` paths as absolute in a finer-grained manner, specifically: ```rust use {a, crate::b, self::c, super::d}; ``` Used to be interpreted as if it were (when `uniform_paths` is not enabled): ```rust use ::{a, crate::b, self::c, super::d}; ``` With this PR, the `CrateRoot` pseudo-keyword indicating an absolute path is only inserted when the first path segment is found (if it's not a keyword), i.e. the example behaves like: ```rust use {::a, crate::b, self::c, super::d}; ``` This should (finally) make `use {path};` fully equivalent to `use path;`. r? @petrochenkov cc @cramertj @joshtriplett @nikomatsakis
2018-09-09Auto merge of #53960 - estebank:issue-51303, r=nagisabors-5/+18
Fix incorrect outer function type parameter message Fix #51303.
2018-09-08Track distinct spans for open and close delimiterDavid Tolnay-2/+3
2018-09-08Fixed 53359: E0432 unresolved import on the same line is now emiting one ↵Pramod Bisht-19/+44
diagnostic Addressed estebank's comments for 53359
2018-09-08resolve: More precise spans for ambiguous resolution errorsVadim Petrochenkov-28/+22
Add labels to ambiguous resolution errors
2018-09-08Add checks for expected macro output in restricted shadowing testsVadim Petrochenkov-0/+2
2018-09-08resolve: Further simplify legacy scopes, add commentsVadim Petrochenkov-40/+45
2018-09-08resolve: Rename some fields related to legacy macro scopesVadim Petrochenkov-51/+60