diff options
| author | Zack M. Davis <code@zackmdavis.net> | 2018-05-19 14:52:24 -0700 |
|---|---|---|
| committer | Zack M. Davis <code@zackmdavis.net> | 2018-05-20 14:13:25 -0700 |
| commit | 98a04291e4db92ae86d7e3a20b5763cb926ebfbf (patch) | |
| tree | be6bad72d6042b9d58445f51a0862d7c40c73b3f /src/test | |
| parent | 6bb4aad51f40536447cd7603ab5be7792bab0a3d (diff) | |
suggestion applicabilities for libsyntax and librustc, run-rustfix tests
Consider this a down payment on #50723. To recap, an `Applicability` enum was recently (#50204) added, to convey to Rustfix and other tools whether we think it's OK for them to blindly apply the suggestion, or whether to prompt a human for guidance (because the suggestion might contain placeholders that we can't infer, or because we think it has a sufficiently high probability of being wrong even though it's— presumably—right often enough to be worth emitting in the first place). When a suggestion is marked as `MaybeIncorrect`, we try to use comments to indicate precisely why (although there are a few places where we just say `// speculative` because the present author's subjective judgement balked at the idea that the suggestion has no false positives). The `run-rustfix` directive is opporunistically set on some relevant UI tests (and a couple tests that were in the `test/ui/suggestions` directory, even if the suggestions didn't originate in librustc or libsyntax). This is less trivial than it sounds, because a surprising number of test files aren't equipped to be tested as fixed even when they contain successfully fixable errors, because, e.g., there are more, not-directly-related errors after fixing. Some test files need an attribute or underscore to avoid unused warnings tripping up the "fixed code is still producing diagnostics" check despite the fixes being correct; this is an interesting contrast-to/inconsistency-with the behavior of UI tests (which secretly pass `-A unused`), a behavior which we probably ought to resolve one way or the other (filed issue #50926). A few suggestion labels are reworded (e.g., to avoid phrasing it as a question, which which is discouraged by the style guidelines listed in `.span_suggestion`'s doc-comment).
Diffstat (limited to 'src/test')
25 files changed, 218 insertions, 28 deletions
diff --git a/src/test/ui/extern-const.fixed b/src/test/ui/extern-const.fixed new file mode 100644 index 00000000000..6e131ca41aa --- /dev/null +++ b/src/test/ui/extern-const.fixed @@ -0,0 +1,25 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// run-rustfix +// compile-flags: -Z continue-parse-after-error + +extern "C" { + static C: u8; //~ ERROR extern items cannot be `const` +} + +fn main() { + // We suggest turning the (illegal) extern `const` into an extern `static`, + // but this also requires `unsafe` (a deny-by-default lint at comment time, + // future error; Issue #36247) + unsafe { + let _x = C; + } +} diff --git a/src/test/ui/extern-const.rs b/src/test/ui/extern-const.rs index a77d7b11895..4a766b9724d 100644 --- a/src/test/ui/extern-const.rs +++ b/src/test/ui/extern-const.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// run-rustfix // compile-flags: -Z continue-parse-after-error extern "C" { @@ -15,5 +16,10 @@ extern "C" { } fn main() { - let x = C; + // We suggest turning the (illegal) extern `const` into an extern `static`, + // but this also requires `unsafe` (a deny-by-default lint at comment time, + // future error; Issue #36247) + unsafe { + let _x = C; + } } diff --git a/src/test/ui/extern-const.stderr b/src/test/ui/extern-const.stderr index f416f596b25..cbed5e56c76 100644 --- a/src/test/ui/extern-const.stderr +++ b/src/test/ui/extern-const.stderr @@ -1,8 +1,8 @@ error: extern items cannot be `const` - --> $DIR/extern-const.rs:14:5 + --> $DIR/extern-const.rs:15:5 | LL | const C: u8; //~ ERROR extern items cannot be `const` - | ^^^^^ help: instead try using: `static` + | ^^^^^ help: try using a static value: `static` error: aborting due to previous error diff --git a/src/test/ui/issue-42954.fixed b/src/test/ui/issue-42954.fixed new file mode 100644 index 00000000000..d05996fb8b9 --- /dev/null +++ b/src/test/ui/issue-42954.fixed @@ -0,0 +1,24 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// run-rustfix + +#![allow(unused_must_use, unused_comparisons)] + +macro_rules! is_plainly_printable { + ($i: ident) => { + ($i as u32) < 0 //~ `<` is interpreted as a start of generic arguments + }; +} + +fn main() { + let c = 'a'; + is_plainly_printable!(c); +} diff --git a/src/test/ui/issue-42954.rs b/src/test/ui/issue-42954.rs index 6fa2c69bf66..8226cedc0c4 100644 --- a/src/test/ui/issue-42954.rs +++ b/src/test/ui/issue-42954.rs @@ -8,6 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// run-rustfix + +#![allow(unused_must_use, unused_comparisons)] + macro_rules! is_plainly_printable { ($i: ident) => { $i as u32 < 0 //~ `<` is interpreted as a start of generic arguments diff --git a/src/test/ui/issue-42954.stderr b/src/test/ui/issue-42954.stderr index 9164434006f..aa332602f9e 100644 --- a/src/test/ui/issue-42954.stderr +++ b/src/test/ui/issue-42954.stderr @@ -1,5 +1,5 @@ error: `<` is interpreted as a start of generic arguments for `u32`, not a comparison - --> $DIR/issue-42954.rs:13:19 + --> $DIR/issue-42954.rs:17:19 | LL | $i as u32 < 0 //~ `<` is interpreted as a start of generic arguments | --------- ^ - interpreted as generic arguments diff --git a/src/test/ui/issue-44406.stderr b/src/test/ui/issue-44406.stderr index de7c11732e4..5cd9b3f065e 100644 --- a/src/test/ui/issue-44406.stderr +++ b/src/test/ui/issue-44406.stderr @@ -8,7 +8,7 @@ error: expected type, found keyword `true` --> $DIR/issue-44406.rs:18:10 | LL | bar(baz: $rest) - | - help: did you mean to use `;` here? + | - help: try using a semicolon: `;` ... LL | foo!(true); //~ ERROR expected type, found keyword | ^^^^ expecting a type here because of type ascription diff --git a/src/test/ui/issue-48636.fixed b/src/test/ui/issue-48636.fixed new file mode 100644 index 00000000000..0ff33c42b1c --- /dev/null +++ b/src/test/ui/issue-48636.fixed @@ -0,0 +1,21 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// run-rustfix + +#![allow(dead_code)] + +struct S { + x: u8, + /// The id of the parent core + y: u8, +} +//~^^^ ERROR found a documentation comment that doesn't document anything +fn main() {} diff --git a/src/test/ui/issue-48636.rs b/src/test/ui/issue-48636.rs index 03e45d88e6c..2ac41211347 100644 --- a/src/test/ui/issue-48636.rs +++ b/src/test/ui/issue-48636.rs @@ -8,6 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// run-rustfix + +#![allow(dead_code)] + struct S { x: u8 /// The id of the parent core diff --git a/src/test/ui/issue-48636.stderr b/src/test/ui/issue-48636.stderr index 4e014a5bd1d..c4706f982ed 100644 --- a/src/test/ui/issue-48636.stderr +++ b/src/test/ui/issue-48636.stderr @@ -1,5 +1,5 @@ error[E0585]: found a documentation comment that doesn't document anything - --> $DIR/issue-48636.rs:13:5 + --> $DIR/issue-48636.rs:17:5 | LL | x: u8 | - help: missing comma here: `,` diff --git a/src/test/ui/mismatched_types/closure-arg-count-expected-type-issue-47244.fixed b/src/test/ui/mismatched_types/closure-arg-count-expected-type-issue-47244.fixed new file mode 100644 index 00000000000..1a7608fea6e --- /dev/null +++ b/src/test/ui/mismatched_types/closure-arg-count-expected-type-issue-47244.fixed @@ -0,0 +1,30 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Regression test for #47244: in this specific scenario, when the +// expected type indicated 1 argument but the closure takes two, we +// would (early on) create type variables for the type of `b`. If the +// user then attempts to invoke a method on `b`, we would get an error +// saying that the type of `b` must be known, which was not very +// helpful. + +// run-rustfix + +use std::collections::HashMap; + +fn main() { + let mut m = HashMap::new(); + m.insert("foo", "bar"); + + let _n = m.iter().map(|(_, b)| { + //~^ ERROR closure is expected to take a single 2-tuple + b.to_string() + }); +} diff --git a/src/test/ui/mismatched_types/closure-arg-count-expected-type-issue-47244.rs b/src/test/ui/mismatched_types/closure-arg-count-expected-type-issue-47244.rs index b6463ca067b..0ca0753490a 100644 --- a/src/test/ui/mismatched_types/closure-arg-count-expected-type-issue-47244.rs +++ b/src/test/ui/mismatched_types/closure-arg-count-expected-type-issue-47244.rs @@ -15,15 +15,16 @@ // saying that the type of `b` must be known, which was not very // helpful. +// run-rustfix + use std::collections::HashMap; -fn main() { - let m = HashMap::new(); - m.insert( "foo", "bar" ); +fn main() { + let mut m = HashMap::new(); + m.insert("foo", "bar"); - m.iter().map( |_, b| { + let _n = m.iter().map(|_, b| { //~^ ERROR closure is expected to take a single 2-tuple - b.to_string() }); } diff --git a/src/test/ui/mismatched_types/closure-arg-count-expected-type-issue-47244.stderr b/src/test/ui/mismatched_types/closure-arg-count-expected-type-issue-47244.stderr index 262c4aa1a7c..c95d8157b0c 100644 --- a/src/test/ui/mismatched_types/closure-arg-count-expected-type-issue-47244.stderr +++ b/src/test/ui/mismatched_types/closure-arg-count-expected-type-issue-47244.stderr @@ -1,14 +1,14 @@ error[E0593]: closure is expected to take a single 2-tuple as argument, but it takes 2 distinct arguments - --> $DIR/closure-arg-count-expected-type-issue-47244.rs:24:14 + --> $DIR/closure-arg-count-expected-type-issue-47244.rs:26:23 | -LL | m.iter().map( |_, b| { - | ^^^ ------ takes 2 distinct arguments - | | - | expected closure that takes a single 2-tuple as argument +LL | let _n = m.iter().map(|_, b| { + | ^^^ ------ takes 2 distinct arguments + | | + | expected closure that takes a single 2-tuple as argument help: change the closure to accept a tuple instead of individual arguments | -LL | m.iter().map( |(_, b)| { - | ^^^^^^^^ +LL | let _n = m.iter().map(|(_, b)| { + | ^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/repr-align-assign.fixed b/src/test/ui/repr-align-assign.fixed new file mode 100644 index 00000000000..62147e7625e --- /dev/null +++ b/src/test/ui/repr-align-assign.fixed @@ -0,0 +1,21 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// run-rustfix + +#![allow(dead_code)] + +#[repr(align(8))] //~ ERROR incorrect `repr(align)` attribute format +struct A(u64); + +#[repr(align(8))] //~ ERROR incorrect `repr(align)` attribute format +struct B(u64); + +fn main() {} diff --git a/src/test/ui/repr-align-assign.rs b/src/test/ui/repr-align-assign.rs index c9780dde235..3bc3b5c64ce 100644 --- a/src/test/ui/repr-align-assign.rs +++ b/src/test/ui/repr-align-assign.rs @@ -8,6 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// run-rustfix + +#![allow(dead_code)] + #[repr(align=8)] //~ ERROR incorrect `repr(align)` attribute format struct A(u64); diff --git a/src/test/ui/repr-align-assign.stderr b/src/test/ui/repr-align-assign.stderr index 1fa1263b946..c325b6968fe 100644 --- a/src/test/ui/repr-align-assign.stderr +++ b/src/test/ui/repr-align-assign.stderr @@ -1,11 +1,11 @@ error[E0693]: incorrect `repr(align)` attribute format - --> $DIR/repr-align-assign.rs:11:8 + --> $DIR/repr-align-assign.rs:15:8 | LL | #[repr(align=8)] //~ ERROR incorrect `repr(align)` attribute format | ^^^^^^^ help: use parentheses instead: `align(8)` error[E0693]: incorrect `repr(align)` attribute format - --> $DIR/repr-align-assign.rs:14:8 + --> $DIR/repr-align-assign.rs:18:8 | LL | #[repr(align="8")] //~ ERROR incorrect `repr(align)` attribute format | ^^^^^^^^^ help: use parentheses instead: `align(8)` diff --git a/src/test/ui/suggestions/issue-32354-suggest-import-rename.fixed b/src/test/ui/suggestions/issue-32354-suggest-import-rename.fixed new file mode 100644 index 00000000000..251f7eb9a24 --- /dev/null +++ b/src/test/ui/suggestions/issue-32354-suggest-import-rename.fixed @@ -0,0 +1,26 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// run-rustfix + +#![allow(unused_imports)] + +pub mod extension1 { + pub trait ConstructorExtension {} +} + +pub mod extension2 { + pub trait ConstructorExtension {} +} + +use extension1::ConstructorExtension; +use extension2::ConstructorExtension as OtherConstructorExtension; //~ ERROR is defined multiple times + +fn main() {} diff --git a/src/test/ui/suggestions/issue-32354-suggest-import-rename.rs b/src/test/ui/suggestions/issue-32354-suggest-import-rename.rs index 9d71ab1a788..57cbeb47a1e 100644 --- a/src/test/ui/suggestions/issue-32354-suggest-import-rename.rs +++ b/src/test/ui/suggestions/issue-32354-suggest-import-rename.rs @@ -8,6 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// run-rustfix + +#![allow(unused_imports)] + pub mod extension1 { pub trait ConstructorExtension {} } diff --git a/src/test/ui/suggestions/issue-32354-suggest-import-rename.stderr b/src/test/ui/suggestions/issue-32354-suggest-import-rename.stderr index 7cf7a1d15a2..f45a5f7dd61 100644 --- a/src/test/ui/suggestions/issue-32354-suggest-import-rename.stderr +++ b/src/test/ui/suggestions/issue-32354-suggest-import-rename.stderr @@ -1,5 +1,5 @@ error[E0252]: the name `ConstructorExtension` is defined multiple times - --> $DIR/issue-32354-suggest-import-rename.rs:20:5 + --> $DIR/issue-32354-suggest-import-rename.rs:24:5 | LL | use extension1::ConstructorExtension; | -------------------------------- previous import of the trait `ConstructorExtension` here diff --git a/src/test/ui/suggestions/pub-ident-fn-or-struct-2.stderr b/src/test/ui/suggestions/pub-ident-fn-or-struct-2.stderr index c945033ad74..e492a8c4756 100644 --- a/src/test/ui/suggestions/pub-ident-fn-or-struct-2.stderr +++ b/src/test/ui/suggestions/pub-ident-fn-or-struct-2.stderr @@ -2,7 +2,7 @@ error: missing `fn` or `struct` for method or struct definition --> $DIR/pub-ident-fn-or-struct-2.rs:11:4 | LL | pub S(); - | ---^- help: if you meant to call a macro, write instead: `S!` + | ---^- help: if you meant to call a macro, try: `S!` error: aborting due to previous error diff --git a/src/test/ui/suggestions/pub-ident-fn-or-struct.stderr b/src/test/ui/suggestions/pub-ident-fn-or-struct.stderr index 9528c15dfa1..c1bff34cec3 100644 --- a/src/test/ui/suggestions/pub-ident-fn-or-struct.stderr +++ b/src/test/ui/suggestions/pub-ident-fn-or-struct.stderr @@ -2,7 +2,7 @@ error: missing `fn` or `struct` for method or struct definition --> $DIR/pub-ident-fn-or-struct.rs:11:4 | LL | pub S (foo) bar - | ---^- help: if you meant to call a macro, write instead: `S!` + | ---^- help: if you meant to call a macro, try: `S!` error: aborting due to previous error diff --git a/src/test/ui/suggestions/pub-ident-fn.fixed b/src/test/ui/suggestions/pub-ident-fn.fixed new file mode 100644 index 00000000000..f2d0c6c3e1d --- /dev/null +++ b/src/test/ui/suggestions/pub-ident-fn.fixed @@ -0,0 +1,18 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// run-rustfix + +pub fn foo(_s: usize) -> bool { true } +//~^ ERROR missing `fn` for method definition + +fn main() { + foo(2); +} diff --git a/src/test/ui/suggestions/pub-ident-fn.rs b/src/test/ui/suggestions/pub-ident-fn.rs index 1d641996420..82c32f57eea 100644 --- a/src/test/ui/suggestions/pub-ident-fn.rs +++ b/src/test/ui/suggestions/pub-ident-fn.rs @@ -8,7 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -pub foo(s: usize) -> bool { true } +// run-rustfix + +pub foo(_s: usize) -> bool { true } //~^ ERROR missing `fn` for method definition fn main() { diff --git a/src/test/ui/suggestions/pub-ident-fn.stderr b/src/test/ui/suggestions/pub-ident-fn.stderr index de7ee71d1b4..f7c96b8b9f4 100644 --- a/src/test/ui/suggestions/pub-ident-fn.stderr +++ b/src/test/ui/suggestions/pub-ident-fn.stderr @@ -1,11 +1,11 @@ error: missing `fn` for method definition - --> $DIR/pub-ident-fn.rs:11:4 + --> $DIR/pub-ident-fn.rs:13:4 | -LL | pub foo(s: usize) -> bool { true } +LL | pub foo(_s: usize) -> bool { true } | ^^^ help: add `fn` here to parse `foo` as a public method | -LL | pub fn foo(s: usize) -> bool { true } +LL | pub fn foo(_s: usize) -> bool { true } | ^^ error: aborting due to previous error diff --git a/src/test/ui/suggestions/type-ascription-instead-of-statement-end.stderr b/src/test/ui/suggestions/type-ascription-instead-of-statement-end.stderr index 02a80d86c84..314c9060d4f 100644 --- a/src/test/ui/suggestions/type-ascription-instead-of-statement-end.stderr +++ b/src/test/ui/suggestions/type-ascription-instead-of-statement-end.stderr @@ -2,7 +2,7 @@ error: expected type, found `0` --> $DIR/type-ascription-instead-of-statement-end.rs:15:5 | LL | println!("test"): - | - help: did you mean to use `;` here? + | - help: try using a semicolon: `;` LL | 0; //~ ERROR expected type, found `0` | ^ expecting a type here because of type ascription |
