Rollup merge of #47838 - euclio:snakecase-suggestion, r=petrochenkov

use correct casing for rename suggestions

If the original name is uppercase, use camel case. Otherwise, use snake
case.
This commit is contained in:
kennytm 2018-01-31 16:36:05 +08:00 committed by GitHub
commit 89ea6d2a3e
8 changed files with 21 additions and 15 deletions

View file

@ -3998,14 +3998,20 @@ impl<'a> Resolver<'a> {
if let (Ok(snippet), false) = (cm.span_to_snippet(binding.span),
binding.is_renamed_extern_crate()) {
let suggested_name = if name.as_str().chars().next().unwrap().is_uppercase() {
format!("Other{}", name)
} else {
format!("other_{}", name)
};
err.span_suggestion(binding.span,
rename_msg,
if snippet.ends_with(';') {
format!("{} as Other{};",
format!("{} as {};",
&snippet[..snippet.len()-1],
name)
suggested_name)
} else {
format!("{} as Other{}", snippet, name)
format!("{} as {}", snippet, suggested_name)
});
} else {
err.span_label(binding.span, rename_msg);

View file

@ -10,8 +10,8 @@ error[E0255]: the name `foo` is defined multiple times
= note: `foo` must be defined only once in the type namespace of this module
help: You can use `as` to change the binding name of the import
|
13 | use foo::foo as Otherfoo;
| ^^^^^^^^^^^^^^^^^^^^
13 | use foo::foo as other_foo;
| ^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error

View file

@ -9,8 +9,8 @@ error[E0252]: the name `foo` is defined multiple times
= note: `foo` must be defined only once in the value namespace of this module
help: You can use `as` to change the binding name of the import
|
23 | use sub2::foo as Otherfoo; //~ ERROR the name `foo` is defined multiple times
| ^^^^^^^^^^^^^^^^^^^^^
23 | use sub2::foo as other_foo; //~ ERROR the name `foo` is defined multiple times
| ^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error

View file

@ -9,8 +9,8 @@ error[E0252]: the name `foo` is defined multiple times
= note: `foo` must be defined only once in the value namespace of this module
help: You can use `as` to change the binding name of the import
|
25 | use a::foo as Otherfoo; //~ ERROR the name `foo` is defined multiple times
| ^^^^^^^^^^^^^^^^^^
25 | use a::foo as other_foo; //~ ERROR the name `foo` is defined multiple times
| ^^^^^^^^^^^^^^^^^^^
error[E0659]: `foo` is ambiguous
--> $DIR/duplicate.rs:56:9

View file

@ -24,8 +24,8 @@ error[E0252]: the name `sync` is defined multiple times
= note: `sync` must be defined only once in the type namespace of this module
help: You can use `as` to change the binding name of the import
|
14 | use std::sync as Othersync; //~ ERROR the name `sync` is defined multiple times
| ^^^^^^^^^^^^^^^^^^^^^^
14 | use std::sync as other_sync; //~ ERROR the name `sync` is defined multiple times
| ^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors

View file

@ -10,8 +10,8 @@ error[E0255]: the name `transmute` is defined multiple times
= note: `transmute` must be defined only once in the value namespace of this module
help: You can use `as` to change the binding name of the import
|
11 | use std::mem::transmute as Othertransmute;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11 | use std::mem::transmute as other_transmute;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error

View file

@ -7,7 +7,7 @@ error[E0259]: the name `std` is defined multiple times
= note: `std` must be defined only once in the type namespace of this module
help: You can use `as` to change the binding name of the import
|
11 | extern crate std as Otherstd;
11 | extern crate std as other_std;
|
error: aborting due to previous error

View file

@ -25,7 +25,7 @@ error[E0252]: the name `bar` is defined multiple times
= note: `bar` must be defined only once in the type namespace of this module
help: You can use `as` to change the binding name of the import
|
15 | self as Otherbar
15 | self as other_bar
|
error: aborting due to 3 previous errors