Skip to content

use correct casing for rename suggestions #47838

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/blind-item-item-shadow.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

4 changes: 2 additions & 2 deletions src/test/ui/double-import.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

4 changes: 2 additions & 2 deletions src/test/ui/imports/duplicate.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/issue-26886.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

4 changes: 2 additions & 2 deletions src/test/ui/resolve-conflict-item-vs-import.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/use-mod.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down