提交 28831861 编写于 作者: E Esteban Küber

Use multiline Diagnostic for candidate in other module

上级 c8af93f0
......@@ -67,6 +67,7 @@
use errors::DiagnosticBuilder;
use std::cell::{Cell, RefCell};
use std::cmp;
use std::fmt;
use std::mem::replace;
use std::rc::Rc;
......@@ -3224,7 +3225,7 @@ fn show_candidates(session: &mut DiagnosticBuilder,
better: bool) {
// don't show more than MAX_CANDIDATES results, so
// 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
// 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",
_ => "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;
for (idx, path_string) in path_strings.iter().enumerate() {
if idx == MAX_CANDIDATES - 1 && count > 1 {
session.help(
&format!(" and {} other candidates", count).to_string(),
);
break;
} else {
session.help(
&format!(" `use {};`", path_string).to_string(),
);
}
}
let end = cmp::min(MAX_CANDIDATES, path_strings.len());
session.help(&format!("possible {}candidate{} into scope:{}{}",
better,
msg_diff,
&path_strings[0..end].iter().map(|candidate| {
format!("\n `use {};`", candidate)
}).collect::<String>(),
if path_strings.len() > MAX_CANDIDATES {
format!("\nand {} other candidates",
path_strings.len() - MAX_CANDIDATES)
} else {
"".to_owned()
}
));
}
/// A somewhat inefficient routine to obtain the name of a module.
......
......@@ -5,7 +5,7 @@ error[E0425]: cannot find value `A` in module `namespaced_enums`
| ^^^^^^^^^^^^^^^^^^^ not found in `namespaced_enums`
|
= 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`
--> $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`
|
= 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`
--> $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`
|
= 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
......@@ -5,9 +5,9 @@ error[E0574]: expected struct, variant or union type, found enum `Result`
| ^^^^^^ not a struct, variant or union type
|
= help: possible better candidates are found in other modules, you can import them into scope:
= help: `use std::fmt::Result;`
= help: `use std::io::Result;`
= help: `use std::thread::Result;`
`use std::fmt::Result;`
`use std::io::Result;`
`use std::thread::Result;`
error: aborting due to previous error
......@@ -5,7 +5,7 @@ error[E0422]: cannot find struct, variant or union type `E` in this scope
| ^ not found in this 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
......@@ -5,9 +5,9 @@ error[E0405]: cannot find trait `Mul` in this scope
| ^^^ not found in this scope
|
= help: possible candidates are found in other modules, you can import them into scope:
= help: `use mul1::Mul;`
= help: `use mul2::Mul;`
= help: `use std::ops::Mul;`
`use mul1::Mul;`
`use mul2::Mul;`
`use std::ops::Mul;`
error[E0412]: cannot find type `Mul` in this scope
--> $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
|
= help: possible candidates are found in other modules, you can import them into scope:
= help: `use mul1::Mul;`
= help: `use mul2::Mul;`
= help: `use mul3::Mul;`
= help: `use mul4::Mul;`
= help: and 2 other candidates
`use mul1::Mul;`
`use mul2::Mul;`
`use mul3::Mul;`
`use mul4::Mul;`
and 2 other candidates
error[E0405]: cannot find trait `ThisTraitReallyDoesntExistInAnyModuleReally` in this scope
--> $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
|
= 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
......@@ -5,7 +5,7 @@ error[E0405]: cannot find trait `T` in this scope
| ^ not found in this 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
......
......@@ -5,7 +5,7 @@ error[E0405]: cannot find trait `OuterTrait` in this scope
| ^^^^^^^^^^ not found in this 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
......@@ -5,7 +5,7 @@ error[E0405]: cannot find trait `T` in this scope
| ^ not found in this 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
......@@ -5,7 +5,7 @@ error[E0404]: expected trait, found type alias `Foo`
| ^^^ type aliases cannot be used for traits
|
= 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
......@@ -5,7 +5,7 @@ error[E0404]: expected trait, found type parameter `Add`
| ^^^ not a trait
|
= 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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册