about summary refs log tree commit diff
path: root/compiler/rustc_builtin_macros/src
AgeCommit message (Collapse)AuthorLines
2023-09-24ConstParamTy: require EqRalf Jung-1/+1
2023-09-18Rollup merge of #115891 - RalfJung:structural-trait-derive, r=nnethercoteMatthias Krüger-114/+42
simplify inject_impl_of_structural_trait There's a comment at `inject_impl_of_structural_trait` saying we cannot use `TraitDef`, but that comment is outdated -- we *can* use `TraitDef` nowadays since it has the `skip_path_as_bound` flag. (The flag needed some fixing, though.)
2023-09-18simplify inject_impl_of_structural_traitRalf Jung-114/+42
2023-09-17Rollup merge of #115611 - lukas-code:format!("{r#ident}"), r=compiler-errorsDylan DPC-26/+46
add diagnostic for raw identifiers in format string Format strings don't support raw identifiers (e.g. `format!("{r#type}")`), but they do support keywords in the format string directly (e.g. `format!("{type}")`). This PR improves the error output when attempting to use a raw identifier in a format string and adds a machine-applicable suggestion to remove the `r#`. fixes https://github.com/rust-lang/rust/issues/115466
2023-09-16Fix invalid markdown codeblock labelGuillaume Gomez-6/+6
2023-09-14Auto merge of #115677 - matthewjasper:let-expr-recovery, r=b-naberbors-1/+1
Improve invalid let expression handling - Move all of the checks for valid let expression positions to parsing. - Add a field to ExprKind::Let in AST/HIR to mark whether it's in a valid location. - Suppress some later errors and MIR construction for invalid let expressions. - Fix a (drop) scope issue that was also responsible for #104172. Fixes #104172 Fixes #104868
2023-09-11Move let expression checking to parsingMatthew Jasper-1/+1
There was an incomplete version of the check in parsing and a second version in AST validation. This meant that some, but not all, invalid uses were allowed inside macros/disabled cfgs. It also means that later passes have a hard time knowing when the let expression is in a valid location, sometimes causing ICEs. - Add a field to ExprKind::Let in AST/HIR to mark whether it's in a valid location. - Suppress later errors and MIR construction for invalid let expressions.
2023-09-08Rename the feature, but not the attribute, to `coverage_attribute`Andy Caldwell-1/+1
2023-09-08Rework no_coverage to coverage(off)Andy Caldwell-5/+5
2023-09-06add diagnostic for raw identifiers in format stringLukas Markeffsky-26/+46
2023-08-27Load include_bytes! directly into an LrcBen Kimock-1/+1
2023-08-11rustc: Move `features` from `Session` to `GlobalCtxt`Vadim Petrochenkov-10/+18
Removes two pieces of mutable state. Follow up to #114622.
2023-08-11Auto merge of #114507 - sebastiantoh:issue-114235, r=jackh726bors-12/+28
Add suggestion to quote inlined format argument as string literal Fixes #114235
2023-08-06Generate better function argument names in global_allocator expansionDavid Tolnay-19/+14
2023-08-05Delete some useless casts from global_allocator expansionDavid Tolnay-14/+6
2023-08-05Add suggestion to quote inlined format argument as string literalSebastian Toh-12/+28
2023-08-04Rollup merge of #114434 - Nilstrieb:indexing-spans, r=est31Matthias Krüger-1/+1
Improve spans for indexing expressions fixes #114388 Indexing is similar to method calls in having an arbitrary left-hand-side and then something on the right, which is the main part of the expression. Method calls already have a span for that right part, but indexing does not. This means that long method chains that use indexing have really bad spans, especially when the indexing panics and that span in coverted into a panic location. This does the same thing as method calls for the AST and HIR, storing an extra span which is then put into the `fn_span` field in THIR. r? compiler-errors
2023-08-04Auto merge of #114414 - cjgillot:early-unnameable-test, r=petrochenkovbors-0/+22
Make test harness lint about unnnameable tests. Implementation of https://github.com/rust-lang/rust/pull/113734#discussion_r1283073418 About the options suggested in https://github.com/rust-lang/rust/issues/36629#issuecomment-404753945: adding this case to unused_attribute was just more complicated. I'll try to understand a bit more what you had in mind in https://github.com/rust-lang/rfcs/pull/2471#issuecomment-397241123 This was just simpler to do in a standalone PR. I'll remove the corresponding changes from https://github.com/rust-lang/rust/pull/113734 later. r? `@petrochenkov`
2023-08-04Improve spans for indexing expressionsNilstrieb-1/+1
Indexing is similar to method calls in having an arbitrary left-hand-side and then something on the right, which is the main part of the expression. Method calls already have a span for that right part, but indexing does not. This means that long method chains that use indexing have really bad spans, especially when the indexing panics and that span in coverted into a panic location. This does the same thing as method calls for the AST and HIR, storing an extra span which is then put into the `fn_span` field in THIR.
2023-08-03Make test harness lint about unnnameable tests.Camille GILLOT-0/+22
2023-08-03Remove `MacDelimiter`.Nicholas Nethercote-6/+9
It's the same as `Delimiter`, minus the `Invisible` variant. I'm generally in favour of using types to make impossible states unrepresentable, but this one feels very low-value, and the conversions between the two types are annoying and confusing. Look at the change in `src/tools/rustfmt/src/expr.rs` for an example: the old code converted from `MacDelimiter` to `Delimiter` and back again, for no good reason. This suggests the author was confused about the types.
2023-07-30inline format!() args up to and including rustc_middleMatthias Krüger-38/+31
2023-07-28Parse generic const itemsLeón Orell Valerian Liehr-0/+1
2023-07-25builtin_macros: raw str in diagnostic outputDavid Wood-44/+49
If a raw string was used in the `env!` invocation, then it should also be shown in the diagnostic messages as a raw string. Signed-off-by: David Wood <david@davidtw.co>
2023-07-24builtin_macros: expect raw strings tooDavid Wood-1/+1
`expr_to_string` allows raw strings through so this code should be expected to handle those. Signed-off-by: David Wood <david@davidtw.co>
2023-07-23fix couple of clippy findings:Matthias Krüger-1/+1
filter_map_identity iter_kv_map needless_question_mark redundant_at_rest_pattern filter_next derivable_impls
2023-07-16Add a comparison between match *self and intrinsics::unreachable()David Tolnay-2/+3
2023-07-16Generate safe stable code for derives on empty enumsDavid Tolnay-4/+13
Generate `match *self {}` instead of `unsafe { core::intrinsics::unreachable() }`. This is: 1. safe 2. stable for the benefit of everyone looking at these derived impls through `cargo expand`. Both expansions compile to the same code at all optimization levels (including `0`).
2023-07-16Auto merge of #113557 - Amanieu:no-builtins-prelude, r=petrochenkovbors-9/+18
Hide `compiler_builtins` in the prelude This crate is a private implementation detail. We only need to insert it into the crate graph for linking and should not expose any of its public API. Fixes #113533
2023-07-14Hide `compiler_builtins` in the preludeAmanieu d'Antras-9/+18
This crate is a private implementation detail. We only need to insert it into the crate graph for linking and should not expose any of its public API. Fixes #113533
2023-07-12Re-format let-else per rustfmt updateMark Rousskov-8/+14
2023-06-28fix typoHe1pa-3/+3
2023-06-25Migrate some rustc_builtin_macros to SessionDiagnosticHe1pa-32/+109
2023-06-24Auto merge of #112802 - lukas-code:fancy-bool, r=Nilstriebbors-64/+61
use ErrorGuaranteed instead of booleans in rustc_builtin_macros implements https://github.com/rust-lang/rust/pull/112366#discussion_r1233821873 No functional changes. Best reviewed with whitespace diff disabled. r? `@Nilstrieb`
2023-06-21Rollup merge of #112790 - WaffleLapkin:syntactically, r=NilstriebNilstrieb-0/+1
Syntactically accept `become` expressions (explicit tail calls experiment) This adds `ast::ExprKind::Become`, implements parsing and properly gates the feature. cc `@scottmcm`
2023-06-19use `ErrorGuaranteed` instead of booleansLukas Markeffsky-64/+61
2023-06-19Auto merge of #112366 - lukas-code:test, r=Nilstriebbors-24/+21
`#[test]` function signature verification improvements This PR contains two improvements to the expansion of the `#[test]` macro. The first one fixes https://github.com/rust-lang/rust/issues/112360 by correctly recovering item statements if the signature verification fails. The second one forbids non-lifetime generics on `#[test]` functions. These were previously allowed if the function returned `()`, but always caused an inference error: before: ```text error[E0282]: type annotations needed --> src/lib.rs:2:1 | 1 | #[test] | ------- in this procedural macro expansion 2 | fn foo<T>() {} | ^^^^^^^^^^^^^^ cannot infer type ``` after: ```text error: functions used as tests can not have any non-lifetime generic parameters --> src/lib.rs:2:1 | 2 | fn foo<T>() {} | ^^^^^^^^^^^^^^ ``` Also includes some basic tests for test function signature verification, because I couldn't find any (???) in the test suite.
2023-06-19Syntatically accept `become` expressionsMaybe Waffle-0/+1
2023-06-16fix ICE on specific malformed asm clobber_abiasquared31415-5/+1
2023-06-07Remove accidental commentclubby789-3/+0
2023-06-07Deny non-lifetime generics for test functions.Lukas Markeffsky-18/+15
Previously, these were allowed if the function returned `()`, but always led to an ambiguity error.
2023-06-06Fix ICE for nested test function with arguments.Lukas Markeffsky-6/+6
2023-05-29Auto merge of #111748 - nnethercote:Cow-DiagnosticMessage, r=WaffleLapkinbors-2/+2
Use `Cow` in `{D,Subd}iagnosticMessage`. Each of `{D,Subd}iagnosticMessage::{Str,Eager}` has a comment: ``` // FIXME(davidtwco): can a `Cow<'static, str>` be used here? ``` This commit answers that question in the affirmative. It's not the most compelling change ever, but it might be worth merging. This requires changing the `impl<'a> From<&'a str>` impls to `impl From<&'static str>`, which involves a bunch of knock-on changes that require/result in call sites being a little more precise about exactly what kind of string they use to create errors, and not just `&str`. This will result in fewer unnecessary allocations, though this will not have any notable perf effects given that these are error paths. Note that I was lazy within Clippy, using `to_string` in a few places to preserve the existing string imprecision. I could have used `impl Into<{D,Subd}iagnosticMessage>` in various places as is done in the compiler, but that would have required changes to *many* call sites (mostly changing `&format("...")` to `format!("...")`) which didn't seem worthwhile. r? `@WaffleLapkin`
2023-05-29Auto merge of #111963 - nnethercote:inline-derived-hash, r=lqdbors-19/+12
Inline derived `hash` Because most of the other derived functions are inlined: `clone`, `default`, `eq`, `partial_cmp`, `cmp`. The exception is `fmt`, but it tends to not be on hot paths as much. r? `@ghost`
2023-05-29Use `Cow` in `{D,Subd}iagnosticMessage`.Nicholas Nethercote-2/+2
Each of `{D,Subd}iagnosticMessage::{Str,Eager}` has a comment: ``` // FIXME(davidtwco): can a `Cow<'static, str>` be used here? ``` This commit answers that question in the affirmative. It's not the most compelling change ever, but it might be worth merging. This requires changing the `impl<'a> From<&'a str>` impls to `impl From<&'static str>`, which involves a bunch of knock-on changes that require/result in call sites being a little more precise about exactly what kind of string they use to create errors, and not just `&str`. This will result in fewer unnecessary allocations, though this will not have any notable perf effects given that these are error paths. Note that I was lazy within Clippy, using `to_string` in a few places to preserve the existing string imprecision. I could have used `impl Into<{D,Subd}iagnosticMessage>` in various places as is done in the compiler, but that would have required changes to *many* call sites (mostly changing `&format("...")` to `format!("...")`) which didn't seem worthwhile.
2023-05-27Auto merge of #111928 - c410-f3r:dqewdas, r=eholkbors-5/+11
[RFC-2011] Expand more expressions cc #44838 Expands `if`, `let`, `match` and also makes `generic_assert_internals` an allowed feature when using `assert!`. `#![feature(generic_assert)]` is still needed to activate everything. ```rust #![feature(generic_assert)] fn fun(a: Option<i32>, b: Option<i32>, c: Option<i32>) { assert!( if a.is_some() { 1 } else { 2 } == 3 && if let Some(elem) = b { elem == 4 } else { false } && match c { Some(_) => true, None => false } ); } fn main() { fun(Some(1), None, Some(2)); } // Assertion failed: assert!( // if a.is_some() { 1 } else { 2 } == 3 // && if let Some(elem) = b { elem == 4 } else { false } // && match c { Some(_) => true, None => false } // ); // // With captures: // a = Some(1) // b = None // c = Some(2) ```
2023-05-26Avoid some unnecessary local `attr` variables.Nicholas Nethercote-19/+11
2023-05-26Inline derived `hash` function.Nicholas Nethercote-2/+3
Because most of the other derived functions are inlined: `clone`, `default`, `eq`, `partial_cmp`, `cmp`. The exception is `fmt`, but it tends to not be on hot paths as much.
2023-05-25Auto merge of #86844 - bjorn3:global_alloc_improvements, r=pnkfelixbors-5/+3
Support #[global_allocator] without the allocator shim This makes it possible to use liballoc/libstd in combination with `--emit obj` if you use `#[global_allocator]`. This is what rust-for-linux uses right now and systemd may use in the future. Currently they have to depend on the exact implementation of the allocator shim to create one themself as `--emit obj` doesn't create an allocator shim. Note that currently the allocator shim also defines the oom error handler, which is normally required too. Once `#![feature(default_alloc_error_handler)]` becomes the only option, this can be avoided. In addition when using only fallible allocator methods and either `--cfg no_global_oom_handling` for liballoc (like rust-for-linux) or `--gc-sections` no references to the oom error handler will exist. To avoid this feature being insta-stable, you will have to define `__rust_no_alloc_shim_is_unstable` to avoid linker errors. (Labeling this with both T-compiler and T-lang as it originally involved both an implementation detail and had an insta-stable user facing change. As noted above, the `__rust_no_alloc_shim_is_unstable` symbol requirement should prevent unintended dependence on this unstable feature.)
2023-05-24[RFC-2011] Expand more expressionsCaio-5/+11