Skip to content

Deny bare trait objects in src/libsyntax #52224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/libsyntax/codemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ pub(super) struct CodeMapFiles {

pub struct CodeMap {
pub(super) files: Lock<CodeMapFiles>,
file_loader: Box<FileLoader + Sync + Send>,
file_loader: Box<dyn FileLoader + Sync + Send>,
// This is used to apply the file path remapping as specified via
// --remap-path-prefix to all FileMaps allocated within this CodeMap.
path_mapping: FilePathMapping,
Expand Down Expand Up @@ -162,7 +162,7 @@ impl CodeMap {

}

pub fn with_file_loader(file_loader: Box<FileLoader + Sync + Send>,
pub fn with_file_loader(file_loader: Box<dyn FileLoader + Sync + Send>,
path_mapping: FilePathMapping)
-> CodeMap {
CodeMap {
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/diagnostics/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ fn get_metadata_path(directory: PathBuf, name: &str) -> PathBuf {
/// For our current purposes the prefix is the target architecture and the name is a crate name.
/// If an error occurs steps will be taken to ensure that no file is created.
pub fn output_metadata(ecx: &ExtCtxt, prefix: &str, name: &str, err_map: &ErrorMap)
-> Result<(), Box<Error>>
-> Result<(), Box<dyn Error>>
{
// Create the directory to place the file in.
let metadata_dir = get_metadata_dir(prefix);
Expand Down
6 changes: 3 additions & 3 deletions src/libsyntax/diagnostics/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub type ErrorMap = BTreeMap<Name, ErrorInfo>;
pub fn expand_diagnostic_used<'cx>(ecx: &'cx mut ExtCtxt,
span: Span,
token_tree: &[TokenTree])
-> Box<MacResult+'cx> {
-> Box<dyn MacResult+'cx> {
let code = match (token_tree.len(), token_tree.get(0)) {
(1, Some(&TokenTree::Token(_, token::Ident(code, _)))) => code,
_ => unreachable!()
Expand Down Expand Up @@ -75,7 +75,7 @@ pub fn expand_diagnostic_used<'cx>(ecx: &'cx mut ExtCtxt,
pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt,
span: Span,
token_tree: &[TokenTree])
-> Box<MacResult+'cx> {
-> Box<dyn MacResult+'cx> {
let (code, description) = match (
token_tree.len(),
token_tree.get(0),
Expand Down Expand Up @@ -145,7 +145,7 @@ pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt,
pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt,
span: Span,
token_tree: &[TokenTree])
-> Box<MacResult+'cx> {
-> Box<dyn MacResult+'cx> {
assert_eq!(token_tree.len(), 3);
let (crate_name, name) = match (&token_tree[0], &token_tree[2]) {
(
Expand Down
51 changes: 26 additions & 25 deletions src/libsyntax/ext/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,18 +153,18 @@ pub trait MultiItemDecorator {
sp: Span,
meta_item: &ast::MetaItem,
item: &Annotatable,
push: &mut FnMut(Annotatable));
push: &mut dyn FnMut(Annotatable));
}

impl<F> MultiItemDecorator for F
where F : Fn(&mut ExtCtxt, Span, &ast::MetaItem, &Annotatable, &mut FnMut(Annotatable))
where F : Fn(&mut ExtCtxt, Span, &ast::MetaItem, &Annotatable, &mut dyn FnMut(Annotatable))
{
fn expand(&self,
ecx: &mut ExtCtxt,
sp: Span,
meta_item: &ast::MetaItem,
item: &Annotatable,
push: &mut FnMut(Annotatable)) {
push: &mut dyn FnMut(Annotatable)) {
(*self)(ecx, sp, meta_item, item, push)
}
}
Expand Down Expand Up @@ -247,18 +247,19 @@ impl<F> AttrProcMacro for F
/// Represents a thing that maps token trees to Macro Results
pub trait TTMacroExpander {
fn expand<'cx>(&self, ecx: &'cx mut ExtCtxt, span: Span, input: TokenStream)
-> Box<MacResult+'cx>;
-> Box<dyn MacResult+'cx>;
}

pub type MacroExpanderFn =
for<'cx> fn(&'cx mut ExtCtxt, Span, &[tokenstream::TokenTree])
-> Box<MacResult+'cx>;
-> Box<dyn MacResult+'cx>;

impl<F> TTMacroExpander for F
where F: for<'cx> Fn(&'cx mut ExtCtxt, Span, &[tokenstream::TokenTree]) -> Box<MacResult+'cx>
where F: for<'cx> Fn(&'cx mut ExtCtxt, Span, &[tokenstream::TokenTree])
-> Box<dyn MacResult+'cx>
{
fn expand<'cx>(&self, ecx: &'cx mut ExtCtxt, span: Span, input: TokenStream)
-> Box<MacResult+'cx> {
-> Box<dyn MacResult+'cx> {
struct AvoidInterpolatedIdents;

impl Folder for AvoidInterpolatedIdents {
Expand Down Expand Up @@ -289,23 +290,23 @@ pub trait IdentMacroExpander {
sp: Span,
ident: ast::Ident,
token_tree: Vec<tokenstream::TokenTree>)
-> Box<MacResult+'cx>;
-> Box<dyn MacResult+'cx>;
}

pub type IdentMacroExpanderFn =
for<'cx> fn(&'cx mut ExtCtxt, Span, ast::Ident, Vec<tokenstream::TokenTree>)
-> Box<MacResult+'cx>;
-> Box<dyn MacResult+'cx>;

impl<F> IdentMacroExpander for F
where F : for<'cx> Fn(&'cx mut ExtCtxt, Span, ast::Ident,
Vec<tokenstream::TokenTree>) -> Box<MacResult+'cx>
Vec<tokenstream::TokenTree>) -> Box<dyn MacResult+'cx>
{
fn expand<'cx>(&self,
cx: &'cx mut ExtCtxt,
sp: Span,
ident: ast::Ident,
token_tree: Vec<tokenstream::TokenTree>)
-> Box<MacResult+'cx>
-> Box<dyn MacResult+'cx>
{
(*self)(cx, sp, ident, token_tree)
}
Expand Down Expand Up @@ -378,7 +379,7 @@ macro_rules! make_MacEager {

impl MacEager {
$(
pub fn $fld(v: $t) -> Box<MacResult> {
pub fn $fld(v: $t) -> Box<dyn MacResult> {
Box::new(MacEager {
$fld: Some(v),
..Default::default()
Expand Down Expand Up @@ -462,7 +463,7 @@ impl DummyResult {
///
/// Use this as a return value after hitting any errors and
/// calling `span_err`.
pub fn any(sp: Span) -> Box<MacResult+'static> {
pub fn any(sp: Span) -> Box<dyn MacResult+'static> {
Box::new(DummyResult { expr_only: false, span: sp })
}

Expand All @@ -471,7 +472,7 @@ impl DummyResult {
/// Use this for macros that must expand to an expression, so even
/// if an error is encountered internally, the user will receive
/// an error that they also used it in the wrong place.
pub fn expr(sp: Span) -> Box<MacResult+'static> {
pub fn expr(sp: Span) -> Box<dyn MacResult+'static> {
Box::new(DummyResult { expr_only: true, span: sp })
}

Expand Down Expand Up @@ -559,7 +560,7 @@ impl MacResult for DummyResult {
}

pub type BuiltinDeriveFn =
for<'cx> fn(&'cx mut ExtCtxt, Span, &MetaItem, &Annotatable, &mut FnMut(Annotatable));
for<'cx> fn(&'cx mut ExtCtxt, Span, &MetaItem, &Annotatable, &mut dyn FnMut(Annotatable));

/// Represents different kinds of macro invocations that can be resolved.
#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
Expand Down Expand Up @@ -590,15 +591,15 @@ pub enum SyntaxExtension {
/// `#[derive(...)]` is a `MultiItemDecorator`.
///
/// Prefer ProcMacro or MultiModifier since they are more flexible.
MultiDecorator(Box<MultiItemDecorator + sync::Sync + sync::Send>),
MultiDecorator(Box<dyn MultiItemDecorator + sync::Sync + sync::Send>),

/// A syntax extension that is attached to an item and modifies it
/// in-place. Also allows decoration, i.e., creating new items.
MultiModifier(Box<MultiItemModifier + sync::Sync + sync::Send>),
MultiModifier(Box<dyn MultiItemModifier + sync::Sync + sync::Send>),

/// A function-like procedural macro. TokenStream -> TokenStream.
ProcMacro {
expander: Box<ProcMacro + sync::Sync + sync::Send>,
expander: Box<dyn ProcMacro + sync::Sync + sync::Send>,
allow_internal_unstable: bool,
edition: Edition,
},
Expand All @@ -607,13 +608,13 @@ pub enum SyntaxExtension {
/// The first TokenSteam is the attribute, the second is the annotated item.
/// Allows modification of the input items and adding new items, similar to
/// MultiModifier, but uses TokenStreams, rather than AST nodes.
AttrProcMacro(Box<AttrProcMacro + sync::Sync + sync::Send>, Edition),
AttrProcMacro(Box<dyn AttrProcMacro + sync::Sync + sync::Send>, Edition),

/// A normal, function-like syntax extension.
///
/// `bytes!` is a `NormalTT`.
NormalTT {
expander: Box<TTMacroExpander + sync::Sync + sync::Send>,
expander: Box<dyn TTMacroExpander + sync::Sync + sync::Send>,
def_info: Option<(ast::NodeId, Span)>,
/// Whether the contents of the macro can
/// directly use `#[unstable]` things (true == yes).
Expand All @@ -633,21 +634,21 @@ pub enum SyntaxExtension {
/// A function-like syntax extension that has an extra ident before
/// the block.
///
IdentTT(Box<IdentMacroExpander + sync::Sync + sync::Send>, Option<Span>, bool),
IdentTT(Box<dyn IdentMacroExpander + sync::Sync + sync::Send>, Option<Span>, bool),

/// An attribute-like procedural macro. TokenStream -> TokenStream.
/// The input is the annotated item.
/// Allows generating code to implement a Trait for a given struct
/// or enum item.
ProcMacroDerive(Box<MultiItemModifier + sync::Sync + sync::Send>,
ProcMacroDerive(Box<dyn MultiItemModifier + sync::Sync + sync::Send>,
Vec<Symbol> /* inert attribute names */, Edition),

/// An attribute-like procedural macro that derives a builtin trait.
BuiltinDerive(BuiltinDeriveFn),

/// A declarative macro, e.g. `macro m() {}`.
DeclMacro {
expander: Box<TTMacroExpander + sync::Sync + sync::Send>,
expander: Box<dyn TTMacroExpander + sync::Sync + sync::Send>,
def_info: Option<(ast::NodeId, Span)>,
is_transparent: bool,
edition: Edition,
Expand Down Expand Up @@ -784,7 +785,7 @@ pub struct ExtCtxt<'a> {
pub parse_sess: &'a parse::ParseSess,
pub ecfg: expand::ExpansionConfig<'a>,
pub root_path: PathBuf,
pub resolver: &'a mut Resolver,
pub resolver: &'a mut dyn Resolver,
pub resolve_err_count: usize,
pub current_expansion: ExpansionData,
pub expansions: HashMap<Span, Vec<String>>,
Expand All @@ -793,7 +794,7 @@ pub struct ExtCtxt<'a> {
impl<'a> ExtCtxt<'a> {
pub fn new(parse_sess: &'a parse::ParseSess,
ecfg: expand::ExpansionConfig<'a>,
resolver: &'a mut Resolver)
resolver: &'a mut dyn Resolver)
-> ExtCtxt<'a> {
ExtCtxt {
parse_sess,
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ macro_rules! ast_fragments {
}
}

fn make_from<'a>(self, result: Box<MacResult + 'a>) -> Option<AstFragment> {
fn make_from<'a>(self, result: Box<dyn MacResult + 'a>) -> Option<AstFragment> {
match self {
AstFragmentKind::OptExpr =>
result.make_expr().map(Some).map(AstFragment::OptExpr),
Expand Down
24 changes: 12 additions & 12 deletions src/libsyntax/ext/quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ pub fn parse_path_panic(parser: &mut Parser, mode: PathStyle) -> ast::Path {
pub fn expand_quote_tokens<'cx>(cx: &'cx mut ExtCtxt,
sp: Span,
tts: &[TokenTree])
-> Box<base::MacResult+'cx> {
-> Box<dyn base::MacResult+'cx> {
let (cx_expr, expr) = expand_tts(cx, sp, tts);
let expanded = expand_wrapper(cx, sp, cx_expr, expr, &[&["syntax", "ext", "quote", "rt"]]);
base::MacEager::expr(expanded)
Expand All @@ -461,55 +461,55 @@ pub fn expand_quote_tokens<'cx>(cx: &'cx mut ExtCtxt,
pub fn expand_quote_expr<'cx>(cx: &'cx mut ExtCtxt,
sp: Span,
tts: &[TokenTree])
-> Box<base::MacResult+'cx> {
-> Box<dyn base::MacResult+'cx> {
let expanded = expand_parse_call(cx, sp, "parse_expr_panic", vec![], tts);
base::MacEager::expr(expanded)
}

pub fn expand_quote_item<'cx>(cx: &'cx mut ExtCtxt,
sp: Span,
tts: &[TokenTree])
-> Box<base::MacResult+'cx> {
-> Box<dyn base::MacResult+'cx> {
let expanded = expand_parse_call(cx, sp, "parse_item_panic", vec![], tts);
base::MacEager::expr(expanded)
}

pub fn expand_quote_pat<'cx>(cx: &'cx mut ExtCtxt,
sp: Span,
tts: &[TokenTree])
-> Box<base::MacResult+'cx> {
-> Box<dyn base::MacResult+'cx> {
let expanded = expand_parse_call(cx, sp, "parse_pat_panic", vec![], tts);
base::MacEager::expr(expanded)
}

pub fn expand_quote_arm(cx: &mut ExtCtxt,
sp: Span,
tts: &[TokenTree])
-> Box<base::MacResult+'static> {
-> Box<dyn base::MacResult+'static> {
let expanded = expand_parse_call(cx, sp, "parse_arm_panic", vec![], tts);
base::MacEager::expr(expanded)
}

pub fn expand_quote_ty(cx: &mut ExtCtxt,
sp: Span,
tts: &[TokenTree])
-> Box<base::MacResult+'static> {
-> Box<dyn base::MacResult+'static> {
let expanded = expand_parse_call(cx, sp, "parse_ty_panic", vec![], tts);
base::MacEager::expr(expanded)
}

pub fn expand_quote_stmt(cx: &mut ExtCtxt,
sp: Span,
tts: &[TokenTree])
-> Box<base::MacResult+'static> {
-> Box<dyn base::MacResult+'static> {
let expanded = expand_parse_call(cx, sp, "parse_stmt_panic", vec![], tts);
base::MacEager::expr(expanded)
}

pub fn expand_quote_attr(cx: &mut ExtCtxt,
sp: Span,
tts: &[TokenTree])
-> Box<base::MacResult+'static> {
-> Box<dyn base::MacResult+'static> {
let expanded = expand_parse_call(cx, sp, "parse_attribute_panic",
vec![cx.expr_bool(sp, true)], tts);

Expand All @@ -519,31 +519,31 @@ pub fn expand_quote_attr(cx: &mut ExtCtxt,
pub fn expand_quote_arg(cx: &mut ExtCtxt,
sp: Span,
tts: &[TokenTree])
-> Box<base::MacResult+'static> {
-> Box<dyn base::MacResult+'static> {
let expanded = expand_parse_call(cx, sp, "parse_arg_panic", vec![], tts);
base::MacEager::expr(expanded)
}

pub fn expand_quote_block(cx: &mut ExtCtxt,
sp: Span,
tts: &[TokenTree])
-> Box<base::MacResult+'static> {
-> Box<dyn base::MacResult+'static> {
let expanded = expand_parse_call(cx, sp, "parse_block_panic", vec![], tts);
base::MacEager::expr(expanded)
}

pub fn expand_quote_meta_item(cx: &mut ExtCtxt,
sp: Span,
tts: &[TokenTree])
-> Box<base::MacResult+'static> {
-> Box<dyn base::MacResult+'static> {
let expanded = expand_parse_call(cx, sp, "parse_meta_item_panic", vec![], tts);
base::MacEager::expr(expanded)
}

pub fn expand_quote_path(cx: &mut ExtCtxt,
sp: Span,
tts: &[TokenTree])
-> Box<base::MacResult+'static> {
-> Box<dyn base::MacResult+'static> {
let mode = mk_parser_path(cx, sp, &["PathStyle", "Type"]);
let expanded = expand_parse_call(cx, sp, "parse_path_panic", vec![mode], tts);
base::MacEager::expr(expanded)
Expand Down
Loading