From 98fd6a5c88a44214f15a43a9e633e3b71876bdb3 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sat, 11 Jan 2020 16:21:30 +0100 Subject: [PATCH] 1. move allow_internal_unstable to rustc_attr 2. as a result, drop rustc_errors dep from syntax --- Cargo.lock | 1 - src/librustc_attr/builtin.rs | 20 +++++++++++++++- .../transform/qualify_min_const_fn.rs | 3 ++- src/libsyntax/Cargo.toml | 1 - src/libsyntax/attr/mod.rs | 24 ------------------- 5 files changed, 21 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6214b56004d..b6e9738f10e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4512,7 +4512,6 @@ version = "0.0.0" dependencies = [ "log", "rustc_data_structures", - "rustc_errors", "rustc_index", "rustc_lexer", "rustc_macros", diff --git a/src/librustc_attr/builtin.rs b/src/librustc_attr/builtin.rs index f13f19073ea..c944537048f 100644 --- a/src/librustc_attr/builtin.rs +++ b/src/librustc_attr/builtin.rs @@ -1,6 +1,6 @@ //! Parsing and validation of builtin attributes -use super::mark_used; +use super::{find_by_name, mark_used}; use rustc_errors::{struct_span_err, Applicability, Handler}; use rustc_feature::{find_gated_cfg, is_builtin_attr_name, Features, GatedCfg}; @@ -1043,3 +1043,21 @@ pub fn find_transparency( let fallback = if is_legacy { Transparency::SemiTransparent } else { Transparency::Opaque }; (transparency.map_or(fallback, |t| t.0), error) } + +pub fn allow_internal_unstable<'a>( + attrs: &[Attribute], + diag: &'a rustc_errors::Handler, +) -> Option + 'a> { + let attr = find_by_name(attrs, sym::allow_internal_unstable)?; + let list = attr.meta_item_list().or_else(|| { + diag.span_err(attr.span, "allow_internal_unstable expects list of feature names"); + None + })?; + Some(list.into_iter().filter_map(move |it| { + let name = it.ident().map(|ident| ident.name); + if name.is_none() { + diag.span_err(it.span(), "`allow_internal_unstable` expects feature names"); + } + name + })) +} diff --git a/src/librustc_mir/transform/qualify_min_const_fn.rs b/src/librustc_mir/transform/qualify_min_const_fn.rs index 49921badf33..6a68ccdddff 100644 --- a/src/librustc_mir/transform/qualify_min_const_fn.rs +++ b/src/librustc_mir/transform/qualify_min_const_fn.rs @@ -1,11 +1,12 @@ use rustc::mir::*; use rustc::ty::{self, adjustment::PointerCast, Predicate, Ty, TyCtxt}; +use rustc_attr as attr; use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_span::symbol::{sym, Symbol}; use rustc_span::Span; use std::borrow::Cow; -use syntax::{ast, attr}; +use syntax::ast; type McfResult = Result<(), (Span, Cow<'static, str>)>; diff --git a/src/libsyntax/Cargo.toml b/src/libsyntax/Cargo.toml index b3e16f740fd..ff03ae3f425 100644 --- a/src/libsyntax/Cargo.toml +++ b/src/libsyntax/Cargo.toml @@ -13,7 +13,6 @@ doctest = false rustc_serialize = { path = "../libserialize", package = "serialize" } log = "0.4" scoped-tls = "1.0" -rustc_errors = { path = "../librustc_errors" } rustc_span = { path = "../librustc_span" } rustc_data_structures = { path = "../librustc_data_structures" } rustc_index = { path = "../librustc_index" } diff --git a/src/libsyntax/attr/mod.rs b/src/libsyntax/attr/mod.rs index e4d4017a345..313f5269235 100644 --- a/src/libsyntax/attr/mod.rs +++ b/src/libsyntax/attr/mod.rs @@ -406,30 +406,6 @@ pub fn find_by_name(attrs: &[Attribute], name: Symbol) -> Option<&Attribute> { attrs.iter().find(|attr| attr.check_name(name)) } -pub fn allow_internal_unstable<'a>( - attrs: &[Attribute], - span_diagnostic: &'a rustc_errors::Handler, -) -> Option + 'a> { - find_by_name(attrs, sym::allow_internal_unstable).and_then(|attr| { - attr.meta_item_list() - .or_else(|| { - span_diagnostic - .span_err(attr.span, "allow_internal_unstable expects list of feature names"); - None - }) - .map(|features| { - features.into_iter().filter_map(move |it| { - let name = it.ident().map(|ident| ident.name); - if name.is_none() { - span_diagnostic - .span_err(it.span(), "`allow_internal_unstable` expects feature names") - } - name - }) - }) - }) -} - pub fn filter_by_name(attrs: &[Attribute], name: Symbol) -> impl Iterator { attrs.iter().filter(move |attr| attr.check_name(name)) }