about summary refs log tree commit diff
path: root/compiler/rustc_builtin_macros/src
AgeCommit message (Collapse)AuthorLines
2021-02-03Auto merge of #81294 - pnkfelix:issue-81211-use-ufcs-in-derive-debug, r=oli-obkbors-17/+21
Use ufcs in derive(Debug) Cc #81211. (Arguably this *is* the fix for it.)
2021-02-02Rollup merge of #81647 - m-ou-se:assert-2021-fix, r=petrochenkovJack Huey-2/+2
Fix bug with assert!() calling the wrong edition of panic!(). The span of `panic!` produced by the `assert` macro did not carry the right edition. This changes `assert` to call the right version. Also adds tests for the 2021 edition of panic and assert, that would've caught this.
2021-02-02Auto merge of #81405 - bugadani:ast, r=cjgillotbors-13/+17
Box the biggest ast::ItemKind variants This PR is a different approach on https://github.com/rust-lang/rust/pull/81400, aiming to save memory in humongous ASTs. The three affected item kind enums are: - `ast::ItemKind` (208 -> 112 bytes) - `ast::AssocItemKind` (176 -> 72 bytes) - `ast::ForeignItemKind` (176 -> 72 bytes)
2021-02-02Bump rustfmt versionMark Rousskov-1/+1
Also switches on formatting of the mir build module
2021-02-01Fix bug with assert!() calling the wrong edition of panic!().Mara Bos-2/+2
The span of `panic!` produced by the `assert` macro did not carry the right edition. This changes `assert` to call the right version.
2021-02-01placate tidy.Felix S. Klock II-10/+4
2021-02-01Use UFCS instead of method calls in `derive(Debug)`. See issue 81211 for ↵Felix S. Klock II-15/+25
discussion.
2021-02-01Auto merge of #80851 - m-ou-se:panic-2021, r=petrochenkovbors-0/+51
Implement Rust 2021 panic This implements the Rust 2021 versions of `panic!()`. See https://github.com/rust-lang/rust/issues/80162 and https://github.com/rust-lang/rfcs/pull/3007. It does so by replacing `{std, core}::panic!()` by a bulitin macro that expands to either `$crate::panic::panic_2015!(..)` or `$crate::panic::panic_2021!(..)` depending on the edition of the caller. This does not yet make std's panic an alias for core's panic on Rust 2021 as the RFC proposes. That will be a separate change: https://github.com/rust-lang/rust/pull/80879/commits/c5273bdfb266c35e8eab9413aa8d58d27fdbe114 That change is blocked on figuring out what to do with https://github.com/rust-lang/rust/issues/80846 first.
2021-02-01Box the biggest ast::ItemKind variantsDániel Buga-13/+17
2021-01-25Implement new panic!() behaviour for Rust 2021.Mara Bos-0/+51
2021-01-24Rollup merge of #80855 - m-ou-se:assert-2021, r=petrochenkovJonas Schievink-5/+21
Expand assert!(expr, args..) to include $crate for hygiene on 2021. This makes `assert!(expr, args..)` properly hygienic in Rust 2021. This is part of rust-lang/rfcs#3007, see #80162. Before edition 2021, this was a breaking change, as `std::panic` and `core::panic` are different. In edition 2021 they will be identical, making it possible to apply proper hygiene here.
2021-01-24Only call span.rust_2021() when necessary.Mara Bos-7/+5
2021-01-20Force token collection to run when parsing nonterminalsAaron Hill-2/+3
Fixes #81007 Previously, we would fail to collect tokens in the proper place when only builtin attributes were present. As a result, we would end up with attribute tokens in the collected `TokenStream`, leading to duplication when we attempted to prepend the attributes from the AST node. We now explicitly track when token collection must be performed due to nomterminal parsing.
2021-01-10resolve: Simplify built-in macro tableVadim Petrochenkov-10/+4
2021-01-09Expand assert!(expr, args..) to include $crate for hygiene on 2021.Mara Bos-1/+19
Before 2021, this was a breaking change, as std::panic and core::panic are different. In edition 2021 they will be identical, making it possible again to apply proper hygiene here.
2021-01-09Don't set builtin_name for builtin macro implementations.Mara Bos-1/+1
This used to be necessary for `is_builtin` in the past, but is no longer required. Co-authored-by: Vadim Petrochenkov <vadim.petrochenkov@gmail.com>
2021-01-09Allow #[rustc_builtin_macro = "name"].Mara Bos-1/+1
This makes it possible to have both std::panic and core::panic as a builtin macro, by using different builtin macro names for each. Also removes SyntaxExtension::is_derive_copy, as the macro name (e.g. sym::Copy) is now tracked and provides that information directly.
2021-01-02reduce borrowing and (de)referencing around match patterns ↵Matthias Krüger-5/+5
(clippy::match_ref_pats)
2021-01-01first pass at default values for const genericsJulian Knodt-1/+2
- Adds optional default values to const generic parameters in the AST and HIR - Parses these optional default values - Adds a `const_generics_defaults` feature gate
2020-12-30Rollup merge of #80495 - jyn514:rename-empty, r=petrochenkovMara Bos-1/+1
Rename kw::Invalid -> kw::Empty See https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/Is.20there.20a.20symbol.20for.20the.20empty.20string.3F/near/220054471 for context. r? `@petrochenkov`
2020-12-30Rename kw::Invalid -> kw::EmptyJoshua Nelson-1/+1
See https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/Is.20there.20a.20symbol.20for.20the.20empty.20string.3F/near/220054471 for context.
2020-12-24use matches!() macro in more placesMatthias Krüger-26/+16
2020-12-22Add some intra-doc links to compiler docsJoshua Nelson-1/+4
2020-12-11fix clippy::unnecessary_filter_mapMatthias Krüger-4/+1
2020-11-26Properly handle attributes on statementsAaron Hill-2/+2
We now collect tokens for the underlying node wrapped by `StmtKind` instead of storing tokens directly in `Stmt`. `LazyTokenStream` now supports capturing a trailing semicolon after it is initially constructed. This allows us to avoid refactoring statement parsing to wrap the parsing of the semicolon in `parse_tokens`. Attributes on item statements (e.g. `fn foo() { #[bar] struct MyStruct; }`) are now treated as item attributes, not statement attributes, which is consistent with how we handle attributes on other kinds of statements. The feature-gating code is adjusted so that proc-macro attributes are still allowed on item statements on stable. Two built-in macros (`#[global_allocator]` and `#[test]`) needed to be adjusted to support being passed `Annotatable::Stmt`.
2020-11-24Handle `Annotatable::Stmt` in some builtin macrosAaron Hill-14/+70
This is preparation for PR #78296, which will require us to handle statement items in addition to normal items.
2020-11-23Reduce boilerplate with the `?` operatorLingMan-10/+6
2020-11-20Auto merge of #78088 - fusion-engineering-forks:panic-fmt-lint, r=estebankbors-22/+30
Add lint for panic!("{}") This adds a lint that warns about `panic!("{}")`. `panic!(msg)` invocations with a single argument use their argument as panic payload literally, without using it as a format string. The same holds for `assert!(expr, msg)`. This lints checks if `msg` is a string literal (after expansion), and warns in case it contained braces. It suggests to insert `"{}", ` to use the message literally, or to add arguments to use it as a format string. ![image](https://user-images.githubusercontent.com/783247/96643867-79eb1080-1328-11eb-8d4e-a5586837c70a.png) This lint is also a good starting point for adding warnings about `panic!(not_a_string)` later, once [`panic_any()`](https://github.com/rust-lang/rust/pull/74622) becomes a stable alternative.
2020-11-19expand: Mark some dead code in derive expansion as unreachableVadim Petrochenkov-20/+3
2020-11-19expand: Tell built-in macros whether we are currently in forced expansion modeVadim Petrochenkov-4/+7
2020-11-15Rollup merge of #79005 - petrochenkov:noinjected, r=davidtwcoJonas Schievink-3/+3
cleanup: Remove `ParseSess::injected_crate_name` Its only remaining use is in pretty-printing where the necessary information can be easily re-computed.
2020-11-13Reserve space in advanceDániel Buga-1/+1
2020-11-13cleanup: Remove `ParseSess::injected_crate_name`Vadim Petrochenkov-3/+3
2020-11-10Changed unwrap_or to unwrap_or_else in some places.Nicholas-Baron-1/+1
The discussion seems to have resolved that this lint is a bit "noisy" in that applying it in all places would result in a reduction in readability. A few of the trivial functions (like `Path::new`) are fine to leave outside of closures. The general rule seems to be that anything that is obviously an allocation (`Box`, `Vec`, `vec![]`) should be in a closure, even if it is a 0-sized allocation.
2020-11-10Rollup merge of #78875 - petrochenkov:cleantarg, r=Mark-SimulacrumJonas Schievink-1/+1
rustc_target: Further cleanup use of target options Follow up to https://github.com/rust-lang/rust/pull/77729. Implements items 2 and 4 from the list in https://github.com/rust-lang/rust/pull/77729#issue-500228243. The first commit collapses uses of `target.options.foo` into `target.foo`. The second commit renames some target options to avoid tautology: `target.target_endian` -> `target.endian` `target.target_c_int_width` -> `target.c_int_width` `target.target_os` -> `target.os` `target.target_env` -> `target.env` `target.target_vendor` -> `target.vendor` `target.target_family` -> `target.os_family` `target.target_mcount` -> `target.mcount` r? `@Mark-Simulacrum`
2020-11-08Collapse all uses of `target.options.foo` into `target.foo`Vadim Petrochenkov-1/+1
with an eye on merging `TargetOptions` into `Target`. `TargetOptions` as a separate structure is mostly an implementation detail of `Target` construction, all its fields logically belong to `Target` and available from `Target` through `Deref` impls.
2020-11-03rustc_ast: `visit_mac` -> `visit_mac_call`Vadim Petrochenkov-1/+1
2020-11-03rustc_ast: Do not panic by default when visiting macro callsVadim Petrochenkov-12/+0
2020-10-21Unconditionally capture tokens for attributes.Aaron Hill-1/+1
This allows us to avoid synthesizing tokens in `prepend_attr`, since we have the original tokens available. We still need to synthesize tokens when expanding `cfg_attr`, but this is an unavoidable consequence of the syntax of `cfg_attr` - the user does not supply the `#` and `[]` tokens that a `cfg_attr` expands to.
2020-10-19Small cleanups in assert!() and panic_fmt lint.Mara Bos-31/+29
(From the PR feedback.) Co-authored-by: Esteban Küber <esteban@kuber.com.ar>
2020-10-18Expand assert!(expr) to panic() function instead of panic!() macro.Mara Bos-26/+36
The panic message might contain braces which should never be interpreted as format placeholders, which panic!() will do in a future edition.
2020-10-15Replace target.target with target and target.ptr_width with target.pointer_widthest31-1/+1
Preparation for a subsequent change that replaces rustc_target::config::Config with its wrapped Target. On its own, this commit breaks the build. I don't like making build-breaking commits, but in this instance I believe that it makes review easier, as the "real" changes of this PR can be seen much more easily. Result of running: find compiler/ -type f -exec sed -i -e 's/target\.target\([)\.,; ]\)/target\1/g' {} \; find compiler/ -type f -exec sed -i -e 's/target\.target$/target/g' {} \; find compiler/ -type f -exec sed -i -e 's/target.ptr_width/target.pointer_width/g' {} \; ./x.py fmt
2020-10-13Rollup merge of #77831 - LingMan:use_std, r=jonas-schievinkYuki Okushi-23/+10
Use std methods on char instead of open coding them
2020-10-11Simplify using is_ascii_alphabetic and is_ascii_alphanumericLingMan-8/+2
2020-10-11Don't duplicate char::is_ascii_digitLingMan-15/+8
2020-10-11Remove unnecessary unsafe block around calls to discriminant_valueTomasz Miąsko-15/+16
Since 63793 the discriminant_value intrinsic is safe to call. Remove unnecessary unsafe block around calls to this intrinsic in built-in derive macros.
2020-10-07Auto merge of #77595 - petrochenkov:asmident, r=oli-obkbors-19/+19
builtin_macros: Fix use of interpolated identifiers in `asm!` Fixes https://github.com/rust-lang/rust/issues/77584
2020-10-06rustc_parse: Make `Parser::unexpected` public and use it in built-in macrosVadim Petrochenkov-4/+3
2020-10-06builtin_macros: Fix use of interpolated identifiers in `asm!`Vadim Petrochenkov-16/+17
2020-10-04Remove extra indirection in LitKind::ByteStrRobin Schoonover-3/+1