Use multiline Diagnostic for candidate in other module

This commit is contained in:
Esteban Küber 2017-01-18 16:33:25 -08:00
parent c8af93f090
commit 2883186180
10 changed files with 37 additions and 36 deletions

View File

@ -67,6 +67,7 @@ use syntax_pos::{Span, DUMMY_SP, MultiSpan};
use errors::DiagnosticBuilder; use errors::DiagnosticBuilder;
use std::cell::{Cell, RefCell}; use std::cell::{Cell, RefCell};
use std::cmp;
use std::fmt; use std::fmt;
use std::mem::replace; use std::mem::replace;
use std::rc::Rc; use std::rc::Rc;
@ -3224,7 +3225,7 @@ fn show_candidates(session: &mut DiagnosticBuilder,
better: bool) { better: bool) {
// don't show more than MAX_CANDIDATES results, so // don't show more than MAX_CANDIDATES results, so
// we're consistent with the trait suggestions // we're consistent with the trait suggestions
const MAX_CANDIDATES: usize = 5; const MAX_CANDIDATES: usize = 4;
// we want consistent results across executions, but candidates are produced // we want consistent results across executions, but candidates are produced
// by iterating through a hash map, so make sure they are ordered: // by iterating through a hash map, so make sure they are ordered:
@ -3237,21 +3238,21 @@ fn show_candidates(session: &mut DiagnosticBuilder,
1 => " is found in another module, you can import it", 1 => " is found in another module, you can import it",
_ => "s are found in other modules, you can import them", _ => "s are found in other modules, you can import them",
}; };
session.help(&format!("possible {}candidate{} into scope:", better, msg_diff));
let count = path_strings.len() as isize - MAX_CANDIDATES as isize + 1; let end = cmp::min(MAX_CANDIDATES, path_strings.len());
for (idx, path_string) in path_strings.iter().enumerate() { session.help(&format!("possible {}candidate{} into scope:{}{}",
if idx == MAX_CANDIDATES - 1 && count > 1 { better,
session.help( msg_diff,
&format!(" and {} other candidates", count).to_string(), &path_strings[0..end].iter().map(|candidate| {
); format!("\n `use {};`", candidate)
break; }).collect::<String>(),
} else { if path_strings.len() > MAX_CANDIDATES {
session.help( format!("\nand {} other candidates",
&format!(" `use {};`", path_string).to_string(), path_strings.len() - MAX_CANDIDATES)
); } else {
} "".to_owned()
} }
));
} }
/// A somewhat inefficient routine to obtain the name of a module. /// A somewhat inefficient routine to obtain the name of a module.

View File

@ -5,7 +5,7 @@ error[E0425]: cannot find value `A` in module `namespaced_enums`
| ^^^^^^^^^^^^^^^^^^^ not found in `namespaced_enums` | ^^^^^^^^^^^^^^^^^^^ not found in `namespaced_enums`
| |
= help: possible candidate is found in another module, you can import it into scope: = help: possible candidate is found in another module, you can import it into scope:
= help: `use namespaced_enums::Foo::A;` `use namespaced_enums::Foo::A;`
error[E0425]: cannot find function `B` in module `namespaced_enums` error[E0425]: cannot find function `B` in module `namespaced_enums`
--> $DIR/enums-are-namespaced-xc.rs:18:13 --> $DIR/enums-are-namespaced-xc.rs:18:13
@ -14,7 +14,7 @@ error[E0425]: cannot find function `B` in module `namespaced_enums`
| ^^^^^^^^^^^^^^^^^^^ not found in `namespaced_enums` | ^^^^^^^^^^^^^^^^^^^ not found in `namespaced_enums`
| |
= help: possible candidate is found in another module, you can import it into scope: = help: possible candidate is found in another module, you can import it into scope:
= help: `use namespaced_enums::Foo::B;` `use namespaced_enums::Foo::B;`
error[E0422]: cannot find struct, variant or union type `C` in module `namespaced_enums` error[E0422]: cannot find struct, variant or union type `C` in module `namespaced_enums`
--> $DIR/enums-are-namespaced-xc.rs:21:13 --> $DIR/enums-are-namespaced-xc.rs:21:13
@ -23,7 +23,7 @@ error[E0422]: cannot find struct, variant or union type `C` in module `namespace
| ^^^^^^^^^^^^^^^^^^^ not found in `namespaced_enums` | ^^^^^^^^^^^^^^^^^^^ not found in `namespaced_enums`
| |
= help: possible candidate is found in another module, you can import it into scope: = help: possible candidate is found in another module, you can import it into scope:
= help: `use namespaced_enums::Foo::C;` `use namespaced_enums::Foo::C;`
error: aborting due to 3 previous errors error: aborting due to 3 previous errors

View File

@ -5,9 +5,9 @@ error[E0574]: expected struct, variant or union type, found enum `Result`
| ^^^^^^ not a struct, variant or union type | ^^^^^^ not a struct, variant or union type
| |
= help: possible better candidates are found in other modules, you can import them into scope: = help: possible better candidates are found in other modules, you can import them into scope:
= help: `use std::fmt::Result;` `use std::fmt::Result;`
= help: `use std::io::Result;` `use std::io::Result;`
= help: `use std::thread::Result;` `use std::thread::Result;`
error: aborting due to previous error error: aborting due to previous error

View File

@ -5,7 +5,7 @@ error[E0422]: cannot find struct, variant or union type `E` in this scope
| ^ not found in this scope | ^ not found in this scope
| |
= help: possible candidate is found in another module, you can import it into scope: = help: possible candidate is found in another module, you can import it into scope:
= help: `use SomeEnum::E;` `use SomeEnum::E;`
error: aborting due to previous error error: aborting due to previous error

View File

@ -5,9 +5,9 @@ error[E0405]: cannot find trait `Mul` in this scope
| ^^^ not found in this scope | ^^^ not found in this scope
| |
= help: possible candidates are found in other modules, you can import them into scope: = help: possible candidates are found in other modules, you can import them into scope:
= help: `use mul1::Mul;` `use mul1::Mul;`
= help: `use mul2::Mul;` `use mul2::Mul;`
= help: `use std::ops::Mul;` `use std::ops::Mul;`
error[E0412]: cannot find type `Mul` in this scope error[E0412]: cannot find type `Mul` in this scope
--> $DIR/issue-21221-1.rs:72:16 --> $DIR/issue-21221-1.rs:72:16
@ -16,11 +16,11 @@ error[E0412]: cannot find type `Mul` in this scope
| ^^^ not found in this scope | ^^^ not found in this scope
| |
= help: possible candidates are found in other modules, you can import them into scope: = help: possible candidates are found in other modules, you can import them into scope:
= help: `use mul1::Mul;` `use mul1::Mul;`
= help: `use mul2::Mul;` `use mul2::Mul;`
= help: `use mul3::Mul;` `use mul3::Mul;`
= help: `use mul4::Mul;` `use mul4::Mul;`
= help: and 2 other candidates and 2 other candidates
error[E0405]: cannot find trait `ThisTraitReallyDoesntExistInAnyModuleReally` in this scope error[E0405]: cannot find trait `ThisTraitReallyDoesntExistInAnyModuleReally` in this scope
--> $DIR/issue-21221-1.rs:83:6 --> $DIR/issue-21221-1.rs:83:6
@ -35,7 +35,7 @@ error[E0405]: cannot find trait `Div` in this scope
| ^^^ not found in this scope | ^^^ not found in this scope
| |
= help: possible candidate is found in another module, you can import it into scope: = help: possible candidate is found in another module, you can import it into scope:
= help: `use std::ops::Div;` `use std::ops::Div;`
error: cannot continue compilation due to previous error error: cannot continue compilation due to previous error

View File

@ -5,7 +5,7 @@ error[E0405]: cannot find trait `T` in this scope
| ^ not found in this scope | ^ not found in this scope
| |
= help: possible candidate is found in another module, you can import it into scope: = help: possible candidate is found in another module, you can import it into scope:
= help: `use foo::bar::T;` `use foo::bar::T;`
error: main function not found error: main function not found

View File

@ -5,7 +5,7 @@ error[E0405]: cannot find trait `OuterTrait` in this scope
| ^^^^^^^^^^ not found in this scope | ^^^^^^^^^^ not found in this scope
| |
= help: possible candidate is found in another module, you can import it into scope: = help: possible candidate is found in another module, you can import it into scope:
= help: `use issue_21221_3::outer::OuterTrait;` `use issue_21221_3::outer::OuterTrait;`
error: cannot continue compilation due to previous error error: cannot continue compilation due to previous error

View File

@ -5,7 +5,7 @@ error[E0405]: cannot find trait `T` in this scope
| ^ not found in this scope | ^ not found in this scope
| |
= help: possible candidate is found in another module, you can import it into scope: = help: possible candidate is found in another module, you can import it into scope:
= help: `use issue_21221_4::T;` `use issue_21221_4::T;`
error: cannot continue compilation due to previous error error: cannot continue compilation due to previous error

View File

@ -5,7 +5,7 @@ error[E0404]: expected trait, found type alias `Foo`
| ^^^ type aliases cannot be used for traits | ^^^ type aliases cannot be used for traits
| |
= help: possible better candidate is found in another module, you can import it into scope: = help: possible better candidate is found in another module, you can import it into scope:
= help: `use issue_3907::Foo;` `use issue_3907::Foo;`
error: cannot continue compilation due to previous error error: cannot continue compilation due to previous error

View File

@ -5,7 +5,7 @@ error[E0404]: expected trait, found type parameter `Add`
| ^^^ not a trait | ^^^ not a trait
| |
= help: possible better candidate is found in another module, you can import it into scope: = help: possible better candidate is found in another module, you can import it into scope:
= help: `use std::ops::Add;` `use std::ops::Add;`
error: main function not found error: main function not found