Skip to content

Commit 2d49909

Browse files
Rollup merge of rust-lang#52224 - ljedrz:dyn_libsyntax, r=oli-obk
Deny bare trait objects in in src/libsyntax Enforce `#![deny(bare_trait_objects)]` in `src/libsyntax`.
2 parents d096f6a + 84dadb6 commit 2d49909

File tree

14 files changed

+76
-73
lines changed

14 files changed

+76
-73
lines changed

src/libsyntax/codemap.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ pub(super) struct CodeMapFiles {
131131

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

163163
}
164164

165-
pub fn with_file_loader(file_loader: Box<FileLoader + Sync + Send>,
165+
pub fn with_file_loader(file_loader: Box<dyn FileLoader + Sync + Send>,
166166
path_mapping: FilePathMapping)
167167
-> CodeMap {
168168
CodeMap {

src/libsyntax/diagnostics/metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ fn get_metadata_path(directory: PathBuf, name: &str) -> PathBuf {
7373
/// For our current purposes the prefix is the target architecture and the name is a crate name.
7474
/// If an error occurs steps will be taken to ensure that no file is created.
7575
pub fn output_metadata(ecx: &ExtCtxt, prefix: &str, name: &str, err_map: &ErrorMap)
76-
-> Result<(), Box<Error>>
76+
-> Result<(), Box<dyn Error>>
7777
{
7878
// Create the directory to place the file in.
7979
let metadata_dir = get_metadata_dir(prefix);

src/libsyntax/diagnostics/plugin.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub type ErrorMap = BTreeMap<Name, ErrorInfo>;
4242
pub fn expand_diagnostic_used<'cx>(ecx: &'cx mut ExtCtxt,
4343
span: Span,
4444
token_tree: &[TokenTree])
45-
-> Box<MacResult+'cx> {
45+
-> Box<dyn MacResult+'cx> {
4646
let code = match (token_tree.len(), token_tree.get(0)) {
4747
(1, Some(&TokenTree::Token(_, token::Ident(code, _)))) => code,
4848
_ => unreachable!()
@@ -75,7 +75,7 @@ pub fn expand_diagnostic_used<'cx>(ecx: &'cx mut ExtCtxt,
7575
pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt,
7676
span: Span,
7777
token_tree: &[TokenTree])
78-
-> Box<MacResult+'cx> {
78+
-> Box<dyn MacResult+'cx> {
7979
let (code, description) = match (
8080
token_tree.len(),
8181
token_tree.get(0),
@@ -145,7 +145,7 @@ pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt,
145145
pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt,
146146
span: Span,
147147
token_tree: &[TokenTree])
148-
-> Box<MacResult+'cx> {
148+
-> Box<dyn MacResult+'cx> {
149149
assert_eq!(token_tree.len(), 3);
150150
let (crate_name, name) = match (&token_tree[0], &token_tree[2]) {
151151
(

src/libsyntax/ext/base.rs

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -153,18 +153,18 @@ pub trait MultiItemDecorator {
153153
sp: Span,
154154
meta_item: &ast::MetaItem,
155155
item: &Annotatable,
156-
push: &mut FnMut(Annotatable));
156+
push: &mut dyn FnMut(Annotatable));
157157
}
158158

159159
impl<F> MultiItemDecorator for F
160-
where F : Fn(&mut ExtCtxt, Span, &ast::MetaItem, &Annotatable, &mut FnMut(Annotatable))
160+
where F : Fn(&mut ExtCtxt, Span, &ast::MetaItem, &Annotatable, &mut dyn FnMut(Annotatable))
161161
{
162162
fn expand(&self,
163163
ecx: &mut ExtCtxt,
164164
sp: Span,
165165
meta_item: &ast::MetaItem,
166166
item: &Annotatable,
167-
push: &mut FnMut(Annotatable)) {
167+
push: &mut dyn FnMut(Annotatable)) {
168168
(*self)(ecx, sp, meta_item, item, push)
169169
}
170170
}
@@ -247,18 +247,19 @@ impl<F> AttrProcMacro for F
247247
/// Represents a thing that maps token trees to Macro Results
248248
pub trait TTMacroExpander {
249249
fn expand<'cx>(&self, ecx: &'cx mut ExtCtxt, span: Span, input: TokenStream)
250-
-> Box<MacResult+'cx>;
250+
-> Box<dyn MacResult+'cx>;
251251
}
252252

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

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

264265
impl Folder for AvoidInterpolatedIdents {
@@ -289,23 +290,23 @@ pub trait IdentMacroExpander {
289290
sp: Span,
290291
ident: ast::Ident,
291292
token_tree: Vec<tokenstream::TokenTree>)
292-
-> Box<MacResult+'cx>;
293+
-> Box<dyn MacResult+'cx>;
293294
}
294295

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

299300
impl<F> IdentMacroExpander for F
300301
where F : for<'cx> Fn(&'cx mut ExtCtxt, Span, ast::Ident,
301-
Vec<tokenstream::TokenTree>) -> Box<MacResult+'cx>
302+
Vec<tokenstream::TokenTree>) -> Box<dyn MacResult+'cx>
302303
{
303304
fn expand<'cx>(&self,
304305
cx: &'cx mut ExtCtxt,
305306
sp: Span,
306307
ident: ast::Ident,
307308
token_tree: Vec<tokenstream::TokenTree>)
308-
-> Box<MacResult+'cx>
309+
-> Box<dyn MacResult+'cx>
309310
{
310311
(*self)(cx, sp, ident, token_tree)
311312
}
@@ -378,7 +379,7 @@ macro_rules! make_MacEager {
378379

379380
impl MacEager {
380381
$(
381-
pub fn $fld(v: $t) -> Box<MacResult> {
382+
pub fn $fld(v: $t) -> Box<dyn MacResult> {
382383
Box::new(MacEager {
383384
$fld: Some(v),
384385
..Default::default()
@@ -462,7 +463,7 @@ impl DummyResult {
462463
///
463464
/// Use this as a return value after hitting any errors and
464465
/// calling `span_err`.
465-
pub fn any(sp: Span) -> Box<MacResult+'static> {
466+
pub fn any(sp: Span) -> Box<dyn MacResult+'static> {
466467
Box::new(DummyResult { expr_only: false, span: sp })
467468
}
468469

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

@@ -559,7 +560,7 @@ impl MacResult for DummyResult {
559560
}
560561

561562
pub type BuiltinDeriveFn =
562-
for<'cx> fn(&'cx mut ExtCtxt, Span, &MetaItem, &Annotatable, &mut FnMut(Annotatable));
563+
for<'cx> fn(&'cx mut ExtCtxt, Span, &MetaItem, &Annotatable, &mut dyn FnMut(Annotatable));
563564

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

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

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

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

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

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

648649
/// A declarative macro, e.g. `macro m() {}`.
649650
DeclMacro {
650-
expander: Box<TTMacroExpander + sync::Sync + sync::Send>,
651+
expander: Box<dyn TTMacroExpander + sync::Sync + sync::Send>,
651652
def_info: Option<(ast::NodeId, Span)>,
652653
is_transparent: bool,
653654
edition: Edition,
@@ -778,7 +779,7 @@ pub struct ExtCtxt<'a> {
778779
pub parse_sess: &'a parse::ParseSess,
779780
pub ecfg: expand::ExpansionConfig<'a>,
780781
pub root_path: PathBuf,
781-
pub resolver: &'a mut Resolver,
782+
pub resolver: &'a mut dyn Resolver,
782783
pub resolve_err_count: usize,
783784
pub current_expansion: ExpansionData,
784785
pub expansions: HashMap<Span, Vec<String>>,
@@ -787,7 +788,7 @@ pub struct ExtCtxt<'a> {
787788
impl<'a> ExtCtxt<'a> {
788789
pub fn new(parse_sess: &'a parse::ParseSess,
789790
ecfg: expand::ExpansionConfig<'a>,
790-
resolver: &'a mut Resolver)
791+
resolver: &'a mut dyn Resolver)
791792
-> ExtCtxt<'a> {
792793
ExtCtxt {
793794
parse_sess,

src/libsyntax/ext/expand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ macro_rules! ast_fragments {
7171
}
7272
}
7373

74-
fn make_from<'a>(self, result: Box<MacResult + 'a>) -> Option<AstFragment> {
74+
fn make_from<'a>(self, result: Box<dyn MacResult + 'a>) -> Option<AstFragment> {
7575
match self {
7676
AstFragmentKind::OptExpr =>
7777
result.make_expr().map(Some).map(AstFragment::OptExpr),

src/libsyntax/ext/quote.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ pub fn parse_path_panic(parser: &mut Parser, mode: PathStyle) -> ast::Path {
452452
pub fn expand_quote_tokens<'cx>(cx: &'cx mut ExtCtxt,
453453
sp: Span,
454454
tts: &[TokenTree])
455-
-> Box<base::MacResult+'cx> {
455+
-> Box<dyn base::MacResult+'cx> {
456456
let (cx_expr, expr) = expand_tts(cx, sp, tts);
457457
let expanded = expand_wrapper(cx, sp, cx_expr, expr, &[&["syntax", "ext", "quote", "rt"]]);
458458
base::MacEager::expr(expanded)
@@ -461,55 +461,55 @@ pub fn expand_quote_tokens<'cx>(cx: &'cx mut ExtCtxt,
461461
pub fn expand_quote_expr<'cx>(cx: &'cx mut ExtCtxt,
462462
sp: Span,
463463
tts: &[TokenTree])
464-
-> Box<base::MacResult+'cx> {
464+
-> Box<dyn base::MacResult+'cx> {
465465
let expanded = expand_parse_call(cx, sp, "parse_expr_panic", vec![], tts);
466466
base::MacEager::expr(expanded)
467467
}
468468

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

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

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

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)