about summary refs log tree commit diff
path: root/compiler/rustc_middle/src/ty
AgeCommit message (Collapse)AuthorLines
2024-12-11Rename projection_def_id to item_def_idMichael Goulet-1/+1
2024-12-10Implement projection and shim for AFIDTMichael Goulet-17/+116
2024-12-10Rollup merge of #134008 - jswrenn:unsafe-fields-copy, r=compiler-errorsLeón Orell Valerian Liehr-5/+10
Make `Copy` unsafe to implement for ADTs with `unsafe` fields As a rule, the application of `unsafe` to a declaration requires that use-sites of that declaration also entail `unsafe`. For example, a field declared `unsafe` may only be read in the lexical context of an `unsafe` block. For nearly all safe traits, the safety obligations of fields are explicitly discharged when they are mentioned in method definitions. For example, idiomatically implementing `Clone` (a safe trait) for a type with unsafe fields will require `unsafe` to clone those fields. Prior to this commit, `Copy` violated this rule. The trait is marked safe, and although it has no explicit methods, its implementation permits reads of `Self`. This commit resolves this by making `Copy` conditionally safe to implement. It remains safe to implement for ADTs without unsafe fields, but unsafe to implement for ADTs with unsafe fields. Tracking: #132922 r? ```@compiler-errors```
2024-12-10Auto merge of #134096 - fmease:rollup-0asgoo8, r=fmeasebors-1/+1
Rollup of 9 pull requests Successful merges: - #133996 (Move most tests for `-l` and `#[link(..)]` into `tests/ui/link-native-libs`) - #134012 (Grammar fixes) - #134032 (docs: better examples for `std::ops::ControlFlow`) - #134040 (bootstrap: print{ln}! -> eprint{ln}! (take 2)) - #134043 (Add test to check unicode identifier version) - #134053 (rustdoc: rename `issue-\d+.rs` tests to have meaningful names (part 10)) - #134055 (interpret: clean up deduplicating allocation functions) - #134073 (dataflow_const_prop: do not eval a ptr address in SwitchInt) - #134084 (Fix typo in RFC mention 3598 -> 3593) r? `@ghost` `@rustbot` modify labels: rollup
2024-12-09review comments: rewordingsEsteban Küber-2/+2
2024-12-09Introduce `default_field_values` featureEsteban Küber-5/+6
Initial implementation of `#[feature(default_field_values]`, proposed in https://github.com/rust-lang/rfcs/pull/3681. Support default fields in enum struct variant Allow default values in an enum struct variant definition: ```rust pub enum Bar { Foo { bar: S = S, baz: i32 = 42 + 3, } } ``` Allow using `..` without a base on an enum struct variant ```rust Bar::Foo { .. } ``` `#[derive(Default)]` doesn't account for these as it is still gating `#[default]` only being allowed on unit variants. Support `#[derive(Default)]` on enum struct variants with all defaulted fields ```rust pub enum Bar { #[default] Foo { bar: S = S, baz: i32 = 42 + 3, } } ``` Check for missing fields in typeck instead of mir_build. Expand test with `const` param case (needs `generic_const_exprs` enabled). Properly instantiate MIR const The following works: ```rust struct S<A> { a: Vec<A> = Vec::new(), } S::<i32> { .. } ``` Add lint for default fields that will always fail const-eval We *allow* this to happen for API writers that might want to rely on users' getting a compile error when using the default field, different to the error that they would get when the field isn't default. We could change this to *always* error instead of being a lint, if we wanted. This will *not* catch errors for partially evaluated consts, like when the expression relies on a const parameter. Suggestions when encountering `Foo { .. }` without `#[feature(default_field_values)]`: - Suggest adding a base expression if there are missing fields. - Suggest enabling the feature if all the missing fields have optional values. - Suggest removing `..` if there are no missing fields.
2024-12-09interpret: clean up deduplicating allocation functionsRalf Jung-1/+1
2024-12-07Tweak wordingEsteban Küber-5/+5
2024-12-07Do not talk about "trait `<Foo = Bar>`"Esteban Küber-2/+4
Pass in an appropriate `Option<DefId>` in more cases from hir ty lowering.
2024-12-07Account for `impl Trait` in "add bound" suggestion messageEsteban Küber-0/+6
2024-12-07Mention type parameter in more cases and don't suggest ~const bound already ↵Esteban Küber-16/+9
there
2024-12-07Use trait name instead of full constraint in suggestion messageEsteban Küber-23/+61
``` help: consider restricting type parameter `T` with traits `Copy` and `Trait` | LL | fn duplicate_custom<T: Copy + Trait>(t: S<T>) -> (S<T>, S<T>) { | ++++++++++++++ ``` ``` help: consider restricting type parameter `V` with trait `Copy` | LL | fn index<'a, K, V: std::marker::Copy>(map: &'a HashMap<K, V>, k: K) -> &'a V { | +++++++++++++++++++ ```
2024-12-07Add test for lack of suggestion in stableEsteban Küber-2/+2
This test will break when `Step` gets stabilized, but punt until then.
2024-12-07reword trait bound suggestion message to include the boundsEsteban Küber-14/+31
2024-12-07Don't suggest restricting bound with unstable traits on stableEsteban Küber-8/+24
On nightly, we mention the trait is unstable ``` error[E0277]: the trait bound `T: Unstable` is not satisfied --> $DIR/unstable-trait-suggestion.rs:13:9 | LL | foo(t) | --- ^ the trait `Unstable` is not implemented for `T` | | | required by a bound introduced by this call | note: required by a bound in `foo` --> $DIR/unstable-trait-suggestion.rs:9:11 | LL | fn foo<T: Unstable>(_: T) {} | ^^^^^^^^ required by this bound in `foo` help: consider restricting type parameter `T` but it is an `unstable` trait | LL | pub fn demo<T: Unstable>(t: T) { | ++++++++++ ``` On stable, we don't suggest the trait at all ``` error[E0277]: the trait bound `T: Unstable` is not satisfied --> $DIR/unstable-trait-suggestion.rs:13:9 | LL | foo(t) | --- ^ the trait `Unstable` is not implemented for `T` | | | required by a bound introduced by this call | note: required by a bound in `foo` --> $DIR/unstable-trait-suggestion.rs:9:11 | LL | fn foo<T: Unstable>(_: T) {} | ^^^^^^^^ required by this bound in `foo` ```
2024-12-07Make `Copy` unsafe to implement for ADTs with `unsafe` fieldsJack Wrenn-5/+10
As a rule, the application of `unsafe` to a declaration requires that use-sites of that declaration also require `unsafe`. For example, a field declared `unsafe` may only be read in the lexical context of an `unsafe` block. For nearly all safe traits, the safety obligations of fields are explicitly discharged when they are mentioned in method definitions. For example, idiomatically implementing `Clone` (a safe trait) for a type with unsafe fields will require `unsafe` to clone those fields. Prior to this commit, `Copy` violated this rule. The trait is marked safe, and although it has no explicit methods, its implementation permits reads of `Self`. This commit resolves this by making `Copy` conditionally safe to implement. It remains safe to implement for ADTs without unsafe fields, but unsafe to implement for ADTs with unsafe fields. Tracking: #132922
2024-12-07Auto merge of #133978 - matthiaskrgr:rollup-6gh1iho, r=matthiaskrgrbors-0/+12
Rollup of 7 pull requests Successful merges: - #130209 (Stabilize `std::io::ErrorKind::CrossesDevices`) - #130254 (Stabilize `std::io::ErrorKind::QuotaExceeded`) - #132187 (Add Extend impls for tuples of arity 1 through 12) - #133875 (handle `--json-output` properly) - #133934 (Do not implement unsafe auto traits for types with unsafe fields) - #133954 (Hide errors whose suggestions would contain error constants or types) - #133960 (rustdoc: remove eq for clean::Attributes) r? `@ghost` `@rustbot` modify labels: rollup
2024-12-06Remove polymorphizationBen Kimock-114/+3
2024-12-06Rollup merge of #133934 - jswrenn:unsafe-fields-auto-traits, r=compiler-errorsMatthias Krüger-0/+12
Do not implement unsafe auto traits for types with unsafe fields If a type has unsafe fields, its safety invariants are not simply the conjunction of its field types' safety invariants. Consequently, it's invalid to reason about the safety properties of these types in a purely structural manner — i.e., the manner in which `auto` traits are implemented. Consequently, auto implementations of unsafe auto traits should not be generated for types with unsafe fields. Tracking: #132922 r? `@compiler-errors`
2024-12-06Rollup merge of #130777 - azhogin:azhogin/reg-struct-return, r=workingjubileeMatthias Krüger-1/+4
rust_for_linux: -Zreg-struct-return commandline flag for X86 (#116973) Command line flag `-Zreg-struct-return` for X86 (32-bit) for rust-for-linux. This flag enables the same behavior as the `abi_return_struct_as_int` target spec key. - Tracking issue: https://github.com/rust-lang/rust/issues/116973
2024-12-05do not implement unsafe auto traits for types with unsafe fieldsJack Wrenn-0/+12
If a type has unsafe fields, its safety invariants are not simply the conjunction of its field types' safety invariants. Consequently, it's invalid to reason about the safety properties of these types in a purely structural manner — i.e., the manner in which `auto` traits are implemented. Makes progress towards #132922.
2024-12-02Rollup merge of #133610 - camelid:move-from_anon_const, r=BoxyUwUGuillaume Gomez-82/+2
Move `Const::{from_anon_const,try_from_lit}` to hir_ty_lowering Fixes #128176. This accomplishes one of the followup items from #131081. These operations are much more about lowering the HIR than about `Const`s themselves. They fit better in hir_ty_lowering with `lower_const_arg` (formerly `Const::from_const_arg`) and the rest. To accomplish this, `const_evaluatable_predicates_of` had to be changed to not use `from_anon_const` anymore. Instead of visiting the HIR and lowering anon consts on the fly, it now visits the `rustc_middle::ty` data structures instead and directly looks for `UnevaluatedConst`s. This approach was proposed in: https://github.com/rust-lang/rust/pull/131081#discussion_r1821189257 r? `@BoxyUwU`
2024-12-02Move `Const::{from_anon_const,try_from_lit}` to hir_ty_loweringNoah Lev-82/+2
These operations are much more about lowering the HIR than about `Const`s themselves. They fit better in hir_ty_lowering with `lower_const_arg` (formerly `Const::from_const_arg`) and the rest. To accomplish this, `const_evaluatable_predicates_of` had to be changed to not use `from_anon_const` anymore. Instead of visiting the HIR and lowering anon consts on the fly, it now visits the `rustc_middle::ty` data structures instead and directly looks for `UnevaluatedConst`s. This approach was proposed in: https://github.com/rust-lang/rust/pull/131081#discussion_r1821189257
2024-12-02remove `Ty::is_copy_modulo_regions`lcnr-15/+18
2024-12-02rust_for_linux: -Zreg-struct-return commandline flag for X86 (#116973)Andrew Zhogin-1/+4
2024-11-29Rollup merge of #133501 - lcnr:post-borrowck-analysis, r=compiler-errorsMatthias Krüger-82/+4
support revealing defined opaque post borrowck By adding a new `TypingMode::PostBorrowckAnalysis`. Currently only supported with the new solver and I didn't look into the way we replace `ReErased`. ``@compiler-errors`` mentioned that always using existentials may be unsound. r? ``@compiler-errors``
2024-11-28Auto merge of #123244 - Mark-Simulacrum:share-inline-never-generics, r=saethlinbors-9/+11
Enable -Zshare-generics for inline(never) functions This avoids inlining cross-crate generic items when possible that are already marked inline(never), implying that the author is not intending for the function to be inlined by callers. As such, having a local copy may make it easier for LLVM to optimize but mostly just adds to binary bloat and codegen time. In practice our benchmarks indicate this is indeed a win for larger compilations, where the extra cost in dynamic linking to these symbols is diminished compared to the advantages in fewer copies that need optimizing in each binary. It might also make sense it expand this with other heuristics (e.g., `#[cold]`) in the future, but this seems like a good starting point. FWIW, I expect that doing cleanup in where we make the decision what should/shouldn't be shared is also a good idea. Way too much code needed to be tweaked to check this. But I'm hoping to leave that for a follow-up PR rather than blocking this on it.
2024-11-28Share inline(never) generics across cratesMark Rousskov-9/+11
This reduces code sizes and better respects programmer intent when marking inline(never). Previously such a marking was essentially ignored for generic functions, as we'd still inline them in remote crates.
2024-11-28uplift fold_regions to rustc_type_irlcnr-82/+4
2024-11-27Rollup merge of #132410 - bjorn3:yet_another_driver_refactor_round, r=cjgillotMatthias Krüger-2/+11
Some more refactorings towards removing driver queries Follow up to https://github.com/rust-lang/rust/pull/127184 ## Custom driver breaking change The `after_analysis` callback is changed to accept `TyCtxt` instead of `Queries`. The only safe query in `Queries` to call at this point is `global_ctxt()` which allows you to enter the `TyCtxt` either way. To fix your custom driver, replace the `queries: &'tcx Queries<'tcx>` argument with `tcx: TyCtxt<'tcx>` and remove your `queries.global_ctxt().unwrap().enter(|tcx| { ... })` call and only keep the contents of the closure. ## Custom driver deprecation The `after_crate_root_parsing` callback is now deprecated. Several custom drivers are incorrectly calling `queries.global_ctxt()` from inside of it, which causes some driver code to be skipped. As such I would like to either remove it in the future or if custom drivers still need it, change it to accept an `&rustc_ast::Crate` instead.
2024-11-26Rollup merge of #115293 - cjgillot:no-fuel, r=wesleywiser,DianQKMichael Goulet-8/+1
Remove -Zfuel. I'm not sure this feature is used. I only found 2 references in a google search, both referring to its introduction. Meanwhile, it's a global mutable state, untracked by incremental compilation, so incompatible with it.
2024-11-26Rollup merge of #133367 - compiler-errors:array-len-mismatch, r=BoxyUwUMichael Goulet-10/+3
Simplify array length mismatch error reporting (to not try to turn consts into target usizes) This changes `TypeError::FixedArrayLen` to use `ExpectedFound<ty::Const<'tcx>>` (instead of `ExpectedFound<u64>`), and renames it to `TypeError::ArrayLen`. This allows us to avoid a `try_to_target_usize` call in the type relation, which ICEs when we have a scalar of the wrong bit length (i.e. u8). This also makes `structurally_relate_tys` to always use this type error kind any time we have a const mismatch resulting from relating the array-len part of `[T; N]`. This has the effect of changing the error message we issue for array length mismatches involving non-valtree consts. I actually quite like the change, though, since before: ``` LL | fn test<const N: usize, const M: usize>() -> [u8; M] { | ------- expected `[u8; M]` because of return type LL | [0; N] | ^^^^^^ expected `M`, found `N` | = note: expected array `[u8; M]` found array `[u8; N]` ``` and after, which I think is far less verbose: ``` LL | fn test<const N: usize, const M: usize>() -> [u8; M] { | ------- expected `[u8; M]` because of return type LL | [0; N] | ^^^^^^ expected an array with a size of M, found one with a size of N ``` The only questions I have are: 1. Should we do something about backticks here? Right now we don't backtick either fully evaluated consts like `2`, or rigid consts like `Foo::BAR`.... but maybe we should? It seems kinda verbose to do for numbers -- maybe we could intercept those specifically. 2. I guess we may still run the risk of leaking unevaluated consts into error reporting like `2 + 1`...? r? ``@BoxyUwU`` Fixes #126359 Fixes #131101
2024-11-26Rollup merge of #133362 - compiler-errors:existential-preds, r=BoxyUwUMichael Goulet-4/+0
No need to re-sort existential preds in relate impl We already assert that these predicates are in the right ordering in `mk_poly_existential_predicates`. r? types
2024-11-26Remove -Zfuel.Camille GILLOT-8/+1
2024-11-25Refactor `where` predicates, and reserve for attributes supportFrank King-2/+2
2024-11-24Rollup merge of #133371 - RalfJung:is_trivially_const_drop, r=compiler-errorsMatthias Krüger-39/+0
remove is_trivially_const_drop I'm not sure this still brings any perf benefits, so let's benchmark this. r? `@compiler-errors`
2024-11-24Simplify array length mismatch error reportingMichael Goulet-10/+3
2024-11-23Auto merge of #133242 - lcnr:questionable-uwu, r=compiler-errors,BoxyUwUbors-128/+36
finish `Reveal` removal After #133212 changed the `TypingMode` to be the only source of truth, this entirely rips out `Reveal`. cc #132279 r? `@compiler-errors`
2024-11-23global old solver cache: use `TypingEnv`lcnr-2/+2
2024-11-23remove remaining references to `Reveal`lcnr-6/+6
2024-11-23no more Reveal :(lcnr-120/+28
2024-11-23Rollup merge of #133366 - compiler-errors:expected-found, r=dtolnay许杰友 Jieyou Xu (Joe)-2/+2
Remove unnecessary bool from `ExpectedFound::new` It's true almost everywhere, and the one place it's not can be replaced w/ an if statement.
2024-11-23Auto merge of #132915 - veluca93:unsafe-fields, r=jswrennbors-5/+13
Implement the unsafe-fields RFC. RFC: rust-lang/rfcs#3458 Tracking: - https://github.com/rust-lang/rust/issues/132922 r? jswrenn
2024-11-23remove is_trivially_const_dropRalf Jung-39/+0
2024-11-23Remove unnecessary bool from ExpectedFoundMichael Goulet-2/+2
2024-11-23Auto merge of #133360 - compiler-errors:rollup-a2o38tq, r=compiler-errorsbors-118/+85
Rollup of 8 pull requests Successful merges: - #132090 (Stop being so bail-y in candidate assembly) - #132658 (Detect const in pattern with typo) - #132911 (Pretty print async fn sugar in opaques and trait bounds) - #133102 (aarch64 softfloat target: always pass floats in int registers) - #133159 (Don't allow `-Zunstable-options` to take a value ) - #133208 (generate-copyright: Now generates a library file too.) - #133215 (Fix missing submodule in `./x vendor`) - #133264 (implement OsString::truncate) r? `@ghost` `@rustbot` modify labels: rollup
2024-11-23No need to re-sort existential predsMichael Goulet-4/+0
2024-11-22Check drop is trivial before checking ty needs dropMichael Goulet-1/+4
2024-11-22Pretty print AsyncFn traits tooMichael Goulet-11/+23
2024-11-22Implement ~const Destruct in new solverMichael Goulet-4/+13