Commit Graph

114 Commits

Author SHA1 Message Date
CensoredUsername
e32da12753 Correct inline assembly clobber formatting.
Fixes the formatting for inline assembly clobbers used in the book.
As this causes llvm to silently ignore the clobber an error is also
added to catch cases in which the wrong formatting was used.
Additionally a test case is added to confirm that this error works.
2016-07-06 15:02:49 +02:00
Zack M. Davis
d37edef9dd prefer if let to match with None => {} arm in some places
This is a spiritual succesor to #34268/8531d581, in which we replaced a
number of matches of None to the unit value with `if let` conditionals
where it was judged that this made for clearer/simpler code (as would be
recommended by Manishearth/rust-clippy's `single_match` lint). The same
rationale applies to matches of None to the empty block.
2016-07-03 16:27:02 -07:00
Jeffrey Seyfried
66ef652559 Disallow derive on items with type macros 2016-06-29 01:25:36 +00:00
Jeffrey Seyfried
9bb3ea0feb Rollup merge of #34436 - jseyfried:no_block_expr, r=eddyb
To allow these braced macro invocation, this PR removes the optional expression from `ast::Block` and instead uses a `StmtKind::Expr` at the end of the statement list.

Currently, braced macro invocations in blocks can expand into statements (and items) except when they are last in a block, in which case they can only expand into expressions.

For example,
```rust
macro_rules! make_stmt {
    () => { let x = 0; }
}

fn f() {
    make_stmt! {} //< This is OK...
    let x = 0; //< ... unless this line is commented out.
}
```

Fixes #34418.
2016-06-26 02:20:14 +00:00
Jeffrey Seyfried
8eddf02800 Rollup merge of #34339 - jseyfried:thin_vec, r=petrochenkov,Manishearth
Generalize and abstract `ThinAttributes` to `ThinVec<Attribute>`.
2016-06-26 02:18:43 +00:00
Jeffrey Seyfried
8748cd92d0 Rollup merge of #34316 - jseyfried:refactor_ast_stmt, r=eddyb
Refactor away `ast::Decl`, refactor `ast::Stmt`, and rename `ast::ExprKind::Again` to `ast::ExprKind::Continue`.
2016-06-26 02:17:27 +00:00
Jeffrey Seyfried
33ea1e330c Rollup merge of #33943 - jseyfried:libsyntax_cleanup, r=nrc
Miscellaneous low priority cleanup in `libsyntax`.
2016-06-26 02:15:04 +00:00
Jeffrey Seyfried
82a15a6a0a Rollup merge of #34385 - cgswords:tstream, r=nrc
syntax-[breaking-change] cc #31645
(Only breaking because ast::TokenTree is now tokenstream::TokenTree.)

This pull request refactors TokenTrees into their own file as src/libsyntax/tokenstream.rs, moving them out of src/libsyntax/ast.rs, in order to prepare for an accompanying TokenStream implementation (per RFC 1566).
2016-06-26 02:11:59 +00:00
Jeffrey Seyfried
060a84d1f7 Refactor away duplicate method ecx.block_all() 2016-06-23 23:26:43 +00:00
Jeffrey Seyfried
b7da35a5aa Remove field expr of ast::Block 2016-06-23 17:42:08 +00:00
Jonathan Turner
6ae3502134 Move errors from libsyntax to its own crate 2016-06-23 08:07:35 -04:00
cgswords
d59accfb06 Refactored tokentrees into their own files in preparation for tokenstreams. Modified tests to point to the new file now. 2016-06-21 11:12:36 -07:00
Jeffrey Seyfried
5033eca65f Generalize and abstract ThinAttributes 2016-06-19 00:01:55 +00:00
Jeffrey Seyfried
962d5c16b5 Fix fallout 2016-06-17 05:21:23 +00:00
Jeffrey Seyfried
2cd6ccf0b1 Simplify gated cfg checking 2016-06-16 19:24:44 +00:00
Jeffrey Seyfried
0644aba0b3 Remove the type parameter from syntax::visit::Visitor 2016-06-14 07:40:32 +00:00
Niko Matsakis
75543c08c7 simplify HR subtyping back to what we did before
A lot of the refactors, however, seem helpful, so leave those in,
particularly since we may want to make this change in the future.
2016-05-31 19:42:22 -04:00
Jeffrey Seyfried
a0e606c380 Use the span of #[derive_Eq] for #[structural_match] 2016-05-28 11:58:45 +00:00
Jeffrey Seyfried
6019816da8 Refactor away set_expn_info 2016-05-28 08:43:35 +00:00
Jeffrey Seyfried
074f4c2c91 Fix spans of generated #[derive_*] attributes 2016-05-28 08:43:34 +00:00
Vadim Petrochenkov
1a1de5bf89 Add a new AST-only type variant ImplicitSelf 2016-05-25 21:55:04 +03:00
Vadim Petrochenkov
5660a00486 Remove ExplicitSelf from AST 2016-05-25 21:55:04 +03:00
bors
1ccada6cd3 Auto merge of #33735 - jseyfried:concat_idents_in_ty_positions, r=nrc
Allow `concat_idents!` in type positions as well as in expression positions

This allows the `concat_idents!` macro in type positions as well as in expression positions.
r? @nrc
2016-05-23 07:53:43 -07:00
Jeffrey Seyfried
e992794282 Allow concat_idents! in type positions as well as in expression positions 2016-05-19 09:25:59 +00:00
Manish Goregaokar
83429f9e31 Rollup merge of #33666 - xen0n:no-more-nest-levels, r=nikomatsakis
syntax_ext: format: nest_level's are no more

Just noticed this while working on #33642 and here's a quick fix, shouldn't touch anything else. It's some historic code indeed...
2016-05-18 14:07:45 +05:30
Wang Xuerui
2ea6c70a1a syntax_ext: format: remove reference to methods in comment 2016-05-16 17:16:32 +08:00
Wang Xuerui
067284b291 syntax_ext: format: nest_level's are no more
`nest_level` is long dead since cac7a2053a
(PR #14831), so is `check_positional_ok()`. Let's bid them farewell.
2016-05-16 16:59:27 +08:00
bors
e87cd7e380 Auto merge of #33505 - petrochenkov:self, r=nrc
Remove ExplicitSelf from HIR

`self` argument is already kept in the argument list and can be retrieved from there if necessary, so there's no need for the duplication.
The same changes can be applied to AST, I'll make them in the next breaking batch.
The first commit also improves parsing of method declarations and fixes https://github.com/rust-lang/rust/issues/33413.

r? @eddyb
2016-05-15 23:14:52 -07:00
Vadim Petrochenkov
212d5d4352 syntax: Refactor parsing of method declarations
Fix spans and expected token lists, fix #33413 + other cosmetic improvements
Add test for #33413
Convert between `Arg` and `ExplicitSelf` precisely
Simplify pretty-printing for methods
2016-05-14 13:23:37 +03:00
Björn Steinbrink
0eeb14eaba Improve derived implementations for enums with lots of fieldless variants
A number of trait methods like PartialEq::eq or Hash::hash don't
actually need a distinct arm for each variant, because the code within
the arm only depends on the number and types of the fields in the
variants. We can easily exploit this fact to create less and better
code for enums with multiple variants that have no fields at all, the
extreme case being C-like enums.

For nickel.rs and its by now infamous 800 variant enum, this reduces
optimized compile times by 25% and non-optimized compile times by 40%.
Also peak memory usage is down by almost 40% (310MB down to 190MB).

To be fair, most other crates don't benefit nearly as much, because
they don't have as huge enums. The crates in the Rust distribution that
I measured saw basically no change in compile times (I only tried
optimized builds) and only 1-2% reduction in peak memory usage.
2016-05-12 21:05:13 +02:00
Seo Sanghyeon
9f6494c16c Remove unused trait imports introduced while in review 2016-05-03 19:33:31 +09:00
Niko Matsakis
2ba5fac1a4 fix rebase flaws 2016-05-02 11:49:26 -04:00
bors
435095f32a Auto merge of #32791 - LeoTestard:feature-gate-clean, r=nikomatsakis
Feature gate clean

This PR does a bit of cleaning in the feature-gate-handling code of libsyntax. It also fixes two bugs (#32782 and #32648). Changes include:

* Change the way the existing features are declared in `feature_gate.rs`. The array of features and the `Features` struct are now defined together by a single macro. `featureck.py` has been updated accordingly. Note: there are now three different arrays for active, removed and accepted features instead of a single one with a `Status` item to tell wether a feature is active, removed, or accepted. This is mainly due to the way I implemented my macro in the first time and I can switch back to a single array if needed. But an advantage of the way it is now is that when an active feature is used, the parser only searches through the list of active features. It goes through the other arrays only if the feature is not found. I like to think that error checking (in this case, checking that an used feature is active) does not slow down compilation of valid code. :) But this is not very important...
* Feature-gate checking pass now use the `Features` structure instead of looking through a string vector. This should speed them up a bit. The construction of the `Features` struct should be faster too since it is build directly when parsing features instead of calling `has_feature` dozens of times.
* The MacroVisitor pass has been removed, it was mostly useless since the `#[cfg]-stripping` phase happens before (fixes #32648). The features that must actually be checked before expansion are now checked at the time they are used. This also allows us to check attributes that are generated by macro expansion and not visible to MacroVisitor, but are also removed by macro expansion and thus not visible to PostExpansionVisitor either. This fixes #32782. Note that in order for `#[derive_*]` to be feature-gated but still accepted when generated by `#[derive(Trait)]`, I had to do a little bit of trickery with spans that I'm not totally confident into. Please review that part carefully. (It's in `libsyntax_ext/deriving/mod.rs`.)::

Note: this is a [breaking change], since programs with feature-gated attributes on macro-generated macro invocations were not rejected before. For example:

```rust
macro_rules! bar (
    () => ()
);

macro_rules! foo (
    () => (
        #[allow_internal_unstable] //~ ERROR allow_internal_unstable side-steps
        bar!();
    );
);
```
foo!();
2016-04-27 18:35:29 -07:00
bors
8f55218189 Auto merge of #31414 - durka:clone-copy, r=alexcrichton
special-case #[derive(Copy, Clone)] with a shallow clone

If a type is Copy then its Clone implementation can be a no-op. Currently `#[derive(Clone)]` generates a deep clone anyway. This can lead to lots of code bloat.

This PR detects the case where Copy and Clone are both being derived (the general case of "is this type Copy" can't be determined by a syntax extension) and generates the shallow Clone impl. Right now this can only be done if there are no type parameters (see https://github.com/rust-lang/rust/issues/31085#issuecomment-178988663), but this restriction can be removed after specialization.

Fixes #31085.
2016-04-26 14:54:37 -07:00
Alex Burka
9249e6a1e2 shallow Clone for #[derive(Copy,Clone)]
Changes #[derive(Copy, Clone)] to use a faster impl of Clone when
both derives are present, and there are no generics in the type.

The faster impl is simply returning *self (which works because the
type is also Copy). See the comments in libsyntax_ext/deriving/clone.rs
for more details.

There are a few types which are Copy but not Clone, in violation
of the definition of Copy. These include large arrays and tuples. The
very existence of these types is arguably a bug, but in order for this
optimization not to change the applicability of #[derive(Copy, Clone)],
the faster Clone impl also injects calls to a new function,
core::clone::assert_receiver_is_clone, to verify that all members are
actually Clone.

This is not a breaking change, because pursuant to RFC 1521, any type
that implements Copy should not do any observable work in its Clone
impl.
2016-04-26 13:49:29 -04:00
Vadim Petrochenkov
9108fb7bae Remove some old code from libsyntax 2016-04-24 21:04:09 +03:00
Vadim Petrochenkov
b32d7b5923 syntax: Merge keywords and remaining special idents in one list
Simplify the macro used for generation of keywords
Make `Keyword::ident` private
2016-04-24 20:59:44 +03:00
Vadim Petrochenkov
e2c821d35e syntax: Make static/super/self/Self keywords + special ident cleanup 2016-04-24 20:59:44 +03:00
Vadim Petrochenkov
546c052d22 syntax: Get rid of token::IdentStyle 2016-04-24 20:59:44 +03:00
Leo Testard
03ab057f97 Remove the MacroVisitor pass.
This pass was supposed to check use of gated features before
`#[cfg]`-stripping but this was not the case since it in fact happens
after. Checks that are actually important and must be done before macro
expansion are now made where the features are actually used. Close #32648.
Also ensure that attributes on macro-generated macro invocations are
checked as well. Close #32782 and #32655.
2016-04-22 01:40:33 +02:00
bors
073a09fd63 Auto merge of #32908 - oli-obk:hygienic_derive_encodable, r=alexcrichton
prevent other `encode` methods from breaking `derive(RustcEncodable)`

fixes https://github.com/rust-lang-nursery/rustc-serialize/issues/151
2016-04-14 08:23:11 -07:00
Oliver Schneider
2fd2210b88 prevent other encode methods from breaking derive(RustcEncodable) 2016-04-12 15:41:46 +02:00
Alex Crichton
552eda70d3 std: Stabilize APIs for the 1.9 release
This commit applies all stabilizations, renamings, and deprecations that the
library team has decided on for the upcoming 1.9 release. All tracking issues
have gone through a cycle-long "final comment period" and the specific APIs
stabilized/deprecated are:

Stable

* `std::panic`
* `std::panic::catch_unwind` (renamed from `recover`)
* `std::panic::resume_unwind` (renamed from `propagate`)
* `std::panic::AssertUnwindSafe` (renamed from `AssertRecoverSafe`)
* `std::panic::UnwindSafe` (renamed from `RecoverSafe`)
* `str::is_char_boundary`
* `<*const T>::as_ref`
* `<*mut T>::as_ref`
* `<*mut T>::as_mut`
* `AsciiExt::make_ascii_uppercase`
* `AsciiExt::make_ascii_lowercase`
* `char::decode_utf16`
* `char::DecodeUtf16`
* `char::DecodeUtf16Error`
* `char::DecodeUtf16Error::unpaired_surrogate`
* `BTreeSet::take`
* `BTreeSet::replace`
* `BTreeSet::get`
* `HashSet::take`
* `HashSet::replace`
* `HashSet::get`
* `OsString::with_capacity`
* `OsString::clear`
* `OsString::capacity`
* `OsString::reserve`
* `OsString::reserve_exact`
* `OsStr::is_empty`
* `OsStr::len`
* `std::os::unix::thread`
* `RawPthread`
* `JoinHandleExt`
* `JoinHandleExt::as_pthread_t`
* `JoinHandleExt::into_pthread_t`
* `HashSet::hasher`
* `HashMap::hasher`
* `CommandExt::exec`
* `File::try_clone`
* `SocketAddr::set_ip`
* `SocketAddr::set_port`
* `SocketAddrV4::set_ip`
* `SocketAddrV4::set_port`
* `SocketAddrV6::set_ip`
* `SocketAddrV6::set_port`
* `SocketAddrV6::set_flowinfo`
* `SocketAddrV6::set_scope_id`
* `<[T]>::copy_from_slice`
* `ptr::read_volatile`
* `ptr::write_volatile`
* The `#[deprecated]` attribute
* `OpenOptions::create_new`

Deprecated

* `std::raw::Slice` - use raw parts of `slice` module instead
* `std::raw::Repr` - use raw parts of `slice` module instead
* `str::char_range_at` - use slicing plus `chars()` plus `len_utf8`
* `str::char_range_at_reverse` - use slicing plus `chars().rev()` plus `len_utf8`
* `str::char_at` - use slicing plus `chars()`
* `str::char_at_reverse` - use slicing plus `chars().rev()`
* `str::slice_shift_char` - use `chars()` plus `Chars::as_str`
* `CommandExt::session_leader` - use `before_exec` instead.

Closes #27719
cc #27751 (deprecating the `Slice` bits)
Closes #27754
Closes #27780
Closes #27809
Closes #27811
Closes #27830
Closes #28050
Closes #29453
Closes #29791
Closes #29935
Closes #30014
Closes #30752
Closes #31262
cc #31398 (still need to deal with `before_exec`)
Closes #31405
Closes #31572
Closes #31755
Closes #31756
2016-04-11 08:57:53 -07:00
Manish Goregaokar
552af51ffb Rollup merge of #32570 - eddyb:tis-but-a-front, r=nikomatsakis
r? @nikomatsakis

Conflicts:
	src/librustc_save_analysis/lib.rs
	src/libsyntax/ast_util.rs
2016-04-06 17:31:16 +05:30
Vadim Petrochenkov
8fe4290f1c Move span into StructField 2016-04-06 11:19:10 +03:00
Vadim Petrochenkov
7f3744f07f Get rid of ast::StructFieldKind 2016-04-06 10:33:15 +03:00
Eduard Burtescu
7bebe80bc2 syntax: dismantle ast_util. 2016-04-06 09:04:15 +03:00
Alex Burka
1e67d8a570 deriving: factor out discriminant_value construction 2016-03-27 01:25:47 -04:00
Alex Burka
c480b6a75d fix #21714 by using discriminant_value in #[derive(Hash)]
This is the same approach taken in #24270, except that this
should not be a breaking change because it only changes the output
of hash functions, which nobody should be relying on.
2016-03-27 01:25:46 -04:00
Niko Matsakis
944dc4aa65 fix cargo.toml for new dependency 2016-03-25 14:39:24 -04:00