forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#113560 - fmease:assoc-tys-in-traits-depr-wc…
…-loc, r=compiler-errors Lint against misplaced where-clauses on associated types in traits Extends the scope of the lint `deprecated_where_clause_location` (rust-lang#89122) from associated types in impls to associated types in any location (impl or trait). This is only relevant for `#![feature(associated_type_defaults)]`. Previously we didn't warn on the following code for example: ```rs #![feature(associated_type_defaults)] trait Trait { type Assoc where u32: Copy = (); } ``` Personally I would've preferred to emit a *hard* error here instead of a lint warning since the feature is unstable but unfortunately we are constrained by back compat as associated type defaults won't necessarily trigger the feature-gate error if they are inside of a macro call (since they use a post-expansion feature-gate due to historical reasons, see also rust-lang#66004). I've renamed and moved related preexisting tests: 1. They test AST validation passes not the parser & thus shouldn't live in `parser/` (historical reasons?). 2. One test file was named after type aliases even though it tests assoc tys. `@rustbot` label A-lint
- Loading branch information
Showing
10 changed files
with
81 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
tests/ui/where-clauses/where-clause-placement-assoc-type-in-trait.fixed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// check-pass | ||
// run-rustfix | ||
|
||
#![feature(associated_type_defaults)] | ||
|
||
trait Trait { | ||
// Not fine, suggests moving. | ||
type Assoc = () where u32: Copy; | ||
//~^ WARNING where clause not allowed here | ||
// Not fine, suggests moving `u32: Copy` | ||
type Assoc2 = () where i32: Copy, u32: Copy; | ||
//~^ WARNING where clause not allowed here | ||
} | ||
|
||
fn main() {} |
15 changes: 15 additions & 0 deletions
15
tests/ui/where-clauses/where-clause-placement-assoc-type-in-trait.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// check-pass | ||
// run-rustfix | ||
|
||
#![feature(associated_type_defaults)] | ||
|
||
trait Trait { | ||
// Not fine, suggests moving. | ||
type Assoc where u32: Copy = (); | ||
//~^ WARNING where clause not allowed here | ||
// Not fine, suggests moving `u32: Copy` | ||
type Assoc2 where u32: Copy = () where i32: Copy; | ||
//~^ WARNING where clause not allowed here | ||
} | ||
|
||
fn main() {} |
29 changes: 29 additions & 0 deletions
29
tests/ui/where-clauses/where-clause-placement-assoc-type-in-trait.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
warning: where clause not allowed here | ||
--> $DIR/where-clause-placement-assoc-type-in-trait.rs:8:16 | ||
| | ||
LL | type Assoc where u32: Copy = (); | ||
| ^^^^^^^^^^^^^^^ | ||
| | ||
= note: see issue #89122 <https://github.com/rust-lang/rust/issues/89122> for more information | ||
= note: `#[warn(deprecated_where_clause_location)]` on by default | ||
help: move it to the end of the type declaration | ||
| | ||
LL - type Assoc where u32: Copy = (); | ||
LL + type Assoc = () where u32: Copy; | ||
| | ||
|
||
warning: where clause not allowed here | ||
--> $DIR/where-clause-placement-assoc-type-in-trait.rs:11:17 | ||
| | ||
LL | type Assoc2 where u32: Copy = () where i32: Copy; | ||
| ^^^^^^^^^^^^^^^ | ||
| | ||
= 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 Assoc2 where u32: Copy = () where i32: Copy; | ||
LL + type Assoc2 = () where i32: Copy, u32: Copy; | ||
| | ||
|
||
warning: 2 warnings emitted | ||
|
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
tests/ui/parser/type-alias-where.stderr → .../where-clause-placement-type-alias.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters