Skip to content

Commit 505b09e

Browse files
committed
Tweak span and add more tests
1 parent d86aff8 commit 505b09e

File tree

3 files changed

+40
-9
lines changed

3 files changed

+40
-9
lines changed

compiler/rustc_parse/src/parser/diagnostics.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -1925,11 +1925,8 @@ impl<'a> Parser<'a> {
19251925
}
19261926
};
19271927
let mut err =
1928-
self.struct_span_err(param.ident.span, "unexpected `const` parameter declaration");
1929-
err.span_label(
1930-
param.ident.span,
1931-
"expected a `const` expression, not a parameter declaration",
1932-
);
1928+
self.struct_span_err(param.span(), "unexpected `const` parameter declaration");
1929+
err.span_label(param.span(), "expected a `const` expression, not a parameter declaration");
19331930
if let (Some(generics), Ok(snippet)) =
19341931
(ty_generics, self.sess.source_map().span_to_snippet(param.span()))
19351932
{

src/test/ui/parser/const-param-decl-on-type-instead-of-impl.rs

+9
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,12 @@ impl NInts<const N: usize> {} //~ ERROR unexpected `const` parameter declaration
44
fn main() {
55
let _: () = 42; //~ ERROR mismatched types
66
}
7+
8+
fn banana(a: <T<const N: usize>>::BAR) {}
9+
//~^ ERROR unexpected `const` parameter declaration
10+
//~| ERROR cannot find type `T` in this scope
11+
fn chaenomeles() {
12+
path::path::Struct::<const N: usize>()
13+
//~^ ERROR unexpected `const` parameter declaration
14+
//~| ERROR failed to resolve: use of undeclared crate or module `path`
15+
}
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,38 @@
11
error: unexpected `const` parameter declaration
2-
--> $DIR/const-param-decl-on-type-instead-of-impl.rs:2:18
2+
--> $DIR/const-param-decl-on-type-instead-of-impl.rs:2:12
33
|
44
LL | impl NInts<const N: usize> {}
5-
| ^ expected a `const` expression, not a parameter declaration
5+
| ^^^^^^^^^^^^^^ expected a `const` expression, not a parameter declaration
66
|
77
help: `const` parameters must be declared for the `impl`
88
|
99
LL | impl<const N: usize> NInts<N> {}
1010
| ++++++++++++++++ ~
1111

12+
error: unexpected `const` parameter declaration
13+
--> $DIR/const-param-decl-on-type-instead-of-impl.rs:8:17
14+
|
15+
LL | fn banana(a: <T<const N: usize>>::BAR) {}
16+
| ^^^^^^^^^^^^^^ expected a `const` expression, not a parameter declaration
17+
18+
error: unexpected `const` parameter declaration
19+
--> $DIR/const-param-decl-on-type-instead-of-impl.rs:12:26
20+
|
21+
LL | path::path::Struct::<const N: usize>()
22+
| ^^^^^^^^^^^^^^ expected a `const` expression, not a parameter declaration
23+
24+
error[E0433]: failed to resolve: use of undeclared crate or module `path`
25+
--> $DIR/const-param-decl-on-type-instead-of-impl.rs:12:5
26+
|
27+
LL | path::path::Struct::<const N: usize>()
28+
| ^^^^ use of undeclared crate or module `path`
29+
30+
error[E0412]: cannot find type `T` in this scope
31+
--> $DIR/const-param-decl-on-type-instead-of-impl.rs:8:15
32+
|
33+
LL | fn banana(a: <T<const N: usize>>::BAR) {}
34+
| ^ not found in this scope
35+
1236
error[E0308]: mismatched types
1337
--> $DIR/const-param-decl-on-type-instead-of-impl.rs:5:17
1438
|
@@ -17,6 +41,7 @@ LL | let _: () = 42;
1741
| |
1842
| expected due to this
1943

20-
error: aborting due to 2 previous errors
44+
error: aborting due to 6 previous errors
2145

22-
For more information about this error, try `rustc --explain E0308`.
46+
Some errors have detailed explanations: E0308, E0412, E0433.
47+
For more information about an error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)