Remove remains of rustc_dirty.

This commit is contained in:
Camille GILLOT 2021-05-16 10:14:57 +02:00
parent 175345b864
commit fc069d3241
9 changed files with 56 additions and 79 deletions

View File

@ -567,10 +567,6 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
rustc_attr!(TEST, rustc_dump_user_substs, AssumedUsed, template!(Word)),
rustc_attr!(TEST, rustc_if_this_changed, AssumedUsed, template!(Word, List: "DepNode")),
rustc_attr!(TEST, rustc_then_this_would_need, AssumedUsed, template!(List: "DepNode")),
rustc_attr!(
TEST, rustc_dirty, AssumedUsed,
template!(List: r#"cfg = "...", /*opt*/ label = "...", /*opt*/ except = "...""#),
),
rustc_attr!(
TEST, rustc_clean, AssumedUsed,
template!(List: r#"cfg = "...", /*opt*/ label = "...", /*opt*/ except = "...""#),

View File

@ -1,6 +1,5 @@
//! Debugging code to test fingerprints computed for query results.
//! For each node marked with `#[rustc_clean]` or `#[rustc_dirty]`,
//! we will compare the fingerprint from the current and from the previous
//! Debugging code to test fingerprints computed for query results. For each node marked with
//! `#[rustc_clean]` we will compare the fingerprint from the current and from the previous
//! compilation session as appropriate:
//!
//! - `#[rustc_clean(cfg="rev2", except="typeck")]` if we are
@ -132,7 +131,7 @@ pub fn check_dirty_clean_annotations(tcx: TyCtxt<'_>) {
return;
}
// can't add `#[rustc_dirty]` etc without opting in to this feature
// can't add `#[rustc_clean]` etc without opting in to this feature
if !tcx.features().rustc_attrs {
return;
}
@ -142,11 +141,7 @@ pub fn check_dirty_clean_annotations(tcx: TyCtxt<'_>) {
let mut dirty_clean_visitor = DirtyCleanVisitor { tcx, checked_attrs: Default::default() };
krate.visit_all_item_likes(&mut dirty_clean_visitor);
let mut all_attrs = FindAllAttrs {
tcx,
attr_names: &[sym::rustc_dirty, sym::rustc_clean],
found_attrs: vec![],
};
let mut all_attrs = FindAllAttrs { tcx, found_attrs: vec![] };
intravisit::walk_crate(&mut all_attrs, krate);
// Note that we cannot use the existing "unused attribute"-infrastructure
@ -164,29 +159,20 @@ pub struct DirtyCleanVisitor<'tcx> {
impl DirtyCleanVisitor<'tcx> {
/// Possibly "deserialize" the attribute into a clean/dirty assertion
fn assertion_maybe(&mut self, item_id: LocalDefId, attr: &Attribute) -> Option<Assertion> {
let is_clean = if self.tcx.sess.check_name(attr, sym::rustc_dirty) {
false
} else if self.tcx.sess.check_name(attr, sym::rustc_clean) {
true
} else {
if !self.tcx.sess.check_name(attr, sym::rustc_clean) {
// skip: not rustc_clean/dirty
return None;
};
}
if !check_config(self.tcx, attr) {
// skip: not the correct `cfg=`
return None;
}
let assertion = self.assertion_auto(item_id, attr, is_clean);
let assertion = self.assertion_auto(item_id, attr);
Some(assertion)
}
/// Gets the "auto" assertion on pre-validated attr, along with the `except` labels.
fn assertion_auto(
&mut self,
item_id: LocalDefId,
attr: &Attribute,
is_clean: bool,
) -> Assertion {
fn assertion_auto(&mut self, item_id: LocalDefId, attr: &Attribute) -> Assertion {
let (name, mut auto) = self.auto_labels(item_id, attr);
let except = self.except(attr);
for e in except.iter() {
@ -198,11 +184,7 @@ impl DirtyCleanVisitor<'tcx> {
self.tcx.sess.span_fatal(attr.span, &msg);
}
}
if is_clean {
Assertion { clean: auto, dirty: except }
} else {
Assertion { clean: except, dirty: auto }
}
Assertion { clean: auto, dirty: except }
}
/// `except=` attribute value
@ -398,9 +380,8 @@ impl ItemLikeVisitor<'tcx> for DirtyCleanVisitor<'tcx> {
}
}
/// Given a `#[rustc_dirty]` or `#[rustc_clean]` attribute, scan
/// for a `cfg="foo"` attribute and check whether we have a cfg
/// flag called `foo`.
/// Given a `#[rustc_clean]` attribute, scan for a `cfg="foo"` attribute and check whether we have
/// a cfg flag called `foo`.
fn check_config(tcx: TyCtxt<'_>, attr: &Attribute) -> bool {
debug!("check_config(attr={:?})", attr);
let config = &tcx.sess.parse_sess.config;
@ -436,21 +417,18 @@ fn expect_associated_value(tcx: TyCtxt<'_>, item: &NestedMetaItem) -> Symbol {
}
}
// A visitor that collects all #[rustc_dirty]/#[rustc_clean] attributes from
// A visitor that collects all #[rustc_clean] attributes from
// the HIR. It is used to verify that we really ran checks for all annotated
// nodes.
pub struct FindAllAttrs<'a, 'tcx> {
pub struct FindAllAttrs<'tcx> {
tcx: TyCtxt<'tcx>,
attr_names: &'a [Symbol],
found_attrs: Vec<&'tcx Attribute>,
}
impl FindAllAttrs<'_, 'tcx> {
impl FindAllAttrs<'tcx> {
fn is_active_attr(&mut self, attr: &Attribute) -> bool {
for attr_name in self.attr_names {
if self.tcx.sess.check_name(attr, *attr_name) && check_config(self.tcx, attr) {
return true;
}
if self.tcx.sess.check_name(attr, sym::rustc_clean) && check_config(self.tcx, attr) {
return true;
}
false
@ -459,17 +437,14 @@ impl FindAllAttrs<'_, 'tcx> {
fn report_unchecked_attrs(&self, mut checked_attrs: FxHashSet<ast::AttrId>) {
for attr in &self.found_attrs {
if !checked_attrs.contains(&attr.id) {
self.tcx.sess.span_err(
attr.span,
"found unchecked `#[rustc_dirty]` / `#[rustc_clean]` attribute",
);
self.tcx.sess.span_err(attr.span, "found unchecked `#[rustc_clean]` attribute");
checked_attrs.insert(attr.id);
}
}
}
}
impl intravisit::Visitor<'tcx> for FindAllAttrs<'_, 'tcx> {
impl intravisit::Visitor<'tcx> for FindAllAttrs<'tcx> {
type Map = Map<'tcx>;
fn nested_visit_map(&mut self) -> intravisit::NestedVisitorMap<Self::Map> {

View File

@ -25,7 +25,10 @@ mod x {
mod y {
use x;
#[rustc_dirty(except="typeck", cfg="cfail2")]
#[rustc_clean(
except="hir_owner,hir_owner_nodes,generics_of,predicates_of,type_of,fn_sig",
cfg="cfail2",
)]
pub fn y() {
//[cfail2]~^ ERROR `hir_owner(y)` should be dirty but is not
//[cfail2]~| ERROR `hir_owner_nodes(y)` should be dirty but is not

View File

@ -370,7 +370,7 @@ enum EnumChangeNameOfTypeParameter<S> {
}
#[cfg(not(cfail1))]
#[rustc_dirty(cfg="cfail2")]
#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,generics_of,predicates_of,type_of")]
#[rustc_clean(cfg="cfail3")]
enum EnumChangeNameOfTypeParameter<T> {
Variant1(T),
@ -386,7 +386,7 @@ enum EnumAddTypeParameter<S> {
}
#[cfg(not(cfail1))]
#[rustc_dirty(cfg="cfail2")]
#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,generics_of,predicates_of,type_of")]
#[rustc_clean(cfg="cfail3")]
enum EnumAddTypeParameter<S, T> {
Variant1(S),
@ -402,7 +402,7 @@ enum EnumChangeNameOfLifetimeParameter<'a> {
}
#[cfg(not(cfail1))]
#[rustc_dirty(cfg="cfail2", except="predicates_of")]
#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,generics_of,type_of")]
#[rustc_clean(cfg="cfail3")]
enum EnumChangeNameOfLifetimeParameter<'b> {
Variant1(&'b u32),
@ -418,7 +418,7 @@ enum EnumAddLifetimeParameter<'a> {
}
#[cfg(not(cfail1))]
#[rustc_dirty(cfg="cfail2", except="predicates_of")]
#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,generics_of,type_of")]
#[rustc_clean(cfg="cfail3")]
enum EnumAddLifetimeParameter<'a, 'b> {
Variant1(&'a u32),
@ -435,7 +435,7 @@ enum EnumAddLifetimeParameterBound<'a, 'b> {
}
#[cfg(not(cfail1))]
#[rustc_dirty(cfg="cfail2", except="generics_of,type_of")]
#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,predicates_of")]
#[rustc_clean(cfg="cfail3")]
enum EnumAddLifetimeParameterBound<'a, 'b: 'a> {
Variant1(&'a u32),
@ -450,7 +450,7 @@ enum EnumAddLifetimeBoundToParameter<'a, T> {
}
#[cfg(not(cfail1))]
#[rustc_dirty(cfg="cfail2", except="type_of")]
#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,generics_of,predicates_of")]
#[rustc_clean(cfg="cfail3")]
enum EnumAddLifetimeBoundToParameter<'a, T: 'a> {
Variant1(T),
@ -466,7 +466,7 @@ enum EnumAddTraitBound<S> {
}
#[cfg(not(cfail1))]
#[rustc_dirty(cfg="cfail2")]
#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,generics_of,predicates_of,type_of")]
#[rustc_clean(cfg="cfail3")]
enum EnumAddTraitBound<T: Sync> {
Variant1(T),
@ -482,7 +482,7 @@ enum EnumAddLifetimeParameterBoundWhere<'a, 'b> {
}
#[cfg(not(cfail1))]
#[rustc_dirty(cfg="cfail2", except="generics_of,type_of")]
#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,predicates_of")]
#[rustc_clean(cfg="cfail3")]
enum EnumAddLifetimeParameterBoundWhere<'a, 'b> where 'b: 'a {
Variant1(&'a u32),
@ -499,7 +499,7 @@ enum EnumAddLifetimeBoundToParameterWhere<'a, T> {
}
#[cfg(not(cfail1))]
#[rustc_dirty(cfg="cfail2", except="type_of")]
#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,generics_of,predicates_of")]
#[rustc_clean(cfg="cfail3")]
enum EnumAddLifetimeBoundToParameterWhere<'a, T> where T: 'a {
Variant1(T),
@ -515,7 +515,7 @@ enum EnumAddTraitBoundWhere<S> {
}
#[cfg(not(cfail1))]
#[rustc_dirty(cfg="cfail2")]
#[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes,generics_of,predicates_of,type_of")]
#[rustc_clean(cfg="cfail3")]
enum EnumAddTraitBoundWhere<T> where T: Sync {
Variant1(T),

View File

@ -21,7 +21,7 @@ extern "C" {
}
#[cfg(not(cfail1))]
#[rustc_dirty(cfg = "cfail2", except = "hir_owner_nodes")]
#[rustc_clean(cfg = "cfail2", except = "hir_owner")]
#[rustc_clean(cfg = "cfail3")]
extern "C" {
pub fn change_function_name2(c: i64) -> i32;
@ -34,7 +34,7 @@ extern "C" {
}
#[cfg(not(cfail1))]
#[rustc_dirty(cfg = "cfail2", except = "hir_owner,hir_owner_nodes")]
#[rustc_clean(cfg = "cfail2")]
#[rustc_clean(cfg = "cfail3")]
extern "C" {
pub fn change_parameter_name(d: i64) -> i32;
@ -47,7 +47,7 @@ extern "C" {
}
#[cfg(not(cfail1))]
#[rustc_dirty(cfg = "cfail2", except = "hir_owner,hir_owner_nodes")]
#[rustc_clean(cfg = "cfail2")]
#[rustc_clean(cfg = "cfail3")]
extern "C" {
pub fn change_parameter_type(c: i32) -> i32;
@ -60,7 +60,7 @@ extern "C" {
}
#[cfg(not(cfail1))]
#[rustc_dirty(cfg = "cfail2", except = "hir_owner,hir_owner_nodes")]
#[rustc_clean(cfg = "cfail2")]
#[rustc_clean(cfg = "cfail3")]
extern "C" {
pub fn change_return_type(c: i32) -> i8;
@ -73,7 +73,7 @@ extern "C" {
}
#[cfg(not(cfail1))]
#[rustc_dirty(cfg = "cfail2", except = "hir_owner,hir_owner_nodes")]
#[rustc_clean(cfg = "cfail2")]
#[rustc_clean(cfg = "cfail3")]
extern "C" {
pub fn add_parameter(c: i32, d: i32) -> i32;
@ -86,7 +86,7 @@ extern "C" {
}
#[cfg(not(cfail1))]
#[rustc_dirty(cfg = "cfail2", except = "hir_owner,hir_owner_nodes")]
#[rustc_clean(cfg = "cfail2")]
#[rustc_clean(cfg = "cfail3")]
extern "C" {
pub fn add_return_type(c: i32) -> i32;
@ -99,7 +99,7 @@ extern "C" {
}
#[cfg(not(cfail1))]
#[rustc_dirty(cfg = "cfail2", except = "hir_owner,hir_owner_nodes")]
#[rustc_clean(cfg = "cfail2")]
#[rustc_clean(cfg = "cfail3")]
extern "C" {
pub fn make_function_variadic(c: i32, ...);
@ -112,7 +112,7 @@ extern "C" {
}
#[cfg(not(cfail1))]
#[rustc_dirty(cfg = "cfail2", except = "hir_owner_nodes")]
#[rustc_clean(cfg = "cfail2", except = "hir_owner")]
#[rustc_clean(cfg = "cfail3")]
extern "rust-call" {
pub fn change_calling_convention(c: i32);
@ -125,7 +125,7 @@ extern "C" {
}
#[cfg(not(cfail1))]
#[rustc_dirty(cfg = "cfail2", except = "hir_owner_nodes")]
#[rustc_clean(cfg = "cfail2", except = "hir_owner")]
#[rustc_clean(cfg = "cfail3")]
extern "C" {
pub fn make_function_public(c: i32);
@ -138,7 +138,7 @@ extern "C" {
}
#[cfg(not(cfail1))]
#[rustc_dirty(cfg = "cfail2", except = "hir_owner_nodes")]
#[rustc_clean(cfg = "cfail2", except = "hir_owner")]
#[rustc_clean(cfg = "cfail3")]
extern "C" {
pub fn add_function1(c: i32);
@ -153,7 +153,7 @@ extern "C" {
}
#[cfg(not(cfail1))]
#[rustc_dirty(cfg = "cfail2", except = "hir_owner,hir_owner_nodes")]
#[rustc_clean(cfg = "cfail2")]
#[rustc_clean(cfg = "cfail3")]
#[link(name = "bar")]
extern "C" {
@ -170,7 +170,7 @@ mod indirectly_change_parameter_type {
#[cfg(not(cfail1))]
use super::c_i64 as c_int;
#[rustc_dirty(cfg = "cfail2", except = "hir_owner,hir_owner_nodes")]
#[rustc_clean(cfg = "cfail2")]
#[rustc_clean(cfg = "cfail3")]
extern "C" {
pub fn indirectly_change_parameter_type(c: c_int);
@ -184,7 +184,7 @@ mod indirectly_change_return_type {
#[cfg(not(cfail1))]
use super::c_i64 as c_int;
#[rustc_dirty(cfg = "cfail2", except = "hir_owner,hir_owner_nodes")]
#[rustc_clean(cfg = "cfail2")]
#[rustc_clean(cfg = "cfail3")]
extern "C" {
pub fn indirectly_change_return_type() -> c_int;

View File

@ -103,7 +103,10 @@ impl Foo {
#[rustc_clean(cfg="cfail2", except="hir_owner")]
#[rustc_clean(cfg="cfail3")]
impl Foo {
#[rustc_dirty(cfg="cfail2", except="type_of,predicates_of,promoted_mir")]
#[rustc_clean(
cfg="cfail2",
except="hir_owner,hir_owner_nodes,fn_sig,generics_of,typeck,associated_item,optimized_mir",
)]
#[rustc_clean(cfg="cfail3")]
pub fn method_selfness(&self) { }
}

View File

@ -4,20 +4,20 @@
#![allow(warnings)]
#![feature(rustc_attrs)]
// Sanity check for the dirty-clean system. We add #[rustc_dirty]/#[rustc_clean]
// Sanity check for the dirty-clean system. We add #[rustc_clean]
// attributes in places that are not checked and make sure that this causes an
// error.
fn main() {
#[rustc_clean(except="hir_owner", cfg="cfail2")]
//[cfail2]~^ ERROR found unchecked `#[rustc_dirty]` / `#[rustc_clean]` attribute
//[cfail2]~^ ERROR found unchecked `#[rustc_clean]` attribute
{
// empty block
}
#[rustc_clean(cfg="cfail2")]
//[cfail2]~^ ERROR found unchecked `#[rustc_dirty]` / `#[rustc_clean]` attribute
//[cfail2]~^ ERROR found unchecked `#[rustc_clean]` attribute
{
// empty block
}
@ -25,10 +25,10 @@ fn main() {
struct _Struct {
#[rustc_clean(except="hir_owner", cfg="cfail2")]
//[cfail2]~^ ERROR found unchecked `#[rustc_dirty]` / `#[rustc_clean]` attribute
//[cfail2]~^ ERROR found unchecked `#[rustc_clean]` attribute
_field1: i32,
#[rustc_clean(cfg="cfail2")]
//[cfail2]~^ ERROR found unchecked `#[rustc_dirty]` / `#[rustc_clean]` attribute
//[cfail2]~^ ERROR found unchecked `#[rustc_clean]` attribute
_field2: i32,
}

View File

@ -5,7 +5,7 @@
#![allow(dead_code)]
#![allow(unused_variables)]
#[rustc_dirty(hir_owner)] //~ ERROR attribute requires -Z query-dep-graph
#[rustc_clean(hir_owner)] //~ ERROR attribute requires -Z query-dep-graph
fn main() {}
#[rustc_if_this_changed(hir_owner)] //~ ERROR attribute requires -Z query-dep-graph

View File

@ -1,7 +1,7 @@
error: attribute requires -Z query-dep-graph to be enabled
--> $DIR/dep-graph-check-attr.rs:8:1
|
LL | #[rustc_dirty(hir_owner)]
LL | #[rustc_clean(hir_owner)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
error: attribute requires -Z query-dep-graph to be enabled