about summary refs log tree commit diff
path: root/src/libsyntax/ext/base.rs
AgeCommit message (Collapse)AuthorLines
2015-03-25Add trivial cast lints.Nick Cameron-3/+3
This permits all coercions to be performed in casts, but adds lints to warn in those cases. Part of this patch moves cast checking to a later stage of type checking. We acquire obligations to check casts as part of type checking where we previously checked them. Once we have type checked a function or module, then we check any cast obligations which have been acquired. That means we have more type information available to check casts (this was crucial to making coercions work properly in place of some casts), but it means that casts cannot feed input into type inference. [breaking change] * Adds two new lints for trivial casts and trivial numeric casts, these are warn by default, but can cause errors if you build with warnings as errors. Previously, trivial numeric casts and casts to trait objects were allowed. * The unused casts lint has gone. * Interactions between casting and type inference have changed in subtle ways. Two ways this might manifest are: - You may need to 'direct' casts more with extra type information, for example, in some cases where `foo as _ as T` succeeded, you may now need to specify the type for `_` - Casts do not influence inference of integer types. E.g., the following used to type check: ``` let x = 42; let y = &x as *const u32; ``` Because the cast would inform inference that `x` must have type `u32`. This no longer applies and the compiler will fallback to `i32` for `x` and thus there will be a type error in the cast. The solution is to add more type information: ``` let x: u32 = 42; let y = &x as *const u32; ```
2015-03-11syntax: move MethMac to MacImplItem and combine {Provided,Required}Method ↵Eduard Burtescu-6/+6
into MethodTraitItem.
2015-03-11syntax: gather common fields of impl & trait items into their respective types.Eduard Burtescu-34/+16
2015-03-11syntax: move indirection around {Trait,Impl}Item, from within.Eduard Burtescu-30/+25
2015-03-06Make #[derive(Anything)] into sugar for #[derive_Anything]Keegan McAllister-4/+2
This is a hack, but I don't think we can do much better as long as `derive` is running at the syntax expansion phase. If the custom_derive feature gate is enabled, this works with user-defined traits and syntax extensions. Without the gate, you can't use e.g. #[derive_Clone] directly, so this does not change the stable language. This commit also cleans up the deriving code somewhat, and forbids some previously-meaningless attribute syntax. For this reason it's technically a [breaking-change]
2015-03-06Auto merge of #22899 - huonw:macro-stability, r=alexcrichtonbors-5/+8
Unstable items used in a macro expansion will now always trigger stability warnings, *unless* the unstable items are directly inside a macro marked with `#[allow_internal_unstable]`. IOW, the compiler warns unless the span of the unstable item is a subspan of the definition of a macro marked with that attribute. E.g. #[allow_internal_unstable] macro_rules! foo { ($e: expr) => {{ $e; unstable(); // no warning only_called_by_foo!(); }} } macro_rules! only_called_by_foo { () => { unstable() } // warning } foo!(unstable()) // warning The unstable inside `foo` is fine, due to the attribute. But the `unstable` inside `only_called_by_foo` is not, since that macro doesn't have the attribute, and the `unstable` passed into `foo` is also not fine since it isn't contained in the macro itself (that is, even though it is only used directly in the macro). In the process this makes the stability tracking much more precise, e.g. previously `println!("{}", unstable())` got no warning, but now it does. As such, this is a bug fix that may cause [breaking-change]s. The attribute is definitely feature gated, since it explicitly allows side-stepping the feature gating system. --- This updates `thread_local!` macro to use the attribute, since it uses unstable features internally (initialising a struct with unstable fields).
2015-03-06Add #[allow_internal_unstable] to track stability for macros better.Huon Wilson-5/+8
Unstable items used in a macro expansion will now always trigger stability warnings, *unless* the unstable items are directly inside a macro marked with `#[allow_internal_unstable]`. IOW, the compiler warns unless the span of the unstable item is a subspan of the definition of a macro marked with that attribute. E.g. #[allow_internal_unstable] macro_rules! foo { ($e: expr) => {{ $e; unstable(); // no warning only_called_by_foo!(); }} } macro_rules! only_called_by_foo { () => { unstable() } // warning } foo!(unstable()) // warning The unstable inside `foo` is fine, due to the attribute. But the `unstable` inside `only_called_by_foo` is not, since that macro doesn't have the attribute, and the `unstable` passed into `foo` is also not fine since it isn't contained in the macro itself (that is, even though it is only used directly in the macro). In the process this makes the stability tracking much more precise, e.g. previously `println!("{}", unstable())` got no warning, but now it does. As such, this is a bug fix that may cause [breaking-change]s. The attribute is definitely feature gated, since it explicitly allows side-stepping the feature gating system.
2015-03-05Rollup merge of #22764 - ivanradanov:fileline_help, r=huonwManish Goregaokar-0/+4
When warnings and errors occur, the associated help message should not print the same code snippet. https://github.com/rust-lang/rust/issues/21938
2015-03-05Auto merge of #22061 - pczarn:quote_matcher_and_attr, r=kmcallisterbors-1/+7
Fixes #19674 Fixes #17396 (already closed, yeah) cc @kmcallister , @cmr
2015-03-04Add quasiquote for matchers and attributesPiotr Czarnecki-1/+7
2015-03-03Switched to Box::new in many places.Felix S. Klock II-3/+3
Many of the modifications putting in `Box::new` calls also include a pointer to Issue 22405, which tracks going back to `box <expr>` if possible in the future. (Still tried to use `Box<_>` where it sufficed; thus some tests still have `box_syntax` enabled, as they use a mix of `box` and `Box::new`.) Precursor for overloaded-`box` and placement-`in`; see Issue 22181.
2015-03-03Change span_help calls to fileline_help where appropriateIvan Radanov Ivanov-0/+4
2015-02-27Replace MacExpr / MacPat / MacItems with MacEagerKeegan McAllister-47/+69
MacEager is a MacResult implementation for the common case where you've already built each form of AST that you might return. Fixes #17637. Based on #18814. This is a [breaking-change] for syntax extensions: * MacExpr::new becomes MacEager::expr. * MacPat::new becomes MacEager::pat. * MacItems::new becomes MacEager::items. It takes a SmallVector directly, not an iterator.
2015-02-20Remove remaining uses of `[]`. This time I tried to use deref coercions ↵Niko Matsakis-11/+11
where possible.
2015-02-18rollup merge of #22287: Ryman/purge_carthographersAlex Crichton-1/+1
This overlaps with #22276 (I left make check running overnight) but covers a number of additional cases and has a few rewrites where the clones are not even necessary. This also implements `RandomAccessIterator` for `iter::Cloned` cc @steveklabnik, you may want to glance at this before #22281 gets the bors treatment
2015-02-18Opt for .cloned() over .map(|x| x.clone()) etc.Kevin Butler-1/+1
2015-02-17Rollup merge of #22383 - pnkfelix:pass-features-along-during-expansion, r=huonwManish Goregaokar-4/+5
Pass features along during expansion Use the set of passed features to detect uses of feature-gated macros without the corresponding feature enabled. Fix #22234. ---- Also, the framework this add (passing along a reference to the features in the expansion context) is a necessary precursor for landing a properly feature-gated desugaring-based overloaded-`box` and placement-`in` (#22181). ---- This is fixing a bug, but since there might be code out there that is unknowingly taking advantage of that bug, I feel obligated to mark this as a: [breaking-change]
2015-02-16Fix fallout in libsyntax from RFC 599. Clarity and efficiency seems to be ↵Niko Matsakis-3/+3
mostly improved, to my eye. Nonetheless, as this commit demonstrates, the previous commits was a [breaking-change]. In practice, breakage is focused on functions of this form: ```rust fn foo(..., object: Box<FnMut()>) ```` where `FnMut()` could be any trait object type. The older scheme defaulted objects in argument position so that they were bounded by a fresh lifetime: ```rust fn foo<'a>(..., object: Box<FnMut()+'a>) ``` This meant that the object could contain borrowed data. The newer scheme defaults to a lifetime bound of `'static`: ```rust fn foo(..., object: Box<FnMut()+'static>) ``` This means that the object cannot contain borrowed data. In some cases, the best fix is to stop using `Box`: ```rust fn foo(..., object: &mut FnMut()) ``` but another option is to write an explicit annotation for the `'a` lifetime that used to be implicit. Both fixes are demonstrated in this commit.
2015-02-15libsyntax: Pass feature set in ExpansionConfig, not just enable_quotes.Felix S. Klock II-4/+5
2015-02-09Process cfg_attr right before stripping cfgKeegan McAllister-2/+0
Fixes #22070. Fixes #19372.
2015-02-07Don't use std:: paths in syntax extensions when compiling a #![no_std] crateKeegan McAllister-0/+5
Fixes #16803. Fixes #14342. Fixes half of #21827 -- slice syntax is still broken.
2015-02-06Libsyntax has been updatedGuillaumeGomez-2/+1
2015-02-06Replace the get method by the deref one on InternedStringGuillaumeGomez-1/+2
2015-01-29s/Show/Debug/gJorge Aparicio-1/+1
2015-01-26Merge remote-tracking branch 'rust-lang/master'Brian Anderson-0/+2
Conflicts: src/librustc/lint/builtin.rs src/librustc/lint/context.rs
2015-01-25Merge remote-tracking branch 'rust-lang/master'Brian Anderson-1/+1
Conflicts: mk/tests.mk src/liballoc/arc.rs src/liballoc/boxed.rs src/liballoc/rc.rs src/libcollections/bit.rs src/libcollections/btree/map.rs src/libcollections/btree/set.rs src/libcollections/dlist.rs src/libcollections/ring_buf.rs src/libcollections/slice.rs src/libcollections/str.rs src/libcollections/string.rs src/libcollections/vec.rs src/libcollections/vec_map.rs src/libcore/any.rs src/libcore/array.rs src/libcore/borrow.rs src/libcore/error.rs src/libcore/fmt/mod.rs src/libcore/iter.rs src/libcore/marker.rs src/libcore/ops.rs src/libcore/result.rs src/libcore/slice.rs src/libcore/str/mod.rs src/libregex/lib.rs src/libregex/re.rs src/librustc/lint/builtin.rs src/libstd/collections/hash/map.rs src/libstd/collections/hash/set.rs src/libstd/sync/mpsc/mod.rs src/libstd/sync/mutex.rs src/libstd/sync/poison.rs src/libstd/sync/rwlock.rs src/libsyntax/feature_gate.rs src/libsyntax/test.rs
2015-01-25Tell the compiler to tell us that `deriving` is dead.Huon Wilson-0/+2
I'm beginning to suspect it's impossible to avoid accidentally writing `#[deriving]` at least once in every program, and it results in non-intuitive error messages: "Foo doesn't have any method in scope `clone`" despite there being a `#[deriv...(Clone)]` attribute! Also, lots of documentation around the internet uses `#[deriving]` so providing this guidance is very helpful (lots of people ask in #rust about this error). Fixes #21166.
2015-01-23Deprecated attributes don't take 'feature' names and are paired with ↵Brian Anderson-1/+2
stable/unstable Conflicts: src/libcore/atomic.rs src/libcore/finally.rs src/test/auxiliary/inherited_stability.rs src/test/auxiliary/lint_stability.rs
2015-01-21Add 'feature' and 'since' to stability attributesBrian Anderson-1/+2
2015-01-17libsyntax: uint types to usizePaul Collier-1/+1
2015-01-15Syntax extensions on trait and impl items.Nick Cameron-0/+106
Allows modifiers to be used on methods, associated types, etc.
2015-01-07rollup merge of #20657: alexcrichton/stabilize-macrosAlex Crichton-11/+0
2015-01-07use slicing sugarJorge Aparicio-6/+6
2015-01-07std: Stablize the macros moduleAlex Crichton-11/+0
This commit performs a pass over the `std::macros` module, applying stability attributes where necessary. In particular, this audits macros for patterns such as: * Standard use of forward-to-format-args via `$($arg:tt)*` (or `+`) * Prevent macro-defined identifiers from leaking into expression arguments as hygiene is not perfectly implemented. * Wherever possible, `$crate` is used now. Specifically, the following actions were taken: * The `std::macros` module itself is no longer public. * The `panic!` macro is stable * The `assert!` macro is stable * The `assert_eq!` macro is stable * The `debug_assert!` macro is stable * The `debug_assert_eq!` macro is stable * The `unreachable!` macro is stable after removing the extra forms to bring the definition in line with the `unimplemented!` macro. * The `try!` macro is stable * The `vec!` macro is stable [breaking-change]
2015-01-07Replace full slice notation with index callsNick Cameron-5/+5
2015-01-05Allow selective macro importKeegan McAllister-2/+4
2015-01-05Move #[macro_reexport] to extern crateKeegan McAllister-0/+10
2015-01-05Reformat metadata for exported macrosKeegan McAllister-21/+1
Instead of copy-pasting the whole macro_rules! item from the original .rs file, we serialize a separate name, attributes list, and body, the latter as pretty-printed TTs. The compilation of macro_rules! macros is decoupled somewhat from the expansion of macros in item position. This filters out comments, and facilitates selective imports.
2015-01-05Replace LetSyntaxTT with MacroRulesTTKeegan McAllister-9/+3
The implementation of LetSyntaxTT was specialized to macro_rules! in various ways. This gets rid of the false generality and simplifies the code.
2015-01-03sed -i -s 's/#\[deriving(/#\[derive(/g' **/*.rsJorge Aparicio-2/+2
2015-01-03syntax: fix falloutJorge Aparicio-1/+1
2015-01-02Accept `derive` instead of `deriving`Nick Cameron-0/+2
[breaking-change] `deriving is still accepted, but gives a deprecation warning
2014-12-31syntax: unbox closures used in function argumentsJorge Aparicio-3/+3
2014-12-23Rename include_bin! to include_bytes!Chris Wong-0/+3
According to [RFC 344][], methods that return `&[u8]` should have names ending in `bytes`. Though `include_bin!` is a macro not a method, it seems reasonable to follow the convention anyway. We keep the old name around for now, but trigger a deprecation warning when it is used. [RFC 344]: https://github.com/rust-lang/rfcs/blob/master/text/0344-conventions-galore.md [breaking-change]
2014-12-22rollup merge of #19891: nikomatsakis/unique-fn-types-3Alex Crichton-9/+19
Conflicts: src/libcore/str.rs src/librustc_trans/trans/closure.rs src/librustc_typeck/collect.rs src/libstd/path/posix.rs src/libstd/path/windows.rs
2014-12-22Fix fallout from changes. In cases where stage0 compiler is needed, weNiko Matsakis-9/+19
cannot use an `as` expression to coerce, so I used a one-off function instead (this is a no-op in stage0, but in stage1+ it triggers coercion from the fn pointer to the fn item type).
2014-12-21Fallout of std::str stabilizationAlex Crichton-5/+5
2014-12-20Allow `Self` in impls.Nick Cameron-1/+1
2014-12-19libsyntax: use `#[deriving(Copy)]`Jorge Aparicio-2/+1
2014-12-15Remove all shadowed lifetimes.Niko Matsakis-2/+2