1. move allow_internal_unstable to rustc_attr

2. as a result, drop rustc_errors dep from syntax
This commit is contained in:
Mazdak Farrokhzad 2020-01-11 16:21:30 +01:00
parent 097d5e1c5e
commit 98fd6a5c88
5 changed files with 21 additions and 28 deletions

View File

@ -4512,7 +4512,6 @@ version = "0.0.0"
dependencies = [
"log",
"rustc_data_structures",
"rustc_errors",
"rustc_index",
"rustc_lexer",
"rustc_macros",

View File

@ -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<impl Iterator<Item = Symbol> + '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
}))
}

View File

@ -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>)>;

View File

@ -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" }

View File

@ -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<impl Iterator<Item = Symbol> + '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<Item = &Attribute> {
attrs.iter().filter(move |attr| attr.check_name(name))
}