1
Fork 0

Check lazy type aliases for well-formedness

This commit is contained in:
León Orell Valerian Liehr 2023-07-30 01:46:20 +02:00
parent 2e0136a131
commit 0ca432844c
No known key found for this signature in database
GPG key ID: D17A07215F68E713
8 changed files with 55 additions and 11 deletions

View file

@ -0,0 +1,18 @@
// Regression test for issue #113736.
// check-pass
#![feature(lazy_type_alias)]
//~^ WARN the feature `lazy_type_alias` is incomplete and may not be safe to use
enum Enum {
Unit,
Tuple(),
Struct {},
}
fn main() {
type Alias = Enum;
let _ = Alias::Unit;
let _ = Alias::Tuple();
let _ = Alias::Struct {};
}

View file

@ -0,0 +1,11 @@
warning: the feature `lazy_type_alias` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/enum-variant.rs:4:12
|
LL | #![feature(lazy_type_alias)]
| ^^^^^^^^^^^^^^^
|
= note: see issue #112792 <https://github.com/rust-lang/rust/issues/112792> for more information
= note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted

View file

@ -0,0 +1,14 @@
// Check that we don't issue the lint `type_alias_bounds` for
// lazy type aliases since the bounds are indeed enforced.
// check-pass
#![feature(lazy_type_alias)]
#![allow(incomplete_features)]
#![deny(type_alias_bounds)]
use std::ops::Mul;
type Alias<T: Mul> = <T as Mul>::Output;
fn main() {}

View file

@ -0,0 +1,8 @@
// Test that we check lazy type aliases for well-formedness.
#![feature(lazy_type_alias)]
#![allow(incomplete_features)]
type Alias<T> = <T as std::ops::Mul>::Output; //~ ERROR cannot multiply `T` by `T`
fn main() {}

View file

@ -0,0 +1,14 @@
error[E0277]: cannot multiply `T` by `T`
--> $DIR/unsatisfied-bounds-type-alias-body.rs:6:17
|
LL | type Alias<T> = <T as std::ops::Mul>::Output;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `T * T`
|
help: consider restricting type parameter `T`
|
LL | type Alias<T: std::ops::Mul> = <T as std::ops::Mul>::Output;
| +++++++++++++++
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.