Rollup merge of #121326 - fmease:detect-empty-leading-where-clauses-on-ty-aliases, r=compiler-errors
Detect empty leading where clauses on type aliases
1. commit: refactor the AST of type alias where clauses
* I could no longer bear the look of `.0.1` and `.1.0`
* Arguably moving `split` out of `TyAlias` into a substruct might not make that much sense from a semantic standpoint since it reprs an index into `TyAlias.predicates` but it's alright and it cleans up the usage sites of `TyAlias`
2. commit: fix an oversight: An empty leading where clause is still a leading where clause
* semantically reject empty leading where clauses on lazy type aliases
* e.g., on `#![feature(lazy_type_alias)] type X where = ();`
* make empty leading where clauses on assoc types trigger lint `deprecated_where_clause_location`
* e.g., `impl Trait for () { type X where = (); }`
This commit is contained in:
commit
dd4ecd1cf4
18 changed files with 248 additions and 150 deletions
|
|
@ -2,14 +2,22 @@
|
|||
|
||||
#![feature(lazy_type_alias)]
|
||||
#![allow(incomplete_features)]
|
||||
#![crate_type = "lib"]
|
||||
|
||||
// Check that we *reject* leading where-clauses on lazy type aliases.
|
||||
|
||||
type Alias<T>
|
||||
pub type Leading0<T>
|
||||
|
||||
= T where String: From<T>;
|
||||
//~^^^ ERROR where clauses are not allowed before the type for type aliases
|
||||
|
||||
fn main() {
|
||||
let _: Alias<&str>;
|
||||
}
|
||||
pub type Leading1<T, U>
|
||||
|
||||
= (T, U)
|
||||
where
|
||||
U: Copy, String: From<T>;
|
||||
|
||||
pub type EmptyLeading0 = () where;
|
||||
//~^ ERROR where clauses are not allowed before the type for type aliases
|
||||
|
||||
pub type EmptyLeading1<T> = T where T: Copy;
|
||||
//~^ ERROR where clauses are not allowed before the type for type aliases
|
||||
|
|
|
|||
|
|
@ -2,15 +2,24 @@
|
|||
|
||||
#![feature(lazy_type_alias)]
|
||||
#![allow(incomplete_features)]
|
||||
#![crate_type = "lib"]
|
||||
|
||||
// Check that we *reject* leading where-clauses on lazy type aliases.
|
||||
|
||||
type Alias<T>
|
||||
where
|
||||
pub type Leading0<T>
|
||||
where //~ ERROR where clauses are not allowed before the type for type aliases
|
||||
String: From<T>,
|
||||
= T;
|
||||
//~^^^ ERROR where clauses are not allowed before the type for type aliases
|
||||
|
||||
fn main() {
|
||||
let _: Alias<&str>;
|
||||
}
|
||||
pub type Leading1<T, U>
|
||||
where //~ ERROR where clauses are not allowed before the type for type aliases
|
||||
String: From<T>,
|
||||
= (T, U)
|
||||
where
|
||||
U: Copy;
|
||||
|
||||
pub type EmptyLeading0 where = ();
|
||||
//~^ ERROR where clauses are not allowed before the type for type aliases
|
||||
|
||||
pub type EmptyLeading1<T> where = T where T: Copy;
|
||||
//~^ ERROR where clauses are not allowed before the type for type aliases
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: where clauses are not allowed before the type for type aliases
|
||||
--> $DIR/leading-where-clause.rs:9:1
|
||||
--> $DIR/leading-where-clause.rs:10:1
|
||||
|
|
||||
LL | / where
|
||||
LL | | String: From<T>,
|
||||
|
|
@ -12,5 +12,42 @@ LL +
|
|||
LL ~ = T where String: From<T>;
|
||||
|
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
error: where clauses are not allowed before the type for type aliases
|
||||
--> $DIR/leading-where-clause.rs:15:1
|
||||
|
|
||||
LL | / where
|
||||
LL | | String: From<T>,
|
||||
| |____________________^
|
||||
|
|
||||
= note: see issue #89122 <https://github.com/rust-lang/rust/issues/89122> for more information
|
||||
help: move it to the end of the type declaration
|
||||
|
|
||||
LL +
|
||||
LL | = (T, U)
|
||||
LL | where
|
||||
LL ~ U: Copy, String: From<T>;
|
||||
|
|
||||
|
||||
error: where clauses are not allowed before the type for type aliases
|
||||
--> $DIR/leading-where-clause.rs:21:24
|
||||
|
|
||||
LL | pub type EmptyLeading0 where = ();
|
||||
| ^^^^^
|
||||
|
|
||||
= note: see issue #89122 <https://github.com/rust-lang/rust/issues/89122> for more information
|
||||
help: move it to the end of the type declaration
|
||||
|
|
||||
LL - pub type EmptyLeading0 where = ();
|
||||
LL + pub type EmptyLeading0 = () where;
|
||||
|
|
||||
|
||||
error: where clauses are not allowed before the type for type aliases
|
||||
--> $DIR/leading-where-clause.rs:24:27
|
||||
|
|
||||
LL | pub type EmptyLeading1<T> where = T where T: Copy;
|
||||
| ^^^^^ help: remove this `where`
|
||||
|
|
||||
= note: see issue #89122 <https://github.com/rust-lang/rust/issues/89122> for more information
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ trait Trait {
|
|||
type Assoc where u32: Copy;
|
||||
// Fine.
|
||||
type Assoc2 where u32: Copy, i32: Copy;
|
||||
//
|
||||
type Assoc3;
|
||||
}
|
||||
|
||||
impl Trait for u32 {
|
||||
|
|
@ -17,6 +19,8 @@ impl Trait for u32 {
|
|||
// Not fine, suggests moving `u32: Copy`
|
||||
type Assoc2 = () where i32: Copy, u32: Copy;
|
||||
//~^ WARNING where clause not allowed here
|
||||
type Assoc3 = () where;
|
||||
//~^ WARNING where clause not allowed here
|
||||
}
|
||||
|
||||
impl Trait for i32 {
|
||||
|
|
@ -25,6 +29,8 @@ impl Trait for i32 {
|
|||
// Not fine, suggests moving both.
|
||||
type Assoc2 = () where u32: Copy, i32: Copy;
|
||||
//~^ WARNING where clause not allowed here
|
||||
type Assoc3 = () where;
|
||||
//~^ WARNING where clause not allowed here
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ trait Trait {
|
|||
type Assoc where u32: Copy;
|
||||
// Fine.
|
||||
type Assoc2 where u32: Copy, i32: Copy;
|
||||
//
|
||||
type Assoc3;
|
||||
}
|
||||
|
||||
impl Trait for u32 {
|
||||
|
|
@ -17,6 +19,8 @@ impl Trait for u32 {
|
|||
// Not fine, suggests moving `u32: Copy`
|
||||
type Assoc2 where u32: Copy = () where i32: Copy;
|
||||
//~^ WARNING where clause not allowed here
|
||||
type Assoc3 where = ();
|
||||
//~^ WARNING where clause not allowed here
|
||||
}
|
||||
|
||||
impl Trait for i32 {
|
||||
|
|
@ -25,6 +29,8 @@ impl Trait for i32 {
|
|||
// Not fine, suggests moving both.
|
||||
type Assoc2 where u32: Copy, i32: Copy = ();
|
||||
//~^ WARNING where clause not allowed here
|
||||
type Assoc3 where = () where;
|
||||
//~^ WARNING where clause not allowed here
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
warning: where clause not allowed here
|
||||
--> $DIR/where-clause-placement-assoc-type-in-impl.rs:15:16
|
||||
--> $DIR/where-clause-placement-assoc-type-in-impl.rs:17:16
|
||||
|
|
||||
LL | type Assoc where u32: Copy = ();
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
|
@ -13,7 +13,7 @@ LL + type Assoc = () where u32: Copy;
|
|||
|
|
||||
|
||||
warning: where clause not allowed here
|
||||
--> $DIR/where-clause-placement-assoc-type-in-impl.rs:18:17
|
||||
--> $DIR/where-clause-placement-assoc-type-in-impl.rs:20:17
|
||||
|
|
||||
LL | type Assoc2 where u32: Copy = () where i32: Copy;
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
|
@ -26,7 +26,20 @@ LL + type Assoc2 = () where i32: Copy, u32: Copy;
|
|||
|
|
||||
|
||||
warning: where clause not allowed here
|
||||
--> $DIR/where-clause-placement-assoc-type-in-impl.rs:26:17
|
||||
--> $DIR/where-clause-placement-assoc-type-in-impl.rs:22:17
|
||||
|
|
||||
LL | type Assoc3 where = ();
|
||||
| ^^^^^
|
||||
|
|
||||
= note: see issue #89122 <https://github.com/rust-lang/rust/issues/89122> for more information
|
||||
help: move it to the end of the type declaration
|
||||
|
|
||||
LL - type Assoc3 where = ();
|
||||
LL + type Assoc3 = () where;
|
||||
|
|
||||
|
||||
warning: where clause not allowed here
|
||||
--> $DIR/where-clause-placement-assoc-type-in-impl.rs:30:17
|
||||
|
|
||||
LL | type Assoc2 where u32: Copy, i32: Copy = ();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
@ -38,5 +51,13 @@ LL - type Assoc2 where u32: Copy, i32: Copy = ();
|
|||
LL + type Assoc2 = () where u32: Copy, i32: Copy;
|
||||
|
|
||||
|
||||
warning: 3 warnings emitted
|
||||
warning: where clause not allowed here
|
||||
--> $DIR/where-clause-placement-assoc-type-in-impl.rs:32:17
|
||||
|
|
||||
LL | type Assoc3 where = () where;
|
||||
| ^^^^^ help: remove this `where`
|
||||
|
|
||||
= note: see issue #89122 <https://github.com/rust-lang/rust/issues/89122> for more information
|
||||
|
||||
warning: 5 warnings emitted
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue