Skip to content

Commit

Permalink
Tweak span and add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Nov 24, 2021
1 parent d86aff8 commit 505b09e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
7 changes: 2 additions & 5 deletions compiler/rustc_parse/src/parser/diagnostics.rs
Expand Up @@ -1925,11 +1925,8 @@ impl<'a> Parser<'a> {
}
};
let mut err =
self.struct_span_err(param.ident.span, "unexpected `const` parameter declaration");
err.span_label(
param.ident.span,
"expected a `const` expression, not a parameter declaration",
);
self.struct_span_err(param.span(), "unexpected `const` parameter declaration");
err.span_label(param.span(), "expected a `const` expression, not a parameter declaration");
if let (Some(generics), Ok(snippet)) =
(ty_generics, self.sess.source_map().span_to_snippet(param.span()))
{
Expand Down
Expand Up @@ -4,3 +4,12 @@ impl NInts<const N: usize> {} //~ ERROR unexpected `const` parameter declaration
fn main() {
let _: () = 42; //~ ERROR mismatched types
}

fn banana(a: <T<const N: usize>>::BAR) {}
//~^ ERROR unexpected `const` parameter declaration
//~| ERROR cannot find type `T` in this scope
fn chaenomeles() {
path::path::Struct::<const N: usize>()
//~^ ERROR unexpected `const` parameter declaration
//~| ERROR failed to resolve: use of undeclared crate or module `path`
}
33 changes: 29 additions & 4 deletions src/test/ui/parser/const-param-decl-on-type-instead-of-impl.stderr
@@ -1,14 +1,38 @@
error: unexpected `const` parameter declaration
--> $DIR/const-param-decl-on-type-instead-of-impl.rs:2:18
--> $DIR/const-param-decl-on-type-instead-of-impl.rs:2:12
|
LL | impl NInts<const N: usize> {}
| ^ expected a `const` expression, not a parameter declaration
| ^^^^^^^^^^^^^^ expected a `const` expression, not a parameter declaration
|
help: `const` parameters must be declared for the `impl`
|
LL | impl<const N: usize> NInts<N> {}
| ++++++++++++++++ ~

error: unexpected `const` parameter declaration
--> $DIR/const-param-decl-on-type-instead-of-impl.rs:8:17
|
LL | fn banana(a: <T<const N: usize>>::BAR) {}
| ^^^^^^^^^^^^^^ expected a `const` expression, not a parameter declaration

error: unexpected `const` parameter declaration
--> $DIR/const-param-decl-on-type-instead-of-impl.rs:12:26
|
LL | path::path::Struct::<const N: usize>()
| ^^^^^^^^^^^^^^ expected a `const` expression, not a parameter declaration

error[E0433]: failed to resolve: use of undeclared crate or module `path`
--> $DIR/const-param-decl-on-type-instead-of-impl.rs:12:5
|
LL | path::path::Struct::<const N: usize>()
| ^^^^ use of undeclared crate or module `path`

error[E0412]: cannot find type `T` in this scope
--> $DIR/const-param-decl-on-type-instead-of-impl.rs:8:15
|
LL | fn banana(a: <T<const N: usize>>::BAR) {}
| ^ not found in this scope

error[E0308]: mismatched types
--> $DIR/const-param-decl-on-type-instead-of-impl.rs:5:17
|
Expand All @@ -17,6 +41,7 @@ LL | let _: () = 42;
| |
| expected due to this

error: aborting due to 2 previous errors
error: aborting due to 6 previous errors

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

0 comments on commit 505b09e

Please sign in to comment.