mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-02 15:32:06 +00:00
Review changes
This commit is contained in:
parent
c920eb88b2
commit
2b151fd5c8
@ -2666,6 +2666,18 @@ pub struct Trait {
|
||||
/// a `where` keyword (`bool`). This is split out from `WhereClause`, since there
|
||||
/// are two locations for where clause on type aliases, but their predicates
|
||||
/// are concatenated together.
|
||||
///
|
||||
/// Take this example:
|
||||
/// ```rust, ignore
|
||||
/// trait Foo {
|
||||
/// type Assoc<'a, 'b> where Self: 'a, Self: 'b;
|
||||
/// }
|
||||
/// impl Foo for () {
|
||||
/// type Assoc<'a, 'b> where Self: 'a = () where Self: 'b;
|
||||
/// // ^^^^^^^^^^^^^^ first where clause
|
||||
/// // ^^^^^^^^^^^^^^ second where clause
|
||||
/// }
|
||||
/// ```
|
||||
#[derive(Copy, Clone, Encodable, Decodable, Debug, Default)]
|
||||
pub struct TyAliasWhereClause(pub bool, pub Span);
|
||||
|
||||
|
@ -1275,10 +1275,14 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
||||
}
|
||||
self.check_type_no_bounds(bounds, "this context");
|
||||
if where_clauses.1.0 {
|
||||
self.err_handler().span_err(
|
||||
let mut err = self.err_handler().struct_span_err(
|
||||
where_clauses.1.1,
|
||||
"where clauses are not allowed after the type for type aliases",
|
||||
)
|
||||
);
|
||||
err.note(
|
||||
"see issue #89122 <https://github.com/rust-lang/rust/issues/89122> for more information",
|
||||
);
|
||||
err.emit();
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
|
@ -819,12 +819,14 @@ pub trait LintContext: Sized {
|
||||
}
|
||||
},
|
||||
BuiltinLintDiagnostics::DeprecatedWhereclauseLocation(new_span, suggestion) => {
|
||||
db.span_suggestion(
|
||||
new_span,
|
||||
"move it here",
|
||||
suggestion,
|
||||
db.multipart_suggestion(
|
||||
"move it to the end of the type declaration",
|
||||
vec![(db.span.primary_span().unwrap(), "".to_string()), (new_span, suggestion)],
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
db.note(
|
||||
"see issue #89122 <https://github.com/rust-lang/rust/issues/89122> for more information",
|
||||
);
|
||||
},
|
||||
}
|
||||
// Rewrap `db`, and pass control to the user.
|
||||
|
30
src/test/ui/parser/type-alias-where-fixable.fixed
Normal file
30
src/test/ui/parser/type-alias-where-fixable.fixed
Normal file
@ -0,0 +1,30 @@
|
||||
// check-pass
|
||||
// run-rustfix
|
||||
|
||||
#![feature(generic_associated_types)]
|
||||
|
||||
trait Trait {
|
||||
// Fine.
|
||||
type Assoc where u32: Copy;
|
||||
// Fine.
|
||||
type Assoc2 where u32: Copy, i32: Copy;
|
||||
}
|
||||
|
||||
impl Trait for u32 {
|
||||
// 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
|
||||
}
|
||||
|
||||
impl Trait for i32 {
|
||||
// Fine.
|
||||
type Assoc = () where u32: Copy;
|
||||
// Not fine, suggests moving both.
|
||||
type Assoc2 = () where u32: Copy, i32: Copy;
|
||||
//~^ WARNING where clause not allowed here
|
||||
}
|
||||
|
||||
fn main() {}
|
30
src/test/ui/parser/type-alias-where-fixable.rs
Normal file
30
src/test/ui/parser/type-alias-where-fixable.rs
Normal file
@ -0,0 +1,30 @@
|
||||
// check-pass
|
||||
// run-rustfix
|
||||
|
||||
#![feature(generic_associated_types)]
|
||||
|
||||
trait Trait {
|
||||
// Fine.
|
||||
type Assoc where u32: Copy;
|
||||
// Fine.
|
||||
type Assoc2 where u32: Copy, i32: Copy;
|
||||
}
|
||||
|
||||
impl Trait for u32 {
|
||||
// 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
|
||||
}
|
||||
|
||||
impl Trait for i32 {
|
||||
// Fine.
|
||||
type Assoc = () where u32: Copy;
|
||||
// Not fine, suggests moving both.
|
||||
type Assoc2 where u32: Copy, i32: Copy = ();
|
||||
//~^ WARNING where clause not allowed here
|
||||
}
|
||||
|
||||
fn main() {}
|
42
src/test/ui/parser/type-alias-where-fixable.stderr
Normal file
42
src/test/ui/parser/type-alias-where-fixable.stderr
Normal file
@ -0,0 +1,42 @@
|
||||
warning: where clause not allowed here
|
||||
--> $DIR/type-alias-where-fixable.rs:15:16
|
||||
|
|
||||
LL | type Assoc where u32: Copy = ();
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(deprecated_where_clause_location)]` on by default
|
||||
= 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 Assoc where u32: Copy = ();
|
||||
LL + type Assoc = () where u32: Copy;
|
||||
|
|
||||
|
||||
warning: where clause not allowed here
|
||||
--> $DIR/type-alias-where-fixable.rs:18: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: where clause not allowed here
|
||||
--> $DIR/type-alias-where-fixable.rs:26:17
|
||||
|
|
||||
LL | type Assoc2 where u32: Copy, 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, i32: Copy = ();
|
||||
LL + type Assoc2 = () where u32: Copy, i32: Copy;
|
||||
|
|
||||
|
||||
warning: 3 warnings emitted
|
||||
|
@ -10,28 +10,4 @@ type Bar = () where u32: Copy;
|
||||
type Baz = () where;
|
||||
//~^ ERROR where clauses are not allowed
|
||||
|
||||
trait Trait {
|
||||
// Fine.
|
||||
type Assoc where u32: Copy;
|
||||
// Fine.
|
||||
type Assoc2 where u32: Copy, i32: Copy;
|
||||
}
|
||||
|
||||
impl Trait for u32 {
|
||||
// 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
|
||||
}
|
||||
|
||||
impl Trait for i32 {
|
||||
// Fine.
|
||||
type Assoc = () where u32: Copy;
|
||||
// Not fine, suggests moving both.
|
||||
type Assoc2 where u32: Copy, i32: Copy = ();
|
||||
//~^ WARNING where clause not allowed here
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
@ -3,32 +3,16 @@ error: where clauses are not allowed after the type for type aliases
|
||||
|
|
||||
LL | type Bar = () where u32: Copy;
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #89122 <https://github.com/rust-lang/rust/issues/89122> for more information
|
||||
|
||||
error: where clauses are not allowed after the type for type aliases
|
||||
--> $DIR/type-alias-where.rs:10:15
|
||||
|
|
||||
LL | type Baz = () where;
|
||||
| ^^^^^
|
||||
|
||||
warning: where clause not allowed here
|
||||
--> $DIR/type-alias-where.rs:22:16
|
||||
|
|
||||
LL | type Assoc where u32: Copy = ();
|
||||
| ^^^^^^^^^^^^^^^ - help: move it here: `where u32: Copy`
|
||||
|
|
||||
= note: `#[warn(deprecated_where_clause_location)]` on by default
|
||||
= note: see issue #89122 <https://github.com/rust-lang/rust/issues/89122> for more information
|
||||
|
||||
warning: where clause not allowed here
|
||||
--> $DIR/type-alias-where.rs:25:17
|
||||
|
|
||||
LL | type Assoc2 where u32: Copy = () where i32: Copy;
|
||||
| ^^^^^^^^^^^^^^^ - help: move it here: `, u32: Copy`
|
||||
|
||||
warning: where clause not allowed here
|
||||
--> $DIR/type-alias-where.rs:33:17
|
||||
|
|
||||
LL | type Assoc2 where u32: Copy, i32: Copy = ();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ - help: move it here: `where u32: Copy, i32: Copy`
|
||||
|
||||
error: aborting due to 2 previous errors; 3 warnings emitted
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user