Skip to content

Commit c242fc3

Browse files
committed
Generic unit tests for attributes on lifetime/type formals in generics list.
1 parent 4c37ad6 commit c242fc3

File tree

3 files changed

+211
-0
lines changed

3 files changed

+211
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// This test ensures that attributes on formals in generic parameter
12+
// lists are included when we are checking for unstable attributes.
13+
//
14+
// Note that feature(generic_param_attrs) *is* enabled here. We are
15+
// checking feature-gating of the attributes themselves, not the
16+
// capability to parse such attributes in that context.
17+
18+
#![feature(generic_param_attrs)]
19+
#![allow(dead_code)]
20+
21+
struct StLt<#[lt_struct] 'a>(&'a u32);
22+
//~^ ERROR The attribute `lt_struct` is currently unknown to the compiler
23+
struct StTy<#[ty_struct] I>(I);
24+
//~^ ERROR The attribute `ty_struct` is currently unknown to the compiler
25+
26+
enum EnLt<#[lt_enum] 'b> { A(&'b u32), B }
27+
//~^ ERROR The attribute `lt_enum` is currently unknown to the compiler
28+
enum EnTy<#[ty_enum] J> { A(J), B }
29+
//~^ ERROR The attribute `ty_enum` is currently unknown to the compiler
30+
31+
trait TrLt<#[lt_trait] 'c> { fn foo(&self, _: &'c [u32]) -> &'c u32; }
32+
//~^ ERROR The attribute `lt_trait` is currently unknown to the compiler
33+
trait TrTy<#[ty_trait] K> { fn foo(&self, _: K); }
34+
//~^ ERROR The attribute `ty_trait` is currently unknown to the compiler
35+
36+
type TyLt<#[lt_type] 'd> = &'d u32;
37+
//~^ ERROR The attribute `lt_type` is currently unknown to the compiler
38+
type TyTy<#[ty_type] L> = (L, );
39+
//~^ ERROR The attribute `ty_type` is currently unknown to the compiler
40+
41+
impl<#[lt_inherent] 'e> StLt<'e> { }
42+
//~^ ERROR The attribute `lt_inherent` is currently unknown to the compiler
43+
impl<#[ty_inherent] M> StTy<M> { }
44+
//~^ ERROR The attribute `ty_inherent` is currently unknown to the compiler
45+
46+
impl<#[lt_impl_for] 'f> TrLt<'f> for StLt<'f> {
47+
//~^ ERROR The attribute `lt_impl_for` is currently unknown to the compiler
48+
fn foo(&self, _: &'f [u32]) -> &'f u32 { loop { } }
49+
}
50+
impl<#[ty_impl_for] N> TrTy<N> for StTy<N> {
51+
//~^ ERROR The attribute `ty_impl_for` is currently unknown to the compiler
52+
fn foo(&self, _: N) { }
53+
}
54+
55+
fn f_lt<#[lt_fn] 'g>(_: &'g [u32]) -> &'g u32 { loop { } }
56+
//~^ ERROR The attribute `lt_fn` is currently unknown to the compiler
57+
fn f_ty<#[ty_fn] O>(_: O) { }
58+
//~^ ERROR The attribute `ty_fn` is currently unknown to the compiler
59+
60+
impl<I> StTy<I> {
61+
fn m_lt<#[lt_meth] 'h>(_: &'h [u32]) -> &'h u32 { loop { } }
62+
//~^ ERROR The attribute `lt_meth` is currently unknown to the compiler
63+
fn m_ty<#[ty_meth] P>(_: P) { }
64+
//~^ ERROR The attribute `ty_meth` is currently unknown to the compiler
65+
}
66+
67+
fn hof_lt<Q>(_: Q)
68+
where Q: for <#[lt_hof] 'i> Fn(&'i [u32]) -> &'i u32
69+
//~^ ERROR The attribute `lt_hof` is currently unknown to the compiler
70+
{
71+
}
72+
73+
fn main() {
74+
75+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// This test ensures that attributes on formals in generic parameter
12+
// lists are rejected if feature(generic_param_attrs) is not enabled.
13+
//
14+
// (We are prefixing all tested features with `rustc_`, to ensure that
15+
// the attributes themselves won't be rejected by the compiler when
16+
// using `rustc_attrs` feature. There is a separate compile-fail/ test
17+
// ensuring that the attribute feature-gating works in this context.)
18+
19+
#![feature(rustc_attrs)]
20+
#![allow(dead_code)]
21+
22+
struct StLt<#[rustc_lt_struct] 'a>(&'a u32);
23+
//~^ ERROR attributes on lifetime bindings are experimental (see issue #34761)
24+
struct StTy<#[rustc_ty_struct] I>(I);
25+
//~^ ERROR attributes on type parameter bindings are experimental (see issue #34761)
26+
27+
enum EnLt<#[rustc_lt_enum] 'b> { A(&'b u32), B }
28+
//~^ ERROR attributes on lifetime bindings are experimental (see issue #34761)
29+
enum EnTy<#[rustc_ty_enum] J> { A(J), B }
30+
//~^ ERROR attributes on type parameter bindings are experimental (see issue #34761)
31+
32+
trait TrLt<#[rustc_lt_trait] 'c> { fn foo(&self, _: &'c [u32]) -> &'c u32; }
33+
//~^ ERROR attributes on lifetime bindings are experimental (see issue #34761)
34+
trait TrTy<#[rustc_ty_trait] K> { fn foo(&self, _: K); }
35+
//~^ ERROR attributes on type parameter bindings are experimental (see issue #34761)
36+
37+
type TyLt<#[rustc_lt_type] 'd> = &'d u32;
38+
//~^ ERROR attributes on lifetime bindings are experimental (see issue #34761)
39+
type TyTy<#[rustc_ty_type] L> = (L, );
40+
//~^ ERROR attributes on type parameter bindings are experimental (see issue #34761)
41+
42+
impl<#[rustc_lt_inherent] 'e> StLt<'e> { }
43+
//~^ ERROR attributes on lifetime bindings are experimental (see issue #34761)
44+
impl<#[rustc_ty_inherent] M> StTy<M> { }
45+
//~^ ERROR attributes on type parameter bindings are experimental (see issue #34761)
46+
47+
impl<#[rustc_lt_impl_for] 'f> TrLt<'f> for StLt<'f> {
48+
//~^ ERROR attributes on lifetime bindings are experimental (see issue #34761)
49+
fn foo(&self, _: &'f [u32]) -> &'f u32 { loop { } }
50+
}
51+
impl<#[rustc_ty_impl_for] N> TrTy<N> for StTy<N> {
52+
//~^ ERROR attributes on type parameter bindings are experimental (see issue #34761)
53+
fn foo(&self, _: N) { }
54+
}
55+
56+
fn f_lt<#[rustc_lt_fn] 'g>(_: &'g [u32]) -> &'g u32 { loop { } }
57+
//~^ ERROR attributes on lifetime bindings are experimental (see issue #34761)
58+
fn f_ty<#[rustc_ty_fn] O>(_: O) { }
59+
//~^ ERROR attributes on type parameter bindings are experimental (see issue #34761)
60+
61+
impl<I> StTy<I> {
62+
fn m_lt<#[rustc_lt_meth] 'h>(_: &'h [u32]) -> &'h u32 { loop { } }
63+
//~^ ERROR attributes on lifetime bindings are experimental (see issue #34761)
64+
fn m_ty<#[rustc_ty_meth] P>(_: P) { }
65+
//~^ ERROR attributes on type parameter bindings are experimental (see issue #34761)
66+
}
67+
68+
fn hof_lt<Q>(_: Q)
69+
where Q: for <#[rustc_lt_hof] 'i> Fn(&'i [u32]) -> &'i u32
70+
//~^ ERROR attributes on lifetime bindings are experimental (see issue #34761)
71+
{
72+
}
73+
74+
fn main() {
75+
76+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// This test ensures we can attach attributes to the formals in all
12+
// places where generic parameter lists occur, assuming appropriate
13+
// feature gates are enabled.
14+
//
15+
// (We are prefixing all tested features with `rustc_`, to ensure that
16+
// the attributes themselves won't be rejected by the compiler when
17+
// using `rustc_attrs` feature. There is a separate compile-fail/ test
18+
// ensuring that the attribute feature-gating works in this context.)
19+
20+
#![feature(generic_param_attrs, rustc_attrs)]
21+
#![allow(dead_code)]
22+
23+
struct StLt<#[rustc_lt_struct] 'a>(&'a u32);
24+
struct StTy<#[rustc_ty_struct] I>(I);
25+
26+
enum EnLt<#[rustc_lt_enum] 'b> { A(&'b u32), B }
27+
enum EnTy<#[rustc_ty_enum] J> { A(J), B }
28+
29+
trait TrLt<#[rustc_lt_trait] 'c> { fn foo(&self, _: &'c [u32]) -> &'c u32; }
30+
trait TrTy<#[rustc_ty_trait] K> { fn foo(&self, _: K); }
31+
32+
type TyLt<#[rustc_lt_type] 'd> = &'d u32;
33+
type TyTy<#[rustc_ty_type] L> = (L, );
34+
35+
impl<#[rustc_lt_inherent] 'e> StLt<'e> { }
36+
impl<#[rustc_ty_inherent] M> StTy<M> { }
37+
38+
impl<#[rustc_lt_impl_for] 'f> TrLt<'f> for StLt<'f> {
39+
fn foo(&self, _: &'f [u32]) -> &'f u32 { loop { } }
40+
}
41+
impl<#[rustc_ty_impl_for] N> TrTy<N> for StTy<N> {
42+
fn foo(&self, _: N) { }
43+
}
44+
45+
fn f_lt<#[rustc_lt_fn] 'g>(_: &'g [u32]) -> &'g u32 { loop { } }
46+
fn f_ty<#[rustc_ty_fn] O>(_: O) { }
47+
48+
impl<I> StTy<I> {
49+
fn m_lt<#[rustc_lt_meth] 'h>(_: &'h [u32]) -> &'h u32 { loop { } }
50+
fn m_ty<#[rustc_ty_meth] P>(_: P) { }
51+
}
52+
53+
fn hof_lt<Q>(_: Q)
54+
where Q: for <#[rustc_lt_hof] 'i> Fn(&'i [u32]) -> &'i u32
55+
{
56+
}
57+
58+
fn main() {
59+
60+
}

0 commit comments

Comments
 (0)