Skip to content

Commit f185265

Browse files
committed
Rollup merge of #39168 - estebank:multiline-candidate, r=petrochenkov
Use multiline Diagnostic for candidate in other module ``` error[E0574]: expected struct, variant or union type, found enum `Result` --> $DIR/issue-16058.rs:19:9 | 19 | Result { | ^^^^^^ not a struct, variant or union type | = help: possible better candidates are found in other modules, you can import them into scope: `use std::fmt::Result;` `use std::io::Result;` `use std::thread::Result;` error: aborting due to previous error ```
2 parents a759406 + 2883186 commit f185265

File tree

10 files changed

+38
-37
lines changed

10 files changed

+38
-37
lines changed

src/librustc_resolve/lib.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ use syntax_pos::{Span, DUMMY_SP, MultiSpan};
6767
use errors::DiagnosticBuilder;
6868

6969
use std::cell::{Cell, RefCell};
70+
use std::cmp;
7071
use std::fmt;
7172
use std::mem::replace;
7273
use std::rc::Rc;
@@ -3266,7 +3267,7 @@ fn show_candidates(session: &mut DiagnosticBuilder,
32663267
better: bool) {
32673268
// don't show more than MAX_CANDIDATES results, so
32683269
// we're consistent with the trait suggestions
3269-
const MAX_CANDIDATES: usize = 5;
3270+
const MAX_CANDIDATES: usize = 4;
32703271

32713272
// we want consistent results across executions, but candidates are produced
32723273
// by iterating through a hash map, so make sure they are ordered:
@@ -3279,21 +3280,21 @@ fn show_candidates(session: &mut DiagnosticBuilder,
32793280
1 => " is found in another module, you can import it",
32803281
_ => "s are found in other modules, you can import them",
32813282
};
3282-
session.help(&format!("possible {}candidate{} into scope:", better, msg_diff));
3283-
3284-
let count = path_strings.len() as isize - MAX_CANDIDATES as isize + 1;
3285-
for (idx, path_string) in path_strings.iter().enumerate() {
3286-
if idx == MAX_CANDIDATES - 1 && count > 1 {
3287-
session.help(
3288-
&format!(" and {} other candidates", count).to_string(),
3289-
);
3290-
break;
3291-
} else {
3292-
session.help(
3293-
&format!(" `use {};`", path_string).to_string(),
3294-
);
3295-
}
3296-
}
3283+
3284+
let end = cmp::min(MAX_CANDIDATES, path_strings.len());
3285+
session.help(&format!("possible {}candidate{} into scope:{}{}",
3286+
better,
3287+
msg_diff,
3288+
&path_strings[0..end].iter().map(|candidate| {
3289+
format!("\n `use {};`", candidate)
3290+
}).collect::<String>(),
3291+
if path_strings.len() > MAX_CANDIDATES {
3292+
format!("\nand {} other candidates",
3293+
path_strings.len() - MAX_CANDIDATES)
3294+
} else {
3295+
"".to_owned()
3296+
}
3297+
));
32973298
}
32983299

32993300
/// A somewhat inefficient routine to obtain the name of a module.

src/test/ui/resolve/enums-are-namespaced-xc.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ error[E0425]: cannot find value `A` in module `namespaced_enums`
55
| ^^^^^^^^^^^^^^^^^^^ not found in `namespaced_enums`
66
|
77
= help: possible candidate is found in another module, you can import it into scope:
8-
= help: `use namespaced_enums::Foo::A;`
8+
`use namespaced_enums::Foo::A;`
99

1010
error[E0425]: cannot find function `B` in module `namespaced_enums`
1111
--> $DIR/enums-are-namespaced-xc.rs:18:13
@@ -14,7 +14,7 @@ error[E0425]: cannot find function `B` in module `namespaced_enums`
1414
| ^^^^^^^^^^^^^^^^^^^ not found in `namespaced_enums`
1515
|
1616
= help: possible candidate is found in another module, you can import it into scope:
17-
= help: `use namespaced_enums::Foo::B;`
17+
`use namespaced_enums::Foo::B;`
1818

1919
error[E0422]: cannot find struct, variant or union type `C` in module `namespaced_enums`
2020
--> $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
2323
| ^^^^^^^^^^^^^^^^^^^ not found in `namespaced_enums`
2424
|
2525
= help: possible candidate is found in another module, you can import it into scope:
26-
= help: `use namespaced_enums::Foo::C;`
26+
`use namespaced_enums::Foo::C;`
2727

2828
error: aborting due to 3 previous errors
2929

src/test/ui/resolve/issue-16058.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ error[E0574]: expected struct, variant or union type, found enum `Result`
55
| ^^^^^^ not a struct, variant or union type
66
|
77
= help: possible better candidates are found in other modules, you can import them into scope:
8-
= help: `use std::fmt::Result;`
9-
= help: `use std::io::Result;`
10-
= help: `use std::thread::Result;`
8+
`use std::fmt::Result;`
9+
`use std::io::Result;`
10+
`use std::thread::Result;`
1111

1212
error: aborting due to previous error
1313

src/test/ui/resolve/issue-17518.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ error[E0422]: cannot find struct, variant or union type `E` in this scope
55
| ^ not found in this scope
66
|
77
= help: possible candidate is found in another module, you can import it into scope:
8-
= help: `use SomeEnum::E;`
8+
`use SomeEnum::E;`
99

1010
error: aborting due to previous error
1111

src/test/ui/resolve/issue-21221-1.stderr

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ error[E0405]: cannot find trait `Mul` in this scope
55
| ^^^ not found in this scope
66
|
77
= help: possible candidates are found in other modules, you can import them into scope:
8-
= help: `use mul1::Mul;`
9-
= help: `use mul2::Mul;`
10-
= help: `use std::ops::Mul;`
8+
`use mul1::Mul;`
9+
`use mul2::Mul;`
10+
`use std::ops::Mul;`
1111

1212
error[E0412]: cannot find type `Mul` in this scope
1313
--> $DIR/issue-21221-1.rs:72:16
@@ -16,11 +16,11 @@ error[E0412]: cannot find type `Mul` in this scope
1616
| ^^^ not found in this scope
1717
|
1818
= help: possible candidates are found in other modules, you can import them into scope:
19-
= help: `use mul1::Mul;`
20-
= help: `use mul2::Mul;`
21-
= help: `use mul3::Mul;`
22-
= help: `use mul4::Mul;`
23-
= help: and 2 other candidates
19+
`use mul1::Mul;`
20+
`use mul2::Mul;`
21+
`use mul3::Mul;`
22+
`use mul4::Mul;`
23+
and 2 other candidates
2424

2525
error[E0405]: cannot find trait `ThisTraitReallyDoesntExistInAnyModuleReally` in this scope
2626
--> $DIR/issue-21221-1.rs:83:6
@@ -35,7 +35,7 @@ error[E0405]: cannot find trait `Div` in this scope
3535
| ^^^ not found in this scope
3636
|
3737
= help: possible candidate is found in another module, you can import it into scope:
38-
= help: `use std::ops::Div;`
38+
`use std::ops::Div;`
3939

4040
error: cannot continue compilation due to previous error
4141

src/test/ui/resolve/issue-21221-2.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ error[E0405]: cannot find trait `T` in this scope
55
| ^ not found in this scope
66
|
77
= help: possible candidate is found in another module, you can import it into scope:
8-
= help: `use foo::bar::T;`
8+
`use foo::bar::T;`
99

1010
error: main function not found
1111

src/test/ui/resolve/issue-21221-3.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ error[E0405]: cannot find trait `OuterTrait` in this scope
55
| ^^^^^^^^^^ not found in this scope
66
|
77
= help: possible candidate is found in another module, you can import it into scope:
8-
= help: `use issue_21221_3::outer::OuterTrait;`
8+
`use issue_21221_3::outer::OuterTrait;`
99

1010
error: cannot continue compilation due to previous error
1111

src/test/ui/resolve/issue-21221-4.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ error[E0405]: cannot find trait `T` in this scope
55
| ^ not found in this scope
66
|
77
= help: possible candidate is found in another module, you can import it into scope:
8-
= help: `use issue_21221_4::T;`
8+
`use issue_21221_4::T;`
99

1010
error: cannot continue compilation due to previous error
1111

src/test/ui/resolve/issue-3907.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ error[E0404]: expected trait, found type alias `Foo`
55
| ^^^ type aliases cannot be used for traits
66
|
77
= help: possible better candidate is found in another module, you can import it into scope:
8-
= help: `use issue_3907::Foo;`
8+
`use issue_3907::Foo;`
99

1010
error: cannot continue compilation due to previous error
1111

src/test/ui/span/issue-35987.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ error[E0404]: expected trait, found type parameter `Add`
55
| ^^^ not a trait
66
|
77
= help: possible better candidate is found in another module, you can import it into scope:
8-
= help: `use std::ops::Add;`
8+
`use std::ops::Add;`
99

1010
error: main function not found
1111

0 commit comments

Comments
 (0)