allow `incomplete_features` in more tests
This PR allows the `incomplete_features` lint for the `traits` and `const-generics` directories. `specialization` will come in a followup PR.
Followup to rust-lang/rust#154174.
Part of https://github.com/rust-lang/rust/issues/154168.
Always check `ConstArgHasType` even when otherwise ignoring
fixes https://github.com/rust-lang/rust/issues/149774
helping @BoxyUwU finish up https://github.com/rust-lang/rust/pull/150322, this is a simple tweak/finishing-up of that PR.
this is a breaking change that crater detected has some issues with in Boxy's PR, and hence needs a t-types FCP. I can go and help fix those crates if/once the break is signed off on.
When encountering an unmet predicate, when we point at the trait impls that do exist, if they are all for the same self type, tweak the wording to make it less verbose.
fix inference variables leaking into HIR const literal lowering logic
Inference variables could leak into further const lowering logic
It ICEs when query system tries to cache `lit_to_const()` after its execution and panics, because inference variables are not hashable for some reason
Fixesrust-lang/rust#153524Fixesrust-lang/rust#153525
When encountering an inference error where a return type must be known, like when calling `Iterator::sum::<T>()` without specifying `T`, look for all `T` that would satisfy `Sum<S>`. If only one, suggest it.
```
error[E0283]: type annotations needed
--> $DIR/cannot-infer-iterator-sum-return-type.rs:4:9
|
LL | let sum = v
| ^^^
...
LL | .sum(); // `sum::<T>` needs `T` to be specified
| --- type must be known at this point
|
= note: cannot satisfy `_: Sum<i32>`
help: the trait `Sum` is implemented for `i32`
--> $SRC_DIR/core/src/iter/traits/accum.rs:LL:COL
::: $SRC_DIR/core/src/iter/traits/accum.rs:LL:COL
|
= note: in this macro invocation
note: required by a bound in `std::iter::Iterator::sum`
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
= note: this error originates in the macro `integer_sum_product` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider giving `sum` an explicit type, where the type for type parameter `S` is specified
|
LL | let sum: i32 = v
| +++++
```
Point turbofish inference errors at the uninferred generic arg
Follow-up to rust-lang/rust#153751.
When a method call has a turbofish with an uninferred generic argument, point the diagnostic span at the specific `_` that couldn't be inferred instead of the method name.
Before:
```rust
LL | S.f::<u32, _>(42);
| ^ cannot infer type of the type parameter `B`
```
After:
```rust
LL | S.f::<u32, _>(42);
| ^ cannot infer type of the type parameter `B`
```
Path expressions (`None::<_>`, `foo::<_>()`) are not handled yet, that's a separate code path.
cc @eggyal
Tweak E0599 note
When not finding a method for a type, but finding it for a single other impl, special case the output to emit a single message instead of a list.
```
error[E0599]: no associated item named `C` found for struct `Fail<i32, u32>` in the current scope
--> $DIR/wrong-projection-self-ty-invalid-bivariant-arg2.rs:15:23
|
LL | struct Fail<T: Proj<Assoc = U>, U>(T);
| ---------------------------------- associated item `C` not found for this struct
...
LL | Fail::<i32, u32>::C
| ^ associated item not found in `Fail<i32, u32>`
|
= note: the associated item was found for `Fail<i32, i32>`
```
instead of
```
= note: the associated item was found for
- `Fail<i32, i32>`
```
Tweak wording of failed predicate in inference error
Special case message talking about `Predicate` that couldn't be satisfied when in inference errors so that we don't say "cannot satisfy `_: Trait`" and instead say "type must implement `Trait`".
Special case message talking about `Predicate` that couldn't be satisfied when in inference errors so that we don't say "cannot satisfy `_: Trait`" and instead say "type must implement `Trait`".
Gate `ConstParamTy_` trait behind `const_param_ty_trait` feature
Initially even when user wasn't using unsized const params, the only way to implement/name `ConstParamTy_` was to use `#![feature(unsized_const_params]`, now its gated under `const_param_ty_trait` feature, implied by `unsized_const_params`.
I've also changed use of `unsized_const_params` in tests which were using it only to implement `ConstParamTy_` without using unsized
r? BoxyUwU
- On `const` and `static` point at the type (like we do for let bindings)
- On fn calls, point at const parameter in fn definition
- On type, point at const parameter in type definition
- On array type lengths, explain that array length is always `usize`
- On enum variant discriminant, mention `repr`
When not finding a method for a type, but finding it for a single other impl, special case the output to emit a single message instead of a list.
```
error[E0599]: no associated item named `C` found for struct `Fail<i32, u32>` in the current scope
--> $DIR/wrong-projection-self-ty-invalid-bivariant-arg2.rs:15:23
|
LL | struct Fail<T: Proj<Assoc = U>, U>(T);
| ---------------------------------- associated item `C` not found for this struct
...
LL | Fail::<i32, u32>::C
| ^ associated item not found in `Fail<i32, u32>`
|
= note: the associated item was found for `Fail<i32, i32>`
```
instead of
```
= note: the associated item was found for
- `Fail<i32, i32>`
```
Make `const_lit_matches_ty` check literal suffixes for exact type match
`const_lit_matches_ty` ignored literal suffixes. This let the `try_lower_anon_const_lit` fast path produce a mistyped `ty::Const::Value`, bypassing the type mismatch error that typeck would otherwise report.
Remove unhelpful hint from trivial bound errors
The `= help: see issue #48214` hint on trivial bound errors isn't useful, most users hitting these errors aren't trying to use the `trivial_bounds` feature. The `disabled_nightly_features` call already handles suggesting the feature gate on nightly.
Closesrust-lang/rust#152872
Fix ICE in `try_to_raw_bytes` when array elements have mismatched
close: rust-lang/rust#152683
After rust-lang/rust#152001, suffixed integer literals preserve their own type during const lowering, so `try_to_raw_bytes` could call `.to_u8()` on a scalar with size > 1, causing an ICE. Fix by using `try_to_bits(Size::from_bytes(1)).ok()` instead.
r? BoxyUwU
mGCA: Enforce WF element types for array valtrees
Fixesrust-lang/rust#152125
Extends WellFormedness checking for const generics to validate that array element types in ValTrees match the declared element type.
### Problem
Before commit, this would have incorrectly compiled
``` rust
#![feature(adt_const_params, min_generic_const_args)]
use std::marker::ConstParamTy;
#[derive(Eq, PartialEq, ConstParamTy)]
struct Foo;
struct Bar;
fn foo<const N: [Foo; 1]>() {}
fn main() {
foo::<{ [Bar] }>();
}
```
### Solution
Added a `ty::Array` arm to checking WellFormedness (similar to the existing `ty::Tuple` arm from rust-lang/rust#150713) which creates `ConstArgHasType` obligations for each array element, ensuring they match the array's declared element type.
I attempted to combine the `Tuple` and `Array` arms into a single arm, but this proved difficult due to pattern matching limitations, and the separate arm is more readable anyway.
### Tests
Added UI test which verifies that the type mismatch is now properly caught, and also returns an appropriate test message
r? @BoxyUwU
Feature gate for defaulted associated type_consts with associated_type_defaults
*[View all comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust/pull/152385)*
This PR for issue rust-lang/rust#130288 extends a feature gate that was already present for defaulted associated types to defaulted type consts under associated_type_defaults.
Code added:
```
if ctxt == AssocCtxt::Trait && rhs.is_some() {
gate!(
&self,
associated_type_defaults,
i.span,
"associated type defaults are unstable"
);
}
```
Error produced:
```
error[E0658]: associated type defaults are unstable
--> $DIR/type-const-associated-default.rs:4:5
|
LL | type const N: usize = 10;
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #29661 <https://github.com/rust-lang/rust/issues/29661> for more information
= help: add `#![feature(associated_type_defaults)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
warning: the feature `min_generic_const_args` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/type-const-associated-default.rs:1:12
|
LL | #![feature(min_generic_const_args)]
| ^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #132980 <https://github.com/rust-lang/rust/issues/132980> for more information
= note: `#[warn(incomplete_features)]` on by default
error: aborting due to 1 previous error; 1 warning emitted
For more information about this error, try `rustc --explain E0658`.
```
Thanks to @BoxyUwU for the guidance on this issue.