-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #15778.
- Loading branch information
Keegan McAllister
committed
Mar 2, 2015
1 parent
1cc8b6e
commit daef3b9
Showing
3 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2015 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. | ||
|
||
// force-host | ||
|
||
#![feature(plugin_registrar)] | ||
#![feature(box_syntax)] | ||
|
||
extern crate syntax; | ||
#[macro_use] extern crate rustc; | ||
|
||
use syntax::{ast, attr}; | ||
use rustc::lint::{Context, LintPass, LintPassObject, LintArray}; | ||
use rustc::plugin::Registry; | ||
|
||
declare_lint!(CRATE_NOT_OKAY, Warn, "crate not marked with #![crate_okay]"); | ||
|
||
struct Pass; | ||
|
||
impl LintPass for Pass { | ||
fn get_lints(&self) -> LintArray { | ||
lint_array!(CRATE_NOT_OKAY) | ||
} | ||
|
||
fn check_crate(&mut self, cx: &Context, krate: &ast::Crate) { | ||
if !attr::contains_name(&krate.attrs, "crate_okay") { | ||
cx.span_lint(CRATE_NOT_OKAY, krate.span, | ||
"crate is not marked with #![crate_okay]"); | ||
} | ||
} | ||
} | ||
|
||
#[plugin_registrar] | ||
pub fn plugin_registrar(reg: &mut Registry) { | ||
reg.register_lint_pass(box Pass as LintPassObject); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright 2015 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. | ||
|
||
// aux-build:lint_for_crate.rs | ||
// ignore-stage1 | ||
// compile-flags: -D crate-not-okay | ||
|
||
#![feature(plugin, custom_attribute)] //~ ERROR crate is not marked with #![crate_okay] | ||
#![plugin(lint_for_crate)] | ||
|
||
pub fn main() { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright 2015 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. | ||
|
||
// aux-build:lint_for_crate.rs | ||
// ignore-stage1 | ||
// compile-flags: -D crate-not-okay | ||
|
||
#![feature(plugin, custom_attribute)] | ||
#![plugin(lint_for_crate)] | ||
#![crate_okay] | ||
|
||
pub fn main() { } |