Skip to content

Commit

Permalink
Use multiline Diagnostic for candidate in other module
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Jan 19, 2017
1 parent c8af93f commit 2883186
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 37 deletions.
33 changes: 17 additions & 16 deletions src/librustc_resolve/lib.rs
Expand Up @@ -67,6 +67,7 @@ use syntax_pos::{Span, DUMMY_SP, MultiSpan};
use errors::DiagnosticBuilder;

use std::cell::{Cell, RefCell};
use std::cmp;
use std::fmt;
use std::mem::replace;
use std::rc::Rc;
Expand Down Expand Up @@ -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:
Expand All @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/resolve/enums-are-namespaced-xc.stderr
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

6 changes: 3 additions & 3 deletions src/test/ui/resolve/issue-16058.stderr
Expand Up @@ -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

2 changes: 1 addition & 1 deletion src/test/ui/resolve/issue-17518.stderr
Expand Up @@ -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

18 changes: 9 additions & 9 deletions src/test/ui/resolve/issue-21221-1.stderr
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

2 changes: 1 addition & 1 deletion src/test/ui/resolve/issue-21221-2.stderr
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/resolve/issue-21221-3.stderr
Expand Up @@ -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

2 changes: 1 addition & 1 deletion src/test/ui/resolve/issue-21221-4.stderr
Expand Up @@ -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

2 changes: 1 addition & 1 deletion src/test/ui/resolve/issue-3907.stderr
Expand Up @@ -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

2 changes: 1 addition & 1 deletion src/test/ui/span/issue-35987.stderr
Expand Up @@ -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

Expand Down

0 comments on commit 2883186

Please sign in to comment.