Skip to content

Commit 263e722

Browse files
committed
Rollup merge of rust-lang#31901 - bluss:suggest-use, r=sanxiyn
suggest: Put the `use` in suggested code inside the quotes Change import a trait suggestion from: help: candidate #1: use `std::io::Write` to help: candidate #1: `use std::io::Write` so that the code can be copied directly. Fixes rust-lang#31864
2 parents f74855e + 5db4316 commit 263e722

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/librustc_typeck/check/method/suggest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ fn suggest_traits_to_import<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
271271

272272
for (i, trait_did) in candidates.iter().enumerate() {
273273
err.fileline_help(span,
274-
&format!("candidate #{}: use `{}`",
274+
&format!("candidate #{}: `use {}`",
275275
i + 1,
276276
fcx.tcx().item_path_str(*trait_did)));
277277
}

src/test/compile-fail/no-method-suggested-traits.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,31 @@ fn main() {
3434
1u32.method();
3535
//~^ HELP following traits are implemented but not in scope, perhaps add a `use` for one of them
3636
//~^^ ERROR no method named
37-
//~^^^ HELP `foo::Bar`
38-
//~^^^^ HELP `no_method_suggested_traits::foo::PubPub`
37+
//~^^^ HELP `use foo::Bar`
38+
//~^^^^ HELP `use no_method_suggested_traits::foo::PubPub`
3939
std::rc::Rc::new(&mut Box::new(&1u32)).method();
4040
//~^ HELP following traits are implemented but not in scope, perhaps add a `use` for one of them
4141
//~^^ ERROR no method named
42-
//~^^^ HELP `foo::Bar`
43-
//~^^^^ HELP `no_method_suggested_traits::foo::PubPub`
42+
//~^^^ HELP `use foo::Bar`
43+
//~^^^^ HELP `use no_method_suggested_traits::foo::PubPub`
4444

4545
'a'.method();
4646
//~^ ERROR no method named
4747
//~^^ HELP the following trait is implemented but not in scope, perhaps add a `use` for it:
48-
//~^^^ HELP `foo::Bar`
48+
//~^^^ HELP `use foo::Bar`
4949
std::rc::Rc::new(&mut Box::new(&'a')).method();
5050
//~^ ERROR no method named
5151
//~^^ HELP the following trait is implemented but not in scope, perhaps add a `use` for it:
52-
//~^^^ HELP `foo::Bar`
52+
//~^^^ HELP `use foo::Bar`
5353

5454
1i32.method();
5555
//~^ ERROR no method named
5656
//~^^ HELP the following trait is implemented but not in scope, perhaps add a `use` for it:
57-
//~^^^ HELP `no_method_suggested_traits::foo::PubPub`
57+
//~^^^ HELP `use no_method_suggested_traits::foo::PubPub`
5858
std::rc::Rc::new(&mut Box::new(&1i32)).method();
5959
//~^ ERROR no method named
6060
//~^^ HELP the following trait is implemented but not in scope, perhaps add a `use` for it:
61-
//~^^^ HELP `no_method_suggested_traits::foo::PubPub`
61+
//~^^^ HELP `use no_method_suggested_traits::foo::PubPub`
6262

6363
Foo.method();
6464
//~^ ERROR no method named

0 commit comments

Comments
 (0)