diff --git a/src/lib.rs b/src/lib.rs index 6c012ae..0be5f52 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -207,7 +207,7 @@ pub fn collect_suggestions( }) .filter_map(collect_span) .collect(); - if replacements.len() == 1 { + if replacements.len() >= 1 { Some(Solution { message: child.message.clone(), replacements, diff --git a/tests/edge-cases/skip-multi-option-lints.fixed.rs b/tests/edge-cases/skip-multi-option-lints.fixed.rs deleted file mode 100644 index 9e12371..0000000 --- a/tests/edge-cases/skip-multi-option-lints.fixed.rs +++ /dev/null @@ -1,5 +0,0 @@ -fn main() { - let xs = vec![String::from("foo")]; - let d: &Display = &xs; - println!("{}", d); -} diff --git a/tests/edge-cases/skip-multi-option-lints.json b/tests/edge-cases/skip-multi-option-lints.json deleted file mode 100644 index dc61ae6..0000000 --- a/tests/edge-cases/skip-multi-option-lints.json +++ /dev/null @@ -1,100 +0,0 @@ -{ - "message": "cannot find type `Display` in this scope", - "code": { - "code": "E0412", - "explanation": "\nThe type name used is not in scope.\n\nErroneous code examples:\n\n```compile_fail,E0412\nimpl Something {} // error: type name `Something` is not in scope\n\n// or:\n\ntrait Foo {\n fn bar(N); // error: type name `N` is not in scope\n}\n\n// or:\n\nfn foo(x: T) {} // type name `T` is not in scope\n```\n\nTo fix this error, please verify you didn't misspell the type name, you did\ndeclare it or imported it into the scope. Examples:\n\n```\nstruct Something;\n\nimpl Something {} // ok!\n\n// or:\n\ntrait Foo {\n type N;\n\n fn bar(_: Self::N); // ok!\n}\n\n// or:\n\nfn foo(x: T) {} // ok!\n```\n\nAnother case that causes this error is when a type is imported into a parent\nmodule. To fix this, you can follow the suggestion and use File directly or\n`use super::File;` which will import the types from the parent namespace. An\nexample that causes this error is below:\n\n```compile_fail,E0412\nuse std::fs::File;\n\nmod foo {\n fn some_function(f: File) {}\n}\n```\n\n```\nuse std::fs::File;\n\nmod foo {\n // either\n use super::File;\n // or\n // use std::fs::File;\n fn foo(f: File) {}\n}\n# fn main() {} // don't insert it for us; that'll break imports\n```\n" - }, - "level": "error", - "spans": [ - { - "file_name": "./tests/everything/skip-multi-option-lints.rs", - "byte_start": 64, - "byte_end": 71, - "line_start": 3, - "line_end": 3, - "column_start": 13, - "column_end": 20, - "is_primary": true, - "text": [ - { - "text": " let d: &Display = &xs;", - "highlight_start": 13, - "highlight_end": 20 - } - ], - "label": "not found in this scope", - "suggested_replacement": null, - "expansion": null - } - ], - "children": [ - { - "message": "possible candidates are found in other modules, you can import them into scope", - "code": null, - "level": "help", - "spans": [ - { - "file_name": "./tests/everything/skip-multi-option-lints.rs", - "byte_start": 0, - "byte_end": 0, - "line_start": 1, - "line_end": 1, - "column_start": 1, - "column_end": 1, - "is_primary": true, - "text": [ - { - "text": "fn main() {", - "highlight_start": 1, - "highlight_end": 1 - } - ], - "label": null, - "suggested_replacement": "use std::fmt::Display;\n\n", - "suggestion_applicability": "Unspecified", - "expansion": null - }, - { - "file_name": "./tests/everything/skip-multi-option-lints.rs", - "byte_start": 0, - "byte_end": 0, - "line_start": 1, - "line_end": 1, - "column_start": 1, - "column_end": 1, - "is_primary": true, - "text": [ - { - "text": "fn main() {", - "highlight_start": 1, - "highlight_end": 1 - } - ], - "label": null, - "suggested_replacement": "use std::path::Display;\n\n", - "suggestion_applicability": "Unspecified", - "expansion": null - } - ], - "children": [], - "rendered": null - } - ], - "rendered": "error[E0412]: cannot find type `Display` in this scope\n --> ./tests/everything/skip-multi-option-lints.rs:3:13\n |\n3 | let d: &Display = &xs;\n | ^^^^^^^ not found in this scope\nhelp: possible candidates are found in other modules, you can import them into scope\n |\n1 | use std::fmt::Display;\n |\n1 | use std::path::Display;\n |\n\n" -} -{ - "message": "aborting due to previous error", - "code": null, - "level": "error", - "spans": [], - "children": [], - "rendered": "error: aborting due to previous error\n\n" -} -{ - "message": "For more information about this error, try `rustc --explain E0412`.", - "code": null, - "level": "", - "spans": [], - "children": [], - "rendered": "For more information about this error, try `rustc --explain E0412`.\n" -} diff --git a/tests/edge-cases/skip-multi-option-lints.rs b/tests/edge-cases/skip-multi-option-lints.rs deleted file mode 100644 index 9e12371..0000000 --- a/tests/edge-cases/skip-multi-option-lints.rs +++ /dev/null @@ -1,5 +0,0 @@ -fn main() { - let xs = vec![String::from("foo")]; - let d: &Display = &xs; - println!("{}", d); -} diff --git a/tests/edge_cases.rs b/tests/edge_cases.rs index 191713b..1b981ef 100644 --- a/tests/edge_cases.rs +++ b/tests/edge_cases.rs @@ -18,7 +18,6 @@ macro_rules! expect_empty_json_test { }; } -expect_empty_json_test! {multiple_fix_options_yield_no_suggestions, "skip-multi-option-lints.json"} expect_empty_json_test! {out_of_bounds_test, "out_of_bounds.recorded.json"} expect_empty_json_test! {utf8_identifiers_test, "utf8_idents.recorded.json"} expect_empty_json_test! {empty, "empty.json"} diff --git a/tests/everything/multiple-solutions.fixed.rs b/tests/everything/multiple-solutions.fixed.rs new file mode 100644 index 0000000..1a26178 --- /dev/null +++ b/tests/everything/multiple-solutions.fixed.rs @@ -0,0 +1,5 @@ +use std::collections::{HashSet}; + +fn main() { + let _: HashSet<()>; +} diff --git a/tests/everything/multiple-solutions.json b/tests/everything/multiple-solutions.json new file mode 100644 index 0000000..89b14cc --- /dev/null +++ b/tests/everything/multiple-solutions.json @@ -0,0 +1,114 @@ +{ + "message": "unused imports: `HashMap`, `VecDeque`", + "code": { + "code": "unused_imports", + "explanation": null + }, + "level": "warning", + "spans": [ + { + "file_name": "src/main.rs", + "byte_start": 23, + "byte_end": 30, + "line_start": 1, + "line_end": 1, + "column_start": 24, + "column_end": 31, + "is_primary": true, + "text": [ + { + "text": "use std::collections::{HashMap, HashSet, VecDeque};", + "highlight_start": 24, + "highlight_end": 31 + } + ], + "label": null, + "suggested_replacement": null, + "suggestion_applicability": null, + "expansion": null + }, + { + "file_name": "src/main.rs", + "byte_start": 41, + "byte_end": 49, + "line_start": 1, + "line_end": 1, + "column_start": 42, + "column_end": 50, + "is_primary": true, + "text": [ + { + "text": "use std::collections::{HashMap, HashSet, VecDeque};", + "highlight_start": 42, + "highlight_end": 50 + } + ], + "label": null, + "suggested_replacement": null, + "suggestion_applicability": null, + "expansion": null + } + ], + "children": [ + { + "message": "#[warn(unused_imports)] on by default", + "code": null, + "level": "note", + "spans": [], + "children": [], + "rendered": null + }, + { + "message": "remove the unused imports", + "code": null, + "level": "help", + "spans": [ + { + "file_name": "src/main.rs", + "byte_start": 23, + "byte_end": 32, + "line_start": 1, + "line_end": 1, + "column_start": 24, + "column_end": 33, + "is_primary": true, + "text": [ + { + "text": "use std::collections::{HashMap, HashSet, VecDeque};", + "highlight_start": 24, + "highlight_end": 33 + } + ], + "label": null, + "suggested_replacement": "", + "suggestion_applicability": "MachineApplicable", + "expansion": null + }, + { + "file_name": "src/main.rs", + "byte_start": 39, + "byte_end": 49, + "line_start": 1, + "line_end": 1, + "column_start": 40, + "column_end": 50, + "is_primary": true, + "text": [ + { + "text": "use std::collections::{HashMap, HashSet, VecDeque};", + "highlight_start": 40, + "highlight_end": 50 + } + ], + "label": null, + "suggested_replacement": "", + "suggestion_applicability": "MachineApplicable", + "expansion": null + } + ], + "children": [], + "rendered": null + } + ], + "rendered": "warning: unused imports: `HashMap`, `VecDeque`\n --> src/main.rs:1:24\n |\n1 | use std::collections::{HashMap, HashSet, VecDeque};\n | ^^^^^^^ ^^^^^^^^\n |\n = note: #[warn(unused_imports)] on by default\nhelp: remove the unused imports\n |\n1 | use std::collections::{HashSet};\n | -- --\n\n" +} diff --git a/tests/everything/multiple-solutions.rs b/tests/everything/multiple-solutions.rs new file mode 100644 index 0000000..401198f --- /dev/null +++ b/tests/everything/multiple-solutions.rs @@ -0,0 +1,5 @@ +use std::collections::{HashMap, HashSet, VecDeque}; + +fn main() { + let _: HashSet<()>; +}