// the thread local rustc uses. syntax_globals and syntax_pos_globals are
// captured and set on the new threads. ty::tls::with_thread_locals sets up
// thread local callbacks from libsyntax
- let main_handler = move |worker: &mut FnMut()| {
+ let main_handler = move |worker: &mut dyn FnMut()| {
syntax::GLOBALS.set(syntax_globals, || {
syntax_pos::GLOBALS.set(syntax_pos_globals, || {
ty::tls::with_thread_locals(|| {
}
pub fn compile_input(
- codegen_backend: Box<CodegenBackend>,
+ codegen_backend: Box<dyn CodegenBackend>,
sess: &Session,
cstore: &CStore,
input_path: &Option<PathBuf>,
/// Allows overriding default rustc query providers,
/// 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,
/// 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> {
}
fn late_callback(
&mut self,
- codegen_backend: &::CodegenBackend,
+ codegen_backend: &dyn (::CodegenBackend),
matches: &::getopts::Matches,
sess: &Session,
- cstore: &::CrateStore,
+ cstore: &dyn (::CrateStore),
input: &Input,
odir: &Option<PathBuf>,
ofile: &Option<PathBuf>,
// 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.
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> {
/// miscellaneous analysis passes on the crate. Return various
/// structures carrying the results of the analysis.
pub fn phase_3_run_analysis_passes<'tcx, F, R>(
- codegen_backend: &CodegenBackend,
+ codegen_backend: &dyn CodegenBackend,
control: &CompileController,
sess: &'tcx Session,
cstore: &'tcx CrateStoreDyn,
F: for<'a> FnOnce(
TyCtxt<'a, 'tcx, 'tcx>,
ty::CrateAnalysis,
- mpsc::Receiver<Box<Any + Send>>,
+ mpsc::Receiver<Box<dyn Any + Send>>,
CompileResult,
) -> R,
{
/// Run the codegen backend, after which the AST and analysis can
/// be discarded.
pub fn phase_4_codegen<'a, 'tcx>(
- codegen_backend: &CodegenBackend,
+ codegen_backend: &dyn CodegenBackend,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
- rx: mpsc::Receiver<Box<Any + Send>>,
-) -> Box<Any> {
+ rx: mpsc::Receiver<Box<dyn Any + Send>>,
+) -> Box<dyn Any> {
time(tcx.sess, "resolving dependency formats", || {
::rustc::middle::dependency_format::calculate(tcx)
});
//!
//! 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",
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
html_root_url = "https://doc.rust-lang.org/nightly/")]
/// features is available on the target machine, by querying LLVM.
pub fn add_configuration(cfg: &mut ast::CrateConfig,
sess: &Session,
- codegen_backend: &CodegenBackend) {
+ codegen_backend: &dyn CodegenBackend) {
let tf = Symbol::intern("target_feature");
for feat in codegen_backend.target_features(sess) {
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
// `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
}
}
-pub fn get_codegen_backend(sess: &Session) -> Box<CodegenBackend> {
+pub fn get_codegen_backend(sess: &Session) -> Box<dyn CodegenBackend> {
static INIT: Once = ONCE_INIT;
#[allow(deprecated)]
#[no_debug]
- static mut LOAD: fn() -> Box<CodegenBackend> = || unreachable!();
+ static mut LOAD: fn() -> Box<dyn CodegenBackend> = || unreachable!();
INIT.call_once(|| {
let codegen_name = sess.opts.debugging_opts.codegen_backend.as_ref()
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
// 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`,
// 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.
pub fn run_compiler<'a>(args: &[String],
- callbacks: Box<CompilerCalls<'a> + sync::Send + 'a>,
- file_loader: Option<Box<FileLoader + Send + Sync + 'static>>,
- emitter_dest: Option<Box<Write + Send>>)
+ callbacks: Box<dyn CompilerCalls<'a> + sync::Send + 'a>,
+ file_loader: Option<Box<dyn FileLoader + Send + Sync + 'static>>,
+ emitter_dest: Option<Box<dyn Write + Send>>)
-> (CompileResult, Option<Session>)
{
syntax::with_globals(|| {
matches: getopts::Matches,
sopts: config::Options,
cfg: ast::CrateConfig,
- mut callbacks: Box<CompilerCalls<'a> + sync::Send + 'a>,
- file_loader: Option<Box<FileLoader + Send + Sync + 'static>>,
- emitter_dest: Option<Box<Write + Send>>
+ mut callbacks: Box<dyn CompilerCalls<'a> + sync::Send + 'a>,
+ file_loader: Option<Box<dyn FileLoader + Send + Sync + 'static>>,
+ emitter_dest: Option<Box<dyn Write + Send>>
) -> (CompileResult, Option<Session>) {
macro_rules! do_or_return {($expr: expr, $sess: expr) => {
match $expr {
/// be called just before actual compilation starts (and before build_controller
/// is called), after all arguments etc. have been completely handled.
fn late_callback(&mut self,
- _: &CodegenBackend,
+ _: &dyn CodegenBackend,
_: &getopts::Matches,
_: &Session,
- _: &CrateStore,
+ _: &dyn CrateStore,
_: &Input,
_: &Option<PathBuf>,
_: &Option<PathBuf>)
}
fn late_callback(&mut self,
- codegen_backend: &CodegenBackend,
+ codegen_backend: &dyn CodegenBackend,
matches: &getopts::Matches,
sess: &Session,
- cstore: &CrateStore,
+ cstore: &dyn CrateStore,
input: &Input,
odir: &Option<PathBuf>,
ofile: &Option<PathBuf>)
impl RustcDefaultCalls {
pub fn list_metadata(sess: &Session,
- cstore: &CrateStore,
+ cstore: &dyn CrateStore,
matches: &getopts::Matches,
input: &Input)
-> Compilation {
}
- fn print_crate_info(codegen_backend: &CodegenBackend,
+ fn print_crate_info(codegen_backend: &dyn CodegenBackend,
sess: &Session,
input: Option<&Input>,
odir: &Option<PathBuf>,
/// Runs `f` in a suitable thread for running `rustc`; returns a
/// `Result` with either the return value of `f` or -- if a panic
/// 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,
R: Send + 'static,
{
hir_map: Option<&hir_map::Map<'tcx>>,
f: F)
-> A
- where F: FnOnce(&PrinterSupport) -> A
+ where F: FnOnce(&dyn PrinterSupport) -> A
{
match *self {
PpmNormal | PpmEveryBodyLoops | PpmExpanded => {
id: &str,
f: F)
-> A
- where F: FnOnce(&HirPrinterSupport, &hir::Crate) -> A
+ where F: FnOnce(&dyn HirPrinterSupport, &hir::Crate) -> A
{
match *self {
PpmNormal => {
///
/// (Rust does not yet support upcasting from a trait object to
/// 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 {
///
/// (Rust does not yet support upcasting from a trait object to
/// 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.
fn node_path(&self, id: ast::NodeId) -> Option<String> {
self.sess
}
- fn pp_ann<'a>(&'a self) -> &'a pprust::PpAnn {
+ fn pp_ann<'a>(&'a self) -> &'a dyn pprust::PpAnn {
self
}
}
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.sess
}
- fn pp_ann<'a>(&'a self) -> &'a pprust::PpAnn {
+ fn pp_ann<'a>(&'a self) -> &'a dyn pprust::PpAnn {
self
}
}
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.sess
}
- fn pp_ann(&self) -> &pprust::PpAnn {
+ fn pp_ann(&self) -> &dyn pprust::PpAnn {
self
}
}
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
}
if let PpmSource(s) = ppm {
// 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| {
debug!("pretty printing source code {:?}", s);
let sess = annotation.sess();
match (ppm, opt_uii) {
(PpmSource(s), _) => {
// 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| {
debug!("pretty printing source code {:?}", s);
let sess = annotation.sess();
}
(PpmHir(s), None) => {
- let out: &mut Write = &mut out;
+ let out: &mut dyn Write = &mut out;
s.call_with_pp_support_hir(sess,
cstore,
hir_map,
}
(PpmHirTree(s), None) => {
- let out: &mut Write = &mut out;
+ let out: &mut dyn Write = &mut out;
s.call_with_pp_support_hir(sess,
cstore,
hir_map,
}
(PpmHir(s), Some(uii)) => {
- let out: &mut Write = &mut out;
+ let out: &mut dyn Write = &mut out;
s.call_with_pp_support_hir(sess,
cstore,
hir_map,
}
(PpmHirTree(s), Some(uii)) => {
- let out: &mut Write = &mut out;
+ let out: &mut dyn Write = &mut out;
s.call_with_pp_support_hir(sess,
cstore,
hir_map,
Some(code) => {
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)
}
}
}
-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();
- (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,
- args: (Box<Emitter + sync::Send>, usize),
+ args: (Box<dyn Emitter + sync::Send>, usize),
body: F)
where F: FnOnce(Env)
{
fn test_env_with_pool<F>(
options: config::Options,
source_string: &str,
- (emitter, expected_err_count): (Box<Emitter + sync::Send>, usize),
+ (emitter, expected_err_count): (Box<dyn Emitter + sync::Send>, usize),
body: F
)
where F: FnOnce(Env)