Skip to content

Commit 2b151fd

Browse files
committed
Review changes
1 parent c920eb8 commit 2b151fd

File tree

8 files changed

+130
-50
lines changed

8 files changed

+130
-50
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2666,6 +2666,18 @@ pub struct Trait {
26662666
/// a `where` keyword (`bool`). This is split out from `WhereClause`, since there
26672667
/// are two locations for where clause on type aliases, but their predicates
26682668
/// are concatenated together.
2669+
///
2670+
/// Take this example:
2671+
/// ```rust, ignore
2672+
/// trait Foo {
2673+
/// type Assoc<'a, 'b> where Self: 'a, Self: 'b;
2674+
/// }
2675+
/// impl Foo for () {
2676+
/// type Assoc<'a, 'b> where Self: 'a = () where Self: 'b;
2677+
/// // ^^^^^^^^^^^^^^ first where clause
2678+
/// // ^^^^^^^^^^^^^^ second where clause
2679+
/// }
2680+
/// ```
26692681
#[derive(Copy, Clone, Encodable, Decodable, Debug, Default)]
26702682
pub struct TyAliasWhereClause(pub bool, pub Span);
26712683

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,10 +1275,14 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
12751275
}
12761276
self.check_type_no_bounds(bounds, "this context");
12771277
if where_clauses.1.0 {
1278-
self.err_handler().span_err(
1278+
let mut err = self.err_handler().struct_span_err(
12791279
where_clauses.1.1,
12801280
"where clauses are not allowed after the type for type aliases",
1281-
)
1281+
);
1282+
err.note(
1283+
"see issue #89122 <https://github.com/rust-lang/rust/issues/89122> for more information",
1284+
);
1285+
err.emit();
12821286
}
12831287
}
12841288
_ => {}

compiler/rustc_lint/src/context.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -819,12 +819,14 @@ pub trait LintContext: Sized {
819819
}
820820
},
821821
BuiltinLintDiagnostics::DeprecatedWhereclauseLocation(new_span, suggestion) => {
822-
db.span_suggestion(
823-
new_span,
824-
"move it here",
825-
suggestion,
822+
db.multipart_suggestion(
823+
"move it to the end of the type declaration",
824+
vec![(db.span.primary_span().unwrap(), "".to_string()), (new_span, suggestion)],
826825
Applicability::MachineApplicable,
827826
);
827+
db.note(
828+
"see issue #89122 <https://github.com/rust-lang/rust/issues/89122> for more information",
829+
);
828830
},
829831
}
830832
// Rewrap `db`, and pass control to the user.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// check-pass
2+
// run-rustfix
3+
4+
#![feature(generic_associated_types)]
5+
6+
trait Trait {
7+
// Fine.
8+
type Assoc where u32: Copy;
9+
// Fine.
10+
type Assoc2 where u32: Copy, i32: Copy;
11+
}
12+
13+
impl Trait for u32 {
14+
// Not fine, suggests moving.
15+
type Assoc = () where u32: Copy;
16+
//~^ WARNING where clause not allowed here
17+
// Not fine, suggests moving `u32: Copy`
18+
type Assoc2 = () where i32: Copy, u32: Copy;
19+
//~^ WARNING where clause not allowed here
20+
}
21+
22+
impl Trait for i32 {
23+
// Fine.
24+
type Assoc = () where u32: Copy;
25+
// Not fine, suggests moving both.
26+
type Assoc2 = () where u32: Copy, i32: Copy;
27+
//~^ WARNING where clause not allowed here
28+
}
29+
30+
fn main() {}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// check-pass
2+
// run-rustfix
3+
4+
#![feature(generic_associated_types)]
5+
6+
trait Trait {
7+
// Fine.
8+
type Assoc where u32: Copy;
9+
// Fine.
10+
type Assoc2 where u32: Copy, i32: Copy;
11+
}
12+
13+
impl Trait for u32 {
14+
// Not fine, suggests moving.
15+
type Assoc where u32: Copy = ();
16+
//~^ WARNING where clause not allowed here
17+
// Not fine, suggests moving `u32: Copy`
18+
type Assoc2 where u32: Copy = () where i32: Copy;
19+
//~^ WARNING where clause not allowed here
20+
}
21+
22+
impl Trait for i32 {
23+
// Fine.
24+
type Assoc = () where u32: Copy;
25+
// Not fine, suggests moving both.
26+
type Assoc2 where u32: Copy, i32: Copy = ();
27+
//~^ WARNING where clause not allowed here
28+
}
29+
30+
fn main() {}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
warning: where clause not allowed here
2+
--> $DIR/type-alias-where-fixable.rs:15:16
3+
|
4+
LL | type Assoc where u32: Copy = ();
5+
| ^^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(deprecated_where_clause_location)]` on by default
8+
= note: see issue #89122 <https://github.com/rust-lang/rust/issues/89122> for more information
9+
help: move it to the end of the type declaration
10+
|
11+
LL - type Assoc where u32: Copy = ();
12+
LL + type Assoc = () where u32: Copy;
13+
|
14+
15+
warning: where clause not allowed here
16+
--> $DIR/type-alias-where-fixable.rs:18:17
17+
|
18+
LL | type Assoc2 where u32: Copy = () where i32: Copy;
19+
| ^^^^^^^^^^^^^^^
20+
|
21+
= note: see issue #89122 <https://github.com/rust-lang/rust/issues/89122> for more information
22+
help: move it to the end of the type declaration
23+
|
24+
LL - type Assoc2 where u32: Copy = () where i32: Copy;
25+
LL + type Assoc2 = () where i32: Copy, u32: Copy;
26+
|
27+
28+
warning: where clause not allowed here
29+
--> $DIR/type-alias-where-fixable.rs:26:17
30+
|
31+
LL | type Assoc2 where u32: Copy, i32: Copy = ();
32+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
33+
|
34+
= note: see issue #89122 <https://github.com/rust-lang/rust/issues/89122> for more information
35+
help: move it to the end of the type declaration
36+
|
37+
LL - type Assoc2 where u32: Copy, i32: Copy = ();
38+
LL + type Assoc2 = () where u32: Copy, i32: Copy;
39+
|
40+
41+
warning: 3 warnings emitted
42+

src/test/ui/parser/type-alias-where.rs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,4 @@ type Bar = () where u32: Copy;
1010
type Baz = () where;
1111
//~^ ERROR where clauses are not allowed
1212

13-
trait Trait {
14-
// Fine.
15-
type Assoc where u32: Copy;
16-
// Fine.
17-
type Assoc2 where u32: Copy, i32: Copy;
18-
}
19-
20-
impl Trait for u32 {
21-
// Not fine, suggests moving.
22-
type Assoc where u32: Copy = ();
23-
//~^ WARNING where clause not allowed here
24-
// Not fine, suggests moving `u32: Copy`
25-
type Assoc2 where u32: Copy = () where i32: Copy;
26-
//~^ WARNING where clause not allowed here
27-
}
28-
29-
impl Trait for i32 {
30-
// Fine.
31-
type Assoc = () where u32: Copy;
32-
// Not fine, suggests moving both.
33-
type Assoc2 where u32: Copy, i32: Copy = ();
34-
//~^ WARNING where clause not allowed here
35-
}
36-
3713
fn main() {}

src/test/ui/parser/type-alias-where.stderr

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,16 @@ error: where clauses are not allowed after the type for type aliases
33
|
44
LL | type Bar = () where u32: Copy;
55
| ^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #89122 <https://github.com/rust-lang/rust/issues/89122> for more information
68

79
error: where clauses are not allowed after the type for type aliases
810
--> $DIR/type-alias-where.rs:10:15
911
|
1012
LL | type Baz = () where;
1113
| ^^^^^
12-
13-
warning: where clause not allowed here
14-
--> $DIR/type-alias-where.rs:22:16
15-
|
16-
LL | type Assoc where u32: Copy = ();
17-
| ^^^^^^^^^^^^^^^ - help: move it here: `where u32: Copy`
18-
|
19-
= note: `#[warn(deprecated_where_clause_location)]` on by default
20-
21-
warning: where clause not allowed here
22-
--> $DIR/type-alias-where.rs:25:17
23-
|
24-
LL | type Assoc2 where u32: Copy = () where i32: Copy;
25-
| ^^^^^^^^^^^^^^^ - help: move it here: `, u32: Copy`
26-
27-
warning: where clause not allowed here
28-
--> $DIR/type-alias-where.rs:33:17
2914
|
30-
LL | type Assoc2 where u32: Copy, i32: Copy = ();
31-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ - help: move it here: `where u32: Copy, i32: Copy`
15+
= note: see issue #89122 <https://github.com/rust-lang/rust/issues/89122> for more information
3216

33-
error: aborting due to 2 previous errors; 3 warnings emitted
17+
error: aborting due to 2 previous errors
3418

0 commit comments

Comments
 (0)