Deny bare trait objects in librustc_driver

This commit is contained in:
ljedrz 2018-07-12 09:11:39 +02:00
parent c946c2539e
commit 58bf387ae3
4 changed files with 52 additions and 50 deletions

View File

@ -118,7 +118,7 @@ pub fn spawn_thread_pool<F: FnOnce(config::Options) -> R + sync::Send, R: sync::
} }
pub fn compile_input( pub fn compile_input(
codegen_backend: Box<CodegenBackend>, codegen_backend: Box<dyn CodegenBackend>,
sess: &Session, sess: &Session,
cstore: &CStore, cstore: &CStore,
input_path: &Option<PathBuf>, input_path: &Option<PathBuf>,
@ -399,10 +399,10 @@ pub struct CompileController<'a> {
/// Allows overriding default rustc query providers, /// Allows overriding default rustc query providers,
/// after `default_provide` has installed them. /// after `default_provide` has installed them.
pub provide: Box<Fn(&mut ty::query::Providers) + 'a>, pub provide: Box<dyn Fn(&mut ty::query::Providers) + 'a>,
/// Same as `provide`, but only for non-local crates, /// Same as `provide`, but only for non-local crates,
/// applied after `default_provide_extern`. /// applied after `default_provide_extern`.
pub provide_extern: Box<Fn(&mut ty::query::Providers) + 'a>, pub provide_extern: Box<dyn Fn(&mut ty::query::Providers) + 'a>,
} }
impl<'a> CompileController<'a> { impl<'a> CompileController<'a> {
@ -471,10 +471,10 @@ impl<'a> ::CompilerCalls<'a> for CompileController<'a> {
} }
fn late_callback( fn late_callback(
&mut self, &mut self,
codegen_backend: &::CodegenBackend, codegen_backend: &dyn (::CodegenBackend),
matches: &::getopts::Matches, matches: &::getopts::Matches,
sess: &Session, sess: &Session,
cstore: &::CrateStore, cstore: &dyn (::CrateStore),
input: &Input, input: &Input,
odir: &Option<PathBuf>, odir: &Option<PathBuf>,
ofile: &Option<PathBuf>, ofile: &Option<PathBuf>,
@ -496,7 +496,7 @@ pub struct PhaseController<'a> {
// If true then the compiler will try to run the callback even if the phase // If true then the compiler will try to run the callback even if the phase
// ends with an error. Note that this is not always possible. // ends with an error. Note that this is not always possible.
pub run_callback_on_error: bool, pub run_callback_on_error: bool,
pub callback: Box<Fn(&mut CompileState) + 'a>, pub callback: Box<dyn Fn(&mut CompileState) + 'a>,
} }
impl<'a> PhaseController<'a> { impl<'a> PhaseController<'a> {
@ -1175,7 +1175,7 @@ pub fn default_provide_extern(providers: &mut ty::query::Providers) {
/// miscellaneous analysis passes on the crate. Return various /// miscellaneous analysis passes on the crate. Return various
/// structures carrying the results of the analysis. /// structures carrying the results of the analysis.
pub fn phase_3_run_analysis_passes<'tcx, F, R>( pub fn phase_3_run_analysis_passes<'tcx, F, R>(
codegen_backend: &CodegenBackend, codegen_backend: &dyn CodegenBackend,
control: &CompileController, control: &CompileController,
sess: &'tcx Session, sess: &'tcx Session,
cstore: &'tcx CrateStoreDyn, cstore: &'tcx CrateStoreDyn,
@ -1191,7 +1191,7 @@ where
F: for<'a> FnOnce( F: for<'a> FnOnce(
TyCtxt<'a, 'tcx, 'tcx>, TyCtxt<'a, 'tcx, 'tcx>,
ty::CrateAnalysis, ty::CrateAnalysis,
mpsc::Receiver<Box<Any + Send>>, mpsc::Receiver<Box<dyn Any + Send>>,
CompileResult, CompileResult,
) -> R, ) -> R,
{ {
@ -1324,10 +1324,10 @@ where
/// Run the codegen backend, after which the AST and analysis can /// Run the codegen backend, after which the AST and analysis can
/// be discarded. /// be discarded.
pub fn phase_4_codegen<'a, 'tcx>( pub fn phase_4_codegen<'a, 'tcx>(
codegen_backend: &CodegenBackend, codegen_backend: &dyn CodegenBackend,
tcx: TyCtxt<'a, 'tcx, 'tcx>, tcx: TyCtxt<'a, 'tcx, 'tcx>,
rx: mpsc::Receiver<Box<Any + Send>>, rx: mpsc::Receiver<Box<dyn Any + Send>>,
) -> Box<Any> { ) -> Box<dyn Any> {
time(tcx.sess, "resolving dependency formats", || { time(tcx.sess, "resolving dependency formats", || {
::rustc::middle::dependency_format::calculate(tcx) ::rustc::middle::dependency_format::calculate(tcx)
}); });

View File

@ -14,6 +14,8 @@
//! //!
//! This API is completely unstable and subject to change. //! This API is completely unstable and subject to change.
#![deny(bare_trait_objects)]
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
html_favicon_url = "https://doc.rust-lang.org/favicon.ico", html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
html_root_url = "https://doc.rust-lang.org/nightly/")] html_root_url = "https://doc.rust-lang.org/nightly/")]
@ -131,7 +133,7 @@ pub mod target_features {
/// features is available on the target machine, by querying LLVM. /// features is available on the target machine, by querying LLVM.
pub fn add_configuration(cfg: &mut ast::CrateConfig, pub fn add_configuration(cfg: &mut ast::CrateConfig,
sess: &Session, sess: &Session,
codegen_backend: &CodegenBackend) { codegen_backend: &dyn CodegenBackend) {
let tf = Symbol::intern("target_feature"); let tf = Symbol::intern("target_feature");
for feat in codegen_backend.target_features(sess) { for feat in codegen_backend.target_features(sess) {
@ -202,7 +204,7 @@ pub fn run<F>(run_compiler: F) -> isize
0 0
} }
fn load_backend_from_dylib(path: &Path) -> fn() -> Box<CodegenBackend> { fn load_backend_from_dylib(path: &Path) -> fn() -> Box<dyn CodegenBackend> {
// Note that we're specifically using `open_global_now` here rather than // Note that we're specifically using `open_global_now` here rather than
// `open`, namely we want the behavior on Unix of RTLD_GLOBAL and RTLD_NOW, // `open`, namely we want the behavior on Unix of RTLD_GLOBAL and RTLD_NOW,
// where NOW means "bind everything right now" because we don't want // where NOW means "bind everything right now" because we don't want
@ -235,12 +237,12 @@ fn load_backend_from_dylib(path: &Path) -> fn() -> Box<CodegenBackend> {
} }
} }
pub fn get_codegen_backend(sess: &Session) -> Box<CodegenBackend> { pub fn get_codegen_backend(sess: &Session) -> Box<dyn CodegenBackend> {
static INIT: Once = ONCE_INIT; static INIT: Once = ONCE_INIT;
#[allow(deprecated)] #[allow(deprecated)]
#[no_debug] #[no_debug]
static mut LOAD: fn() -> Box<CodegenBackend> = || unreachable!(); static mut LOAD: fn() -> Box<dyn CodegenBackend> = || unreachable!();
INIT.call_once(|| { INIT.call_once(|| {
let codegen_name = sess.opts.debugging_opts.codegen_backend.as_ref() let codegen_name = sess.opts.debugging_opts.codegen_backend.as_ref()
@ -264,7 +266,7 @@ pub fn get_codegen_backend(sess: &Session) -> Box<CodegenBackend> {
backend backend
} }
fn get_codegen_sysroot(backend_name: &str) -> fn() -> Box<CodegenBackend> { fn get_codegen_sysroot(backend_name: &str) -> fn() -> Box<dyn CodegenBackend> {
// For now we only allow this function to be called once as it'll dlopen a // For now we only allow this function to be called once as it'll dlopen a
// few things, which seems to work best if we only do that once. In // few things, which seems to work best if we only do that once. In
// general this assertion never trips due to the once guard in `get_codegen_backend`, // general this assertion never trips due to the once guard in `get_codegen_backend`,
@ -454,9 +456,9 @@ fn get_codegen_sysroot(backend_name: &str) -> fn() -> Box<CodegenBackend> {
// See comments on CompilerCalls below for details about the callbacks argument. // See comments on CompilerCalls below for details about the callbacks argument.
// The FileLoader provides a way to load files from sources other than the file system. // The FileLoader provides a way to load files from sources other than the file system.
pub fn run_compiler<'a>(args: &[String], pub fn run_compiler<'a>(args: &[String],
callbacks: Box<CompilerCalls<'a> + sync::Send + 'a>, callbacks: Box<dyn CompilerCalls<'a> + sync::Send + 'a>,
file_loader: Option<Box<FileLoader + Send + Sync + 'static>>, file_loader: Option<Box<dyn FileLoader + Send + Sync + 'static>>,
emitter_dest: Option<Box<Write + Send>>) emitter_dest: Option<Box<dyn Write + Send>>)
-> (CompileResult, Option<Session>) -> (CompileResult, Option<Session>)
{ {
syntax::with_globals(|| { syntax::with_globals(|| {
@ -478,9 +480,9 @@ fn run_compiler_with_pool<'a>(
matches: getopts::Matches, matches: getopts::Matches,
sopts: config::Options, sopts: config::Options,
cfg: ast::CrateConfig, cfg: ast::CrateConfig,
mut callbacks: Box<CompilerCalls<'a> + sync::Send + 'a>, mut callbacks: Box<dyn CompilerCalls<'a> + sync::Send + 'a>,
file_loader: Option<Box<FileLoader + Send + Sync + 'static>>, file_loader: Option<Box<dyn FileLoader + Send + Sync + 'static>>,
emitter_dest: Option<Box<Write + Send>> emitter_dest: Option<Box<dyn Write + Send>>
) -> (CompileResult, Option<Session>) { ) -> (CompileResult, Option<Session>) {
macro_rules! do_or_return {($expr: expr, $sess: expr) => { macro_rules! do_or_return {($expr: expr, $sess: expr) => {
match $expr { match $expr {
@ -662,10 +664,10 @@ pub trait CompilerCalls<'a> {
/// be called just before actual compilation starts (and before build_controller /// be called just before actual compilation starts (and before build_controller
/// is called), after all arguments etc. have been completely handled. /// is called), after all arguments etc. have been completely handled.
fn late_callback(&mut self, fn late_callback(&mut self,
_: &CodegenBackend, _: &dyn CodegenBackend,
_: &getopts::Matches, _: &getopts::Matches,
_: &Session, _: &Session,
_: &CrateStore, _: &dyn CrateStore,
_: &Input, _: &Input,
_: &Option<PathBuf>, _: &Option<PathBuf>,
_: &Option<PathBuf>) _: &Option<PathBuf>)
@ -870,10 +872,10 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
} }
fn late_callback(&mut self, fn late_callback(&mut self,
codegen_backend: &CodegenBackend, codegen_backend: &dyn CodegenBackend,
matches: &getopts::Matches, matches: &getopts::Matches,
sess: &Session, sess: &Session,
cstore: &CrateStore, cstore: &dyn CrateStore,
input: &Input, input: &Input,
odir: &Option<PathBuf>, odir: &Option<PathBuf>,
ofile: &Option<PathBuf>) ofile: &Option<PathBuf>)
@ -979,7 +981,7 @@ pub fn enable_save_analysis(control: &mut CompileController) {
impl RustcDefaultCalls { impl RustcDefaultCalls {
pub fn list_metadata(sess: &Session, pub fn list_metadata(sess: &Session,
cstore: &CrateStore, cstore: &dyn CrateStore,
matches: &getopts::Matches, matches: &getopts::Matches,
input: &Input) input: &Input)
-> Compilation { -> Compilation {
@ -1007,7 +1009,7 @@ impl RustcDefaultCalls {
} }
fn print_crate_info(codegen_backend: &CodegenBackend, fn print_crate_info(codegen_backend: &dyn CodegenBackend,
sess: &Session, sess: &Session,
input: Option<&Input>, input: Option<&Input>,
odir: &Option<PathBuf>, odir: &Option<PathBuf>,
@ -1486,7 +1488,7 @@ fn parse_crate_attrs<'a>(sess: &'a Session, input: &Input) -> PResult<'a, Vec<as
/// Runs `f` in a suitable thread for running `rustc`; returns a /// Runs `f` in a suitable thread for running `rustc`; returns a
/// `Result` with either the return value of `f` or -- if a panic /// `Result` with either the return value of `f` or -- if a panic
/// occurs -- the panic value. /// occurs -- the panic value.
pub fn in_rustc_thread<F, R>(f: F) -> Result<R, Box<Any + Send>> pub fn in_rustc_thread<F, R>(f: F) -> Result<R, Box<dyn Any + Send>>
where F: FnOnce() -> R + Send + 'static, where F: FnOnce() -> R + Send + 'static,
R: Send + 'static, R: Send + 'static,
{ {

View File

@ -170,7 +170,7 @@ impl PpSourceMode {
hir_map: Option<&hir_map::Map<'tcx>>, hir_map: Option<&hir_map::Map<'tcx>>,
f: F) f: F)
-> A -> A
where F: FnOnce(&PrinterSupport) -> A where F: FnOnce(&dyn PrinterSupport) -> A
{ {
match *self { match *self {
PpmNormal | PpmEveryBodyLoops | PpmExpanded => { PpmNormal | PpmEveryBodyLoops | PpmExpanded => {
@ -208,7 +208,7 @@ impl PpSourceMode {
id: &str, id: &str,
f: F) f: F)
-> A -> A
where F: FnOnce(&HirPrinterSupport, &hir::Crate) -> A where F: FnOnce(&dyn HirPrinterSupport, &hir::Crate) -> A
{ {
match *self { match *self {
PpmNormal => { PpmNormal => {
@ -265,7 +265,7 @@ trait PrinterSupport: pprust::PpAnn {
/// ///
/// (Rust does not yet support upcasting from a trait object to /// (Rust does not yet support upcasting from a trait object to
/// an object for one of its super-traits.) /// an object for one of its super-traits.)
fn pp_ann<'a>(&'a self) -> &'a pprust::PpAnn; fn pp_ann<'a>(&'a self) -> &'a dyn pprust::PpAnn;
} }
trait HirPrinterSupport<'hir>: pprust_hir::PpAnn { trait HirPrinterSupport<'hir>: pprust_hir::PpAnn {
@ -281,7 +281,7 @@ trait HirPrinterSupport<'hir>: pprust_hir::PpAnn {
/// ///
/// (Rust does not yet support upcasting from a trait object to /// (Rust does not yet support upcasting from a trait object to
/// an object for one of its super-traits.) /// an object for one of its super-traits.)
fn pp_ann<'a>(&'a self) -> &'a pprust_hir::PpAnn; fn pp_ann<'a>(&'a self) -> &'a dyn pprust_hir::PpAnn;
/// Computes an user-readable representation of a path, if possible. /// Computes an user-readable representation of a path, if possible.
fn node_path(&self, id: ast::NodeId) -> Option<String> { fn node_path(&self, id: ast::NodeId) -> Option<String> {
@ -305,7 +305,7 @@ impl<'hir> PrinterSupport for NoAnn<'hir> {
self.sess self.sess
} }
fn pp_ann<'a>(&'a self) -> &'a pprust::PpAnn { fn pp_ann<'a>(&'a self) -> &'a dyn pprust::PpAnn {
self self
} }
} }
@ -319,7 +319,7 @@ impl<'hir> HirPrinterSupport<'hir> for NoAnn<'hir> {
self.hir_map.as_ref() self.hir_map.as_ref()
} }
fn pp_ann<'a>(&'a self) -> &'a pprust_hir::PpAnn { fn pp_ann<'a>(&'a self) -> &'a dyn pprust_hir::PpAnn {
self self
} }
} }
@ -346,7 +346,7 @@ impl<'hir> PrinterSupport for IdentifiedAnnotation<'hir> {
self.sess self.sess
} }
fn pp_ann<'a>(&'a self) -> &'a pprust::PpAnn { fn pp_ann<'a>(&'a self) -> &'a dyn pprust::PpAnn {
self self
} }
} }
@ -397,7 +397,7 @@ impl<'hir> HirPrinterSupport<'hir> for IdentifiedAnnotation<'hir> {
self.hir_map.as_ref() self.hir_map.as_ref()
} }
fn pp_ann<'a>(&'a self) -> &'a pprust_hir::PpAnn { fn pp_ann<'a>(&'a self) -> &'a dyn pprust_hir::PpAnn {
self self
} }
} }
@ -458,7 +458,7 @@ impl<'a> PrinterSupport for HygieneAnnotation<'a> {
self.sess self.sess
} }
fn pp_ann(&self) -> &pprust::PpAnn { fn pp_ann(&self) -> &dyn pprust::PpAnn {
self self
} }
} }
@ -496,7 +496,7 @@ impl<'b, 'tcx> HirPrinterSupport<'tcx> for TypedAnnotation<'b, 'tcx> {
Some(&self.tcx.hir) Some(&self.tcx.hir)
} }
fn pp_ann<'a>(&'a self) -> &'a pprust_hir::PpAnn { fn pp_ann<'a>(&'a self) -> &'a dyn pprust_hir::PpAnn {
self self
} }
@ -896,7 +896,7 @@ pub fn print_after_parsing(sess: &Session,
if let PpmSource(s) = ppm { if let PpmSource(s) = ppm {
// Silently ignores an identified node. // Silently ignores an identified node.
let out: &mut Write = &mut out; let out: &mut dyn Write = &mut out;
s.call_with_pp_support(sess, None, move |annotation| { s.call_with_pp_support(sess, None, move |annotation| {
debug!("pretty printing source code {:?}", s); debug!("pretty printing source code {:?}", s);
let sess = annotation.sess(); let sess = annotation.sess();
@ -953,7 +953,7 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
match (ppm, opt_uii) { match (ppm, opt_uii) {
(PpmSource(s), _) => { (PpmSource(s), _) => {
// Silently ignores an identified node. // Silently ignores an identified node.
let out: &mut Write = &mut out; let out: &mut dyn Write = &mut out;
s.call_with_pp_support(sess, Some(hir_map), move |annotation| { s.call_with_pp_support(sess, Some(hir_map), move |annotation| {
debug!("pretty printing source code {:?}", s); debug!("pretty printing source code {:?}", s);
let sess = annotation.sess(); let sess = annotation.sess();
@ -969,7 +969,7 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
} }
(PpmHir(s), None) => { (PpmHir(s), None) => {
let out: &mut Write = &mut out; let out: &mut dyn Write = &mut out;
s.call_with_pp_support_hir(sess, s.call_with_pp_support_hir(sess,
cstore, cstore,
hir_map, hir_map,
@ -993,7 +993,7 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
} }
(PpmHirTree(s), None) => { (PpmHirTree(s), None) => {
let out: &mut Write = &mut out; let out: &mut dyn Write = &mut out;
s.call_with_pp_support_hir(sess, s.call_with_pp_support_hir(sess,
cstore, cstore,
hir_map, hir_map,
@ -1009,7 +1009,7 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
} }
(PpmHir(s), Some(uii)) => { (PpmHir(s), Some(uii)) => {
let out: &mut Write = &mut out; let out: &mut dyn Write = &mut out;
s.call_with_pp_support_hir(sess, s.call_with_pp_support_hir(sess,
cstore, cstore,
hir_map, hir_map,
@ -1043,7 +1043,7 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
} }
(PpmHirTree(s), Some(uii)) => { (PpmHirTree(s), Some(uii)) => {
let out: &mut Write = &mut out; let out: &mut dyn Write = &mut out;
s.call_with_pp_support_hir(sess, s.call_with_pp_support_hir(sess,
cstore, cstore,
hir_map, hir_map,
@ -1137,7 +1137,7 @@ fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session,
Some(code) => { Some(code) => {
let variants = gather_flowgraph_variants(tcx.sess); let variants = gather_flowgraph_variants(tcx.sess);
let out: &mut Write = &mut out; let out: &mut dyn Write = &mut out;
print_flowgraph(variants, tcx, code, mode, out) print_flowgraph(variants, tcx, code, mode, out)
} }

View File

@ -88,13 +88,13 @@ impl Emitter for ExpectErrorEmitter {
} }
} }
fn errors(msgs: &[&str]) -> (Box<Emitter + sync::Send>, usize) { fn errors(msgs: &[&str]) -> (Box<dyn Emitter + sync::Send>, usize) {
let v = msgs.iter().map(|m| m.to_string()).collect(); let v = msgs.iter().map(|m| m.to_string()).collect();
(box ExpectErrorEmitter { messages: v } as Box<Emitter + sync::Send>, msgs.len()) (box ExpectErrorEmitter { messages: v } as Box<dyn Emitter + sync::Send>, msgs.len())
} }
fn test_env<F>(source_string: &str, fn test_env<F>(source_string: &str,
args: (Box<Emitter + sync::Send>, usize), args: (Box<dyn Emitter + sync::Send>, usize),
body: F) body: F)
where F: FnOnce(Env) where F: FnOnce(Env)
{ {
@ -112,7 +112,7 @@ fn test_env<F>(source_string: &str,
fn test_env_with_pool<F>( fn test_env_with_pool<F>(
options: config::Options, options: config::Options,
source_string: &str, source_string: &str,
(emitter, expected_err_count): (Box<Emitter + sync::Send>, usize), (emitter, expected_err_count): (Box<dyn Emitter + sync::Send>, usize),
body: F body: F
) )
where F: FnOnce(Env) where F: FnOnce(Env)