Suppress lint type_alias_bounds for ty aliases containing const projections under GCE
This commit is contained in:
parent
63a54d93be
commit
a8b3dfd253
3 changed files with 144 additions and 0 deletions
|
@ -1437,6 +1437,16 @@ impl<'tcx> LateLintPass<'tcx> for TypeAliasBounds {
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
// FIXME(generic_const_exprs): Revisit this before stabilization.
|
||||
// See also `tests/ui/const-generics/generic_const_exprs/type-alias-bounds.rs`.
|
||||
let ty = cx.tcx.type_of(item.owner_id).instantiate_identity();
|
||||
if ty.has_type_flags(ty::TypeFlags::HAS_CT_PROJECTION)
|
||||
&& cx.tcx.features().generic_const_exprs
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// NOTE(inherent_associated_types): While we currently do take some bounds in type
|
||||
// aliases into consideration during IAT *selection*, we don't perform full use+def
|
||||
// site wfchecking for such type aliases. Therefore TAB should still trigger.
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
error[E0277]: the trait bound `String: Copy` is not satisfied
|
||||
--> $DIR/type-alias-bounds.rs:23:12
|
||||
|
|
||||
LL | let _: AliasConstUnused<String>;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String`
|
||||
|
|
||||
note: required by a bound in `ct_unused_0::AliasConstUnused`
|
||||
--> $DIR/type-alias-bounds.rs:20:30
|
||||
|
|
||||
LL | type AliasConstUnused<T: Copy> = (T, I32<{ DATA }>);
|
||||
| ^^^^ required by this bound in `AliasConstUnused`
|
||||
|
||||
error[E0277]: the trait bound `String: Copy` is not satisfied
|
||||
--> $DIR/type-alias-bounds.rs:31:12
|
||||
|
|
||||
LL | let _: AliasConstUnused;
|
||||
| ^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String`
|
||||
|
|
||||
note: required by a bound in `ct_unused_1::AliasConstUnused`
|
||||
--> $DIR/type-alias-bounds.rs:29:41
|
||||
|
|
||||
LL | type AliasConstUnused where String: Copy = I32<{ 0; 0 }>;
|
||||
| ^^^^ required by this bound in `AliasConstUnused`
|
||||
|
||||
error[E0277]: the trait bound `String: Copy` is not satisfied
|
||||
--> $DIR/type-alias-bounds.rs:39:12
|
||||
|
|
||||
LL | let _: AliasFnUnused<String>;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String`
|
||||
|
|
||||
note: required by a bound in `AliasFnUnused`
|
||||
--> $DIR/type-alias-bounds.rs:36:27
|
||||
|
|
||||
LL | type AliasFnUnused<T: Copy> = (T, I32<{ code() }>);
|
||||
| ^^^^ required by this bound in `AliasFnUnused`
|
||||
|
||||
error[E0277]: the trait bound `String: Copy` is not satisfied
|
||||
--> $DIR/type-alias-bounds.rs:57:12
|
||||
|
|
||||
LL | let _: AliasAssocConstUsed<String>;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String`
|
||||
|
|
||||
note: required by a bound in `AliasAssocConstUsed`
|
||||
--> $DIR/type-alias-bounds.rs:55:41
|
||||
|
|
||||
LL | type AliasAssocConstUsed<T: Trait + Copy> = I32<{ T::DATA }>;
|
||||
| ^^^^ required by this bound in `AliasAssocConstUsed`
|
||||
|
||||
error[E0277]: the trait bound `String: Copy` is not satisfied
|
||||
--> $DIR/type-alias-bounds.rs:65:12
|
||||
|
|
||||
LL | let _: AliasFnUsed<String>;
|
||||
| ^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String`
|
||||
|
|
||||
note: required by a bound in `AliasFnUsed`
|
||||
--> $DIR/type-alias-bounds.rs:62:33
|
||||
|
|
||||
LL | type AliasFnUsed<T: Trait + Copy> = I32<{ code::<T>() }>;
|
||||
| ^^^^ required by this bound in `AliasFnUsed`
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
|
@ -0,0 +1,71 @@
|
|||
//@ revisions: pos neg
|
||||
//@[pos] check-pass
|
||||
|
||||
#![feature(generic_const_exprs)]
|
||||
#![feature(trivial_bounds)] // only used in test case `ct_unused_1`
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
// FIXME(generic_const_exprs): Revisit this before stabilization.
|
||||
// Check that we don't emit the lint `type_alias_bounds` for (eager) type aliases
|
||||
// whose RHS contains a const projection (aka uneval'ed const).
|
||||
// Since anon consts inherit the parent generics and predicates and we effectively
|
||||
// check them before and after instantiaton for well-formedness, the type alias
|
||||
// bounds are in every sense "enforced".
|
||||
// Note that the test cases whose name ends in "unused" just demonstrate that this
|
||||
// holds even if the const projections don't "visibly" capture any generics and/or
|
||||
// predicates.
|
||||
#![deny(type_alias_bounds)]
|
||||
|
||||
fn ct_unused_0() {
|
||||
type AliasConstUnused<T: Copy> = (T, I32<{ DATA }>);
|
||||
const DATA: i32 = 0;
|
||||
#[cfg(neg)]
|
||||
let _: AliasConstUnused<String>;
|
||||
//[neg]~^ ERROR the trait bound `String: Copy` is not satisfied
|
||||
}
|
||||
|
||||
fn ct_unused_1() {
|
||||
#[allow(trivial_bounds)]
|
||||
type AliasConstUnused where String: Copy = I32<{ 0; 0 }>;
|
||||
#[cfg(neg)]
|
||||
let _: AliasConstUnused;
|
||||
//[neg]~^ ERROR the trait bound `String: Copy` is not satisfied
|
||||
}
|
||||
|
||||
fn fn_unused() {
|
||||
type AliasFnUnused<T: Copy> = (T, I32<{ code() }>);
|
||||
const fn code() -> i32 { 0 }
|
||||
#[cfg(neg)]
|
||||
let _: AliasFnUnused<String>;
|
||||
//[neg]~^ ERROR the trait bound `String: Copy` is not satisfied
|
||||
}
|
||||
|
||||
trait Trait {
|
||||
type Proj;
|
||||
const DATA: i32;
|
||||
}
|
||||
|
||||
impl Trait for String {
|
||||
type Proj = i32;
|
||||
const DATA: i32 = 0;
|
||||
}
|
||||
|
||||
// Regression test for issue #94398.
|
||||
fn assoc_ct_used() {
|
||||
type AliasAssocConstUsed<T: Trait + Copy> = I32<{ T::DATA }>;
|
||||
#[cfg(neg)]
|
||||
let _: AliasAssocConstUsed<String>;
|
||||
//[neg]~^ ERROR the trait bound `String: Copy` is not satisfied
|
||||
}
|
||||
|
||||
fn fn_used() {
|
||||
type AliasFnUsed<T: Trait + Copy> = I32<{ code::<T>() }>;
|
||||
const fn code<T: Trait>() -> i32 { T::DATA }
|
||||
#[cfg(neg)]
|
||||
let _: AliasFnUsed<String>;
|
||||
//[neg]~^ ERROR the trait bound `String: Copy` is not satisfied
|
||||
}
|
||||
|
||||
struct I32<const N: i32>;
|
||||
|
||||
fn main() {}
|
Loading…
Add table
Reference in a new issue