about summary refs log tree commit diff
path: root/tests/ui/const-generics
AgeCommit message (Collapse)AuthorLines
2024-03-21Auto merge of #121123 - compiler-errors:item-assumptions, r=oli-obkbors-8/+17
Split an item bounds and an item's super predicates This is the moral equivalent of #107614, but instead for predicates this applies to **item bounds**. This PR splits out the item bounds (i.e. *all* predicates that are assumed to hold for the alias) from the item *super predicates*, which are the subset of item bounds which share the same self type as the alias. ## Why? Much like #107614, there are places in the compiler where we *only* care about super-predicates, and considering predicates that possibly don't have anything to do with the alias is problematic. This includes things like closure signature inference (which is at its core searching for `Self: Fn(..)` style bounds), but also lints like `#[must_use]`, error reporting for aliases, computing type outlives predicates. Even in cases where considering all of the `item_bounds` doesn't lead to bugs, unnecessarily considering irrelevant bounds does lead to a regression (#121121) due to doing extra work in the solver. ## Example 1 - Trait Aliases This is best explored via an example: ``` type TAIT<T> = impl TraitAlias<T>; trait TraitAlias<T> = A + B where T: C; ``` The item bounds list for `Tait<T>` will include: * `Tait<T>: A` * `Tait<T>: B` * `T: C` While `item_super_predicates` query will include just the first two predicates. Side-note: You may wonder why `T: C` is included in the item bounds for `TAIT`? This is because when we elaborate `TraitAlias<T>`, we will also elaborate all the predicates on the trait. ## Example 2 - Associated Type Bounds ``` type TAIT<T> = impl Iterator<Item: A>; ``` The `item_bounds` list for `TAIT<T>` will include: * `Tait<T>: Iterator` * `<Tait<T> as Iterator>::Item: A` But the `item_super_predicates` will just include the first bound, since that's the only bound that is relevant to the *alias* itself. ## So what This leads to some diagnostics duplication just like #107614, but none of it will be user-facing. We only see it in the UI test suite because we explicitly disable diagnostic deduplication. Regarding naming, I went with `super_predicates` kind of arbitrarily; this can easily be changed, but I'd consider better names as long as we don't block this PR in perpetuity.
2024-03-21Provide structured suggestion for unconstrained generic constantEsteban Küber-91/+258
``` error: unconstrained generic constant --> $DIR/const-argument-if-length.rs:18:10 | LL | pad: [u8; is_zst::<T>()], | ^^^^^^^^^^^^^^^^^^^ | help: try adding a `where` bound | LL | pub struct AtLeastByte<T: ?Sized> where [(); is_zst::<T>()]: { | ++++++++++++++++++++++++++ ``` Detect when the constant expression isn't `usize` and suggest casting: ``` error: unconstrained generic constant --> f300.rs:6:10 | 6 | bb::<{!N}>(); | ^^^^ -Ztrack-diagnostics: created at compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs:3539:36 | help: try adding a `where` bound | 5 | fn b<const N: bool>() where [(); {!N} as usize]: { | ++++++++++++++++++++++++++ ``` Fix #122395.
2024-03-20register opaques that reference errorsAli MJ Al-Nasrawy-3/+19
2024-03-20make `type_flags(ReError) & HAS_ERROR`Ali MJ Al-Nasrawy-42/+1
2024-03-20Bless test fallout (duplicate diagnostics)Michael Goulet-8/+17
2024-03-19Auto merge of #119212 - w-utter:pretty-print-const-expr, r=compiler-errorsbors-10/+8
Fix representation when printing abstract consts Previously, when printing a const generic expr, it would only display it as `{{const expr}}`. This allows for a more legible representation when printing these out. I also zipped the types with their constants for abstract consts that contain function calls when using type annotations, eg: `foo(S: usize, true: bool) -> usize` insteaad of `foo(S, true): fn(usize, bool) -> usize` for conciseness.
2024-03-18Provide structured suggestion for `#![feature(foo)]`Esteban Küber-73/+256
``` error: `S2<'_>` is forbidden as the type of a const generic parameter --> $DIR/lifetime-in-const-param.rs:5:23 | LL | struct S<'a, const N: S2>(&'a ()); | ^^ | = note: the only supported types are integers, `bool` and `char` help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types | LL + #![feature(adt_const_params)] | ``` Fix #55941.
2024-03-17added pretty_print_const_exprwill-10/+8
2024-03-14Auto merge of #122347 - oli-obk:track_errors13, r=compiler-errorsbors-32/+32
Revert "Auto merge of #122140 - oli-obk:track_errors13, r=davidtwco" This reverts commit 65cd843ae06ad00123c131a431ed5304e4cd577a, reversing changes made to d255c6a57c393db6221b1ff700daea478436f1cd. reverts https://github.com/rust-lang/rust/pull/122140 It was a large regression in wall time due to trashing CPU caches
2024-03-11Revert "Auto merge of #122140 - oli-obk:track_errors13, r=davidtwco"Oli Scherer-32/+32
This reverts commit 65cd843ae06ad00123c131a431ed5304e4cd577a, reversing changes made to d255c6a57c393db6221b1ff700daea478436f1cd.
2024-03-11Remove some unnecessary allow(incomplete_features)Michael Goulet-10/+5
2024-03-11Run a single huge `par_body_owners` instead of many small ones after each other.Oli Scherer-32/+32
This improves parallel rustc parallelism by avoiding the bottleneck after each individual `par_body_owners` (because it needs to wait for queries to finish, so if there is one long running one, a lot of cores will be idle while waiting for the single query).
2024-03-09Auto merge of #122150 - ShoyuVanilla:replace-typewalker, r=lcnrbors-1/+10
Replace `TypeWalker` usage with `TypeVisitor` in `wf.rs` Resolves #121693
2024-03-08Auto merge of #121500 - oli-obk:track_errors12, r=petrochenkovbors-20/+20
Merge `collect_mod_item_types` query into `check_well_formed` follow-up to https://github.com/rust-lang/rust/pull/121154 this removes more potential parallel-compiler bottlenecks and moves diagnostics for the same items next to each other, instead of grouping diagnostics by analysis kind
2024-03-08Auto merge of #122078 - gurry:121443-ice-layout-is-sized-alt, r=oli-obkbors-2/+27
Check that return type is WF in typeck Ensures that non-WF types do not pass typeck and then later ICE in MIR/const eval Fixes #121443
2024-03-08Replace `TypeWalker` usage with `TypeVisitor`Shoyu Vanilla-1/+10
2024-03-07Use the same collection order as check_mod_type_wfOli Scherer-20/+20
2024-03-07Merge `check_mod_impl_wf` and `check_mod_type_wf`Oli Scherer-7/+38
2024-03-06Check that return type is WF in typeckGurinder Singh-2/+27
Without it non-WF types could pass typeck and then later fail in MIR/const eval
2024-03-02Auto merge of #121657 - estebank:issue-119665, r=davidtwcobors-3/+3
Detect more cases of `=` to `:` typo When a `Local` is fully parsed, but not followed by a `;`, keep the `:` span arround and mention it. If the type could continue being parsed as an expression, suggest replacing the `:` with a `=`. ``` error: expected one of `!`, `+`, `->`, `::`, `;`, or `=`, found `.` --> file.rs:2:32 | 2 | let _: std::env::temp_dir().join("foo"); | - ^ expected one of `!`, `+`, `->`, `::`, `;`, or `=` | | | while parsing the type for `_` | help: use `=` if you meant to assign ``` Fix #119665.
2024-03-01Detect more cases of `=` to `:` typoEsteban Küber-3/+3
When a `Local` is fully parsed, but not followed by a `;`, keep the `:` span arround and mention it. If the type could continue being parsed as an expression, suggest replacing the `:` with a `=`. ``` error: expected one of `!`, `+`, `->`, `::`, `;`, or `=`, found `.` --> file.rs:2:32 | 2 | let _: std::env::temp_dir().join("foo"); | - ^ expected one of `!`, `+`, `->`, `::`, `;`, or `=` | | | while parsing the type for `_` | help: use `=` if you meant to assign ``` Fix #119665.
2024-02-29Make infer higher ranked equate use bidirectional subtyping in invariant contextSantiago Pastorino-1/+17
2024-02-25Auto merge of #120393 - Urgau:rfc3373-non-local-defs, r=WaffleLapkinbors-0/+2
Implement RFC 3373: Avoid non-local definitions in functions This PR implements [RFC 3373: Avoid non-local definitions in functions](https://github.com/rust-lang/rust/issues/120363).
2024-02-22remove `sub_relations` from infcx, recompute in diagnosticslcnr-9/+8
we don't track them when canonicalizing or when freshening, resulting in instable caching in the old solver, and issues when instantiating query responses in the new one.
2024-02-20Auto merge of #121087 - oli-obk:eager_const_failures, r=lcnrbors-12/+2
Always evaluate free constants and statics, even if previous errors occurred work towards https://github.com/rust-lang/rust/issues/79738 We will need to evaluate static items before the `definitions.freeze()` below, as we will start creating new `DefId`s (for nested allocations) within the `eval_static_initializer` query. But even without that motivation, this is a good change. Hard errors should always be reported and not silenced if other errors happened earlier.
2024-02-19Always evaluate free constants and statics, even if previous errors occurredOli Scherer-12/+2
2024-02-18Change leak check lint message to behavior is likely to change in the futureSantiago Pastorino-8/+6
2024-02-17Allow newly added non_local_definitions lint in testsUrgau-0/+2
2024-02-16[AUTO-GENERATED] Migrate ui tests from `//` to `//@` directives许杰友 Jieyou Xu (Joe)-337/+337
2024-02-14Continue compilation even if inherent impl checks failOli Scherer-2/+15
2024-02-14Use the correct char type on all platformsOli Scherer-9/+8
2024-02-14Continue compilation after check_mod_type_wf errorsOli Scherer-25/+239
2024-02-08Continue to borrowck even if there were previous errorsOli Scherer-3/+60
2024-02-07Update testsr0cky-6/+38
2024-02-04Auto merge of #120649 - matthiaskrgr:rollup-ek80j61, r=matthiaskrgrbors-26/+91
Rollup of 8 pull requests Successful merges: - #119759 (Add FileCheck annotations to dataflow-const-prop tests) - #120323 (On E0277 be clearer about implicit `Sized` bounds on type params and assoc types) - #120473 (Only suggest removal of `as_*` and `to_` conversion methods on E0308) - #120540 (add test for try-block-in-match-arm) - #120547 (`#![feature(inline_const_pat)]` is no longer incomplete) - #120552 (Correctly check `never_type` feature gating) - #120555 (put pnkfelix (me) back on the review queue.) - #120556 (Improve the diagnostics for unused generic parameters) r? `@ghost` `@rustbot` modify labels: rollup
2024-02-04Rollup merge of #120556 - fmease:improve-unused-generic-param-diags, r=oli-obkMatthias Krüger-26/+91
Improve the diagnostics for unused generic parameters * Don't emit two errors (namely E0091 *and* E0392) for unused type parameters on *lazy* type aliases * Fix the diagnostic help message of E0392 for *lazy* type aliases: Don't talk about the “fields” of lazy type aliases (use the term “body” instead) and don't suggest `PhantomData` for them, it doesn't make much sense * Consolidate the diagnostics for E0091 (unused type parameters in type aliases) and E0392 (unused generic parameters due to bivariance) and make it translatable * Still keep the error codes distinct (for now) * Naturally leads to better diagnostics for E0091 r? ```@oli-obk``` (to ballast your review load :P) or compiler
2024-02-03Rollup merge of #120531 - oli-obk:track_errors7, r=estebankMatthias Krüger-7/+44
Remove a bunch of `has_errors` checks that have no meaningful or the wrong effect r? `@nnethercote`
2024-02-01Improve the diagnostics for unused generic parametersLeón Orell Valerian Liehr-26/+91
2024-01-31Remove a has_errors check that only hides errors after unrelated items have ↵Oli Scherer-7/+44
errored.
2024-01-30Provide more context on derived obligation error primary labelEsteban Küber-7/+7
Expand the primary span of E0277 when the immediate unmet bound is not what the user wrote: ``` error[E0277]: the trait bound `i32: Bar` is not satisfied --> f100.rs:6:6 | 6 | <i32 as Foo>::foo(); | ^^^ the trait `Bar` is not implemented for `i32`, which is required by `i32: Foo` | help: this trait has no implementations, consider adding one --> f100.rs:2:1 | 2 | trait Bar {} | ^^^^^^^^^ note: required for `i32` to implement `Foo` --> f100.rs:3:14 | 3 | impl<T: Bar> Foo for T {} | --- ^^^ ^ | | | unsatisfied trait bound introduced here ``` Fix #40120.
2024-01-30Rollup merge of #120293 - estebank:issue-102629, r=nnethercoteGuillaume Gomez-15/+15
Deduplicate more sized errors on call exprs Change the implicit `Sized` `Obligation` `Span` for call expressions to include the whole expression. This aids the existing deduplication machinery to reduce the number of errors caused by a single unsized expression.
2024-01-26Auto merge of #116167 - RalfJung:structural-eq, r=lcnrbors-50/+15
remove StructuralEq trait The documentation given for the trait is outdated: *all* function pointers implement `PartialEq` and `Eq` these days. So the `StructuralEq` trait doesn't really seem to have any reason to exist any more. One side-effect of this PR is that we allow matching on some consts that do not implement `Eq`. However, we already allowed matching on floats and consts containing floats, so this is not new, it is just allowed in more cases now. IMO it makes no sense at all to allow float matching but also sometimes require an `Eq` instance. If we want to require `Eq` we should adjust https://github.com/rust-lang/rust/pull/115893 to check for `Eq`, and rule out float matching for good. Fixes https://github.com/rust-lang/rust/issues/115881
2024-01-25Rollup merge of #119895 - oli-obk:track_errors_3, r=matthewjasperMatthias Krüger-1/+10
Remove `track_errors` entirely follow up to https://github.com/rust-lang/rust/pull/119869 r? `@matthewjasper` There are some diagnostic changes adding new diagnostics or not emitting some anymore. We can improve upon that in follow-up work imo.
2024-01-24remove StructuralEq traitRalf Jung-50/+15
2024-01-24Deduplicate more sized errors on call exprsEsteban Küber-15/+15
Change the implicit `Sized` `Obligation` `Span` for call expressions to include the whole expression. This aids the existing deduplication machinery to reduce the number of errors caused by a single unsized expression.
2024-01-24Remove extra # from urlest31-2/+2
2024-01-23Rollup merge of #119805 - chenyukang:yukang-fix-119530, r=davidtwcoLeón Orell Valerian Liehr-0/+4
Suggest array::from_fn for array initialization Fixes #119530
2024-01-23Remove track_errors entirelyOli Scherer-1/+10
2024-01-22Make generic const type mismatches not hide trait impls from the trait solverOli Scherer-3/+50
2024-01-21Suggest arry::from_fn for array initializationyukang-0/+4