Skip to content

Commit

Permalink
Added regression test for using generic parameters on modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Regueiro committed Dec 26, 2018
1 parent 5a36f9e commit 8eb1a9e
Show file tree
Hide file tree
Showing 35 changed files with 306 additions and 279 deletions.
2 changes: 1 addition & 1 deletion src/librustc/hir/mod.rs
Expand Up @@ -420,7 +420,7 @@ pub struct GenericArgs {
/// The generic arguments for this path segment.
pub args: HirVec<GenericArg>,
/// Bindings (equality constraints) on associated types, if present.
/// E.g., `Foo<A=Bar>`.
/// E.g., `Foo<A = Bar>`.
pub bindings: HirVec<TypeBinding>,
/// Were arguments written in parenthesized form `Fn(T) -> U`?
/// This is required mostly for pretty-printing and diagnostics,
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_typeck/astconv.rs
Expand Up @@ -1437,20 +1437,20 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
if err_for_lt { continue }
err_for_lt = true;
(struct_span_err!(self.tcx().sess, lt.span, E0110,
"lifetime parameters are not allowed on this type"),
"lifetime arguments are not allowed on this entity"),
lt.span,
"lifetime")
}
hir::GenericArg::Type(ty) => {
if err_for_ty { continue }
err_for_ty = true;
(struct_span_err!(self.tcx().sess, ty.span, E0109,
"type parameters are not allowed on this type"),
"type arguments are not allowed on this entity"),
ty.span,
"type")
}
};
span_err.span_label(span, format!("{} parameter not allowed", kind))
span_err.span_label(span, format!("{} argument not allowed", kind))
.emit();
if err_for_lt && err_for_ty {
break;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/diagnostics.rs
Expand Up @@ -1291,7 +1291,7 @@ You tried to give a type parameter to a type which doesn't need it. Erroneous
code example:
```compile_fail,E0109
type X = u32<i32>; // error: type parameters are not allowed on this type
type X = u32<i32>; // error: type arguments are not allowed on this entity
```
Please check that you used the correct type and recheck its definition. Perhaps
Expand Down
36 changes: 18 additions & 18 deletions src/test/ui/enum-variant-generic-args.rs
Expand Up @@ -7,59 +7,59 @@ type AliasFixed = Enum<()>;
impl<T> Enum<T> {
fn ts_variant() {
Self::TSVariant::<()>(());
//~^ ERROR type parameters are not allowed on this type [E0109]
//~^ ERROR type arguments are not allowed on this entity [E0109]
Self::<()>::TSVariant(());
//~^ ERROR type parameters are not allowed on this type [E0109]
//~^ ERROR type arguments are not allowed on this entity [E0109]
Self::<()>::TSVariant::<()>(());
//~^ ERROR type parameters are not allowed on this type [E0109]
//~^^ ERROR type parameters are not allowed on this type [E0109]
//~^ ERROR type arguments are not allowed on this entity [E0109]
//~^^ ERROR type arguments are not allowed on this entity [E0109]
}

fn s_variant() {
Self::SVariant::<()>(());
//~^ ERROR type parameters are not allowed on this type [E0109]
//~^ ERROR type arguments are not allowed on this entity [E0109]
Self::<()>::SVariant(());
//~^ ERROR type parameters are not allowed on this type [E0109]
//~^ ERROR type arguments are not allowed on this entity [E0109]
Self::<()>::SVariant::<()>(());
//~^ ERROR type parameters are not allowed on this type [E0109]
//~^^ ERROR type parameters are not allowed on this type [E0109]
//~^ ERROR type arguments are not allowed on this entity [E0109]
//~^^ ERROR type arguments are not allowed on this entity [E0109]
}
}

fn main() {
// Tuple struct variant

Enum::<()>::TSVariant::<()>(());
//~^ ERROR type parameters are not allowed on this type [E0109]
//~^ ERROR type arguments are not allowed on this entity [E0109]

Alias::TSVariant::<()>(());
//~^ ERROR type parameters are not allowed on this type [E0109]
//~^ ERROR type arguments are not allowed on this entity [E0109]
Alias::<()>::TSVariant::<()>(());
//~^ ERROR type parameters are not allowed on this type [E0109]
//~^ ERROR type arguments are not allowed on this entity [E0109]

AliasFixed::TSVariant::<()>(());
//~^ ERROR type parameters are not allowed on this type [E0109]
//~^ ERROR type arguments are not allowed on this entity [E0109]
AliasFixed::<()>::TSVariant(());
//~^ ERROR wrong number of type arguments: expected 0, found 1 [E0107]
AliasFixed::<()>::TSVariant::<()>(());
//~^ ERROR type parameters are not allowed on this type [E0109]
//~^ ERROR type arguments are not allowed on this entity [E0109]
//~^^ ERROR wrong number of type arguments: expected 0, found 1 [E0107]

// Struct variant

Enum::<()>::SVariant::<()>(());
//~^ ERROR type parameters are not allowed on this type [E0109]
//~^ ERROR type arguments are not allowed on this entity [E0109]

Alias::SVariant::<()>(());
//~^ ERROR type parameters are not allowed on this type [E0109]
//~^ ERROR type arguments are not allowed on this entity [E0109]
Alias::<()>::SVariant::<()>(());
//~^ ERROR type parameters are not allowed on this type [E0109]
//~^ ERROR type arguments are not allowed on this entity [E0109]

AliasFixed::SVariant::<()>(());
//~^ ERROR type parameters are not allowed on this type [E0109]
//~^ ERROR type arguments are not allowed on this entity [E0109]
AliasFixed::<()>::SVariant(());
//~^ ERROR wrong number of type arguments: expected 0, found 1 [E0107]
AliasFixed::<()>::SVariant::<()>(());
//~^ ERROR type parameters are not allowed on this type [E0109]
//~^ ERROR type arguments are not allowed on this entity [E0109]
//~^^ ERROR wrong number of type arguments: expected 0, found 1 [E0107]
}
68 changes: 34 additions & 34 deletions src/test/ui/enum-variant-generic-args.stderr
Expand Up @@ -7,35 +7,35 @@ LL | Enum::<()>::SVariant::<()>(());
| | did you mean `TSVariant`?
| did you mean `Enum::SVariant { /* fields */ }`?

error[E0109]: type parameters are not allowed on this type
error[E0109]: type arguments are not allowed on this entity
--> $DIR/enum-variant-generic-args.rs:9:27
|
LL | Self::TSVariant::<()>(());
| ^^ type parameter not allowed
| ^^ type argument not allowed

error[E0109]: type parameters are not allowed on this type
error[E0109]: type arguments are not allowed on this entity
--> $DIR/enum-variant-generic-args.rs:11:16
|
LL | Self::<()>::TSVariant(());
| ^^ type parameter not allowed
| ^^ type argument not allowed

error[E0109]: type parameters are not allowed on this type
error[E0109]: type arguments are not allowed on this entity
--> $DIR/enum-variant-generic-args.rs:13:16
|
LL | Self::<()>::TSVariant::<()>(());
| ^^ type parameter not allowed
| ^^ type argument not allowed

error[E0109]: type parameters are not allowed on this type
error[E0109]: type arguments are not allowed on this entity
--> $DIR/enum-variant-generic-args.rs:13:33
|
LL | Self::<()>::TSVariant::<()>(());
| ^^ type parameter not allowed
| ^^ type argument not allowed

error[E0109]: type parameters are not allowed on this type
error[E0109]: type arguments are not allowed on this entity
--> $DIR/enum-variant-generic-args.rs:19:26
|
LL | Self::SVariant::<()>(());
| ^^ type parameter not allowed
| ^^ type argument not allowed

error[E0618]: expected function, found enum variant `<Self>::SVariant::<()>`
--> $DIR/enum-variant-generic-args.rs:19:9
Expand All @@ -52,11 +52,11 @@ help: `<Self>::SVariant::<()>` is a unit variant, you need to write it without t
LL | <Self>::SVariant::<()>;
| ^^^^^^^^^^^^^^^^^^^^^^

error[E0109]: type parameters are not allowed on this type
error[E0109]: type arguments are not allowed on this entity
--> $DIR/enum-variant-generic-args.rs:21:16
|
LL | Self::<()>::SVariant(());
| ^^ type parameter not allowed
| ^^ type argument not allowed

error[E0618]: expected function, found enum variant `<Self<()>>::SVariant`
--> $DIR/enum-variant-generic-args.rs:21:9
Expand All @@ -73,17 +73,17 @@ help: `<Self<()>>::SVariant` is a unit variant, you need to write it without the
LL | <Self<()>>::SVariant;
| ^^^^^^^^^^^^^^^^^^^^

error[E0109]: type parameters are not allowed on this type
error[E0109]: type arguments are not allowed on this entity
--> $DIR/enum-variant-generic-args.rs:23:16
|
LL | Self::<()>::SVariant::<()>(());
| ^^ type parameter not allowed
| ^^ type argument not allowed

error[E0109]: type parameters are not allowed on this type
error[E0109]: type arguments are not allowed on this entity
--> $DIR/enum-variant-generic-args.rs:23:32
|
LL | Self::<()>::SVariant::<()>(());
| ^^ type parameter not allowed
| ^^ type argument not allowed

error[E0618]: expected function, found enum variant `<Self<()>>::SVariant::<()>`
--> $DIR/enum-variant-generic-args.rs:23:9
Expand All @@ -100,29 +100,29 @@ help: `<Self<()>>::SVariant::<()>` is a unit variant, you need to write it witho
LL | <Self<()>>::SVariant::<()>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0109]: type parameters are not allowed on this type
error[E0109]: type arguments are not allowed on this entity
--> $DIR/enum-variant-generic-args.rs:32:29
|
LL | Enum::<()>::TSVariant::<()>(());
| ^^ type parameter not allowed
| ^^ type argument not allowed

error[E0109]: type parameters are not allowed on this type
error[E0109]: type arguments are not allowed on this entity
--> $DIR/enum-variant-generic-args.rs:35:24
|
LL | Alias::TSVariant::<()>(());
| ^^ type parameter not allowed
| ^^ type argument not allowed

error[E0109]: type parameters are not allowed on this type
error[E0109]: type arguments are not allowed on this entity
--> $DIR/enum-variant-generic-args.rs:37:30
|
LL | Alias::<()>::TSVariant::<()>(());
| ^^ type parameter not allowed
| ^^ type argument not allowed

error[E0109]: type parameters are not allowed on this type
error[E0109]: type arguments are not allowed on this entity
--> $DIR/enum-variant-generic-args.rs:40:29
|
LL | AliasFixed::TSVariant::<()>(());
| ^^ type parameter not allowed
| ^^ type argument not allowed

error[E0107]: wrong number of type arguments: expected 0, found 1
--> $DIR/enum-variant-generic-args.rs:42:18
Expand All @@ -136,17 +136,17 @@ error[E0107]: wrong number of type arguments: expected 0, found 1
LL | AliasFixed::<()>::TSVariant::<()>(());
| ^^ unexpected type argument

error[E0109]: type parameters are not allowed on this type
error[E0109]: type arguments are not allowed on this entity
--> $DIR/enum-variant-generic-args.rs:44:35
|
LL | AliasFixed::<()>::TSVariant::<()>(());
| ^^ type parameter not allowed
| ^^ type argument not allowed

error[E0109]: type parameters are not allowed on this type
error[E0109]: type arguments are not allowed on this entity
--> $DIR/enum-variant-generic-args.rs:53:23
|
LL | Alias::SVariant::<()>(());
| ^^ type parameter not allowed
| ^^ type argument not allowed

error[E0618]: expected function, found enum variant `<Alias>::SVariant::<()>`
--> $DIR/enum-variant-generic-args.rs:53:5
Expand All @@ -163,11 +163,11 @@ help: `<Alias>::SVariant::<()>` is a unit variant, you need to write it without
LL | <Alias>::SVariant::<()>;
| ^^^^^^^^^^^^^^^^^^^^^^^

error[E0109]: type parameters are not allowed on this type
error[E0109]: type arguments are not allowed on this entity
--> $DIR/enum-variant-generic-args.rs:55:29
|
LL | Alias::<()>::SVariant::<()>(());
| ^^ type parameter not allowed
| ^^ type argument not allowed

error[E0618]: expected function, found enum variant `<Alias<()>>::SVariant::<()>`
--> $DIR/enum-variant-generic-args.rs:55:5
Expand All @@ -184,11 +184,11 @@ help: `<Alias<()>>::SVariant::<()>` is a unit variant, you need to write it with
LL | <Alias<()>>::SVariant::<()>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0109]: type parameters are not allowed on this type
error[E0109]: type arguments are not allowed on this entity
--> $DIR/enum-variant-generic-args.rs:58:28
|
LL | AliasFixed::SVariant::<()>(());
| ^^ type parameter not allowed
| ^^ type argument not allowed

error[E0618]: expected function, found enum variant `<AliasFixed>::SVariant::<()>`
--> $DIR/enum-variant-generic-args.rs:58:5
Expand Down Expand Up @@ -232,11 +232,11 @@ error[E0107]: wrong number of type arguments: expected 0, found 1
LL | AliasFixed::<()>::SVariant::<()>(());
| ^^ unexpected type argument

error[E0109]: type parameters are not allowed on this type
error[E0109]: type arguments are not allowed on this entity
--> $DIR/enum-variant-generic-args.rs:62:34
|
LL | AliasFixed::<()>::SVariant::<()>(());
| ^^ type parameter not allowed
| ^^ type argument not allowed

error[E0618]: expected function, found enum variant `<AliasFixed<()>>::SVariant::<()>`
--> $DIR/enum-variant-generic-args.rs:62:5
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/error-codes/E0109.stderr
@@ -1,8 +1,8 @@
error[E0109]: type parameters are not allowed on this type
error[E0109]: type arguments are not allowed on this entity
--> $DIR/E0109.rs:1:14
|
LL | type X = u32<i32>; //~ ERROR E0109
| ^^^ type parameter not allowed
| ^^^ type argument not allowed

error: aborting due to previous error

Expand Down
12 changes: 10 additions & 2 deletions src/test/ui/error-codes/E0110.stderr
@@ -1,8 +1,16 @@
error[E0110]: lifetime parameters are not allowed on this type
<<<<<<< HEAD
error[E0110]: lifetime arguments are not allowed on this entity
--> $DIR/E0110.rs:1:14
||||||| merged common ancestors
error[E0110]: lifetime parameters are not allowed on this type
--> $DIR/E0110.rs:11:14
=======
error[E0110]: lifetime arguments are not allowed on this entity
--> $DIR/E0110.rs:11:14
>>>>>>> Added regression test for using generic parameters on modules.
|
LL | type X = u32<'static>; //~ ERROR E0110
| ^^^^^^^ lifetime parameter not allowed
| ^^^^^^^ lifetime argument not allowed

error: aborting due to previous error

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-22706.rs
@@ -1,3 +1,3 @@
fn is_copy<T: ::std::marker<i32>::Copy>() {}
//~^ ERROR type parameters are not allowed on this type [E0109]
//~^ ERROR type arguments are not allowed on this entity [E0109]
fn main() {}
4 changes: 2 additions & 2 deletions src/test/ui/issues/issue-22706.stderr
@@ -1,8 +1,8 @@
error[E0109]: type parameters are not allowed on this type
error[E0109]: type arguments are not allowed on this entity
--> $DIR/issue-22706.rs:1:29
|
LL | fn is_copy<T: ::std::marker<i32>::Copy>() {}
| ^^^ type parameter not allowed
| ^^^ type argument not allowed

error: aborting due to previous error

Expand Down
10 changes: 10 additions & 0 deletions src/test/ui/mod-subitem-as-enum-variant.rs
@@ -0,0 +1,10 @@

mod Mod {
pub struct FakeVariant<T>(pub T);
}

fn main() {
Mod::FakeVariant::<i32>(0);
Mod::<i32>::FakeVariant(0);
//~^ ERROR type arguments are not allowed on this entity [E0109]
}
9 changes: 9 additions & 0 deletions src/test/ui/mod-subitem-as-enum-variant.stderr
@@ -0,0 +1,9 @@
error[E0109]: type arguments are not allowed on this entity
--> $DIR/mod-subitem-as-enum-variant.rs:8:11
|
LL | Mod::<i32>::FakeVariant(0);
| ^^^ type argument not allowed

error: aborting due to previous error

For more information about this error, try `rustc --explain E0109`.

0 comments on commit 8eb1a9e

Please sign in to comment.