about summary refs log tree commit diff
path: root/src/libsyntax
AgeCommit message (Collapse)AuthorLines
2017-04-07Auto merge of #39987 - japaric:used, r=arielb1bors-0/+8
#[used] attribute (For an explanation of what this feature does, read the commit message) I'd like to propose landing this as an experimental feature (experimental as in: no clear stabilization path -- like `asm!`, `#[linkage]`) as it's low maintenance (I think) and relevant to the "Usage in resource-constrained environments" exploration area. The main use case I see is running code before `main`. This could be used, for instance, to cheaply initialize an allocator before `main` where the alternative is to use `lazy_static` to initialize the allocator on its first use which it's more expensive (atomics) and doesn't work on ARM Cortex-M0 microcontrollers (no `AtomicUsize` on that platform) Here's a `std` example of that: ``` rust unsafe extern "C" fn before_main_1() { println!("Hello"); } unsafe extern "C" fn before_main_2() { println!("World"); } #[link_section = ".init_arary"] #[used] static INIT_ARRAY: [unsafe extern "C" fn(); 2] = [before_main_1, before_main_2]; fn main() { println!("Goodbye"); } ``` ``` $ rustc -C lto -C opt-level=3 before_main.rs $ ./before_main Hello World Goodbye ``` In general, this pattern could be used to let *dependencies* run code before `main` (which sounds like it could go very wrong in some cases). There are probably other use cases; I hope that the people I have cc-ed can comment on those. Note that I'm personally unsure if the above pattern is something we want to promote / allow and that's why I'm proposing this feature as experimental. If this leads to more footguns than benefits then we can just axe the feature. cc @nikomatsakis ^ I know you have some thoughts on having a process for experimental features though I'm fine with writing an RFC before landing this. - `dead_code` lint will have to be updated to special case `#[used]` symbols. - Should we extend `#[used]` to work on non-generic functions? cc rust-lang/rfcs#1002 cc rust-lang/rfcs#1459 cc @dpc @JinShil
2017-04-06Introduce HashStable trait and base ICH implementations on it.Michael Woerister-0/+25
This initial commit provides implementations for HIR, MIR, and everything that also needs to be supported for those two.
2017-04-05Rollup merge of #41050 - jseyfried:fix_derive_parsing, r=petrochenkovCorey Farwell-1/+22
macros: fix bug parsing `#[derive]` invocations Fixes #40962 (introduced in #40346). r? @nrc
2017-04-05document the implementation a bit moreJorge Aparicio-2/+2
2017-04-05Rollup merge of #40815 - estebank:issue-40006, r=GuillaumeGomezAriel Ben-Yehuda-15/+42
Identify missing item category in `impl`s ```rust struct S; impl S { pub hello_method(&self) { println!("Hello"); } } fn main() { S.hello_method(); } ``` ```rust error: missing `fn` for method declaration --> file.rs:3:4 | 3 | pub hello_method(&self) { | ^ missing `fn` ``` Fix #40006. r? @pnkfelix CC @jonathandturner @GuillaumeGomez
2017-04-05add an #[used] attributeJorge Aparicio-0/+8
similar to GCC's __attribute((used))__. This attribute prevents LLVM from optimizing away a non-exported symbol, within a compilation unit (object file), when there are no references to it. This is better explained with an example: ``` #[used] static LIVE: i32 = 0; static REFERENCED: i32 = 0; static DEAD: i32 = 0; fn internal() {} pub fn exported() -> &'static i32 { &REFERENCED } ``` Without optimizations, LLVM pretty much preserves all the static variables and functions within the compilation unit. ``` $ rustc --crate-type=lib --emit=obj symbols.rs && nm -C symbols.o 0000000000000000 t drop::h1be0f8f27a2ba94a 0000000000000000 r symbols::REFERENCED::hb3bdfd46050bc84c 0000000000000000 r symbols::DEAD::hc2ea8f9bd06f380b 0000000000000000 r symbols::LIVE::h0970cf9889edb56e 0000000000000000 T symbols::exported::h6f096c2b1fc292b2 0000000000000000 t symbols::internal::h0ac1aadbc1e3a494 ``` With optimizations, LLVM will drop dead code. Here `internal` is dropped because it's not a exported function/symbol (i.e. not `pub`lic). `DEAD` is dropped for the same reason. `REFERENCED` is preserved, even though it's not exported, because it's referenced by the `exported` function. Finally, `LIVE` survives because of the `#[used]` attribute even though it's not exported or referenced. ``` $ rustc --crate-type=lib -C opt-level=3 --emit=obj symbols.rs && nm -C symbols.o 0000000000000000 r symbols::REFERENCED::hb3bdfd46050bc84c 0000000000000000 r symbols::LIVE::h0970cf9889edb56e 0000000000000000 T symbols::exported::h6f096c2b1fc292b2 ``` Note that the linker knows nothing about `#[used]` and will drop `LIVE` because no other object references to it. ``` $ echo 'fn main() {}' >> symbols.rs $ rustc symbols.rs && nm -C symbols | grep LIVE ``` At this time, `#[used]` only works on `static` variables.
2017-04-05Use proper span for tuple index parsed as floatEsteban Küber-3/+3
Fix diagnostic suggestion from: ```rust help: try parenthesizing the first index | (1, (2, 3)).((1, (2, 3)).1).1; ``` to the correct: ```rust help: try parenthesizing the first index | ((1, (2, 3)).1).1; ```
2017-04-05Rollup merge of #40870 - alexcrichton:stabilize-windows-subsystem, r=aturonCorey Farwell-9/+3
rustc: Stabilize the `#![windows_subsystem]` attribute This commit stabilizes the `#![windows_subsystem]` attribute which is a conservative exposure of the `/SUBSYSTEM` linker flag on Widnows platforms. This is useful for creating applications as well as console programs. Closes #37499
2017-04-04Merge branch 'master' into issue-32540Esteban Küber-1662/+671
2017-04-03Fix bug parsing `#[derive]` macro invocations.Jeffrey Seyfried-1/+22
2017-04-03Merge branch 'master' into issue-40006Esteban Küber-1663/+672
2017-04-02Introduce `TyErr` independent from `TyInfer`Esteban Küber-3/+31
Add a `TyErr` type to represent unknown types in places where parse errors have happened, while still able to build the AST. Initially only used to represent incorrectly written fn arguments and avoid "expected X parameters, found Y" errors when called with the appropriate amount of parameters. We cannot use `TyInfer` for this as `_` is not allowed as a valid argument type. Example output: ```rust error: expected one of `:` or `@`, found `,` --> file.rs:12:9 | 12 | fn bar(x, y: usize) {} | ^ error[E0061]: this function takes 2 parameters but 3 parameters were supplied --> file.rs:19:9 | 12 | fn bar(x, y) {} | --------------- defined here ... 19 | bar(1, 2, 3); | ^^^^^^^ expected 2 parameters ```
2017-04-01rustc: Stabilize the `#![windows_subsystem]` attributeAlex Crichton-9/+3
This commit stabilizes the `#![windows_subsystem]` attribute which is a conservative exposure of the `/SUBSYSTEM` linker flag on Widnows platforms. This is useful for creating applications as well as console programs. Closes #37499
2017-03-31Auto merge of #40620 - laumann:slash-in-diagnostics-path, r=BurntSushibors-4/+5
Replace hardcoded forward slash with path::MAIN_SEPARATOR Fixes #40149
2017-03-30port the match code to use `CoerceMany`Niko Matsakis-0/+1
`match { }` now (correctly?) indicates divergence, which results in more unreachable warnings. We also avoid fallback to `!` if there is just one arm (see new test: `match-unresolved-one-arm.rs`).
2017-03-30Replace hardcoded forward slash with path::MAIN_SEPARATORThomas Jespersen-4/+5
Fixes #40149
2017-03-30Improve `Path` spans.Jeffrey Seyfried-67/+95
2017-03-29Refactor how spans are combined in the parser.Jeffrey Seyfried-399/+337
2017-03-29Merge `ExpnId` and `SyntaxContext`.Jeffrey Seyfried-868/+163
2017-03-29Remove code in `syntax::codemap`.Jeffrey Seyfried-185/+0
2017-03-29Move `syntax::ext::hygiene` to `syntax_pos::hygiene`.Jeffrey Seyfried-134/+15
2017-03-27Fix unittestsEsteban Küber-1/+1
2017-03-27Simplify error outputEsteban Küber-11/+6
2017-03-27Rollup merge of #40813 - jseyfried:fix_expansion_regression, r=nrcAlex Crichton-1/+1
macros: fix ICE on some nested macro definitions Fixes #40770. r? @nrc
2017-03-27Fix various useless derefs and slicingsOliver Schneider-10/+9
2017-03-27allow `InternedString` to be compared to `str` directlyOliver Schneider-4/+40
2017-03-26Auto merge of #40347 - alexcrichton:rm-liblog, r=brsonbors-1/+1
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-25Improve wording and spans for unexpected tokenEsteban Küber-6/+19
* Point at where the token was expected instead of the last token successfuly parsed. * Only show `unexpected token` if the next char and the unexpected token don't have the same span. * Change some cfail and pfail tests to ui test. * Don't show all possible tokens in span label if they are more than 6.
2017-03-24Point at last valid token on failed `expect_one_of`Esteban Küber-14/+14
```rust error: expected one of `.`, `;`, `?`, `}`, or an operator, found `)` --> $DIR/token-error-correct-3.rs:29:9 | 25 | foo() | - expected one of `.`, `;`, `?`, `}`, or an operator after this ... 29 | } else { | ^ unexpected token ```
2017-03-24Identify missing item category in `impl`sEsteban Küber-15/+47
```rust struct S; impl S { pub hello_method(&self) { println!("Hello"); } } fn main() { S.hello_method(); } ``` ```rust error: can't qualify macro invocation with `pub` --> file.rs:3:4 | 3 | pub hello_method(&self) { | ^^^- - expected `!` here for a macro invocation | | | did you mean to write `fn` here for a method declaration? | = help: try adjusting the macro to put `pub` inside the invocation ```
2017-03-25Fix ICE with nested macros in certain situations.Jeffrey Seyfried-1/+1
2017-03-23Remove internal liblogAlex Crichton-1/+1
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-23Rollup merge of #40627 - estebank:pub-restricted, r=petrochenkovCorey Farwell-26/+38
Add diagnostic for incorrect `pub (restriction)` Given the following statement ```rust pub (a) fn afn() {} ``` Provide the following diagnostic: ```rust error: incorrect restriction in `pub` --> file.rs:15:1 | 15 | pub (a) fn afn() {} | ^^^ | = help: some valid visibility restrictions are: `pub(crate)`: visible only on the current crate `pub(super)`: visible only in the current module's parent `pub(in path::to::module)`: visible only on the specified path help: to make this visible only to module `a`, add `in` before the path: | pub (in a) fn afn() {} ``` Follow up to #40340, fix #40599, cc #32409.
2017-03-22Add diagnostic for incorrect `pub (restriction)`Esteban Küber-26/+38
Given the following statement ```rust pub (a) fn afn() {} ``` Provide the following diagnostic: ```rust error: incorrect restriction in `pub` --> file.rs:15:1 | 15 | pub (a) fn afn() {} | ^^^^^^^ | = help: some valid visibility restrictions are: `pub(crate)`: visible only on the current crate `pub(super)`: visible only in the current module's parent `pub(in path::to::module)`: visible only on the specified path help: to make this visible only to module `a`, add `in` before the path: | pub (in a) fn afn() {} ``` Remove cruft from old `pub(path)` syntax.
2017-03-22Introduce HirId, a replacement for NodeId after lowering to HIR.Michael Woerister-11/+3
HirId has a more stable representation than NodeId, meaning that modifications to one item don't influence (part of) the IDs within other items. The other part is a DefIndex for which there already is a way of stable hashing and persistence. This commit introduces the HirId type and generates a HirId for every NodeId during HIR lowering, but the resulting values are not yet used anywhere, except in consistency checks.
2017-03-22Implement indexed_vec::Idx for ast::NodeIdMichael Woerister-0/+11
2017-03-21Refactor parsing of trait object typesVadim Petrochenkov-246/+220
2017-03-20Rollup merge of #40556 - cramertj:stabilize-pub-restricted, r=petrochenkovCorey Farwell-14/+3
Stabilize pub(restricted) Fix https://github.com/rust-lang/rust/issues/32409
2017-03-19Rollup merge of #40532 - jseyfried:improve_tokenstream_quoter, r=nrcCorey Farwell-0/+6
macros: improve the `TokenStream` quoter This PR - renames the `TokenStream` quoter from `qquote!` to `quote!`, - uses `$` instead of `unquote` (e.g. `let toks: TokenStream = ...; quote!([$toks])`), - allows unquoting `Token`s as well as `TokenTree`s and `TokenStream`s (fixes #39746), and - to preserve syntactic space, requires that `$` be followed by - a single identifier to unquote, or - another `$` to produce a literal `$`. r? @nrc
2017-03-19Rollup merge of #40589 - topecongiro:floating-point-literal, r=nagisaCorey Farwell-1/+1
Parse 0e+10 as a valid floating-point literal Fixes issue #40408.
2017-03-19Rollup merge of #40441 - tschottdorf:promotable-rfc, r=eddybCorey Farwell-0/+3
Add feature gate for rvalue-static-promotion Probably needs more tests (which ones?) and there may be other things that need to be done. Also not sure whether the version that introduces the flag is really `1.15.1`. See https://github.com/rust-lang/rfcs/pull/1414. Updates #38865.
2017-03-19Auto merge of #40346 - jseyfried:path_and_tokenstream_attr, r=nrcbors-350/+691
`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-18Parse 0e+10 as a valid floating-point literaltopecongiro-1/+1
Fixes issue #40408.
2017-03-15Stabilize pub(restricted)Taylor Cramer-14/+3
2017-03-15Improve the `TokenStream` quoter.Jeffrey Seyfried-0/+6
2017-03-14Point out correct turbofish usage on `Foo<Bar<Baz>>`Esteban Küber-1/+4
Whenever we parse a chain of binary operations, as long as the first operation is `<` and the subsequent operations are either `>` or `<`, present the following diagnostic help: use `::<...>` instead of `<...>` if you meant to specify type arguments This will lead to spurious recommendations on situations like `2 < 3 < 4` but should be clear from context that the help doesn't apply in that case.
2017-03-14Add feature toggle for rvalue-static-promotion RFCTobias Schottdorf-0/+3
See https://github.com/rust-lang/rfcs/pull/1414. Updates #38865.
2017-03-14Auto merge of #39921 - cramertj:add-catch-to-ast, r=nikomatsakisbors-1/+47
Add catch {} to AST Part of #39849. Builds on #39864.
2017-03-14Liberalize attributes.Jeffrey Seyfried-120/+187
2017-03-14Refactor `Attribute` to use `Path` and `TokenStream` instead of `MetaItem`.Jeffrey Seyfried-229/+504