Commit Graph

4997 Commits

Author SHA1 Message Date
Amanieu d'Antras 65707dfc00 Use a struct instead of a tuple for inline asm output operands 2015-12-05 10:11:20 +00:00
Amanieu d'Antras 9d7b113b44 Add proper support for indirect output constraints in inline asm 2015-12-05 08:18:30 +00:00
bors 77ed39cfe3 Auto merge of #29850 - Kimundi:attributes_that_make_a_statement, r=pnkfelix
See https://github.com/rust-lang/rfcs/pull/16 and https://github.com/rust-lang/rust/issues/15701

- Added syntax support for attributes on expressions and all syntax nodes in statement position.
- Extended `#[cfg]` folder to allow removal of statements, and
of expressions in optional positions like expression lists and trailing
block expressions.
- Extended lint checker to recognize lint levels on expressions and
locals.
- As per RFC, attributes are not yet accepted on `if` expressions.

Examples:
  ```rust
let x = y;
{
        ...
}
assert_eq!((1, #[cfg(unset)] 2, 3), (1, 3));

let FOO = 0;
```

Implementation wise, there are a few rough corners and open questions:
- The parser work ended up a bit ugly.
- The pretty printer change was based mostly on guessing.
- Similar to the `if` case, there are some places in the grammar where a new `Expr` node starts,
  but where it seemed weird to accept attributes and hence the parser doesn't. This includes:
  - const expressions in patterns
  - in the middle of an postfix operator chain (that is, after `.`, before indexing, before calls)
  - on range expressions, since `#[attr] x .. y` parses as  `(#[attr] x) .. y`, which is inconsistent with
    `#[attr] .. y` which would parse as `#[attr] (.. y)`
- Attributes are added as additional `Option<Box<Vec<Attribute>>>` fields in expressions and locals.
- Memory impact has not been measured yet.
- A cfg-away trailing expression in a block does not currently promote the previous `StmtExpr` in a block to a new trailing expr. That is to say, this won't work:
```rust
let x = {
    #[cfg(foo)]
    Foo { data: x }
    #[cfg(not(foo))]
    Foo { data: y }
};
```
- One-element tuples can have their inner expression removed to become Unit, but just Parenthesis can't. Eg, `(#[cfg(unset)] x,) == ()` but `(#[cfg(unset)] x) == error`. This seemed reasonable to me since tuples and unit are type constructors, but could probably be argued either way.
- Attributes on macro nodes are currently unconditionally dropped during macro expansion, which seemed fine since macro disappear at that point?
- Attributes on `ast::ExprParens` will be prepend-ed to the inner expression in the hir folder.
- The work on pretty printer tests for this did trigger, but not fix errors regarding macros:
  - expression `foo![]` prints as `foo!()`
  - expression `foo!{}` prints as `foo!()`
  - statement `foo![];` prints as `foo!();`
  - statement `foo!{};` prints as `foo!();`
  - statement `foo!{}` triggers a `None` unwrap ICE.
2015-12-04 08:46:29 +00:00
Bryce Van Dyk 0ee230a094 libterm: bring across changes from term
This brings across changes made to the term library to libterm. This
includes removing instances or unwrap, fixing format string handling, and
removing a TODO.

This fix does not bring all changes across, as term now relies on cargo
deps that cannot be brought into the rust build at this stage, but has
attempted as best to cross port changes not relying on this. This notably
limits extra functionality since implemented int he Terminal trait in
Term.

This is in partly in response to rust issue #29992.
2015-12-03 19:27:59 +13:00
bors eb1d018c01 Auto merge of #25570 - oli-obk:const_indexing, r=nikomatsakis
This PR allows the constant evaluation of index operations on constant arrays and repeat expressions. This allows index expressions to appear in the expression path of the length expression of a repeat expression or an array type.

An example is

```rust
const ARR: [usize; 5] = [1, 2, 3, 4, 5];
const ARR2: [usize; ARR[1]] = [42, 99];
```

In most other locations llvm's const evaluator figures it out already. This is not specific to index expressions and could be remedied in the future.
2015-12-01 19:47:38 +00:00
Marvin Löbel 3f33cbcbff Improved comments around dropped attributes in the macro expander 2015-11-30 22:26:03 +01:00
Marvin Löbel 5eaf31b7b2 Simplyfied map_thin_attrs() 2015-11-30 21:12:26 +01:00
bors 323781cdf7 Auto merge of #30075 - kyeah:mac-span, r=sanxiyn
Fixes #28424 (item macros), #30067 (impl item macros), and pattern macros.
2015-11-29 06:00:05 +00:00
Kevin Yeh 920120ed4c Use last_span for macro spans 2015-11-28 23:54:54 -06: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
Marvin Löbel 296c3613ca Added stmt_expr_attribute feature gate 2015-11-26 21:47:44 +01:00
Marvin Löbel c56b47ab8c Some TLC for the MoveMap trait 2015-11-26 21:46:12 +01:00
Marvin Löbel 0608b1d414 Fixed macro expander not folding attributes (though I'm not sure if that is actually neccessary) 2015-11-26 21:46:12 +01:00
Marvin Löbel f0beba0217 Moved and refactored ThinAttributes 2015-11-26 21:46:12 +01:00
Marvin Löbel 2a8f358de7 Add syntax support for attributes on expressions and all syntax
nodes in statement position.

Extended #[cfg] folder to allow removal of statements, and
of expressions in optional positions like expression lists and trailing
block expressions.

Extended lint checker to recognize lint levels on expressions and
locals.
2015-11-26 21:46:12 +01:00
Kevin Yeh b4295b9fb0 Fix spans for macros 2015-11-26 14:38:45 -06:00
Florian Hartwig 9ba657cad5 Add '!' to macro name suggestion, use fileline_help instead of span_help 2015-11-26 11:59:41 +01:00
bors 6d88afe477 Auto merge of #30015 - petrochenkov:staged, r=brson
Closes https://github.com/rust-lang/rust/issues/30008

`#[stable]`, `#[unstable]` and `#[rustc_deprecated]` are now guarded by `#[feature(staged_api)]`

r? @brson
2015-11-26 10:22:37 +00:00
Florian Hartwig a5e5c67756 Add suggestion of similar macro names to macro undefined error message 2015-11-26 00:21:38 +01:00
Jonas Schievink fc9f9882f3 Fix "Cannot fill in a NT" ICE 2015-11-25 20:58:57 +01:00
Vadim Petrochenkov be8ace8cac Remove all uses of #[staged_api] 2015-11-25 21:55:26 +03:00
Vadim Petrochenkov 5127d24a3e Remove #[staged_api] 2015-11-25 21:55:26 +03:00
bors 7fa2c6ca31 Auto merge of #30011 - jonas-schievink:macro-context, r=nrc
Fixes #22425

Also fixes #30007, since it's just a change from `true` to `false`.
2015-11-25 03:02:05 +00:00
Jonas Schievink 52d3de7a7e Remove "this" 2015-11-24 16:34:48 +01:00
Steve Klabnik 731ff93a76 Rollup merge of #30004 - michaelwoerister:primitive-ty-to-str, r=alexcrichton
Good candidate for a rollup, this one.
2015-11-24 09:43:46 -05:00
bors 561d0884e5 Auto merge of #30000 - Manishearth:unreachable-call, r=nrc
Fixes #1889
2015-11-24 06:58:25 +00:00
Manish Goregaokar 7fbcb51589 Fix unreachable code in libsyntax 2015-11-24 10:05:51 +05:30
bors 040a77f772 Auto merge of #29952 - petrochenkov:depr, r=brson
Part of https://github.com/rust-lang/rust/issues/29935

The deprecation lint is still called "deprecated", so people can continue using `#[allow(deprecated)]` and similar things.
2015-11-23 20:08:49 +00:00
Jonas Schievink d4a0e545e7 Print the macro context name on incomplete parse
Fixes #22425

Also fixes #30007, since it's just a change from `true` to `false`.
2015-11-23 21:06:51 +01:00
Michael Woerister 3be1d8ca7d Avoid some code duplication around getting names of numeric types. 2015-11-23 15:59:36 +01:00
Manish Goregaokar 99925fb562 Look up macro names as well when suggesting replacements for function resolve errors
fixes #5780
2015-11-22 06:48:46 +05:30
Vadim Petrochenkov a613059e3f Rename #[deprecated] to #[rustc_deprecated] 2015-11-20 16:11:20 +03:00
Oliver Schneider 64051221b6 add feature gate const_indexing
tracking issue is #29947
2015-11-20 10:43:04 +01:00
Niko Matsakis e14562d515 Rework the IdVisitor so that it only visits item contents (and doesn't
visit nested items). This is what all clients wanted anyhow.
2015-11-18 19:22:18 -05:00
Huon Wilson 41f7f0c341 Add some unicode aliases for ". 2015-11-18 17:16:32 +11:00
bors b2f539375a Auto merge of #29887 - sanxiyn:match-ref-pats, r=sfackler 2015-11-17 20:10:25 +00:00
bors b31cc644d1 Auto merge of #29766 - oli-obk:impl_item, r=nikomatsakis
[breaking change]

I'm not sure if those renames are ok. [TokenType::Tt* to TokenType::*](https://github.com/rust-lang/rust/pull/29582) was obvious, but for all those Item-enums it's less obvious to me what the right way forward is due to the underscore.
2015-11-17 18:24:19 +00:00
Seo Sanghyeon 95f6ea920d Fix match_ref_pats flagged by Clippy 2015-11-17 23:24:49 +09:00
bors 1b2614847d Auto merge of #29837 - Wafflespeanut:unicode_chars, r=Manishearth
fixes #25957
2015-11-17 07:42:03 +00:00
Ravi Shankar 7f63c7cf4c Detect confusing unicode characters and show the alternative 2015-11-17 12:14:28 +05:30
Oliver Schneider d09220de13 rename ast::ImplItem_::*ImplItem to ast::ImplItemKind::* 2015-11-16 10:35:30 +01:00
bors bf78389656 Auto merge of #29828 - sanxiyn:check-macro, r=nrc
Fix #27409.
2015-11-16 05:48:35 +00:00
Seo Sanghyeon cce7b8bd25 Check macro definition and do not expand invalid macros 2015-11-14 19:50:46 +09:00
Seo Sanghyeon 289b1b400a Reindent code 2015-11-14 19:18:32 +09:00
Seo Sanghyeon fdadba5786 Store TokenTree in MacroRulesMacroExpander 2015-11-14 19:11:40 +09:00
Kyle Mayes 44d8abcc0f Move the panicking parse functions out of the parser
Since these functions are only used by the AST quoting syntax extensions, they should be there instead of in the parser.
2015-11-13 22:18:59 -05:00
bors b12a3582b1 Auto merge of #29761 - eefriedman:rename-nopanic, r=sanxiyn
Just `sed s/_nopanic//g`.  Hopefully makes libsyntax a bit more
readable.
2015-11-13 10:28:25 +00:00
bors d5fde83ae7 Auto merge of #29807 - nrc:op_span, r=brson
cc @nagisa
2015-11-12 23:48:56 +00:00
Nick Cameron 224c789ef2 Fix a bad span for binops 2015-11-13 09:34:41 +13:00