about summary refs log tree commit diff
path: root/src/test/ui/const-generics
AgeCommit message (Collapse)AuthorLines
2022-02-28Rollup merge of #93389 - cameron1024:issue-90847-regression, r=Mark-SimulacrumMatthias Krüger-0/+9
regression for issue 90847 Adds a regression test for issue #90847
2022-02-25Suggest {} around more bad const generic exprsMichael Goulet-0/+81
2022-02-20Gracefully handle non-UTF-8 string slices when pretty printingTomasz Miąsko-16/+0
2022-02-16allow special behavior when printing const inferlcnr-4/+4
2022-02-14Make `find_similar_impl_candidates` a little fuzzier.Ben Reeves-0/+2
2022-02-12ReblessDeadbeef-2/+5
2022-02-12Rebased and improved errorsDeadbeef-4/+20
2022-02-12bless youDeadbeef-3/+7
2022-02-11fix tests, add new tests checking borrowck CFTE ICEMichael Goulet-0/+15
2022-02-11Revert "Auto merge of #92007 - oli-obk:lazy_tait2, r=nikomatsakis"Oli Scherer-12/+12
This reverts commit e7cc3bddbe0d0e374d05e7003e662bba1742dbae, reversing changes made to 734368a200904ef9c21db86c595dc04263c87be0.
2022-02-10fix min_const_generics oversightlcnr-0/+29
2022-02-07Auto merge of #92007 - oli-obk:lazy_tait2, r=nikomatsakisbors-12/+12
Lazy type-alias-impl-trait Previously opaque types were processed by 1. replacing all mentions of them with inference variables 2. memorizing these inference variables in a side-table 3. at the end of typeck, resolve the inference variables in the side table and use the resolved type as the hidden type of the opaque type This worked okayish for `impl Trait` in return position, but required lots of roundabout type inference hacks and processing. This PR instead stops this process of replacing opaque types with inference variables, and just keeps the opaque types around. Whenever an opaque type `O` is compared with another type `T`, we make the comparison succeed and record `T` as the hidden type. If `O` is compared to `U` while there is a recorded hidden type for it, we grab the recorded type (`T`) and compare that against `U`. This makes implementing * https://github.com/rust-lang/rfcs/pull/2515 much simpler (previous attempts on the inference based scheme were very prone to ICEs and general misbehaviour that was not explainable except by random implementation defined oddities). r? `@nikomatsakis` fixes #93411 fixes #88236
2022-02-05resolve lifetimes for const generic defaultsMichael Goulet-0/+36
2022-02-02Lazily resolve type-alias-impl-trait defining usesOli Scherer-12/+12
by using an opaque type obligation to bubble up comparisons between opaque types and other types Also uses proper obligation causes so that the body id works, because out of some reason nll uses body ids for logic instead of just diagnostics.
2022-01-31regression test for issue 90847cameron-0/+9
2022-01-30Bless all pretty printer tests and ui testsDavid Tolnay-1/+1
2022-01-20Rollup merge of #92582 - lcnr:generic-arg-infer, r=BoxyUwUMatthias Krüger-21/+180
improve `_` constants in item signature handling removing the "type" from the error messages does slightly worsen the error messages for types, but figuring out whether the placeholder is for a type or a constant and correctly dealing with that seemed fairly difficult to me so I took the easy way out :sparkles: Imo the error message is still clear enough. r? `@BoxyUwU` cc `@estebank`
2022-01-18Rollup merge of #92780 - b-naber:postpone-const-eval-coherence, r=lcnrMatthias Krüger-4/+40
Directly use ConstValue for single literals in blocks Addresses the minimal repro in https://github.com/rust-lang/rust/issues/92186, but doesn't fix the underlying problem (which would be solved by solving the anon subst problem afaict). I do, however, think that it makes sense in general to treat single literals in anon blocks as const values directly, especially in light of the problem that the issue refers to (anon const evaluation being postponed until infer variables in substs can be resolved, which was introduced by https://github.com/rust-lang/rust/pull/90023), i.e. while we do get warnings for those unnecessary braces, we should try to avoid errors caused by those braces if possible.
2022-01-18generic_arg_infer: placeholder in signature errlcnr-21/+180
2022-01-18Auto merge of #87648 - JulianKnodt:const_eq_constrain, r=oli-obkbors-16/+52
allow eq constraints on associated constants Updates #70256 (cc `@varkor,` `@Centril)`
2022-01-18Rollup merge of #92640 - compiler-errors:array-deref-on-newtype, r=lcnrMatthias Krüger-0/+27
Fix ICEs related to `Deref<Target=[T; N]>` on newtypes 1. Stash a const infer's type into the canonical var during canonicalization, so we can recreate the fresh const infer with that same type. For example, given `[T; _]` we know `_` is a `usize`. If we go from infer => canonical => infer, we shouldn't forget that variable is a usize. Fixes #92626 Fixes #83704 2. Don't stash the autoderef'd slice type that we get from method lookup, but instead recreate it during method confirmation. We need to do this because the type we receive back after picking the method references a type variable that does not exist after probing is done. Fixes #92637 ... A better solution for the second issue would be to actually _properly_ implement `Deref` for `[T; N]` instead of fixing this autoderef hack to stop leaking inference variables. But I actually looked into this, and there are many complications with const impls.
2022-01-17Add term to ExistentialProjectionkadmin-4/+24
Also prevent ICE when adding a const in associated const equality.
2022-01-17Use Term in ProjectionPredicatekadmin-16/+32
ProjectionPredicate should be able to handle both associated types and consts so this adds the first step of that. It mainly just pipes types all the way down, not entirely sure how to handle consts, but hopefully that'll come with time.
2022-01-17add and update testsb-naber-4/+40
2022-01-17Rollup merge of #92876 - compiler-errors:fix-turbofish-lifetime-suggestion, ↵Matthias Krüger-12/+12
r=nagisa Fix suggesting turbofish with lifetime arguments Now we suggest turbofish correctly given exprs like `foo<'_>`. Also fix suggestion when we have `let x = foo<bar, baz>;` which was broken.
2022-01-13Fix suggesting turbofish with lifetime argumentsMichael Goulet-12/+12
2022-01-14fix bugEllen-11/+15
2022-01-12Add new tests, fix up old testsMichael Goulet-0/+27
2022-01-04Rollup merge of #91907 - lcnr:const-arg-infer, r=BoxyUwUMatthias Krüger-0/+80
Allow `_` as the length of array types and repeat expressions r? `@BoxyUwU` cc `@varkor`
2021-12-27Rollup merge of #90586 - jswrenn:relax-privacy-lints, r=petrochenkovMatthias Krüger-39/+3
Relax priv-in-pub lint on generic bounds and where clauses of trait impls. The priv-in-pub lint is a legacy mechanism of the compiler, supplanted by a reachability-based [type privacy](https://github.com/rust-lang/rfcs/blob/master/text/2145-type-privacy.md) analysis. This PR does **not** relax type privacy; it only relaxes the lint (as proposed by the type privacy RFC) in the case of trait impls. ## Current Behavior On public trait impls, it's currently an **error** to have a `where` bound constraining a private type with a trait: ```rust pub trait Trait {} pub struct Type {} struct Priv {} impl Trait for Priv {} impl Trait for Type where Priv: Trait // ERROR {} ``` ...and it's a **warning** to have have a public type constrained by a private trait: ```rust pub trait Trait {} pub struct Type {} pub struct Pub {} trait Priv {} impl Priv for Pub {} impl Trait for Type where Pub: Priv // WARNING {} ``` This lint applies to `where` clauses in other contexts, too; e.g. on free functions: ```rust struct Priv<T>(T); pub trait Pub {} impl<T: Pub> Pub for Priv<T> {} pub fn function<T>() where Priv<T>: Pub // WARNING {} ``` **These constraints could be relaxed without issue.** ## New Behavior This lint is relaxed for `where` clauses on trait impls, such that it's okay to have a `where` bound constraining a private type with a trait: ```rust pub trait Trait {} pub struct Type {} struct Priv {} impl Trait for Priv {} impl Trait for Type where Priv: Trait // OK {} ``` ...and it's okay to have a public type constrained by a private trait: ```rust pub trait Trait {} pub struct Type {} pub struct Pub {} trait Priv {} impl Priv for Pub {} impl Trait for Type where Pub: Priv // OK {} ``` ## Rationale While the priv-in-pub lint is not essential for soundness, it *can* help programmers avoid pitfalls that would make their libraries difficult to use by others. For instance, such a lint *is* useful for free functions; e.g. if a downstream crate tries to call the `function` in the previous snippet in a generic context: ```rust fn callsite<T>() where Priv<T>: Pub // ERROR: omitting this bound is a compile error, but including it is too { function::<T>() } ``` ...it cannot do so without repeating `function`'s `where` bound, which we cannot do because `Priv` is out-of-scope. A lint for this case is arguably helpful. However, this same reasoning **doesn't** hold for trait impls. To call an unconstrained method on a public trait impl with private bounds, you don't need to forward those private bounds, you can forward the public trait: ```rust mod upstream { pub trait Trait { fn method(&self) {} } pub struct Type<T>(T); pub struct Pub<T>(T); trait Priv {} impl<T: Priv> Priv for Pub<T> {} impl<T> Trait for Type<T> where Pub<T>: Priv // WARNING {} } mod downstream { use super::upstream::*; fn function<T>(value: Type<T>) where Type<T>: Trait // <- no private deets! { value.method(); } } ``` **This PR only eliminates the lint on trait impls.** It leaves it intact for all other contexts, including trait definitions, inherent impls, and function definitions. It doesn't need to exist in those cases either, but I figured I'd first target a case where it's mostly pointless. ## Other Notes - See discussion [on zulip](https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/relax.20priv-in-pub.20lint.20for.20trait.20impl.20.60where.60.20bounds/near/222458397). - This PR effectively reverts #79291.
2021-12-27relax priv-in-pub lint on generic bounds and where clauses in trait implsJack Wrenn-39/+3
2021-12-23implement `generic_arg_infer` for array lengthslcnr-0/+80
2021-12-18Rollup merge of #89090 - cjgillot:bare-dyn, r=jackh726Matthias Krüger-23/+11
Lint bare traits in AstConv. Removing the lint from lowering allows to: - make lowering querification easier; - have the lint implementation in only one place. r? `@estebank`
2021-12-14testEllen-0/+25
2021-12-13extra test for bug i foundEllen-0/+15
2021-12-13hurray for portable simd finding a nice test for this FIXMEEllen-0/+26
2021-12-12Auto merge of #90207 - BoxyUwU:stabilise_cg_defaults, r=lcnrbors-206/+46
Stabilise `feature(const_generics_defaults)` `feature(const_generics_defaults)` is complete implementation wise and has a pretty extensive test suite so I think is ready for stabilisation. needs stabilisation report and maybe an RFC :sweat_smile: r? `@lcnr` cc `@rust-lang/project-const-generics`
2021-12-11Auto merge of #91769 - estebank:type-trait-bound-span-2, r=oli-obkbors-2/+2
Tweak assoc type obligation spans * Point at RHS of associated type in obligation span * Point at `impl` assoc type on projection error * Reduce verbosity of recursive obligations * Point at source of binding lifetime obligation * Tweak "required bound" note * Tweak "expected... found opaque (return) type" labels * Point at set type in impl assoc type WF errors r? `@oli-obk` This is a(n uncontroversial) subset of #85799.
2021-12-11Tweak assoc type obligation spansEsteban Kuber-2/+2
* Point at RHS of associated type in obligation span * Point at `impl` assoc type on projection error * Reduce verbosity of recursive obligations * Point at source of binding lifetime obligation * Tweak "required bound" note * Tweak "expected... found opaque (return) type" labels * Point at set type in impl assoc type WF errors
2021-12-10Rollup merge of #91678 - b-naber:tests-for-postpone-const-eval, r=jackh726Matthias Krüger-0/+387
Add tests fixed by #90023 The following issues were fixed by https://github.com/rust-lang/rust/pull/90023 Fixes https://github.com/rust-lang/rust/issues/79674 Fixes https://github.com/rust-lang/rust/issues/83765 Fixes https://github.com/rust-lang/rust/issues/86033 Fixes https://github.com/rust-lang/rust/issues/90318 Fixes https://github.com/rust-lang/rust/issues/88468 The following issues were duplicates of https://github.com/rust-lang/rust/issues/90654 Fixes https://github.com/rust-lang/rust/issues/86850 Fixes https://github.com/rust-lang/rust/issues/89022 r? ````@jackh726````
2021-12-10update testsEllen-206/+46
2021-12-08add testsb-naber-0/+387
2021-12-08Rollup merge of #91551 - b-naber:const-eval-normalization-ice, r=oli-obkMatthias Krüger-0/+61
Allow for failure of subst_normalize_erasing_regions in const_eval Fixes https://github.com/rust-lang/rust/issues/72845 Using associated types that cannot be normalized previously resulted in an ICE. We now allow for normalization failure and return a "TooGeneric" error in that case. r? ```@RalfJung``` maybe?
2021-12-07Refer to const params as "const params" and not "type params"Esteban Kuber-1/+1
2021-12-07Refer to uninferred `const` params by their name, instead of `{ _: _ }`Esteban Kuber-1/+1
When the value of a const param isn't inferred, replace it with the param name from the definition.
2021-12-07Only shown relevant type params in E0283 labelEsteban Kuber-1/+1
When we point at a binding to suggest giving it a type, erase all the type for ADTs that have been resolved, leaving only the ones that could not be inferred. For small shallow types this is not a problem, but for big nested types with lots of params, this can otherwise cause a lot of unnecessary visual output.
2021-12-05Rollup merge of #91437 - dtolnay:emptybrace, r=nagisaMatthias Krüger-2/+2
Pretty print empty blocks as {} **Example:** ```rust macro_rules! p { ($e:expr) => { println!("{}", stringify!($e)); }; ($i:item) => { println!("{}", stringify!($i)); }; } fn main() { p!(if true {}); p!(struct S {}); } ``` **Before:** ```console if true { } struct S { } ``` **After:** ```console if true {} struct S {} ``` This affects [`dbg!`](https://doc.rust-lang.org/std/macro.dbg.html), as well as ecosystem uses of stringify such as in [`anyhow::ensure!`](https://docs.rs/anyhow/1/anyhow/macro.ensure.html). Printing a `{ }` in today's heavily rustfmt'd world comes out looking jarring/sloppy.
2021-12-05Rollup merge of #90529 - b-naber:reborrows-consts, r=lcnrMatthias Krüger-1/+23
Skip reborrows in AbstractConstBuilder Fixes https://github.com/rust-lang/rust/issues/90455 Temporary fix to prevent confusing diagnostics that refer to implicit borrows and derefs until we allow borrows and derefs on constant expressions. r? `@oli-obk`
2021-12-05add test and bless existing onesb-naber-0/+61
2021-12-05bless testsb-naber-1/+1