Skip to content

Commit 043d461

Browse files
committed
use correct casing for rename suggestions
If the original name is uppercase, use camel case. Otherwise, use snake case.
1 parent 21882aa commit 043d461

8 files changed

+21
-15
lines changed

src/librustc_resolve/lib.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -3998,14 +3998,20 @@ impl<'a> Resolver<'a> {
39983998

39993999
if let (Ok(snippet), false) = (cm.span_to_snippet(binding.span),
40004000
binding.is_renamed_extern_crate()) {
4001+
let suggested_name = if name.as_str().chars().next().unwrap().is_uppercase() {
4002+
format!("Other{}", name)
4003+
} else {
4004+
format!("other_{}", name)
4005+
};
4006+
40014007
err.span_suggestion(binding.span,
40024008
rename_msg,
40034009
if snippet.ends_with(';') {
4004-
format!("{} as Other{};",
4010+
format!("{} as {};",
40054011
&snippet[..snippet.len()-1],
4006-
name)
4012+
suggested_name)
40074013
} else {
4008-
format!("{} as Other{}", snippet, name)
4014+
format!("{} as {}", snippet, suggested_name)
40094015
});
40104016
} else {
40114017
err.span_label(binding.span, rename_msg);

src/test/ui/blind-item-item-shadow.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ error[E0255]: the name `foo` is defined multiple times
1010
= note: `foo` must be defined only once in the type namespace of this module
1111
help: You can use `as` to change the binding name of the import
1212
|
13-
13 | use foo::foo as Otherfoo;
14-
| ^^^^^^^^^^^^^^^^^^^^
13+
13 | use foo::foo as other_foo;
14+
| ^^^^^^^^^^^^^^^^^^^^^
1515

1616
error: aborting due to previous error
1717

src/test/ui/double-import.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ error[E0252]: the name `foo` is defined multiple times
99
= note: `foo` must be defined only once in the value namespace of this module
1010
help: You can use `as` to change the binding name of the import
1111
|
12-
23 | use sub2::foo as Otherfoo; //~ ERROR the name `foo` is defined multiple times
13-
| ^^^^^^^^^^^^^^^^^^^^^
12+
23 | use sub2::foo as other_foo; //~ ERROR the name `foo` is defined multiple times
13+
| ^^^^^^^^^^^^^^^^^^^^^^
1414

1515
error: aborting due to previous error
1616

src/test/ui/imports/duplicate.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ error[E0252]: the name `foo` is defined multiple times
99
= note: `foo` must be defined only once in the value namespace of this module
1010
help: You can use `as` to change the binding name of the import
1111
|
12-
25 | use a::foo as Otherfoo; //~ ERROR the name `foo` is defined multiple times
13-
| ^^^^^^^^^^^^^^^^^^
12+
25 | use a::foo as other_foo; //~ ERROR the name `foo` is defined multiple times
13+
| ^^^^^^^^^^^^^^^^^^^
1414

1515
error[E0659]: `foo` is ambiguous
1616
--> $DIR/duplicate.rs:56:9

src/test/ui/issue-26886.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ error[E0252]: the name `sync` is defined multiple times
2424
= note: `sync` must be defined only once in the type namespace of this module
2525
help: You can use `as` to change the binding name of the import
2626
|
27-
14 | use std::sync as Othersync; //~ ERROR the name `sync` is defined multiple times
28-
| ^^^^^^^^^^^^^^^^^^^^^^
27+
14 | use std::sync as other_sync; //~ ERROR the name `sync` is defined multiple times
28+
| ^^^^^^^^^^^^^^^^^^^^^^^
2929

3030
error: aborting due to 2 previous errors
3131

src/test/ui/resolve-conflict-item-vs-import.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ error[E0255]: the name `transmute` is defined multiple times
1010
= note: `transmute` must be defined only once in the value namespace of this module
1111
help: You can use `as` to change the binding name of the import
1212
|
13-
11 | use std::mem::transmute as Othertransmute;
14-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13+
11 | use std::mem::transmute as other_transmute;
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1515

1616
error: aborting due to previous error
1717

src/test/ui/suggestions/issue-45799-bad-extern-crate-rename-suggestion-formatting.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ error[E0259]: the name `std` is defined multiple times
77
= note: `std` must be defined only once in the type namespace of this module
88
help: You can use `as` to change the binding name of the import
99
|
10-
11 | extern crate std as Otherstd;
10+
11 | extern crate std as other_std;
1111
|
1212

1313
error: aborting due to previous error

src/test/ui/use-mod.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ error[E0252]: the name `bar` is defined multiple times
2525
= note: `bar` must be defined only once in the type namespace of this module
2626
help: You can use `as` to change the binding name of the import
2727
|
28-
15 | self as Otherbar
28+
15 | self as other_bar
2929
|
3030

3131
error: aborting due to 3 previous errors

0 commit comments

Comments
 (0)