Change to lint
This commit is contained in:
parent
c20b4f5584
commit
3f504f6984
8 changed files with 75 additions and 21 deletions
|
@ -15,7 +15,9 @@ use rustc_ast_pretty::pprust::{self, State};
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_errors::{error_code, pluralize, struct_span_err, Applicability};
|
use rustc_errors::{error_code, pluralize, struct_span_err, Applicability};
|
||||||
use rustc_parse::validate_attr;
|
use rustc_parse::validate_attr;
|
||||||
use rustc_session::lint::builtin::{MISSING_ABI, PATTERNS_IN_FNS_WITHOUT_BODY};
|
use rustc_session::lint::builtin::{
|
||||||
|
DEPRECATED_WHERE_CLAUSE_LOCATION, MISSING_ABI, PATTERNS_IN_FNS_WITHOUT_BODY,
|
||||||
|
};
|
||||||
use rustc_session::lint::{BuiltinLintDiagnostics, LintBuffer};
|
use rustc_session::lint::{BuiltinLintDiagnostics, LintBuffer};
|
||||||
use rustc_session::Session;
|
use rustc_session::Session;
|
||||||
use rustc_span::source_map::Spanned;
|
use rustc_span::source_map::Spanned;
|
||||||
|
@ -123,11 +125,11 @@ impl<'a> AstValidator<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_gat_where(
|
fn check_gat_where(
|
||||||
&self,
|
&mut self,
|
||||||
|
id: NodeId,
|
||||||
before_predicates: &[WherePredicate],
|
before_predicates: &[WherePredicate],
|
||||||
where_clauses: (ast::TyAliasWhereClause, ast::TyAliasWhereClause),
|
where_clauses: (ast::TyAliasWhereClause, ast::TyAliasWhereClause),
|
||||||
) {
|
) {
|
||||||
let sess = &self.session;
|
|
||||||
if !before_predicates.is_empty() {
|
if !before_predicates.is_empty() {
|
||||||
let mut state = State::new();
|
let mut state = State::new();
|
||||||
if !where_clauses.1.0 {
|
if !where_clauses.1.0 {
|
||||||
|
@ -145,14 +147,16 @@ impl<'a> AstValidator<'a> {
|
||||||
state.print_where_predicate(p);
|
state.print_where_predicate(p);
|
||||||
}
|
}
|
||||||
let suggestion = state.s.eof();
|
let suggestion = state.s.eof();
|
||||||
sess.struct_span_err(where_clauses.0.1, "where clause not allowed here")
|
self.lint_buffer.buffer_lint_with_diagnostic(
|
||||||
.span_suggestion(
|
DEPRECATED_WHERE_CLAUSE_LOCATION,
|
||||||
|
id,
|
||||||
|
where_clauses.0.1,
|
||||||
|
"where clause not allowed here",
|
||||||
|
BuiltinLintDiagnostics::DeprecatedWhereclauseLocation(
|
||||||
where_clauses.1.1.shrink_to_hi(),
|
where_clauses.1.1.shrink_to_hi(),
|
||||||
"move it here",
|
|
||||||
suggestion,
|
suggestion,
|
||||||
Applicability::MachineApplicable,
|
),
|
||||||
)
|
);
|
||||||
.emit();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1568,6 +1572,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
||||||
self.check_type_no_bounds(bounds, "`impl`s");
|
self.check_type_no_bounds(bounds, "`impl`s");
|
||||||
if ty.is_some() {
|
if ty.is_some() {
|
||||||
self.check_gat_where(
|
self.check_gat_where(
|
||||||
|
item.id,
|
||||||
generics.where_clause.predicates.split_at(*where_predicates_split).0,
|
generics.where_clause.predicates.split_at(*where_predicates_split).0,
|
||||||
*where_clauses,
|
*where_clauses,
|
||||||
);
|
);
|
||||||
|
|
|
@ -818,6 +818,14 @@ pub trait LintContext: Sized {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
BuiltinLintDiagnostics::DeprecatedWhereclauseLocation(new_span, suggestion) => {
|
||||||
|
db.span_suggestion(
|
||||||
|
new_span,
|
||||||
|
"move it here",
|
||||||
|
suggestion,
|
||||||
|
Applicability::MachineApplicable,
|
||||||
|
);
|
||||||
|
},
|
||||||
}
|
}
|
||||||
// Rewrap `db`, and pass control to the user.
|
// Rewrap `db`, and pass control to the user.
|
||||||
decorate(LintDiagnosticBuilder::new(db));
|
decorate(LintDiagnosticBuilder::new(db));
|
||||||
|
|
|
@ -3127,6 +3127,7 @@ declare_lint_pass! {
|
||||||
DUPLICATE_MACRO_ATTRIBUTES,
|
DUPLICATE_MACRO_ATTRIBUTES,
|
||||||
SUSPICIOUS_AUTO_TRAIT_IMPLS,
|
SUSPICIOUS_AUTO_TRAIT_IMPLS,
|
||||||
UNEXPECTED_CFGS,
|
UNEXPECTED_CFGS,
|
||||||
|
DEPRECATED_WHERE_CLAUSE_LOCATION,
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3737,3 +3738,36 @@ declare_lint! {
|
||||||
reference: "issue #93367 <https://github.com/rust-lang/rust/issues/93367>",
|
reference: "issue #93367 <https://github.com/rust-lang/rust/issues/93367>",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
declare_lint! {
|
||||||
|
/// The `deprecated_where_clause_location` lint detects when a where clause in front of the equals
|
||||||
|
/// in an associated type.
|
||||||
|
///
|
||||||
|
/// ### Example
|
||||||
|
///
|
||||||
|
/// ```rust
|
||||||
|
/// #![feature(generic_associated_types)]
|
||||||
|
///
|
||||||
|
/// trait Trait {
|
||||||
|
/// type Assoc<'a> where Self: 'a;
|
||||||
|
/// }
|
||||||
|
///
|
||||||
|
/// impl Trait for () {
|
||||||
|
/// type Assoc<'a> where Self: 'a = ();
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// {{produces}}
|
||||||
|
///
|
||||||
|
/// ### Explanation
|
||||||
|
///
|
||||||
|
/// The preferred location for where clauses on associated types in impls
|
||||||
|
/// is after the type. However, for most of generic associated types development,
|
||||||
|
/// it was only accepted before the equals. To provide a transition period and
|
||||||
|
/// further evaluate this change, both are currently accepted. At some point in
|
||||||
|
/// the future, this may be disallowed at an edition boundary; but, that is
|
||||||
|
/// undecided currently.
|
||||||
|
pub DEPRECATED_WHERE_CLAUSE_LOCATION,
|
||||||
|
Warn,
|
||||||
|
"deprecated where clause location"
|
||||||
|
}
|
||||||
|
|
|
@ -427,6 +427,7 @@ pub enum BuiltinLintDiagnostics {
|
||||||
NamedAsmLabel(String),
|
NamedAsmLabel(String),
|
||||||
UnicodeTextFlow(Span, String),
|
UnicodeTextFlow(Span, String),
|
||||||
UnexpectedCfg((Symbol, Span), Option<(Symbol, Span)>),
|
UnexpectedCfg((Symbol, Span), Option<(Symbol, Span)>),
|
||||||
|
DeprecatedWhereclauseLocation(Span, String),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Lints that are buffered up early on in the `Session` before the
|
/// Lints that are buffered up early on in the `Session` before the
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
error: where clause not allowed here
|
warning: where clause not allowed here
|
||||||
--> $DIR/issue-87735.rs:15:19
|
--> $DIR/issue-87735.rs:15:19
|
||||||
|
|
|
|
||||||
LL | type Output<'a> where Self: 'a = &'a [T];
|
LL | type Output<'a> where Self: 'a = &'a [T];
|
||||||
| ^^^^^^^^^^^^^^ - help: move it here: `where Self: 'a`
|
| ^^^^^^^^^^^^^^ - help: move it here: `where Self: 'a`
|
||||||
|
|
|
||||||
|
= note: `#[warn(deprecated_where_clause_location)]` on by default
|
||||||
|
|
||||||
error: where clause not allowed here
|
warning: where clause not allowed here
|
||||||
--> $DIR/issue-87735.rs:36:19
|
--> $DIR/issue-87735.rs:36:19
|
||||||
|
|
|
|
||||||
LL | type Output<'a> where Self: 'a = FooRef<'a, U>;
|
LL | type Output<'a> where Self: 'a = FooRef<'a, U>;
|
||||||
|
@ -16,6 +18,6 @@ error[E0207]: the type parameter `U` is not constrained by the impl trait, self
|
||||||
LL | impl<'b, T, U> AsRef2 for Foo<T>
|
LL | impl<'b, T, U> AsRef2 for Foo<T>
|
||||||
| ^ unconstrained type parameter
|
| ^ unconstrained type parameter
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
error: aborting due to previous error; 2 warnings emitted
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0207`.
|
For more information about this error, try `rustc --explain E0207`.
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
error: where clause not allowed here
|
warning: where clause not allowed here
|
||||||
--> $DIR/issue-87748.rs:16:24
|
--> $DIR/issue-87748.rs:16:24
|
||||||
|
|
|
|
||||||
LL | type Assoc<'a, 'b> where 'b: 'a = u32;
|
LL | type Assoc<'a, 'b> where 'b: 'a = u32;
|
||||||
| ^^^^^^^^^^^^ - help: move it here: `where 'b: 'a`
|
| ^^^^^^^^^^^^ - help: move it here: `where 'b: 'a`
|
||||||
|
|
|
||||||
|
= note: `#[warn(deprecated_where_clause_location)]` on by default
|
||||||
|
|
||||||
error[E0478]: lifetime bound not satisfied
|
error[E0478]: lifetime bound not satisfied
|
||||||
--> $DIR/issue-87748.rs:18:5
|
--> $DIR/issue-87748.rs:18:5
|
||||||
|
@ -21,6 +23,6 @@ note: but lifetime parameter must outlive the anonymous lifetime #1 defined here
|
||||||
LL | fn do_sth(_: u32) {}
|
LL | fn do_sth(_: u32) {}
|
||||||
| ^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to previous error; 1 warning emitted
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0478`.
|
For more information about this error, try `rustc --explain E0478`.
|
||||||
|
|
|
@ -20,10 +20,10 @@ trait Trait {
|
||||||
impl Trait for u32 {
|
impl Trait for u32 {
|
||||||
// Not fine, suggests moving.
|
// Not fine, suggests moving.
|
||||||
type Assoc where u32: Copy = ();
|
type Assoc where u32: Copy = ();
|
||||||
//~^ ERROR where clause not allowed here
|
//~^ WARNING where clause not allowed here
|
||||||
// Not fine, suggests moving `u32: Copy`
|
// Not fine, suggests moving `u32: Copy`
|
||||||
type Assoc2 where u32: Copy = () where i32: Copy;
|
type Assoc2 where u32: Copy = () where i32: Copy;
|
||||||
//~^ ERROR where clause not allowed here
|
//~^ WARNING where clause not allowed here
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Trait for i32 {
|
impl Trait for i32 {
|
||||||
|
@ -31,7 +31,7 @@ impl Trait for i32 {
|
||||||
type Assoc = () where u32: Copy;
|
type Assoc = () where u32: Copy;
|
||||||
// Not fine, suggests moving both.
|
// Not fine, suggests moving both.
|
||||||
type Assoc2 where u32: Copy, i32: Copy = ();
|
type Assoc2 where u32: Copy, i32: Copy = ();
|
||||||
//~^ ERROR where clause not allowed here
|
//~^ WARNING where clause not allowed here
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -10,23 +10,25 @@ error: where clauses are not allowed after the type for type aliases
|
||||||
LL | type Baz = () where;
|
LL | type Baz = () where;
|
||||||
| ^^^^^
|
| ^^^^^
|
||||||
|
|
||||||
error: where clause not allowed here
|
warning: where clause not allowed here
|
||||||
--> $DIR/type-alias-where.rs:22:16
|
--> $DIR/type-alias-where.rs:22:16
|
||||||
|
|
|
|
||||||
LL | type Assoc where u32: Copy = ();
|
LL | type Assoc where u32: Copy = ();
|
||||||
| ^^^^^^^^^^^^^^^ - help: move it here: `where u32: Copy`
|
| ^^^^^^^^^^^^^^^ - help: move it here: `where u32: Copy`
|
||||||
|
|
|
||||||
|
= note: `#[warn(deprecated_where_clause_location)]` on by default
|
||||||
|
|
||||||
error: where clause not allowed here
|
warning: where clause not allowed here
|
||||||
--> $DIR/type-alias-where.rs:25:17
|
--> $DIR/type-alias-where.rs:25:17
|
||||||
|
|
|
|
||||||
LL | type Assoc2 where u32: Copy = () where i32: Copy;
|
LL | type Assoc2 where u32: Copy = () where i32: Copy;
|
||||||
| ^^^^^^^^^^^^^^^ - help: move it here: `, u32: Copy`
|
| ^^^^^^^^^^^^^^^ - help: move it here: `, u32: Copy`
|
||||||
|
|
||||||
error: where clause not allowed here
|
warning: where clause not allowed here
|
||||||
--> $DIR/type-alias-where.rs:33:17
|
--> $DIR/type-alias-where.rs:33:17
|
||||||
|
|
|
|
||||||
LL | type Assoc2 where u32: Copy, i32: Copy = ();
|
LL | type Assoc2 where u32: Copy, i32: Copy = ();
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ - help: move it here: `where u32: Copy, i32: Copy`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ - help: move it here: `where u32: Copy, i32: Copy`
|
||||||
|
|
||||||
error: aborting due to 5 previous errors
|
error: aborting due to 2 previous errors; 3 warnings emitted
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue