Skip to content

Commit b5f94c6

Browse files
committed
Use more accurate span for : to :: suggestion
1 parent dd40e0b commit b5f94c6

9 files changed

+12
-8
lines changed

compiler/rustc_parse/src/errors.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1562,9 +1562,11 @@ pub(crate) struct ExpectedFnPathFoundFnKeyword {
15621562
#[diag(parse_path_single_colon)]
15631563
pub(crate) struct PathSingleColon {
15641564
#[primary_span]
1565-
#[suggestion(applicability = "machine-applicable", code = "::", style = "verbose")]
15661565
pub span: Span,
15671566

1567+
#[suggestion(applicability = "machine-applicable", code = ":", style = "verbose")]
1568+
pub suggestion: Span,
1569+
15681570
#[note(parse_type_ascription_removed)]
15691571
pub type_ascription: Option<()>,
15701572
}

compiler/rustc_parse/src/parser/path.rs

+2
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ impl<'a> Parser<'a> {
258258
self.bump(); // bump past the colon
259259
self.dcx().emit_err(PathSingleColon {
260260
span: self.prev_token.span,
261+
suggestion: self.prev_token.span.shrink_to_hi(),
261262
type_ascription: self
262263
.psess
263264
.unstable_features
@@ -329,6 +330,7 @@ impl<'a> Parser<'a> {
329330
err.cancel();
330331
err = self.dcx().create_err(PathSingleColon {
331332
span: self.token.span,
333+
suggestion: self.prev_token.span.shrink_to_hi(),
332334
type_ascription: self
333335
.psess
334336
.unstable_features

tests/ui/generics/single-colon-path-not-const-generics.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ LL | a: Vec<foo::bar:A>,
1010
help: use a double colon instead
1111
|
1212
LL | a: Vec<foo::bar::A>,
13-
| ~~
13+
| +
1414

1515
error: aborting due to 1 previous error
1616

tests/ui/suggestions/type-ascription-instead-of-method.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ LL | let _ = Box:new("foo".to_string());
88
help: use a double colon instead
99
|
1010
LL | let _ = Box::new("foo".to_string());
11-
| ~~
11+
| +
1212

1313
error: aborting due to 1 previous error
1414

tests/ui/suggestions/type-ascription-instead-of-path.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ LL | std:io::stdin();
88
help: use a double colon instead
99
|
1010
LL | std::io::stdin();
11-
| ~~
11+
| +
1212

1313
error: aborting due to 1 previous error
1414

tests/ui/suggestions/type-ascription-instead-of-variant.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ LL | let _ = Option:Some("");
88
help: use a double colon instead
99
|
1010
LL | let _ = Option::Some("");
11-
| ~~
11+
| +
1212

1313
error: aborting due to 1 previous error
1414

tests/ui/type/ascription/issue-47666.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ LL | let _ = Option:Some(vec![0, 1]);
88
help: use a double colon instead
99
|
1010
LL | let _ = Option::Some(vec![0, 1]);
11-
| ~~
11+
| +
1212

1313
error: aborting due to 1 previous error
1414

tests/ui/type/ascription/issue-54516.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ LL | println!("{}", std::mem:size_of::<BTreeMap<u32, u32>>());
88
help: use a double colon instead
99
|
1010
LL | println!("{}", std::mem::size_of::<BTreeMap<u32, u32>>());
11-
| ~~
11+
| +
1212

1313
error: aborting due to 1 previous error
1414

tests/ui/type/ascription/issue-60933.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ LL | let _: usize = std::mem:size_of::<u32>();
88
help: use a double colon instead
99
|
1010
LL | let _: usize = std::mem::size_of::<u32>();
11-
| ~~
11+
| +
1212

1313
error: aborting due to 1 previous error
1414

0 commit comments

Comments
 (0)