Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,19 @@ impl<'a> AstValidator<'a> {
{
let mut state = State::new();

let mut needs_comma = !ty_alias.after_where_clause.predicates.is_empty();
if !ty_alias.after_where_clause.has_where_token {
state.space();
state.word_space("where");
} else if !needs_comma {
state.space();
}

let mut first = ty_alias.after_where_clause.predicates.is_empty();
for p in &ty_alias.generics.where_clause.predicates {
if !first {
if needs_comma {
state.word_space(",");
}
first = false;
needs_comma = true;
state.print_where_predicate(p);
}

Expand Down Expand Up @@ -1832,7 +1834,11 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
Some((right, snippet))
}
};
let left_sp = err.span;
let left_sp = self
.sess
.source_map()
.span_extend_prev_while(err.span, char::is_whitespace)
.unwrap_or(err.span);
self.lint_buffer.dyn_buffer_lint(
DEPRECATED_WHERE_CLAUSE_LOCATION,
item.id,
Expand All @@ -1846,9 +1852,9 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
sugg,
}
}
None => {
errors::DeprecatedWhereClauseLocationSugg::RemoveWhere { span: left_sp }
}
None => errors::DeprecatedWhereClauseLocationSugg::RemoveWhere {
span: err.span,
},
};
errors::DeprecatedWhereClauseLocation { suggestion }.into_diag(dcx, level)
},
Expand Down
17 changes: 17 additions & 0 deletions tests/ui/where-clauses/alias-type-where-suggest-issue-153567.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//@ check-pass
//@ run-rustfix
//@ compile-flags: --force-warn deprecated_where_clause_location


#![allow(dead_code)]

trait Trait {
type Assoc;
}

impl Trait for i32 {
type Assoc = () where i32: Copy;
//~^ WARNING where clause not allowed here
}

fn main() {}
17 changes: 17 additions & 0 deletions tests/ui/where-clauses/alias-type-where-suggest-issue-153567.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//@ check-pass
//@ run-rustfix
//@ compile-flags: --force-warn deprecated_where_clause_location


#![allow(dead_code)]

trait Trait {
type Assoc;
}

impl Trait for i32 {
type Assoc where i32: Copy = () where;
//~^ WARNING where clause not allowed here
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
warning: where clause not allowed here
--> $DIR/alias-type-where-suggest-issue-153567.rs:13:16
|
LL | type Assoc where i32: Copy = () where;
| ^^^^^^^^^^^^^^^
|
= note: see issue #89122 <https://github.com/rust-lang/rust/issues/89122> for more information
= note: requested on the command line with `--force-warn deprecated-where-clause-location`
help: move it to the end of the type declaration
|
LL - type Assoc where i32: Copy = () where;
LL + type Assoc = () where i32: Copy;
|

warning: 1 warning emitted

Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ trait Trait {

impl Trait for u32 {
// Not fine, suggests moving.
type Assoc = () where u32: Copy;
type Assoc = () where u32: Copy;
//~^ WARNING where clause not allowed here
// Not fine, suggests moving `u32: Copy`
type Assoc2 = () where i32: Copy, u32: Copy;
type Assoc2 = () where i32: Copy, u32: Copy;
//~^ WARNING where clause not allowed here
type Assoc3 = () where;
type Assoc3 = () where;
//~^ 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;
type Assoc2 = () where u32: Copy, i32: Copy;
//~^ WARNING where clause not allowed here
type Assoc3 = () where;
//~^ WARNING where clause not allowed here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ LL | type Assoc where u32: Copy = ();
help: move it to the end of the type declaration
|
LL - type Assoc where u32: Copy = ();
LL + type Assoc = () where u32: Copy;
LL + type Assoc = () where u32: Copy;
|

warning: where clause not allowed here
Expand All @@ -22,7 +22,7 @@ LL | type Assoc2 where u32: Copy = () where i32: Copy;
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;
LL + type Assoc2 = () where i32: Copy, u32: Copy;
|

warning: where clause not allowed here
Expand All @@ -35,7 +35,7 @@ LL | type Assoc3 where = ();
help: move it to the end of the type declaration
|
LL - type Assoc3 where = ();
LL + type Assoc3 = () where;
LL + type Assoc3 = () where;
|

warning: where clause not allowed here
Expand All @@ -48,7 +48,7 @@ LL | type Assoc2 where u32: Copy, i32: Copy = ();
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;
LL + type Assoc2 = () where u32: Copy, i32: Copy;
|

warning: where clause not allowed here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

trait Trait {
// Not fine, suggests moving.
type Assoc = () where u32: Copy;
type Assoc = () where u32: Copy;
//~^ WARNING where clause not allowed here
// Not fine, suggests moving `u32: Copy`
type Assoc2 = () where i32: Copy, u32: Copy;
type Assoc2 = () where i32: Copy, u32: Copy;
//~^ WARNING where clause not allowed here
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ LL | type Assoc where u32: Copy = ();
help: move it to the end of the type declaration
|
LL - type Assoc where u32: Copy = ();
LL + type Assoc = () where u32: Copy;
LL + type Assoc = () where u32: Copy;
|

warning: where clause not allowed here
Expand All @@ -22,7 +22,7 @@ LL | type Assoc2 where u32: Copy = () where i32: Copy;
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;
LL + type Assoc2 = () where i32: Copy, u32: Copy;
|

warning: 2 warnings emitted
Expand Down
Loading