mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 15:01:51 +00:00
Generic unit tests for attributes on lifetime/type formals in generics list.
This commit is contained in:
parent
4c37ad6607
commit
c242fc3ea3
75
src/test/compile-fail/attr-on-generic-formals-are-visited.rs
Normal file
75
src/test/compile-fail/attr-on-generic-formals-are-visited.rs
Normal file
@ -0,0 +1,75 @@
|
||||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// This test ensures that attributes on formals in generic parameter
|
||||
// lists are included when we are checking for unstable attributes.
|
||||
//
|
||||
// Note that feature(generic_param_attrs) *is* enabled here. We are
|
||||
// checking feature-gating of the attributes themselves, not the
|
||||
// capability to parse such attributes in that context.
|
||||
|
||||
#![feature(generic_param_attrs)]
|
||||
#![allow(dead_code)]
|
||||
|
||||
struct StLt<#[lt_struct] 'a>(&'a u32);
|
||||
//~^ ERROR The attribute `lt_struct` is currently unknown to the compiler
|
||||
struct StTy<#[ty_struct] I>(I);
|
||||
//~^ ERROR The attribute `ty_struct` is currently unknown to the compiler
|
||||
|
||||
enum EnLt<#[lt_enum] 'b> { A(&'b u32), B }
|
||||
//~^ ERROR The attribute `lt_enum` is currently unknown to the compiler
|
||||
enum EnTy<#[ty_enum] J> { A(J), B }
|
||||
//~^ ERROR The attribute `ty_enum` is currently unknown to the compiler
|
||||
|
||||
trait TrLt<#[lt_trait] 'c> { fn foo(&self, _: &'c [u32]) -> &'c u32; }
|
||||
//~^ ERROR The attribute `lt_trait` is currently unknown to the compiler
|
||||
trait TrTy<#[ty_trait] K> { fn foo(&self, _: K); }
|
||||
//~^ ERROR The attribute `ty_trait` is currently unknown to the compiler
|
||||
|
||||
type TyLt<#[lt_type] 'd> = &'d u32;
|
||||
//~^ ERROR The attribute `lt_type` is currently unknown to the compiler
|
||||
type TyTy<#[ty_type] L> = (L, );
|
||||
//~^ ERROR The attribute `ty_type` is currently unknown to the compiler
|
||||
|
||||
impl<#[lt_inherent] 'e> StLt<'e> { }
|
||||
//~^ ERROR The attribute `lt_inherent` is currently unknown to the compiler
|
||||
impl<#[ty_inherent] M> StTy<M> { }
|
||||
//~^ ERROR The attribute `ty_inherent` is currently unknown to the compiler
|
||||
|
||||
impl<#[lt_impl_for] 'f> TrLt<'f> for StLt<'f> {
|
||||
//~^ ERROR The attribute `lt_impl_for` is currently unknown to the compiler
|
||||
fn foo(&self, _: &'f [u32]) -> &'f u32 { loop { } }
|
||||
}
|
||||
impl<#[ty_impl_for] N> TrTy<N> for StTy<N> {
|
||||
//~^ ERROR The attribute `ty_impl_for` is currently unknown to the compiler
|
||||
fn foo(&self, _: N) { }
|
||||
}
|
||||
|
||||
fn f_lt<#[lt_fn] 'g>(_: &'g [u32]) -> &'g u32 { loop { } }
|
||||
//~^ ERROR The attribute `lt_fn` is currently unknown to the compiler
|
||||
fn f_ty<#[ty_fn] O>(_: O) { }
|
||||
//~^ ERROR The attribute `ty_fn` is currently unknown to the compiler
|
||||
|
||||
impl<I> StTy<I> {
|
||||
fn m_lt<#[lt_meth] 'h>(_: &'h [u32]) -> &'h u32 { loop { } }
|
||||
//~^ ERROR The attribute `lt_meth` is currently unknown to the compiler
|
||||
fn m_ty<#[ty_meth] P>(_: P) { }
|
||||
//~^ ERROR The attribute `ty_meth` is currently unknown to the compiler
|
||||
}
|
||||
|
||||
fn hof_lt<Q>(_: Q)
|
||||
where Q: for <#[lt_hof] 'i> Fn(&'i [u32]) -> &'i u32
|
||||
//~^ ERROR The attribute `lt_hof` is currently unknown to the compiler
|
||||
{
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// This test ensures that attributes on formals in generic parameter
|
||||
// lists are rejected if feature(generic_param_attrs) is not enabled.
|
||||
//
|
||||
// (We are prefixing all tested features with `rustc_`, to ensure that
|
||||
// the attributes themselves won't be rejected by the compiler when
|
||||
// using `rustc_attrs` feature. There is a separate compile-fail/ test
|
||||
// ensuring that the attribute feature-gating works in this context.)
|
||||
|
||||
#![feature(rustc_attrs)]
|
||||
#![allow(dead_code)]
|
||||
|
||||
struct StLt<#[rustc_lt_struct] 'a>(&'a u32);
|
||||
//~^ ERROR attributes on lifetime bindings are experimental (see issue #34761)
|
||||
struct StTy<#[rustc_ty_struct] I>(I);
|
||||
//~^ ERROR attributes on type parameter bindings are experimental (see issue #34761)
|
||||
|
||||
enum EnLt<#[rustc_lt_enum] 'b> { A(&'b u32), B }
|
||||
//~^ ERROR attributes on lifetime bindings are experimental (see issue #34761)
|
||||
enum EnTy<#[rustc_ty_enum] J> { A(J), B }
|
||||
//~^ ERROR attributes on type parameter bindings are experimental (see issue #34761)
|
||||
|
||||
trait TrLt<#[rustc_lt_trait] 'c> { fn foo(&self, _: &'c [u32]) -> &'c u32; }
|
||||
//~^ ERROR attributes on lifetime bindings are experimental (see issue #34761)
|
||||
trait TrTy<#[rustc_ty_trait] K> { fn foo(&self, _: K); }
|
||||
//~^ ERROR attributes on type parameter bindings are experimental (see issue #34761)
|
||||
|
||||
type TyLt<#[rustc_lt_type] 'd> = &'d u32;
|
||||
//~^ ERROR attributes on lifetime bindings are experimental (see issue #34761)
|
||||
type TyTy<#[rustc_ty_type] L> = (L, );
|
||||
//~^ ERROR attributes on type parameter bindings are experimental (see issue #34761)
|
||||
|
||||
impl<#[rustc_lt_inherent] 'e> StLt<'e> { }
|
||||
//~^ ERROR attributes on lifetime bindings are experimental (see issue #34761)
|
||||
impl<#[rustc_ty_inherent] M> StTy<M> { }
|
||||
//~^ ERROR attributes on type parameter bindings are experimental (see issue #34761)
|
||||
|
||||
impl<#[rustc_lt_impl_for] 'f> TrLt<'f> for StLt<'f> {
|
||||
//~^ ERROR attributes on lifetime bindings are experimental (see issue #34761)
|
||||
fn foo(&self, _: &'f [u32]) -> &'f u32 { loop { } }
|
||||
}
|
||||
impl<#[rustc_ty_impl_for] N> TrTy<N> for StTy<N> {
|
||||
//~^ ERROR attributes on type parameter bindings are experimental (see issue #34761)
|
||||
fn foo(&self, _: N) { }
|
||||
}
|
||||
|
||||
fn f_lt<#[rustc_lt_fn] 'g>(_: &'g [u32]) -> &'g u32 { loop { } }
|
||||
//~^ ERROR attributes on lifetime bindings are experimental (see issue #34761)
|
||||
fn f_ty<#[rustc_ty_fn] O>(_: O) { }
|
||||
//~^ ERROR attributes on type parameter bindings are experimental (see issue #34761)
|
||||
|
||||
impl<I> StTy<I> {
|
||||
fn m_lt<#[rustc_lt_meth] 'h>(_: &'h [u32]) -> &'h u32 { loop { } }
|
||||
//~^ ERROR attributes on lifetime bindings are experimental (see issue #34761)
|
||||
fn m_ty<#[rustc_ty_meth] P>(_: P) { }
|
||||
//~^ ERROR attributes on type parameter bindings are experimental (see issue #34761)
|
||||
}
|
||||
|
||||
fn hof_lt<Q>(_: Q)
|
||||
where Q: for <#[rustc_lt_hof] 'i> Fn(&'i [u32]) -> &'i u32
|
||||
//~^ ERROR attributes on lifetime bindings are experimental (see issue #34761)
|
||||
{
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
}
|
60
src/test/run-pass/attr-on-generic-formals.rs
Normal file
60
src/test/run-pass/attr-on-generic-formals.rs
Normal file
@ -0,0 +1,60 @@
|
||||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// This test ensures we can attach attributes to the formals in all
|
||||
// places where generic parameter lists occur, assuming appropriate
|
||||
// feature gates are enabled.
|
||||
//
|
||||
// (We are prefixing all tested features with `rustc_`, to ensure that
|
||||
// the attributes themselves won't be rejected by the compiler when
|
||||
// using `rustc_attrs` feature. There is a separate compile-fail/ test
|
||||
// ensuring that the attribute feature-gating works in this context.)
|
||||
|
||||
#![feature(generic_param_attrs, rustc_attrs)]
|
||||
#![allow(dead_code)]
|
||||
|
||||
struct StLt<#[rustc_lt_struct] 'a>(&'a u32);
|
||||
struct StTy<#[rustc_ty_struct] I>(I);
|
||||
|
||||
enum EnLt<#[rustc_lt_enum] 'b> { A(&'b u32), B }
|
||||
enum EnTy<#[rustc_ty_enum] J> { A(J), B }
|
||||
|
||||
trait TrLt<#[rustc_lt_trait] 'c> { fn foo(&self, _: &'c [u32]) -> &'c u32; }
|
||||
trait TrTy<#[rustc_ty_trait] K> { fn foo(&self, _: K); }
|
||||
|
||||
type TyLt<#[rustc_lt_type] 'd> = &'d u32;
|
||||
type TyTy<#[rustc_ty_type] L> = (L, );
|
||||
|
||||
impl<#[rustc_lt_inherent] 'e> StLt<'e> { }
|
||||
impl<#[rustc_ty_inherent] M> StTy<M> { }
|
||||
|
||||
impl<#[rustc_lt_impl_for] 'f> TrLt<'f> for StLt<'f> {
|
||||
fn foo(&self, _: &'f [u32]) -> &'f u32 { loop { } }
|
||||
}
|
||||
impl<#[rustc_ty_impl_for] N> TrTy<N> for StTy<N> {
|
||||
fn foo(&self, _: N) { }
|
||||
}
|
||||
|
||||
fn f_lt<#[rustc_lt_fn] 'g>(_: &'g [u32]) -> &'g u32 { loop { } }
|
||||
fn f_ty<#[rustc_ty_fn] O>(_: O) { }
|
||||
|
||||
impl<I> StTy<I> {
|
||||
fn m_lt<#[rustc_lt_meth] 'h>(_: &'h [u32]) -> &'h u32 { loop { } }
|
||||
fn m_ty<#[rustc_ty_meth] P>(_: P) { }
|
||||
}
|
||||
|
||||
fn hof_lt<Q>(_: Q)
|
||||
where Q: for <#[rustc_lt_hof] 'i> Fn(&'i [u32]) -> &'i u32
|
||||
{
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user