Commit Graph

1113 Commits

Author SHA1 Message Date
Esteban Küber
73f6f5e096 Sort enum suggestions 2017-04-03 10:57:45 -07:00
Esteban Küber
b946ecd020 Suggest using enum when a variant is used as a type
Given a file:

```rust
enum Fruit {
    Apple(i64),
    Orange(i64),
}

fn should_return_fruit() -> Apple {
    Apple(5)
}
```

Provide the following output:

```rust
error[E0412]: cannot find type `Apple` in this scope
  --> file.rs:16:29
   |
16 | fn should_return_fruit() -> Apple {
   |                             ^^^^^ not found in this scope
   |
help: there is an enum variant `Fruit::Apple`, did you mean to use `Fruit`?
  --> file.rs:12:5
   |
12 |     Apple(i64),
   |     ^^^^^^^^^^

error[E0425]: cannot find function `Apple` in this scope
  --> file.rs:17:5
   |
17 |     Apple(5)
   |     ^^^^^ not found in this scope
   |
   = help: possible candidate is found in another module, you can import it into scope:
             `use Fruit::Apple;`
```
2017-04-02 09:33:41 -07:00
Jeffrey Seyfried
1979f96549 Move syntax::ext::hygiene to syntax_pos::hygiene. 2017-03-29 00:41:08 +00:00
Alex Crichton
0dbf84b737 Rollup merge of #40853 - ollie27:error-index, r=steveklabnik
Fix broken Markdown and bad links in the error index

This makes sure RFC links point to the RFC text not the pull request.

r? @steveklabnik
2017-03-27 15:56:26 -07:00
Oliver Middleton
99a069eec9 Fix broken Markdown and bad links in the error index
This makes sure RFC links point to the RFC text not the pull request.
2017-03-27 15:21:04 +01:00
Jeffrey Seyfried
737511ee11 Ensure that macro resolutions in trait positions get finalized. 2017-03-27 05:22:18 +00:00
bors
bcfd5c48b7 Auto merge of #40501 - jseyfried:shadow_builtin_macros, r=nrc
Allow `use` macro imports to shadow global macros

Terminology:
 - global scope: builtin macros, macros from the prelude, `#[macro_use]`, or `#![plugin(..)]`.
 - legacy scope: crate-local `macro_rules!`.
 - modern scope: `use` macro imports, `macro` (once implemented).

Today, the legacy scope can shadow the global scope (modulo RFC 1560 expanded shadowing restrictions). However, the modern scope cannot shadow or be shadowed by either the global or legacy scopes, leading to ambiguity errors.

This PR allows the modern scope to shadow the global scope (subject to some restrictions).
More specifically, a name in the global scope is as shadowable as a glob import in the module `self`. In other words, we imagine a special, implicit glob import in each module item:
```rust
mod foo {
    #[lexical_only] // Not accessible via `foo::<name>`, like pre-RFC 1560 `use` imports.
    #[shadowable_by_legacy_scope] // for back-compat
    use <global_macros>::*;
}
```

r? @nrc
2017-03-26 11:45:13 +00:00
Jeffrey Seyfried
d64d3814c4 Rename builtin => global. 2017-03-24 21:06:01 +00:00
Jeffrey Seyfried
64e9af47f4 Allow declarative macros 2.0 and use macro imports to shadow builtin macros. 2017-03-24 21:05:52 +00:00
Alex Crichton
e341d603fe Remove internal liblog
This commit deletes the internal liblog in favor of the implementation that
lives on crates.io. Similarly it's also setting a convention for adding crates
to the compiler. The main restriction right now is that we want compiler
implementation details to be unreachable from normal Rust code (e.g. requires a
feature), and by default everything in the sysroot is reachable via `extern
crate`.

The proposal here is to require that crates pulled in have these lines in their
`src/lib.rs`:

    #![cfg_attr(rustbuild, feature(staged_api, rustc_private))]
    #![cfg_attr(rustbuild, unstable(feature = "rustc_private", issue = "27812"))]

This'll mean that by default they're not using these attributes but when
compiled as part of the compiler they do a few things:

* Mark themselves as entirely unstable via the `staged_api` feature and the
  `#![unstable]` attribute.
* Allow usage of other unstable crates via `feature(rustc_private)` which is
  required if the crate relies on any other crates to compile (other than std).
2017-03-23 11:28:00 -07:00
Corey Farwell
880f03b28c Rollup merge of #40509 - jseyfried:duplicate_check_macro_exports, r=nrc
Forbid conflicts between macros 1.0 exports and macros 2.0 exports

This PR forbids for conflicts between `#[macro_export]`/`#[macro_reexport]` macro exports and `pub use` macro exports. For example,
```rust
// crate A:
pub use macros::foo;
//^ This is allowed today, will be forbidden by this PR.

// crate B:
extern crate A; // This triggers a confusing error today.
use A::foo; // This could refer to refer to either macro export in crate A.
```

r? @nrc
2017-03-22 19:30:23 -04:00
Jeffrey Seyfried
bd862d29d3
Fix bug in legacy #[derive] processing logic. 2017-03-21 16:53:34 -04:00
Jeffrey Seyfried
678e882ce2
Check for conflicts between macros 1.0 exports (#[macro_export], #[macro_reexport])
and macros 2.0 exports (`pub use` macro re-exports and `pub macro` (once implemented)
at the crate root.
2017-03-21 16:23:18 -04:00
Corey Farwell
c949f49c27 Rollup merge of #40583 - jseyfried:fix_include_macro_regression, r=nrc
macros: fix regression with `include!()`

Fixes #40469, a regression when `include!()`ing a `macro_rules!` containing `$crate`.
r? @nrc
2017-03-19 10:18:16 -04:00
bors
9c15de4fd5 Auto merge of #40346 - jseyfried:path_and_tokenstream_attr, r=nrc
`TokenStream`-based attributes, paths in attribute and derive macro invocations

This PR
 - refactors `Attribute` to use  `Path` and `TokenStream` instead of `MetaItem`.
 - supports macro invocation paths for attribute procedural macros.
   - e.g. `#[::foo::attr_macro] struct S;`, `#[cfg_attr(all(), foo::attr_macro)] struct S;`
 - supports macro invocation paths for derive procedural macros.
   - e.g. `#[derive(foo::Bar, super::Baz)] struct S;`
 - supports arbitrary tokens as arguments to attribute procedural macros.
   - e.g. `#[foo::attr_macro arbitrary + tokens] struct S;`
 - supports using arbitrary tokens in "inert attributes" with derive procedural macros.
   - e.g. `#[derive(Foo)] struct S(#[inert arbitrary + tokens] i32);`
where `#[proc_macro_derive(Foo, attributes(inert))]`

r? @nrc
2017-03-19 10:56:08 +00:00
Jeffrey Seyfried
cb96adea15 Fix regression when include!()ing a macro_rules! containing a $crate:: path. 2017-03-17 22:20:41 +00:00
Jeffrey Seyfried
839c2860cc Liberalize attributes. 2017-03-14 04:39:21 +00:00
Jeffrey Seyfried
68c1cc68b4 Refactor Attribute to use Path and TokenStream instead of MetaItem. 2017-03-14 04:03:43 +00:00
Corey Farwell
8d1c5700f0 Rollup merge of #40369 - petrochenkov:segspan, r=eddyb
Give spans to individual path segments in AST

And use these spans in path resolution diagnostics.

The spans are spans of identifiers in segments, not whole segments. I'm not sure what spans are more useful in general, but identifier spans are a better fit for resolve errors.

HIR still doesn't have spans.

Fixes https://github.com/rust-lang/rust/pull/38927#discussion_r95336667 https://github.com/rust-lang/rust/pull/38890#issuecomment-271731008

r? @nrc @eddyb
2017-03-12 12:48:46 -04:00
Vadim Petrochenkov
ffdcf74866 resolve: Use path segment spans in smart_resolve_path 2017-03-10 08:21:45 -08:00
Vadim Petrochenkov
32575a0487 Give spans to individual path segments in AST 2017-03-10 08:21:45 -08:00
Jeffrey Seyfried
8c98996934 Avoid using Mark and Invocation for macro defs. 2017-03-10 08:08:32 -08:00
Jeffrey Seyfried
e839486318 Move resolve_invoc from syntax to resolve. 2017-03-10 08:08:32 -08:00
Jeffrey Seyfried
212b6c2550 Refactor out ast::ItemKind::MacroDef. 2017-03-10 08:08:32 -08:00
bors
f91c3f6755 Auto merge of #39713 - estebank:issue-39698, r=jonathandturner
Clean up "pattern doesn't bind x" messages

Group "missing variable bind" spans in `or` matches and clarify wording
for the two possible cases: when a variable from the first pattern is
not in any of the subsequent patterns, and when a variable in any of the
other patterns is not in the first one.

Before:

```rust
error[E0408]: variable `a` from pattern #1 is not bound in pattern #2
  --> file.rs:10:23
   |
10 |         T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
   |                       ^^^^^^^^^^^ pattern doesn't bind `a`

error[E0408]: variable `b` from pattern #2 is not bound in pattern #1
  --> file.rs:10:32
   |
10 |         T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
   |                                ^ pattern doesn't bind `b`

error[E0408]: variable `a` from pattern #1 is not bound in pattern #3
  --> file.rs:10:37
   |
10 |         T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
   |                                     ^^^^^^^^ pattern doesn't bind `a`

error[E0408]: variable `d` from pattern #1 is not bound in pattern #3
  --> file.rs:10:37
   |
10 |         T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
   |                                     ^^^^^^^^ pattern doesn't bind `d`

error[E0408]: variable `c` from pattern #3 is not bound in pattern #1
  --> file.rs:10:43
   |
10 |         T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
   |                                           ^ pattern doesn't bind `c`

error[E0408]: variable `d` from pattern #1 is not bound in pattern #4
  --> file.rs:10:48
   |
10 |         T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
   |                                                ^^^^^^^^ pattern doesn't bind `d`

error: aborting due to 6 previous errors
```

After:

```rust
error[E0408]: variable `d` is not bound in all patterns
  --> $DIR/issue-39698.rs:20:37
   |
20 |         T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
   |                  -          -       ^^^^^^^^   ^^^^^^^^ pattern doesn't bind `d`
   |                  |          |       |
   |                  |          |       pattern doesn't bind `d`
   |                  |          variable not in all patterns
   |                  variable not in all patterns

error[E0408]: variable `c` is not bound in all patterns
  --> $DIR/issue-39698.rs:20:48
   |
20 |         T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
   |         ^^^^^^^^^^^   ^^^^^^^^^^^         -    ^^^^^^^^ pattern doesn't bind `c`
   |         |             |                   |
   |         |             |                   variable not in all patterns
   |         |             pattern doesn't bind `c`
   |         pattern doesn't bind `c`

error[E0408]: variable `a` is not bound in all patterns
  --> $DIR/issue-39698.rs:20:37
   |
20 |         T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
   |               -       ^^^^^^^^^^^   ^^^^^^^^         - variable not in all patterns
   |               |       |             |
   |               |       |             pattern doesn't bind `a`
   |               |       pattern doesn't bind `a`
   |               variable not in all patterns

error[E0408]: variable `b` is not bound in all patterns
  --> $DIR/issue-39698.rs:20:37
   |
20 |         T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
   |         ^^^^^^^^^^^            -    ^^^^^^^^   ^^^^^^^^ pattern doesn't bind `b`
   |         |                      |    |
   |         |                      |    pattern doesn't bind `b`
   |         |                      variable not in all patterns
   |         pattern doesn't bind `b`

error: aborting due to 4 previous errors
```

Fixes #39698.
2017-03-08 09:30:13 +00:00
Esteban Küber
3ffa4b5240 Use BTreeSet instead of FxHashSet 2017-03-06 00:20:26 -03:00
Esteban Küber
75eface16d Clean up "pattern doesn't bind x" messages
Group "missing variable bind" spans in `or` matches and clarify wording
for the two possible cases: when a variable from the first pattern is
not in any of the subsequent patterns, and when a variable in any of the
other patterns is not in the first one.

Before:

```
error[E0408]: variable `a` from pattern #1 is not bound in pattern #2
  --> file.rs:10:23
   |
10 |         T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
   |                       ^^^^^^^^^^^ pattern doesn't bind `a`

error[E0408]: variable `b` from pattern #2 is not bound in pattern #1
  --> file.rs:10:32
   |
10 |         T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
   |                                ^ pattern doesn't bind `b`

error[E0408]: variable `a` from pattern #1 is not bound in pattern #3
  --> file.rs:10:37
   |
10 |         T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
   |                                     ^^^^^^^^ pattern doesn't bind `a`

error[E0408]: variable `d` from pattern #1 is not bound in pattern #3
  --> file.rs:10:37
   |
10 |         T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
   |                                     ^^^^^^^^ pattern doesn't bind `d`

error[E0408]: variable `c` from pattern #3 is not bound in pattern #1
  --> file.rs:10:43
   |
10 |         T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
   |                                           ^ pattern doesn't bind `c`

error[E0408]: variable `d` from pattern #1 is not bound in pattern #4
  --> file.rs:10:48
   |
10 |         T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
   |                                                ^^^^^^^^ pattern doesn't bind `d`

error: aborting due to 6 previous errors
```

After:

```
error[E0408]: variable `a` is not bound in all patterns
  --> file.rs:20:37
   |
20 |         T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => {
intln!("{:?}", a); }
   |               -       ^^^^^^^^^^^   ^^^^^^^^         - variable
t in all patterns
   |               |       |             |
   |               |       |             pattern doesn't bind `a`
   |               |       pattern doesn't bind `a`
   |               variable not in all patterns

error[E0408]: variable `d` is not bound in all patterns
  --> file.rs:20:37
   |
20 |         T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => {
intln!("{:?}", a); }
   |                  -          -       ^^^^^^^^   ^^^^^^^^ pattern
esn't bind `d`
   |                  |          |       |
   |                  |          |       pattern doesn't bind `d`
   |                  |          variable not in all patterns
   |                  variable not in all patterns

error[E0408]: variable `b` is not bound in all patterns
  --> file.rs:20:37
   |
20 |         T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => {
intln!("{:?}", a); }
   |         ^^^^^^^^^^^            -    ^^^^^^^^   ^^^^^^^^ pattern
esn't bind `b`
   |         |                      |    |
   |         |                      |    pattern doesn't bind `b`
   |         |                      variable not in all patterns
   |         pattern doesn't bind `b`

error[E0408]: variable `c` is not bound in all patterns
  --> file.rs:20:48
   |
20 |         T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => {
intln!("{:?}", a); }
   |         ^^^^^^^^^^^   ^^^^^^^^^^^         -    ^^^^^^^^ pattern
esn't bind `c`
   |         |             |                   |
   |         |             |                   variable not in all
tterns
   |         |             pattern doesn't bind `c`
   |         pattern doesn't bind `c`

error: aborting due to 4 previous errors
```

* Have only one presentation for binding consistency errors
* Point to same binding in multiple patterns when possible
* Check inconsistent bindings in all arms
* Simplify wording of diagnostic message
* Sort emition and spans of binding errors for deterministic output
2017-03-06 00:20:26 -03:00
Jeffrey Seyfried
9fe7d3ffe4 Fix const expression macro invocations. 2017-03-05 23:58:19 +00:00
bors
73d31e3f7b Auto merge of #40242 - cramertj:fix-while-let-ribs-scope, r=petrochenkov
Fix missing WhileLet pattern scope

Fix #40235
2017-03-04 10:21:30 +00:00
Taylor Cramer
75a35ef028 Fix missing WhileLet pattern scope 2017-03-03 09:40:44 -08:00
Jeffrey Seyfried
f6eaaf350e Integrate TokenStream. 2017-03-03 02:15:37 +00:00
Eduard Burtescu
b5c4244c6c rustc: introduce a query system for type information in ty::maps. 2017-02-25 17:07:59 +02:00
Eduard-Mihai Burtescu
e8d01ea4c7 rustc: store type parameter defaults outside of ty::Generics. 2017-02-25 17:07:59 +02:00
Eduard-Mihai Burtescu
a6a5c32e0e Rollup merge of #39953 - keeperofdakeys:macro-error, r=jseyfried
Provide suggestions for unknown macros imported with `use`

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

r? @jseyfried
2017-02-25 14:13:23 +02:00
Eduard-Mihai Burtescu
ad9079bae4 Rollup merge of #39864 - cramertj:normalize-breaks, r=nikomatsakis
Normalize labeled and unlabeled breaks

Part of #39849.
2017-02-25 14:13:16 +02:00
Josh Driver
da6dc5331f Add macro suggestions for macros imported with use
This commit searchs modules for macro suggestions.
It also removes imported macro_rules from macro_names,
and adds more corner case checks for which macros
should be suggested in specific contexts.
2017-02-23 20:28:35 +10:30
Josh Driver
4ecdc68153 Move MacroKind into Def::Macro 2017-02-23 20:12:33 +10:30
Austin Bonander
dac25e2b27 Don't assume plugin-whitelisted attributes are proc macro attributes
closes #40001
2017-02-22 15:43:03 -08:00
Vadim Petrochenkov
bf95c29c98 Privatize fields of PathResolution
Ensure Def::Err has depth == 0
2017-02-19 00:34:08 +03:00
Taylor Cramer
4d65622dcd Properly implement labeled breaks in while conditions 2017-02-18 12:28:44 -08:00
Josh Driver
2d91e7aab8 Refactor macro resolution errors + add derive macro suggestions 2017-02-16 22:03:15 +10:30
Jeffrey Seyfried
2cc61eebb7 Allow using inert attributes from proc_macro_derives with #![feature(proc_macro)]. 2017-02-12 07:20:04 +00:00
Jeffrey Seyfried
4b413bc393 Move legacy custom derives collection into resolver.find_attr_invoc(). 2017-02-12 03:22:52 +00:00
Corey Farwell
cd5c520cc2 Rollup merge of #39443 - phungleson:remove-unresolved-things, r=nikomatsakis
Don't suggest to use things which weren't found either

Fixes #38054

The best code I can come up with, suggestions are welcome.

Basically, removing ```. Did you mean to use `DoesntExist1`?``` in the code below, because it is useless.

```rust
error[E0432]: unresolved import `DoesntExist1`
 --> src/lib.rs:1:5
  |
1 | use DoesntExist1;
  |     ^^^^^^^^^^^^ no `DoesntExist1` in the root

error[E0432]: unresolved import `DoesntExist2`
 --> src/lib.rs:2:5
  |
2 | use DoesntExist2;
  |     ^^^^^^^^^^^^ no `DoesntExist2` in the root. Did you mean to use `DoesntExist1`?
```
2017-02-05 09:14:48 -05:00
Josh Driver
fbdd038866 Move derive macro expansion into the MacroExpander
This removes the expand_derives function, and sprinkles
the functionality throughout the Invocation Collector,
Expander and Resolver.
2017-02-05 09:31:02 +10:30
Josh Driver
0a7380d7fc Rename CustomDerive to ProcMacroDerive for macros 1.1 2017-02-05 09:31:02 +10:30
Son
823e185a40 Suggest only if resolution was previously resolved 2017-02-02 22:05:49 +11:00
Vadim Petrochenkov
d38a8ad488 Improve diagnostics for inaccessible constructors 2017-01-29 02:57:14 +03:00
Vadim Petrochenkov
8b060e25ba Implement compatibility lint for legacy constructor visibilities 2017-01-29 02:57:14 +03:00
Vadim Petrochenkov
18b96cf286 Privatize constructors of tuple structs with private fields 2017-01-29 02:57:14 +03:00