Skip to content

Commit 9a07a7c

Browse files
committed
Fix use rename suggestion
1 parent e1d731c commit 9a07a7c

8 files changed

+26
-16
lines changed

compiler/rustc_resolve/src/diagnostics.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
383383
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(binding_span) {
384384
if pos <= snippet.len() {
385385
span = binding_span
386-
.with_hi(binding_span.lo() + BytePos(pos as u32))
387-
.shrink_to_hi();
386+
.with_lo(binding_span.lo() + BytePos(pos as u32))
387+
.with_hi(
388+
binding_span.hi()
389+
- BytePos(if snippet.ends_with(';') { 1 } else { 0 }),
390+
);
388391
suggestion = Some(format!(" as {}", suggested_name,))
389392
}
390393
}

tests/ui/imports/issue-45829/import-self.stderr

+3-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ LL | use foo::self;
4848
= note: `foo` must be defined only once in the type namespace of this module
4949
help: you can use `as` to change the binding name of the import
5050
|
51-
LL | use foo as other_foo::self;
52-
| ++++++++++++
51+
LL - use foo::self;
52+
LL + use foo as other_foo;
53+
|
5354

5455
error[E0252]: the name `A` is defined multiple times
5556
--> $DIR/import-self.rs:16:11

tests/ui/imports/issue-45829/issue-45829.stderr

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ LL | use foo::{A, B as A};
99
= note: `A` must be defined only once in the type namespace of this module
1010
help: you can use `as` to change the binding name of the import
1111
|
12-
LL | use foo::{A, B as OtherA as A};
13-
| +++++++++
12+
LL - use foo::{A, B as A};
13+
LL + use foo::{A, B as OtherA};
14+
|
1415

1516
error: aborting due to 1 previous error
1617

tests/ui/imports/issue-45829/rename-use-vs-extern.stderr

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ LL | use std as issue_45829_b;
99
= note: `issue_45829_b` must be defined only once in the type namespace of this module
1010
help: you can use `as` to change the binding name of the import
1111
|
12-
LL | use std as other_issue_45829_b as issue_45829_b;
13-
| ++++++++++++++++++++++
12+
LL - use std as issue_45829_b;
13+
LL + use std as other_issue_45829_b;
14+
|
1415

1516
error: aborting due to 1 previous error
1617

tests/ui/imports/issue-45829/rename-use-with-tabs.stderr

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ LL | use foo::{A, bar::B as A};
99
= note: `A` must be defined only once in the type namespace of this module
1010
help: you can use `as` to change the binding name of the import
1111
|
12-
LL | use foo::{A, bar::B as OtherA as A};
13-
| +++++++++
12+
LL - use foo::{A, bar::B as A};
13+
LL + use foo::{A, bar::B as OtherA};
14+
|
1415

1516
error: aborting due to 1 previous error
1617

tests/ui/imports/issue-45829/rename-with-path.stderr

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ LL | use std::{collections::HashMap as A, sync::Arc as A};
99
= note: `A` must be defined only once in the type namespace of this module
1010
help: you can use `as` to change the binding name of the import
1111
|
12-
LL | use std::{collections::HashMap as A, sync::Arc as OtherA as A};
13-
| +++++++++
12+
LL - use std::{collections::HashMap as A, sync::Arc as A};
13+
LL + use std::{collections::HashMap as A, sync::Arc as OtherA};
14+
|
1415

1516
error: aborting due to 1 previous error
1617

tests/ui/imports/issue-45829/rename.stderr

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ LL | use std as core;
99
= note: `core` must be defined only once in the type namespace of this module
1010
help: you can use `as` to change the binding name of the import
1111
|
12-
LL | use std as other_core as core;
13-
| +++++++++++++
12+
LL - use std as core;
13+
LL + use std as other_core;
14+
|
1415

1516
error: aborting due to 1 previous error
1617

tests/ui/resolve/resolve-conflict-import-vs-extern-crate.stderr

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ LL | use std::slice as std;
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-
LL | use std::slice as other_std as std;
11-
| ++++++++++++
10+
LL - use std::slice as std;
11+
LL + use std::slice as other_std;
12+
|
1213

1314
error: aborting due to 1 previous error
1415

0 commit comments

Comments
 (0)