Skip to content

Commit daef3b9

Browse files
committed
Add regression tests for rust-lang#15778
Fixes rust-lang#15778.
1 parent 1cc8b6e commit daef3b9

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

src/test/auxiliary/lint_for_crate.rs

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2015 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+
// force-host
12+
13+
#![feature(plugin_registrar)]
14+
#![feature(box_syntax)]
15+
16+
extern crate syntax;
17+
#[macro_use] extern crate rustc;
18+
19+
use syntax::{ast, attr};
20+
use rustc::lint::{Context, LintPass, LintPassObject, LintArray};
21+
use rustc::plugin::Registry;
22+
23+
declare_lint!(CRATE_NOT_OKAY, Warn, "crate not marked with #![crate_okay]");
24+
25+
struct Pass;
26+
27+
impl LintPass for Pass {
28+
fn get_lints(&self) -> LintArray {
29+
lint_array!(CRATE_NOT_OKAY)
30+
}
31+
32+
fn check_crate(&mut self, cx: &Context, krate: &ast::Crate) {
33+
if !attr::contains_name(&krate.attrs, "crate_okay") {
34+
cx.span_lint(CRATE_NOT_OKAY, krate.span,
35+
"crate is not marked with #![crate_okay]");
36+
}
37+
}
38+
}
39+
40+
#[plugin_registrar]
41+
pub fn plugin_registrar(reg: &mut Registry) {
42+
reg.register_lint_pass(box Pass as LintPassObject);
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2015 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+
// aux-build:lint_for_crate.rs
12+
// ignore-stage1
13+
// compile-flags: -D crate-not-okay
14+
15+
#![feature(plugin, custom_attribute)] //~ ERROR crate is not marked with #![crate_okay]
16+
#![plugin(lint_for_crate)]
17+
18+
pub fn main() { }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2015 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+
// aux-build:lint_for_crate.rs
12+
// ignore-stage1
13+
// compile-flags: -D crate-not-okay
14+
15+
#![feature(plugin, custom_attribute)]
16+
#![plugin(lint_for_crate)]
17+
#![crate_okay]
18+
19+
pub fn main() { }

0 commit comments

Comments
 (0)