summary refs log tree commit diff
path: root/compiler/rustc_passes/src
AgeCommit message (Collapse)AuthorLines
2023-10-20Make `#[repr(Rust)]` and `#[repr(C)]` incompatible with one anotherLeón Orell Valerian Liehr-4/+18
(cherry picked from commit d0b99e3efe62b5acc107da9c84331eae6cbe5a0d)
2023-09-27Auto merge of #116163 - compiler-errors:lazyness, r=oli-obkbors-4/+4
Don't store lazyness in `DefKind::TyAlias` 1. Don't store lazyness of a type alias in its `DefKind`, but instead via a query. 2. This allows us to treat type aliases as lazy if `#[feature(lazy_type_alias)]` *OR* if the alias contains a TAIT, rather than having checks for both in separate parts of the codebase. r? `@oli-obk` cc `@fmease`
2023-09-26Rollup merge of #116162 - fmease:gate-n-validate-rustc_safe_intrinsic, ↵Matthias Krüger-0/+35
r=Nilstrieb Gate and validate `#[rustc_safe_intrinsic]` Copied over from #116159: > This was added as ungated in https://github.com/rust-lang/rust/pull/100719/files#diff-09c366d3ad3ec9a42125253b610ca83cad6b156aa2a723f6c7e83eddef7b1e8fR502, probably because the author looked at the surrounding attributes, which are ungated because they are gated specially behind the staged_api feature. > > I don't think we need to crater this, the attribute is entirely useless without the intrinsics feature, which is already unstable.. r? ``@Nilstrieb``
2023-09-26Don't store lazyness in DefKindMichael Goulet-4/+4
2023-09-25Gate and validate #[rustc_safe_intrinsic]León Orell Valerian Liehr-0/+35
2023-09-22Allow higher-ranked fn sigs in ValuePairsMichael Goulet-1/+4
2023-09-22Auto merge of #114776 - fee1-dead-contrib:enable-effects-in-libcore, r=oli-obkbors-2/+10
Enable effects for libcore ~~r? `@oli-obk~~` forgot you are on vacation, oops
2023-09-22Auto merge of #115910 - eduardosm:lang-fns-target-features, r=cjgillotbors-3/+39
Prevent using `#[target_feature]` on lang item functions Fixes https://github.com/rust-lang/rust/issues/109411 and also prevents from using `#[target_feature]` on other `fn` lang items to mitigate the concerns from https://github.com/rust-lang/rust/issues/109411#issuecomment-1477030273.
2023-09-21Prevent promotion of const fn calls in inline constsOli Scherer-2/+2
2023-09-20fix bugs with effects fallbackDeadbeef-2/+10
2023-09-18Prevent using `#[target_feature]` on lang item functionsEduardo Sánchez Muñoz-3/+39
2023-09-17Auto merge of #114452 - weiznich:feature/diagnostic_on_unimplemented, ↵bors-1/+21
r=compiler-errors `#[diagnostic::on_unimplemented]` without filters This commit adds support for a `#[diagnostic::on_unimplemented]` attribute with the following options: * `message` to customize the primary error message * `note` to add a customized note message to an error message * `label` to customize the label part of the error message The relevant behavior is specified in [RFC-3366](https://rust-lang.github.io/rfcs/3366-diagnostic-attribute-namespace.html)
2023-09-16Auto merge of #114494 - est31:extend_useless_ptr_null_checks, r=jackh726bors-0/+3
Make useless_ptr_null_checks smarter about some std functions This teaches the `useless_ptr_null_checks` lint that some std functions can't ever return null pointers, because they need to point to valid data, get references as input, etc. This is achieved by introducing an `#[rustc_never_returns_null_ptr]` attribute and adding it to these std functions (gated behind bootstrap `cfg_attr`). Later on, the attribute could maybe be used to tell LLVM that the returned pointer is never null. I don't expect much impact of that though, as the functions are pretty shallow and usually the input data is already never null. Follow-up of PR #113657 Fixes #114442
2023-09-14Auto merge of #114656 - bossmc:rework-no-coverage-attr, r=oli-obkbors-22/+16
Rework `no_coverage` to `coverage(off)` As discussed at the tail of https://github.com/rust-lang/rust/issues/84605 this replaces the `no_coverage` attribute with a `coverage` attribute that takes sub-parameters (currently `off` and `on`) to control the coverage instrumentation. Allows future-proofing for things like `coverage(off, reason="Tested live", issue="#12345")` or similar.
2023-09-12`#[diagnostic::on_unimplemented]` without filtersGeorg Semmler-1/+21
This commit adds support for a `#[diagnostic::on_unimplemented]` attribute with the following options: * `message` to customize the primary error message * `note` to add a customized note message to an error message * `label` to customize the label part of the error message Co-authored-by: León Orell Valerian Liehr <me@fmease.dev> Co-authored-by: Michael Goulet <michael@errs.io>
2023-09-11Disentangle `Debug` and `Display` for `Ty`.Nicholas Nethercote-1/+3
The `Debug` impl for `Ty` just calls the `Display` impl for `Ty`. This is surprising and annoying. In particular, it means `Debug` doesn't show as much information as `Debug` for `TyKind` does. And `Debug` is used in some user-facing error messages, which seems bad. This commit changes the `Debug` impl for `Ty` to call the `Debug` impl for `TyKind`. It also does a number of follow-up changes to preserve existing output, many of which involve inserting `with_no_trimmed_paths!` calls. It also adds `Display` impls for `UserType` and `Canonical`. Some tests have changes to expected output: - Those that use the `rustc_abi(debug)` attribute. - Those that use the `EMIT_MIR` annotation. In each case the output is slightly uglier than before. This isn't ideal, but it's pretty weird (particularly for the attribute) that the output is using `Debug` in the first place. They're fairly obscure attributes (I hadn't heard of them) so I'm not worried by this. For `async-is-unwindsafe.stderr`, there is one line that now lacks a full path. This is a consistency improvement, because all the other mentions of `Context` in this test lack a path.
2023-09-10Encode only MIR that can be used by other cratesTomasz Miąsko-0/+4
Only reachable items might participate in the code generation in the downstream crates. Omit redundant optimized MIR of unreachable items from a crate metadata. Additionally, include reachable closures in reachable set, so that unreachable closures can be omitted on the same basis.
2023-09-09better spans for WF errorsRalf Jung-3/+8
2023-09-09use hir_crate_items(()).definitions() instead of hir().items()Ralf Jung-41/+18
2023-09-09rustc_layout, rustc_abi: make sure the types are well-formedRalf Jung-27/+47
2023-09-08Rework no_coverage to coverage(off)Andy Caldwell-22/+16
2023-09-08turns out Layout has some more things to worry about -- move ABI comparison ↵Ralf Jung-17/+3
into helper function like is_bool, and some special magic extra fields
2023-09-08also ensure that size and alignment are the sameRalf Jung-3/+7
2023-09-08accept some differences for rustc_abi(assert_eq), so that we can test more ↵Ralf Jung-3/+1
things to be compatible
2023-09-07add support for rustc_abi(assert_eq) and use it to test some ↵Ralf Jung-2/+85
repr(transparent) cases
2023-09-06rustc_layout/abi: error when attribute is applied to the wrong thingRalf Jung-32/+64
2023-09-06rustc_abi: also support debugging function pointersRalf Jung-37/+87
2023-08-27add rustc_abi debugging attributeRalf Jung-9/+113
2023-08-25Auto merge of #114201 - Centri3:explicit-repr-rust, r=WaffleLapkinbors-0/+1
Allow explicit `#[repr(Rust)]` This is identical to no `repr()` at all. For `Rust, packed` and `Rust, align(x)`, it should be the same as no `Rust` at all (as, afaik, `#[repr(align(16))]` uses the Rust ABI.) The main use case for this is being able to explicitly say "I want to use the Rust ABI" in very very rare circumstances where the first obvious choice would be the C ABI yet is undesirable, which is already possible with functions as `extern "Rust"`. This would be useful for silencing https://github.com/rust-lang/rust-clippy/pull/11253. It's also more consistent with `extern`. The lack of this also tripped me up a bit when I was new to Rust, as I expected this to be possible.
2023-08-24Auto merge of #115131 - frank-king:feature/unnamed-fields-lite, r=petrochenkovbors-0/+2
Parse unnamed fields and anonymous structs or unions (no-recovery) It is part of #114782 which implements #49804. Only parse anonymous structs or unions in struct field definition positions. r? `@petrochenkov`
2023-08-24Parse unnamed fields and anonymous structs or unionsFrank King-0/+2
Anonymous structs or unions are only allowed in struct field definitions. Co-authored-by: carbotaniuman <41451839+carbotaniuman@users.noreply.github.com>
2023-08-22Contents of reachable statics is reachableTomasz Miąsko-7/+3
2023-08-19remove redundant var rebindingsMatthias Krüger-2/+0
2023-08-15Rollup merge of #114819 - estebank:issue-78124, r=compiler-errorsMatthias Krüger-1/+1
Point at return type when it influences non-first `match` arm When encountering code like ```rust fn foo() -> i32 { match 0 { 1 => return 0, 2 => "", _ => 1, } } ``` Point at the return type and not at the prior arm, as that arm has type `!` which isn't influencing the arm corresponding to arm `2`. Fix #78124.
2023-08-15Rollup merge of #114772 - fee1-dead-contrib:typed-did, r=b-naberGuillaume Gomez-14/+14
Add `{Local}ModDefId` to more strongly type DefIds` Based on #110862 by `@Nilstrieb`
2023-08-14Move scrutinee `HirId` into `MatchSource::TryDesugar`Esteban Küber-1/+1
2023-08-14Use `{Local}ModDefId` in many queriesNilstrieb-14/+14
2023-08-13Remove reached_eof from ParseSessbjorn3-6/+0
It was only ever set in a function which isn't called anywhere.
2023-08-13Auto merge of #114723 - petrochenkov:noplugin2, r=davidtwcobors-1/+1
rustc: Move `features` from `Session` to `GlobalCtxt` Removes one more piece of mutable state. Follow up to #114622. The rule I used for passing feature in function signatures: - if a crate already depends on `rustc_middle`, then `Session` is replaced with `TyCtxt` - otherwise session and features are passed as a pair `sess: &Session, features: &Features` The code in `rustc_lint` is ultimately used for implementing a trait from `rustc_expand`, so it also doesn't use tcx despite the dependency on `rustc_middle`.
2023-08-12Auto merge of #114710 - Urgau:fix-expect-dead_code-114557, r=cjgillotbors-33/+93
Respect `#[expect]` the same way `#[allow]` is with the `dead_code` lint This PR makes the `#[expect]` attribute being respected in the same way the `#[allow]` attribute is with the `dead_code` lint. The fix is much more involved than I would have liked (and it's not because I didn't tried!), because the implementation took advantage of the fact that firing a lint in a allow context is a nop (for the user, as the lint is suppressed) to not fire-it at all. And will it's fine for `#[allow]`, it definitively isn't for `#[expect]`, as the presence and absence of the lint is significant. So a big part of the PR is just adding the context information of whenever an item is on the worklist because of an `[allow]`/`#[expect]` or not. Fixes https://github.com/rust-lang/rust/issues/114557
2023-08-11rustc: Move `features` from `Session` to `GlobalCtxt`Vadim Petrochenkov-1/+1
Removes two pieces of mutable state. Follow up to #114622.
2023-08-10Respect `#[expect]` the same way `#[allow]` is with the `dead_code` lintUrgau-33/+93
2023-08-09rustc: Move `crate_types` from `Session` to `GlobalCtxt`Vadim Petrochenkov-6/+6
Removes a piece of mutable state. Follow up to #114578.
2023-08-08Auto merge of #114545 - fee1-dead-contrib:lower-impl-effect, r=oli-obkbors-8/+2
correctly lower `impl const` to bind to host effect param r? `@oli-obk`
2023-08-08Rollup merge of #114566 - fmease:type-alias-laziness-is-crate-specific, ↵Matthias Krüger-3/+3
r=oli-obk Store the laziness of type aliases in their `DefKind` Previously, we would treat paths referring to type aliases as *lazy* type aliases if the current crate had lazy type aliases enabled independently of whether the crate which the alias was defined in had the feature enabled or not. With this PR, the laziness of a type alias depends on the crate it is defined in. This generally makes more sense to me especially if / once lazy type aliases become the default in a new edition and we need to think about *edition interoperability*: Consider the hypothetical case where the dependency crate has an older edition (and thus eager type aliases), it exports a type alias with bounds & a where-clause (which are void but technically valid), the dependent crate has the latest edition (and thus lazy type aliases) and it uses that type alias. Arguably, the bounds should *not* be checked since at any time, the dependency crate should be allowed to change the bounds at will with a *non*-major version bump & without negatively affecting downstream crates. As for the reverse case (dependency: lazy type aliases, dependent: eager type aliases), I guess it rules out anything from slight confusion to mild annoyance from upstream crate authors that would be caused by the compiler ignoring the bounds of their type aliases in downstream crates with older editions. --- This fixes #114468 since before, my assumption that the type alias associated with a given weak projection was lazy (and therefore had its variances computed) did not necessarily hold in cross-crate scenarios (which [I kinda had a hunch about](https://github.com/rust-lang/rust/pull/114253#discussion_r1278608099)) as outlined above. Now it does hold. `@rustbot` label F-lazy_type_alias r? `@oli-obk`
2023-08-07check_attrs: Warn when #[macro_export] is used on macros 2.0Arthur Cohen-0/+18
The compiler should emit a more specific error when the `#[macro_export]` attribute is present on a decl macro, instead of silently ignoring it. This commit adds the required error message in rustc_passes/messages.ftl, as well as a note. A new variant is added to the `errors::MacroExport` enum, specifically for the case where the attribute is added to a macro 2.0.
2023-08-07Store the laziness of type aliases in the DefKindLeón Orell Valerian Liehr-3/+3
2023-08-06lower impl const to bind to host effect paramDeadbeef-8/+2
2023-08-05Add #[rustc_never_returns_null_ptr]est31-0/+3
And look for it in the useless_ptr_null_checks lint
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.