summary refs log tree commit diff
path: root/compiler/rustc_builtin_macros/src
AgeCommit message (Collapse)AuthorLines
2022-03-14Drop forget_guarantee, introduced only on masterMark Rousskov-4/+1
2022-03-14Downgrade `#[test]` on macro call to warningEsteban Kuber-8/+12
Follow up to #92959. Address #94508.
2022-02-18Rollup merge of #92959 - asquared31415:test-non-fn-help, r=estebankMatthias Krüger-6/+16
Add more info and suggestions to use of #[test] on invalid items This pr changes the diagnostics for using `#[test]` on an item that can't be used as a test to explain that the attribute has no meaningful effect on non-functions and suggests the use of `#[cfg(test)]` for conditional compilation instead. Example change: ```rs #[test] mod test {} ``` previously output ``` error: only functions may be used as tests --> src/lib.rs:2:1 | 2 | mod test {} | ^^^^^^^^^^^ ``` now outputs ``` error: the `#[test]` attribute may only be used on a non-associated function --> $DIR/test-on-not-fn.rs:3:1 | LL | #[test] | ^^^^^^^ LL | mod test {} | ----------- expected a non-associated function, found a module | = note: the `#[test]` macro causes a a function to be run on a test and has no effect on non-functions help: replace with conditional compilation to make the item only exist when tests are being run | LL | #[cfg(test)] | ~~~~~~~~~~~~ ```
2022-02-18Rollup merge of #92933 - bjorn3:no_bin_lib_mixing, r=estebankMatthias Krüger-5/+0
Deny mixing bin crate type with lib crate types The produced library would get a main shim too which conflicts with the main shim of the executable linking the library. ``` $ cat > main1.rs <<EOF fn main() {} pub fn bar() {} EOF $ cat > main2.rs <<EOF extern crate main1; fn main() { main1::bar(); } EOF $ rustc --crate-type bin --crate-type lib main1.rs $ rustc -L. main2.rs error: linking with `cc` failed: exit status: 1 [...] = note: /usr/bin/ld: /tmp/crate_bin_lib/libmain1.rlib(main1.main1.707747aa-cgu.0.rcgu.o): in function `main': main1.707747aa-cgu.0:(.text.main+0x0): multiple definition of `main'; main2.main2.02a148fe-cgu.0.rcgu.o:main2.02a148fe-cgu.0:(.text.main+0x0): first defined here collect2: error: ld returned 1 exit status ```
2022-02-17Rollup merge of #94011 - est31:let_else, r=lcnrMatthias Krüger-3/+2
Even more let_else adoptions Continuation of #89933, #91018, #91481, #93046, #93590.
2022-02-17Rollup merge of #94030 - ChayimFriedman2:issue-94010, r=petrochenkovMatthias Krüger-15/+15
Correctly mark the span of captured arguments in `format_args!()` It should not include the braces, or misspelling suggestions will be wrong. Fixes #94010.
2022-02-16Adopt let_else in even more placesest31-3/+2
2022-02-16Rollup merge of #92366 - jhpratt:derive-default-enum, r=Mark-SimulacrumMatthias Krüger-3/+0
Resolve concern of `derive_default_enum` This resolves the concern in favor of prohibiting multiple instances of the attribute. This is similar to non-helper attributes as introduced in #88681. ``@rustbot`` label +S-waiting-on-review +T-libs-api
2022-02-16Correctly mark the span of captured arguments in `format_args!()`Chayim Refael Friedman-15/+15
It should only include the identifier, or misspelling suggestions will be wrong.
2022-02-11Remove the alt_std_name optionbjorn3-2/+1
This option introduced in #15820 allows a custom crate to be imported in the place of std, but with the name std. I don't think there is any value to this. At most it is confusing users of a driver that uses this option. There are no users of this option on github. If anyone still needs it, they can emulate it injecting #![no_core] in addition to their own prelude.
2022-02-08Rollup merge of #91950 - estebank:point-at-type-of-non-allocator, ↵Matthias Krüger-10/+12
r=matthewjasper Point at type when a `static` `#[global_allocator]` doesn't `impl` `GlobalAlloc`
2022-02-08Rollup merge of #93672 - lcnr:const-param-defaults-xx, r=matthewjasperMatthias Krüger-1/+1
update comment wrt const param defaults after #93669 i looked through all other uses of `GenericParamKind::Const` again to detect if we missed the `default` there as well, but afaict we really only missed lifetime resolution '^^ at least i found an outdated comment :3
2022-02-07Rollup merge of #93416 - name1e5s:chore/remove_allow_fail, r=m-ou-seMara Bos-9/+0
remove `allow_fail` test flag close #93345
2022-02-07Rollup merge of #93394 - m-ou-se:fix-93378, r=estebankMara Bos-11/+24
Don't allow {} to refer to implicit captures in format_args. Fixes #93378
2022-02-07Auto merge of #93179 - Urgau:unreachable-2021, r=m-ou-se,oli-obkbors-6/+28
Fix invalid special casing of the unreachable! macro This pull-request fix an invalid special casing of the `unreachable!` macro in the same way the `panic!` macro was solved, by adding two new internal only macros `unreachable_2015` and `unreachable_2021` edition dependent and turn `unreachable!` into a built-in macro that do dispatching. This logic is stolen from the `panic!` macro. ~~This pull-request also adds an internal feature `format_args_capture_non_literal` that allows capturing arguments from formatted string that expanded from macros. The original RFC #2795 mentioned this as a future possibility. This feature is [required](https://github.com/rust-lang/rust/issues/92137#issuecomment-1018630522) because of concatenation that needs to be done inside the macro:~~ ```rust $crate::concat!("internal error: entered unreachable code: ", $fmt) ``` **In summary** the new behavior for the `unreachable!` macro with this pr is: Edition 2021: ```rust let x = 5; unreachable!("x is {x}"); ``` ``` internal error: entered unreachable code: x is 5 ``` Edition <= 2018: ```rust let x = 5; unreachable!("x is {x}"); ``` ``` internal error: entered unreachable code: x is {x} ``` Also note that the change in this PR are **insta-stable** and **breaking changes** but this a considered as being a [bug](https://github.com/rust-lang/rust/issues/92137#issuecomment-998441613). If someone could start a perf run and then a crater run this would be appreciated. Fixes https://github.com/rust-lang/rust/issues/92137
2022-02-05update commentlcnr-1/+1
2022-02-01add a rustc::query_stability lintlcnr-0/+1
2022-01-31Fix invalid special casing of the unreachable! macroLoïc BRANSTETT-6/+28
2022-01-31Rollup merge of #93461 - dtolnay:fmtyield, r=davidtwcoMatthias Krüger-4/+51
Accommodate yield points in the format_args expansion Fixes #93274. For the case `println!("{} {:?}", "", async {}.await)` in the issue, the expansion before: ```rust ::std::io::_print( ::core::fmt::Arguments::new_v1( &["", " ", "\n"], &[ ::core::fmt::ArgumentV1::new(&"", ::core::fmt::Display::fmt), ::core::fmt::ArgumentV1::new(&async {}.await, ::core::fmt::Debug::fmt), ], ), ); ``` After: ```rust ::std::io::_print( ::core::fmt::Arguments::new_v1( &["", " ", "\n"], &match (&"", &async {}.await) { _args => [ ::core::fmt::ArgumentV1::new(_args.0, ::core::fmt::Display::fmt), ::core::fmt::ArgumentV1::new(_args.1, ::core::fmt::Debug::fmt), ], }, ), ); ```
2022-01-31Auto merge of #90891 - nbdd0121:format, r=Mark-Simulacrumbors-4/+14
Create `core::fmt::ArgumentV1` with generics instead of fn pointer Split from (and prerequisite of) #90488, as this seems to have perf implication. `@rustbot` label: +T-libs
2022-01-30Mac callsDavid Tolnay-3/+5
2022-01-30Accommodate yield points in the format_args expansionDavid Tolnay-4/+49
2022-01-29Rename _args -> args in format_args expansionDavid Tolnay-3/+3
2022-01-29Create `core::fmt::ArgumentV1` with generics instead of fn pointerGary Guo-4/+14
2022-01-28remove allow_fail test flagyuhaixin.hx-9/+0
2022-01-28Don't allow {} to refer to implicit captures in format_args.Mara Bos-11/+24
2022-01-17add more info to invalid use of #[test] on invalid itemsasquared31415-6/+16
2022-01-17Fix comment about spans during borrowck per PR 91359 reviewDavid Tolnay-1/+1
2022-01-17Replace confusing is_sorted_by in format_args implementationDavid Tolnay-13/+16
2022-01-17Emit simpler code from format_argsDavid Tolnay-61/+76
2022-01-17Auto merge of #92816 - tmiasko:rm-llvm-asm, r=Amanieubors-314/+0
Remove deprecated LLVM-style inline assembly The `llvm_asm!` was deprecated back in #87590 1.56.0, with intention to remove it once `asm!` was stabilized, which already happened in #91728 1.59.0. Now it is time to remove `llvm_asm!` to avoid continued maintenance cost. Closes #70173. Closes #92794. Closes #87612. Closes #82065. cc `@rust-lang/wg-inline-asm` r? `@Amanieu`
2022-01-15Deny mixing bin crate type with lib crate typesbjorn3-5/+0
The produced library would get a main shim too which conflicts with the main shim of the executable linking the library. ``` $ cat > main1.rs <<EOF fn main() {} pub fn bar() {} EOF $ cat > main2.rs <<EOF extern crate main1; fn main() { main1::bar(); } EOF $ rustc --crate-type bin --crate-type lib main1.rs $ rustc -L. main2.rs error: linking with `cc` failed: exit status: 1 [...] = note: /usr/bin/ld: /tmp/crate_bin_lib/libmain1.rlib(main1.main1.707747aa-cgu.0.rcgu.o): in function `main': main1.707747aa-cgu.0:(.text.main+0x0): multiple definition of `main'; main2.main2.02a148fe-cgu.0.rcgu.o:main2.02a148fe-cgu.0:(.text.main+0x0): first defined here collect2: error: ld returned 1 exit status ```
2022-01-12Remove deprecated LLVM-style inline assemblyTomasz Miąsko-314/+0
2022-01-10Update AsmArgs field visibility for rustfmtYacin Tmimi-4/+4
To more easily allow rustfmt to format the asm! macro as specified in rust-dev-tools/fmt-rfcs#152 certain fields are made public.
2022-01-02Auto merge of #92066 - Smittyvb:concat_bytes-repeat, r=nagisabors-40/+65
Support [x; n] expressions in concat_bytes! Currently trying to use `concat_bytes!` with a repeating array value like `[42; 5]` results in an error: ``` error: expected a byte literal --> src/main.rs:3:27 | 3 | let x = concat_bytes!([3; 4]); | ^^^^^^ | = note: only byte literals (like `b"foo"`, `b's'`, and `[3, 4, 5]`) can be passed to `concat_bytes!()` ``` This makes it so repeating array syntax can be used the same way normal arrays can be. The RFC doesn't explicitly mention repeat expressions, but it seems reasonable to allow them as well, since normal arrays are allowed. It is possible to make the compiler get stuck compiling forever with `concat_bytes!([3; 999999999])`, but I don't think that's much of an issue since you can do that already with `const X: [u8; 999999999] = [3; 999999999];`. Contributes to #87555.
2021-12-31update testsDavid Renshaw-3/+3
2021-12-31[rustc_builtin_macros] add indices to ↵David Renshaw-16/+12
format_foreign::printf::Substitution::Escape
2021-12-28Remove FIXMEJacob Pratt-3/+0
This resolves the concern in favor of prohibiting multiple instances of the attribute. This is similar to non-helper attributes as introduced in #88681.
2021-12-27Clarify that repeat count must be positiveSmitty-1/+1
2021-12-21rustc_builtin_macros: make asm mod public for rustfmtCaleb Cartwright-3/+3
2021-12-19Auto merge of #91957 - nnethercote:rm-SymbolStr, r=oli-obkbors-7/+7
Remove `SymbolStr` This was originally proposed in https://github.com/rust-lang/rust/pull/74554#discussion_r466203544. As well as removing the icky `SymbolStr` type, it allows the removal of a lot of `&` and `*` occurrences. Best reviewed one commit at a time. r? `@oli-obk`
2021-12-18Support [x; n] expressions in concat_bytes!Smitty-40/+65
Contributes to #87555.
2021-12-18Rollup merge of #92016 - calebcartwright:expose-asm-args-parsing, r=AmanieuMatthias Krüger-29/+43
builtin_macros: allow external consumers for AsmArgs parsing As discussed in Zulip (https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/parsing.20of.20AsmArgs.20for.20inline.20assembly), we need a function entry point that rustfmt can leverage from a pre-expansion context to get a more structured representation of the asm args without having to duplicate/maintain the token stream parsing r? ```@Amanieu``` and/or ```@joshtriplett```
2021-12-16builtin_macros: allow external consumers for AsmArgs parsingCaleb Cartwright-29/+43
2021-12-16Rollup merge of #91172 - Ethiraric:ethiraric/fix90979, r=petrochenkovMatthias Krüger-4/+39
Warn when a `#[test]`-like built-in attribute macro is present multiple times. Fixes #90979.
2021-12-15Add a lint for duplicated attributes.Ethiraric-4/+39
2021-12-15Remove unnecessary sigils around `Symbol::as_str()` calls.Nicholas Nethercote-7/+7
2021-12-15Point at type when a `static` `#[global_allocator]` doesn't `impl` `GlobalAlloc`Esteban Kuber-10/+12
2021-12-15Rollup merge of #91881 - Patrick-Poitras:stabilize-iter-zip, r=scottmcmMatthias Krüger-1/+0
Stabilize `iter::zip` Hello all! As the tracking issue (#83574) for `iter::zip` completed the final commenting period without any concerns being raised, I hereby submit this stabilization PR on the issue. As the pull request that introduced the feature (#82917) states, the `iter::zip` function is a shorter way to zip two iterators. As it's generally a quality-of-life/ergonomic improvement, it has been integrated into the codebase without any trouble, and has been used in many places across the rust compiler and standard library since March without any issues. For more details, I would refer to `@cuviper's` original PR, or the [function's documentation](https://doc.rust-lang.org/std/iter/fn.zip.html).
2021-12-14Stabilize iter::zip.PFPoitras-1/+0