mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-30 02:33:55 +00:00
Use lint instead of warning
This commit is contained in:
parent
1a9239c964
commit
a745614f44
@ -117,6 +117,13 @@ declare_lint! {
|
||||
Allow,
|
||||
"detects trivial casts of numeric types which could be removed"
|
||||
}
|
||||
|
||||
declare_lint! {
|
||||
pub PRIVATE_IN_PUBLIC,
|
||||
Warn,
|
||||
"detect private items in public interfaces not caught by the old implementation"
|
||||
}
|
||||
|
||||
/// Does nothing as a lint pass, but registers some `Lint`s
|
||||
/// which are used by other parts of the compiler.
|
||||
#[derive(Copy, Clone)]
|
||||
@ -141,6 +148,7 @@ impl LintPass for HardwiredLints {
|
||||
FAT_PTR_TRANSMUTES,
|
||||
TRIVIAL_CASTS,
|
||||
TRIVIAL_NUMERIC_CASTS,
|
||||
PRIVATE_IN_PUBLIC,
|
||||
CONST_ERR
|
||||
)
|
||||
}
|
||||
|
@ -146,6 +146,9 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
|
||||
UNUSED_MUT, UNREACHABLE_CODE, UNUSED_MUST_USE,
|
||||
UNUSED_UNSAFE, PATH_STATEMENTS, UNUSED_ATTRIBUTES);
|
||||
|
||||
add_lint_group!(sess, "future_incompatible",
|
||||
PRIVATE_IN_PUBLIC);
|
||||
|
||||
// We have one lint pass defined specially
|
||||
store.register_late_pass(sess, false, box lint::GatherNodeLevels);
|
||||
|
||||
|
@ -38,6 +38,7 @@ use std::mem::replace;
|
||||
use rustc_front::hir;
|
||||
use rustc_front::intravisit::{self, Visitor};
|
||||
|
||||
use rustc::lint;
|
||||
use rustc::middle::def;
|
||||
use rustc::middle::def_id::DefId;
|
||||
use rustc::middle::privacy::{AccessLevel, AccessLevels};
|
||||
@ -1488,9 +1489,17 @@ impl<'a, 'tcx: 'a, 'v> Visitor<'v> for SearchInterfaceForPrivateItemsVisitor<'a,
|
||||
}
|
||||
if item.vis != hir::Public {
|
||||
if !self.is_quiet {
|
||||
let is_warning = !self.old_error_set.contains(&ty.id);
|
||||
span_err_or_warn!(is_warning, self.tcx.sess, ty.span, E0446,
|
||||
"private type in public interface");
|
||||
if self.old_error_set.contains(&ty.id) {
|
||||
span_err!(self.tcx.sess, ty.span, E0446,
|
||||
"private type in public interface");
|
||||
} else {
|
||||
self.tcx.sess.add_lint (
|
||||
lint::builtin::PRIVATE_IN_PUBLIC,
|
||||
node_id,
|
||||
ty.span,
|
||||
"private type in public interface".to_string()
|
||||
);
|
||||
}
|
||||
}
|
||||
self.is_public = false;
|
||||
}
|
||||
@ -1515,9 +1524,15 @@ impl<'a, 'tcx: 'a, 'v> Visitor<'v> for SearchInterfaceForPrivateItemsVisitor<'a,
|
||||
if let Some(ast_map::NodeItem(ref item)) = self.tcx.map.find(node_id) {
|
||||
if item.vis != hir::Public {
|
||||
if !self.is_quiet {
|
||||
let is_warning = !self.old_error_set.contains(&trait_ref.ref_id);
|
||||
span_err_or_warn!(is_warning, self.tcx.sess, trait_ref.path.span, E0445,
|
||||
"private trait in public interface");
|
||||
if self.old_error_set.contains(&trait_ref.ref_id) {
|
||||
span_err!(self.tcx.sess, trait_ref.path.span, E0445,
|
||||
"private trait in public interface");
|
||||
} else {
|
||||
self.tcx.sess.add_lint(lint::builtin::PRIVATE_IN_PUBLIC,
|
||||
node_id,
|
||||
trait_ref.path.span,
|
||||
"private trait in public interface".to_string());
|
||||
}
|
||||
}
|
||||
self.is_public = false;
|
||||
}
|
||||
|
16
src/test/compile-fail/issue-28450-1.rs
Normal file
16
src/test/compile-fail/issue-28450-1.rs
Normal file
@ -0,0 +1,16 @@
|
||||
// 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.
|
||||
|
||||
// Checks for private types in public interfaces
|
||||
|
||||
type Foo = u8;
|
||||
pub fn foo(f: Foo) {} //~ ERROR private type in public interface
|
||||
|
||||
fn main() {}
|
@ -10,6 +10,8 @@
|
||||
|
||||
// Checks for private types in public interfaces
|
||||
|
||||
#![feature(rustc_attrs)]
|
||||
|
||||
struct Priv;
|
||||
|
||||
pub use self::private::public;
|
||||
@ -28,9 +30,6 @@ impl<T> Pointer for *const T { type Pointee = T; }
|
||||
pub type __CFArrayRevealed = <CFArrayRef as Pointer>::Pointee;
|
||||
//~^ WARN private type in public interface
|
||||
|
||||
type Foo = u8;
|
||||
pub fn foo(f: Foo) {} //~ ERROR private type in public interface
|
||||
|
||||
pub trait Exporter {
|
||||
type Output;
|
||||
}
|
||||
@ -49,6 +48,7 @@ pub fn block() -> <Helper as Exporter>::Output {
|
||||
Inner
|
||||
}
|
||||
|
||||
fn main() {
|
||||
#[rustc_error]
|
||||
fn main() { //~ ERROR compilation successful
|
||||
block().poke();
|
||||
}
|
||||
|
33
src/test/compile-fail/lint-private-in-public.rs
Normal file
33
src/test/compile-fail/lint-private-in-public.rs
Normal file
@ -0,0 +1,33 @@
|
||||
// Copyright 2014 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.
|
||||
|
||||
mod m1 {
|
||||
#![deny(private_in_public)]
|
||||
|
||||
pub struct Pub;
|
||||
struct Priv;
|
||||
|
||||
impl Pub {
|
||||
pub fn f() -> Priv {} //~ ERROR private type in public interface
|
||||
}
|
||||
}
|
||||
|
||||
mod m2 {
|
||||
#![deny(future_incompatible)]
|
||||
|
||||
pub struct Pub;
|
||||
struct Priv;
|
||||
|
||||
impl Pub {
|
||||
pub fn f() -> Priv {} //~ ERROR private type in public interface
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
41
src/test/compile-fail/lint-visible-private-types-1.rs
Normal file
41
src/test/compile-fail/lint-visible-private-types-1.rs
Normal file
@ -0,0 +1,41 @@
|
||||
// Copyright 2014 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.
|
||||
|
||||
#![feature(rustc_attrs)]
|
||||
#![allow(dead_code)]
|
||||
|
||||
use std::marker;
|
||||
|
||||
struct Private<T>(marker::PhantomData<T>);
|
||||
pub struct Public<T>(marker::PhantomData<T>);
|
||||
|
||||
pub trait PubTrait {
|
||||
type Output;
|
||||
}
|
||||
|
||||
type PrivAlias = Public<i8>;
|
||||
|
||||
trait PrivTrait2 {
|
||||
type Alias;
|
||||
}
|
||||
impl PrivTrait2 for Private<isize> {
|
||||
type Alias = Public<u8>;
|
||||
}
|
||||
|
||||
impl PubTrait for PrivAlias {
|
||||
type Output = Private<isize>; //~ WARN private type in public interface
|
||||
}
|
||||
|
||||
impl PubTrait for <Private<isize> as PrivTrait2>::Alias {
|
||||
type Output = Private<isize>; //~ WARN private type in public interface
|
||||
}
|
||||
|
||||
#[rustc_error]
|
||||
fn main() {} //~ ERROR compilation successful
|
@ -75,8 +75,8 @@ pub trait PubTrait {
|
||||
}
|
||||
|
||||
impl PubTrait for Public<isize> {
|
||||
fn bar(&self) -> Private<isize> { panic!() } //~ WARN private type in public interface
|
||||
fn baz() -> Private<isize> { panic!() } //~ WARN private type in public interface
|
||||
fn bar(&self) -> Private<isize> { panic!() } // Warns in lint checking phase
|
||||
fn baz() -> Private<isize> { panic!() } // Warns in lint checking phase
|
||||
}
|
||||
impl PubTrait for Public<Private<isize>> {
|
||||
fn bar(&self) -> Private<isize> { panic!() }
|
||||
@ -121,22 +121,3 @@ impl<T: ParamTrait<Private<isize>>> //~ ERROR private type in public interface
|
||||
ParamTrait<T> for Public<i8> {
|
||||
fn foo() -> T { panic!() }
|
||||
}
|
||||
|
||||
type PrivAlias = Public<i8>;
|
||||
|
||||
trait PrivTrait2 {
|
||||
type Alias;
|
||||
}
|
||||
impl PrivTrait2 for Private<isize> {
|
||||
type Alias = Public<u8>;
|
||||
}
|
||||
|
||||
impl PubTrait for PrivAlias {
|
||||
fn bar(&self) -> Private<isize> { panic!() } //~ WARN private type in public interface
|
||||
fn baz() -> Private<isize> { panic!() } //~ WARN private type in public interface
|
||||
}
|
||||
|
||||
impl PubTrait for <Private<isize> as PrivTrait2>::Alias {
|
||||
fn bar(&self) -> Private<isize> { panic!() } //~ WARN private type in public interface
|
||||
fn baz() -> Private<isize> { panic!() } //~ WARN private type in public interface
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user