about summary refs log tree commit diff
path: root/tests/ui/const-generics
AgeCommit message (Collapse)AuthorLines
2024-07-22On generic and lifetime removal suggestion, do not leave behind stray `,`Esteban Küber-5/+5
2024-07-22Change suggestion message wordingEsteban Küber-10/+10
2024-07-22Use verbose suggestion for "wrong # of generics"Esteban Küber-27/+56
2024-07-21Rollup merge of #128020 - compiler-errors:nlb-no-const, r=BoxyUwUJubilee-2/+9
Just totally fully deny late-bound consts Kinda don't care about supporting this until we have where clauses on binders. They're super busted and should be reworked in due time, and they are approximately 100% useless until then 😸 Fixes #127970 Fixes #127009 r? ``@BoxyUwU``
2024-07-21Auto merge of #127722 - BoxyUwU:new_adt_const_params_limitations, ↵bors-364/+818
r=compiler-errors Forbid borrows and unsized types from being used as the type of a const generic under `adt_const_params` Fixes #112219 Fixes #112124 Fixes #112125 ### Motivation Currently the `adt_const_params` feature allows writing `Foo<const N: [u8]>` this is entirely useless as it is not possible to write an expression which evaluates to a type that is not `Sized`. In order to actually use unsized types in const generics they are typically written as `const N: &[u8]` which *is* possible to provide a value of. Unfortunately allowing the types of const parameters to contain references is non trivial (#120961) as it introduces a number of difficult questions about how equality of references in the type system should behave. References in the types of const generics is largely only useful for using unsized types in const generics. This PR introduces a new feature gate `unsized_const_parameters` and moves support for `const N: [u8]` and `const N: &...` from `adt_const_params` into it. The goal here hopefully is to experiment with allowing `const N: [u8]` to work without references and then eventually completely forbid references in const generics. Splitting this out into a new feature gate means that stabilization of `adt_const_params` does not have to resolve #120961 which is the only remaining "big" blocker for the feature. Remaining issues after this are a few ICEs and naming bikeshed for `ConstParamTy`. ### Implementation The implementation is slightly subtle here as we would like to ensure that a stabilization of `adt_const_params` is forwards compatible with any outcome of `unsized_const_parameters`. This is inherently tricky as we do not support unstable trait implementations and we determine whether a type is valid as the type of a const parameter via a trait bound. There are a few constraints here: - We would like to *allow for the possibility* of adding a `Sized` supertrait to `ConstParamTy` in the event that we wind up opting to not support unsized types and instead requiring people to write the 'sized version', e.g. `const N: [u8; M]` instead of `const N: [u8]`. - Crates should be able to enable `unsized_const_parameters` and write trait implementations of `ConstParamTy` for `!Sized` types without downstream crates that only enable `adt_const_params` being able to observe this (required for std to be able to `impl<T> ConstParamTy for [T]` Ultimately the way this is accomplished is via having two traits (sad), `ConstParamTy` and `UnsizedConstParamTy`. Depending on whether `unsized_const_parameters` is enabled or not we change which trait is used to check whether a type is allowed to be a const parameter. Long term (when stabilizing `UnsizedConstParamTy`) it should be possible to completely merge these traits (and derive macros), only having a single `trait ConstParamTy` and `macro ConstParamTy`. Under `adt_const_params` it is now illegal to directly refer to `ConstParamTy` it is only used as an internal impl detail by `derive(ConstParamTy)` and checking const parameters are well formed. This is necessary in order to ensure forwards compatibility with all possible future directions for `feature(unsized_const_parameters)`. Generally the intuition here should be that `ConstParamTy` is the stable trait that everything uses, and `UnsizedConstParamTy` is that plus unstable implementations (well, I suppose `ConstParamTy` isn't stable yet :P).
2024-07-20Just totally fully deny late-bound constsMichael Goulet-2/+9
2024-07-17Split part of `adt_const_params` into `unsized_const_params`Boxy-364/+818
2024-07-16Add `ConstArgKind::Path` and make `ConstArg` its own HIR nodeNoah Lev-84/+83
This is a very large commit since a lot needs to be changed in order to make the tests pass. The salient changes are: - `ConstArgKind` gets a new `Path` variant, and all const params are now represented using it. Non-param paths still use `ConstArgKind::Anon` to prevent this change from getting too large, but they will soon use the `Path` variant too. - `ConstArg` gets a distinct `hir_id` field and its own variant in `hir::Node`. This affected many parts of the compiler that expected the parent of an `AnonConst` to be the containing context (e.g., an array repeat expression). They have been changed to check the "grandparent" where necessary. - Some `ast::AnonConst`s now have their `DefId`s created in rustc_ast_lowering rather than `DefCollector`. This is because in some cases they will end up becoming a `ConstArgKind::Path` instead, which has no `DefId`. We have to solve this in a hacky way where we guess whether the `AnonConst` could end up as a path const since we can't know for sure until after name resolution (`N` could refer to a free const or a nullary struct). If it has no chance as being a const param, then we create a `DefId` in `DefCollector` -- otherwise we decide during ast_lowering. This will have to be updated once all path consts use `ConstArgKind::Path`. - We explicitly use `ConstArgHasType` for array lengths, rather than implicitly relying on anon const type feeding -- this is due to the addition of `ConstArgKind::Path`. - Some tests have their outputs changed, but the changes are for the most part minor (including removing duplicate or almost-duplicate errors). One test now ICEs, but it is for an incomplete, unstable feature and is now tracked at #127009.
2024-07-11Account for `let foo = expr`; to suggest `const foo: Ty = expr;`Esteban Küber-2/+2
2024-07-11Use verbose style when suggesting changing `const` with `let`Esteban Küber-2/+5
2024-07-11Auto merge of #127311 - oli-obk:do_not_count_errors, r=compiler-errorsbors-32/+7
Avoid follow-up errors and ICEs after missing lifetime errors on data structures Tuple struct constructors are functions, so when we call them typeck will use the signature tuple struct constructor function to provide type hints. Since typeck mostly ignores and erases lifetimes, we end up never seeing the error lifetime in writeback, thus not tainting the typeck result. Now, we eagerly taint typeck results by tainting from `resolve_vars_if_possible`, which is called all over the place. I did not carry over all the `crashes` test suite tests, as they are really all the same cause (missing or unknown lifetime names in tuple struct definitions or generic arg lists). fixes #124262 fixes #124083 fixes #125155 fixes #125888 fixes #125992 fixes #126666 fixes #126648 fixes #127268 fixes #127266 fixes #127304
2024-07-11Avoid follow-up errors and ICEs after missing lifetime errors on data structuresOli Scherer-32/+7
2024-07-11Always use a colon in `//@ normalize-*:` headersZalathar-3/+3
2024-07-09Automatically taint when reporting errors from ItemCtxtOli Scherer-245/+66
2024-07-05Rollup merge of #127107 - mu001999-contrib:dead/enhance-2, r=pnkfelixMichael Goulet-0/+2
Improve dead code analysis Fixes #120770 1. check impl items later if self ty is private although the trait method is public, cause we must use the ty firstly if it's private 2. mark the adt live if it appears in pattern, like generic argument, this implies the use of the adt 3. based on the above, we can handle the case that private adts impl Default, so that we don't need adding rustc_trivial_field_reads on Default, and the logic in should_ignore_item r? ``@pnkfelix``
2024-07-04Improve dead code analysismu001999-0/+2
2024-07-04Better suggestion span for missing type parameterEsteban Küber-2/+10
2024-07-03Rollup merge of #127245 - BoxyUwU:gce_hang_test, r=NilstriebJacob Pratt-0/+32
Add a test for `generic_const_exprs` Fixes #103770 r? ``@Nilstrieb``
2024-07-02add testBoxy-0/+32
2024-07-02Add testBoxy-0/+69
2024-07-01Auto merge of #126996 - oli-obk:do_not_count_errors, r=nnethercotebors-79/+267
Automatically taint InferCtxt when errors are emitted r? `@nnethercote` Basically `InferCtxt::dcx` now returns a `DiagCtxt` that refers back to the `Cell<Option<ErrorGuaranteed>>` of the `InferCtxt` and thus when invoking `Diag::emit`, and the diagnostic is an error, we taint the `InferCtxt` directly. That change on its own has no effect at all, because `InferCtxt` already tracks whether errors have been emitted by recording the global error count when it gets opened, and checking at the end whether the count changed. So I removed that error count check, which had a bit of fallout that I immediately fixed by invoking `InferCtxt::dcx` instead of `TyCtxt::dcx` in a bunch of places. The remaining new errors are because an error was reported in another query, and never bubbled up. I think they are minor enough for this to be ok, and sometimes it actually improves diagnostics, by not silencing useful diagnostics anymore. fixes #126485 (cc `@olafes)` There are more improvements we can do (like tainting in hir ty lowering), but I would rather do that in follow up PRs, because it requires some refactorings.
2024-07-01Auto merge of #127176 - fee1-dead-contrib:fx-requires-next-solver, ↵bors-12/+53
r=compiler-errors Make `feature(effects)` require `-Znext-solver` Per https://github.com/rust-lang/rust/pull/120639#pullrequestreview-2144804638 I made this a hard error because otherwise it should be a lint and that seemed more complicated. Not sure if this is the best place to put the error though. r? project-const-traits
2024-06-30Migrate tests to use `-Znext-solver`Deadbeef-12/+53
2024-06-30Update test commentBoxy-10/+14
2024-06-29Auto merge of #120639 - fee1-dead-contrib:new-effects-desugaring, r=oli-obkbors-58/+16
Implement new effects desugaring cc `@rust-lang/project-const-traits.` Will write down notes once I have finished. * [x] See if we want `T: Tr` to desugar into `T: Tr, T::Effects: Compat<true>` * [x] Fix ICEs on `type Assoc: ~const Tr` and `type Assoc<T: ~const Tr>` * [ ] add types and traits to minicore test * [ ] update rustc-dev-guide Fixes #119717 Fixes #123664 Fixes #124857 Fixes #126148
2024-06-28Don't inline drop shims with unsubstituted generic consts in MIR inlinerMichael Goulet-261/+1
2024-06-28Failing test for computing drop shim that has const paramMichael Goulet-0/+278
2024-06-28bless tests part 1Deadbeef-58/+15
2024-06-28implement new effects desugaringDeadbeef-0/+1
2024-06-26Automatically taint InferCtxt when errors are emittedOli Scherer-79/+267
2024-06-25Rollup merge of #126618 - mu001999-contrib:dead/enhance, r=pnkfelixMatthias Krüger-0/+1
Mark assoc tys live only if the corresponding trait is live r? ````@pnkfelix````
2024-06-22Make `effects` an incomplete featureDeadbeef-1/+12
2024-06-19Const generic parameters aren't bounds, even if we end up erroring because ↵Oli Scherer-36/+36
of the bound that binds the parameter's type
2024-06-19Taint infcx when reporting errorsOli Scherer-51/+250
2024-06-18Mark assoc tys live only if the trait is livemu001999-0/+1
2024-06-17Use subtyping instead of equality, since method resolution also uses subtypingOli Scherer-1/+1
2024-06-16Rollup merge of #126127 - Alexendoo:other-trait-diag, r=pnkfelixJacob Pratt-8/+8
Spell out other trait diagnostic I recently saw somebody confused about the diagnostic thinking it was suggesting to add an `as` cast. This change is longer but I think it's clearer
2024-06-14Rollup merge of #126054 - veera-sivarajan:bugfix-113073-bound-on-generics-2, ↵Matthias Krüger-41/+7
r=fee1-dead `E0229`: Suggest Moving Type Constraints to Type Parameter Declaration Fixes #113073 This PR suggests `impl<T: Bound> Trait<T> for Foo` when finding `impl Trait<T: Bound> for Foo`. Tangentially, it also improves a handful of other error messages. It accomplishes this in two steps: 1. Check if constrained arguments and parameter names appear in the same order and delay emitting "incorrect number of generic arguments" error because it can be confusing for the programmer to see `0 generic arguments provided` when there are `n` constrained generic arguments. 2. Inside `E0229`, suggest declaring the type parameter right after the `impl` keyword by finding the relevant impl block's span for type parameter declaration. This also handles lifetime declarations correctly. Also, the multi part suggestion doesn't use the fluent error mechanism because translating all the errors to fluent style feels outside the scope of this PR. I will handle it in a separate PR if this gets approved.
2024-06-13Tweak output of import suggestionsEsteban Küber-1/+1
When both `std::` and `core::` items are available, only suggest the `std::` ones. We ensure that in `no_std` crates we suggest `core::` items. Ensure that the list of items suggested to be imported are always in the order of local crate items, `std`/`core` items and finally foreign crate items. Tweak wording of import suggestion: if there are multiple items but they are all of the same kind, we use the kind name and not the generic "items". Fix #83564.
2024-06-12Rollup merge of #126228 - BoxyUwU:nested_repeat_expr_generics, r=compiler-errorsGuillaume Gomez-0/+31
Provide correct parent for nested anon const Fixes #126147 99% of this PR is just comments explaining what the issue is. `tcx.parent(` and `hir().get_parent_item(` give different results as the hir owner for all the hir of anon consts is the enclosing function. I didn't attempt to change that as being a hir owner requires a `DefId` and long term we want to stop creating anon consts' `DefId`s before hir ty lowering. So i just opted to change `generics_of` to use `tcx.parent` to get the parent for `AnonConst`'s. I'm not entirely sure about this being what we want, it does seem weird that we have two ways of getting the parent of an `AnonConst` and they both give different results. Alternatively we could just go ahead and make `const_evaluatable_unchecked` a hard error and stop providing generics to repeat exprs. Then this isn't an issue. (The FCW has been around for almost 4 years now) r? ````@compiler-errors````
2024-06-12Spell out other trait diagnosticAlex Macleod-8/+8
2024-06-12Require any function with a tait in its signature to actually constrain a ↵Oli Scherer-15/+29
hidden type
2024-06-10Correct parent for nested anon constsBoxy-0/+31
2024-06-07Rollup merge of #125572 - mu001999-contrib:dead/enhance, r=pnkfelixMatthias Krüger-1/+4
Detect pub structs never constructed and unused associated constants <!-- If this PR is related to an unstable feature or an otherwise tracked effort, please link to the relevant tracking issue here. If you don't know of a related tracking issue or there are none, feel free to ignore this. This PR will get automatically assigned to a reviewer. In case you would like a specific user to review your work, you can assign it to them by using r​? <reviewer name> --> Lints never constructed public structs. If we don't provide public methods to construct public structs with private fields, and don't construct them in the local crate. They would be never constructed. So that we can detect such public structs. --- Update: Also lints unused associated constants in traits.
2024-06-05Update TestsVeera-41/+7
2024-06-05Bless tests and handle tests/crashesBoxy-38/+270
2024-06-05Detect pub structs never constructed and unused associated constants in traitsr0cky-1/+4
2024-06-04Rollup merge of #125968 - BoxyUwU:shrink_ty_expr, r=oli-obkMichael Goulet-1/+13
Store the types of `ty::Expr` arguments in the `ty::Expr` Part of #125958 In attempting to remove the `ty` field on `Const` it will become necessary to store the `Ty<'tcx>` inside of `Expr<'tcx>`. In order to do this without blowing up the size of `ConstKind`, we start storing the type/const args as `GenericArgs` r? `@oli-obk`
2024-06-04Rollup merge of #125667 - oli-obk:taintify, r=TaKO8KiMichael Goulet-4/+31
Silence follow-up errors directly based on error types and regions During type_of, we used to just return an error type if there were any errors encountered. This is problematic, because it means a struct declared as `struct Foo<'static>` will end up not finding any inherent or trait impls because those impl blocks' `Self` type will be `{type error}` instead of `Foo<'re_error>`. Now it's the latter, silencing nonsensical follow-up errors about `Foo` not having any methods. Unfortunately that now allows for new follow-up errors, because borrowck treats `'re_error` as `'static`, causing nonsensical errors about non-error lifetimes not outliving `'static`. So what I also did was to just strip all outlives bounds that borrowck found, thus never letting it check them. There are probably more nuanced ways to do this, but I worried there would be other nonsensical errors if some outlives bounds were missing. Also from the test changes, it looked like an improvement everywhere.
2024-06-04bless privacy tests (only diagnostic duplication)Oli Scherer-1/+13