parenthesized_params_in_types_and_modules -> error
This commit is contained in:
parent
98d2c510dd
commit
b54c5781b8
12 changed files with 59 additions and 158 deletions
|
@ -122,31 +122,6 @@ error: literal out of range for u8
|
|||
|
|
||||
```
|
||||
|
||||
## parenthesized-params-in-types-and-modules
|
||||
|
||||
This lint detects incorrect parentheses. Some example code that triggers this
|
||||
lint:
|
||||
|
||||
```rust,ignore
|
||||
let x = 5 as usize();
|
||||
```
|
||||
|
||||
This will produce:
|
||||
|
||||
```text
|
||||
error: parenthesized parameters may only be used with a trait
|
||||
--> src/main.rs:2:21
|
||||
|
|
||||
2 | let x = 5 as usize();
|
||||
| ^^
|
||||
|
|
||||
= note: `#[deny(parenthesized_params_in_types_and_modules)]` on by default
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #42238 <https://github.com/rust-lang/rust/issues/42238>
|
||||
```
|
||||
|
||||
To fix it, remove the `()`s.
|
||||
|
||||
## pub-use-of-private-extern-crate
|
||||
|
||||
This lint detects a specific situation of re-exporting a private `extern crate`;
|
||||
|
|
|
@ -44,8 +44,7 @@ use crate::hir::def::{Namespace, Res, DefKind, PartialRes, PerNS};
|
|||
use crate::hir::{GenericArg, ConstArg};
|
||||
use crate::hir::ptr::P;
|
||||
use crate::lint;
|
||||
use crate::lint::builtin::{self, PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES,
|
||||
ELIDED_LIFETIMES_IN_PATHS};
|
||||
use crate::lint::builtin::{self, ELIDED_LIFETIMES_IN_PATHS};
|
||||
use crate::middle::cstore::CrateStore;
|
||||
use crate::session::Session;
|
||||
use crate::session::config::nightly_options;
|
||||
|
@ -298,7 +297,6 @@ enum ParamMode {
|
|||
|
||||
enum ParenthesizedGenericArgs {
|
||||
Ok,
|
||||
Warn,
|
||||
Err,
|
||||
}
|
||||
|
||||
|
@ -1695,29 +1693,19 @@ impl<'a> LoweringContext<'a> {
|
|||
};
|
||||
let parenthesized_generic_args = match partial_res.base_res() {
|
||||
// `a::b::Trait(Args)`
|
||||
Res::Def(DefKind::Trait, _)
|
||||
if i + 1 == proj_start => ParenthesizedGenericArgs::Ok,
|
||||
Res::Def(DefKind::Trait, _) if i + 1 == proj_start => {
|
||||
ParenthesizedGenericArgs::Ok
|
||||
}
|
||||
// `a::b::Trait(Args)::TraitItem`
|
||||
Res::Def(DefKind::Method, _)
|
||||
| Res::Def(DefKind::AssocConst, _)
|
||||
| Res::Def(DefKind::AssocTy, _)
|
||||
if i + 2 == proj_start =>
|
||||
{
|
||||
Res::Def(DefKind::Method, _) |
|
||||
Res::Def(DefKind::AssocConst, _) |
|
||||
Res::Def(DefKind::AssocTy, _) if i + 2 == proj_start => {
|
||||
ParenthesizedGenericArgs::Ok
|
||||
}
|
||||
// Avoid duplicated errors.
|
||||
Res::Err => ParenthesizedGenericArgs::Ok,
|
||||
// An error
|
||||
Res::Def(DefKind::Struct, _)
|
||||
| Res::Def(DefKind::Enum, _)
|
||||
| Res::Def(DefKind::Union, _)
|
||||
| Res::Def(DefKind::TyAlias, _)
|
||||
| Res::Def(DefKind::Variant, _) if i + 1 == proj_start =>
|
||||
{
|
||||
ParenthesizedGenericArgs::Err
|
||||
}
|
||||
// A warning for now, for compatibility reasons.
|
||||
_ => ParenthesizedGenericArgs::Warn,
|
||||
_ => ParenthesizedGenericArgs::Err,
|
||||
};
|
||||
|
||||
let num_lifetimes = type_def_id.map_or(0, |def_id| {
|
||||
|
@ -1780,7 +1768,7 @@ impl<'a> LoweringContext<'a> {
|
|||
segment,
|
||||
param_mode,
|
||||
0,
|
||||
ParenthesizedGenericArgs::Warn,
|
||||
ParenthesizedGenericArgs::Err,
|
||||
itctx.reborrow(),
|
||||
None,
|
||||
));
|
||||
|
@ -1856,15 +1844,6 @@ impl<'a> LoweringContext<'a> {
|
|||
}
|
||||
GenericArgs::Parenthesized(ref data) => match parenthesized_generic_args {
|
||||
ParenthesizedGenericArgs::Ok => self.lower_parenthesized_parameter_data(data),
|
||||
ParenthesizedGenericArgs::Warn => {
|
||||
self.resolver.lint_buffer().buffer_lint(
|
||||
PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES,
|
||||
CRATE_NODE_ID,
|
||||
data.span,
|
||||
msg.into(),
|
||||
);
|
||||
(hir::GenericArgs::none(), true)
|
||||
}
|
||||
ParenthesizedGenericArgs::Err => {
|
||||
let mut err = struct_span_err!(self.sess, data.span, E0214, "{}", msg);
|
||||
err.span_label(data.span, "only `Fn` traits may use parentheses");
|
||||
|
|
|
@ -207,16 +207,6 @@ declare_lint! {
|
|||
};
|
||||
}
|
||||
|
||||
declare_lint! {
|
||||
pub PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES,
|
||||
Deny,
|
||||
"detects parenthesized generic parameters in type and module names",
|
||||
@future_incompatible = FutureIncompatibleInfo {
|
||||
reference: "issue #42238 <https://github.com/rust-lang/rust/issues/42238>",
|
||||
edition: None,
|
||||
};
|
||||
}
|
||||
|
||||
declare_lint! {
|
||||
pub LATE_BOUND_LIFETIME_ARGUMENTS,
|
||||
Warn,
|
||||
|
@ -528,7 +518,6 @@ declare_lint_pass! {
|
|||
SAFE_PACKED_BORROWS,
|
||||
PATTERNS_IN_FNS_WITHOUT_BODY,
|
||||
MISSING_FRAGMENT_SPECIFIER,
|
||||
PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES,
|
||||
LATE_BOUND_LIFETIME_ARGUMENTS,
|
||||
ORDER_DEPENDENT_TRAIT_OBJECTS,
|
||||
DEPRECATED,
|
||||
|
|
|
@ -340,6 +340,8 @@ fn register_builtins(store: &mut lint::LintStore, no_interleave_lints: bool) {
|
|||
"converted into hard error, see https://github.com/rust-lang/rust/issues/37872");
|
||||
store.register_removed("safe_extern_statics",
|
||||
"converted into hard error, see https://github.com/rust-lang/rust/issues/36247");
|
||||
store.register_removed("parenthesized_params_in_types_and_modules",
|
||||
"converted into hard error, see https://github.com/rust-lang/rust/issues/42238");
|
||||
}
|
||||
|
||||
fn register_internals(store: &mut lint::LintStore) {
|
||||
|
|
|
@ -1,13 +1,9 @@
|
|||
#![allow(unused)]
|
||||
|
||||
fn main() {
|
||||
{ fn f<X: ::std::marker()::Send>() {} }
|
||||
//~^ ERROR parenthesized type parameters may only be used with a `Fn` trait
|
||||
//~| WARN previously accepted
|
||||
|
||||
{ fn f() -> impl ::std::marker()::Send { } }
|
||||
//~^ ERROR parenthesized type parameters may only be used with a `Fn` trait
|
||||
//~| WARN previously accepted
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -15,4 +11,3 @@ struct X;
|
|||
|
||||
impl ::std::marker()::Copy for X {}
|
||||
//~^ ERROR parenthesized type parameters may only be used with a `Fn` trait
|
||||
//~| WARN previously accepted
|
||||
|
|
|
@ -1,30 +1,21 @@
|
|||
error: parenthesized type parameters may only be used with a `Fn` trait
|
||||
--> $DIR/issue-32995-2.rs:4:22
|
||||
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
|
||||
--> $DIR/issue-32995-2.rs:2:22
|
||||
|
|
||||
LL | { fn f<X: ::std::marker()::Send>() {} }
|
||||
| ^^^^^^^^
|
||||
|
|
||||
= note: `#[deny(parenthesized_params_in_types_and_modules)]` on by default
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #42238 <https://github.com/rust-lang/rust/issues/42238>
|
||||
| ^^^^^^^^ only `Fn` traits may use parentheses
|
||||
|
||||
error: parenthesized type parameters may only be used with a `Fn` trait
|
||||
--> $DIR/issue-32995-2.rs:8:29
|
||||
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
|
||||
--> $DIR/issue-32995-2.rs:5:29
|
||||
|
|
||||
LL | { fn f() -> impl ::std::marker()::Send { } }
|
||||
| ^^^^^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #42238 <https://github.com/rust-lang/rust/issues/42238>
|
||||
| ^^^^^^^^ only `Fn` traits may use parentheses
|
||||
|
||||
error: parenthesized type parameters may only be used with a `Fn` trait
|
||||
--> $DIR/issue-32995-2.rs:16:13
|
||||
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
|
||||
--> $DIR/issue-32995-2.rs:12:13
|
||||
|
|
||||
LL | impl ::std::marker()::Copy for X {}
|
||||
| ^^^^^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #42238 <https://github.com/rust-lang/rust/issues/42238>
|
||||
| ^^^^^^^^ only `Fn` traits may use parentheses
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0214`.
|
||||
|
|
|
@ -1,33 +1,24 @@
|
|||
#![allow(unused)]
|
||||
|
||||
fn main() {
|
||||
let x: usize() = 1;
|
||||
//~^ ERROR parenthesized type parameters may only be used with a `Fn` trait
|
||||
//~| WARN previously accepted
|
||||
|
||||
let b: ::std::boxed()::Box<_> = Box::new(1);
|
||||
//~^ ERROR parenthesized type parameters may only be used with a `Fn` trait
|
||||
//~| WARN previously accepted
|
||||
|
||||
let p = ::std::str::()::from_utf8(b"foo").unwrap();
|
||||
//~^ ERROR parenthesized type parameters may only be used with a `Fn` trait
|
||||
//~| WARN previously accepted
|
||||
|
||||
let p = ::std::str::from_utf8::()(b"foo").unwrap();
|
||||
//~^ ERROR parenthesized type parameters may only be used with a `Fn` trait
|
||||
//~| WARN previously accepted
|
||||
|
||||
let o : Box<dyn (::std::marker()::Send)> = Box::new(1);
|
||||
//~^ ERROR parenthesized type parameters may only be used with a `Fn` trait
|
||||
//~| WARN previously accepted
|
||||
|
||||
let o : Box<dyn Send + ::std::marker()::Sync> = Box::new(1);
|
||||
//~^ ERROR parenthesized type parameters may only be used with a `Fn` trait
|
||||
//~| WARN previously accepted
|
||||
}
|
||||
|
||||
fn foo<X:Default>() {
|
||||
let d : X() = Default::default();
|
||||
//~^ ERROR parenthesized type parameters may only be used with a `Fn` trait
|
||||
//~| WARN previously accepted
|
||||
}
|
||||
|
|
|
@ -1,66 +1,45 @@
|
|||
error: parenthesized type parameters may only be used with a `Fn` trait
|
||||
--> $DIR/issue-32995.rs:4:12
|
||||
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
|
||||
--> $DIR/issue-32995.rs:2:12
|
||||
|
|
||||
LL | let x: usize() = 1;
|
||||
| ^^^^^^^
|
||||
|
|
||||
= note: `#[deny(parenthesized_params_in_types_and_modules)]` on by default
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #42238 <https://github.com/rust-lang/rust/issues/42238>
|
||||
| ^^^^^^^ only `Fn` traits may use parentheses
|
||||
|
||||
error: parenthesized type parameters may only be used with a `Fn` trait
|
||||
--> $DIR/issue-32995.rs:8:19
|
||||
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
|
||||
--> $DIR/issue-32995.rs:5:19
|
||||
|
|
||||
LL | let b: ::std::boxed()::Box<_> = Box::new(1);
|
||||
| ^^^^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #42238 <https://github.com/rust-lang/rust/issues/42238>
|
||||
| ^^^^^^^ only `Fn` traits may use parentheses
|
||||
|
||||
error: parenthesized type parameters may only be used with a `Fn` trait
|
||||
--> $DIR/issue-32995.rs:12:20
|
||||
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
|
||||
--> $DIR/issue-32995.rs:8:20
|
||||
|
|
||||
LL | let p = ::std::str::()::from_utf8(b"foo").unwrap();
|
||||
| ^^^^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #42238 <https://github.com/rust-lang/rust/issues/42238>
|
||||
| ^^^^^^^ only `Fn` traits may use parentheses
|
||||
|
||||
error: parenthesized type parameters may only be used with a `Fn` trait
|
||||
--> $DIR/issue-32995.rs:16:25
|
||||
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
|
||||
--> $DIR/issue-32995.rs:11:25
|
||||
|
|
||||
LL | let p = ::std::str::from_utf8::()(b"foo").unwrap();
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #42238 <https://github.com/rust-lang/rust/issues/42238>
|
||||
| ^^^^^^^^^^^^^ only `Fn` traits may use parentheses
|
||||
|
||||
error: parenthesized type parameters may only be used with a `Fn` trait
|
||||
--> $DIR/issue-32995.rs:20:29
|
||||
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
|
||||
--> $DIR/issue-32995.rs:14:29
|
||||
|
|
||||
LL | let o : Box<dyn (::std::marker()::Send)> = Box::new(1);
|
||||
| ^^^^^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #42238 <https://github.com/rust-lang/rust/issues/42238>
|
||||
| ^^^^^^^^ only `Fn` traits may use parentheses
|
||||
|
||||
error: parenthesized type parameters may only be used with a `Fn` trait
|
||||
--> $DIR/issue-32995.rs:24:35
|
||||
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
|
||||
--> $DIR/issue-32995.rs:17:35
|
||||
|
|
||||
LL | let o : Box<dyn Send + ::std::marker()::Sync> = Box::new(1);
|
||||
| ^^^^^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #42238 <https://github.com/rust-lang/rust/issues/42238>
|
||||
| ^^^^^^^^ only `Fn` traits may use parentheses
|
||||
|
||||
error: parenthesized type parameters may only be used with a `Fn` trait
|
||||
--> $DIR/issue-32995.rs:30:13
|
||||
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
|
||||
--> $DIR/issue-32995.rs:22:13
|
||||
|
|
||||
LL | let d : X() = Default::default();
|
||||
| ^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #42238 <https://github.com/rust-lang/rust/issues/42238>
|
||||
| ^^^ only `Fn` traits may use parentheses
|
||||
|
||||
error: aborting due to 7 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0214`.
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
pub fn foo(num: i32) -> i32 {
|
||||
let foo: i32::from_be(num);
|
||||
//~^ ERROR expected type, found local variable `num`
|
||||
//~| ERROR type arguments are not allowed for this type
|
||||
//~| ERROR parenthesized type parameters may only be used with a `Fn` trait
|
||||
//~| ERROR ambiguous associated type
|
||||
//~| WARNING this was previously accepted by the compiler but is being phased out
|
||||
foo
|
||||
}
|
||||
|
||||
|
|
|
@ -6,15 +6,20 @@ LL | let foo: i32::from_be(num);
|
|||
| |
|
||||
| help: use `=` if you meant to assign
|
||||
|
||||
error: parenthesized type parameters may only be used with a `Fn` trait
|
||||
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
|
||||
--> $DIR/let-binding-init-expr-as-ty.rs:2:19
|
||||
|
|
||||
LL | let foo: i32::from_be(num);
|
||||
| ^^^^^^^^^^^^
|
||||
| |
|
||||
| only `Fn` traits may use parentheses
|
||||
| help: use angle brackets instead: `from_be<num>`
|
||||
|
||||
error[E0109]: type arguments are not allowed for this type
|
||||
--> $DIR/let-binding-init-expr-as-ty.rs:2:27
|
||||
|
|
||||
= note: `#[deny(parenthesized_params_in_types_and_modules)]` on by default
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #42238 <https://github.com/rust-lang/rust/issues/42238>
|
||||
LL | let foo: i32::from_be(num);
|
||||
| ^^^ type argument not allowed
|
||||
|
||||
error[E0223]: ambiguous associated type
|
||||
--> $DIR/let-binding-init-expr-as-ty.rs:2:14
|
||||
|
@ -22,7 +27,7 @@ error[E0223]: ambiguous associated type
|
|||
LL | let foo: i32::from_be(num);
|
||||
| ^^^^^^^^^^^^^^^^^ help: use fully-qualified syntax: `<i32 as Trait>::from_be`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0223, E0573.
|
||||
For more information about an error, try `rustc --explain E0223`.
|
||||
Some errors have detailed explanations: E0109, E0214, E0223, E0573.
|
||||
For more information about an error, try `rustc --explain E0109`.
|
||||
|
|
|
@ -8,7 +8,6 @@ impl Reactor {
|
|||
//~^ ERROR cannot find value `input_cells` in this scope
|
||||
//~| ERROR parenthesized type parameters may only be used with a `Fn` trait
|
||||
//~| ERROR wrong number of type arguments: expected 1, found 0
|
||||
//~| WARNING this was previously accepted by the compiler but is being phased out
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,15 +4,11 @@ error[E0425]: cannot find value `input_cells` in this scope
|
|||
LL | input_cells: Vec::new()
|
||||
| ^^^^^^^^^^^ a field by this name exists in `Self`
|
||||
|
||||
error: parenthesized type parameters may only be used with a `Fn` trait
|
||||
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
|
||||
--> $DIR/issue-34255-1.rs:7:27
|
||||
|
|
||||
LL | input_cells: Vec::new()
|
||||
| ^^^^^
|
||||
|
|
||||
= note: `#[deny(parenthesized_params_in_types_and_modules)]` on by default
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #42238 <https://github.com/rust-lang/rust/issues/42238>
|
||||
| ^^^^^ only `Fn` traits may use parentheses
|
||||
|
||||
error[E0107]: wrong number of type arguments: expected 1, found 0
|
||||
--> $DIR/issue-34255-1.rs:7:22
|
||||
|
@ -22,5 +18,5 @@ LL | input_cells: Vec::new()
|
|||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0107, E0425.
|
||||
Some errors have detailed explanations: E0107, E0214, E0425.
|
||||
For more information about an error, try `rustc --explain E0107`.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue