From a170183ba39c32b9f85c50a379dc4f9b8bd6e0fa Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Wed, 11 Sep 2013 16:26:06 -0700 Subject: [PATCH] librusti: Eliminate `@fn`. --- src/librusti/rusti.rs | 23 ++++++++++++++++------- src/librusti/utils.rs | 8 ++++---- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/librusti/rusti.rs b/src/librusti/rusti.rs index 0d024812c21..462c0a29236 100644 --- a/src/librusti/rusti.rs +++ b/src/librusti/rusti.rs @@ -72,6 +72,7 @@ extern mod syntax; use std::{libc, io, os, task}; use std::cell::Cell; +use extra::rl::CompletionCb; use extra::rl; use rustc::driver::{driver, session}; @@ -520,6 +521,19 @@ pub fn main() { main_args(args); } +struct Completer; + +impl CompletionCb for Completer { + fn complete(&self, line: ~str, suggest: &fn(~str)) { + if line.starts_with(":") { + suggest(~":clear"); + suggest(~":exit"); + suggest(~":help"); + suggest(~":load"); + } + } +} + pub fn main_args(args: &[~str]) { #[fixed_stack_segment]; #[inline(never)]; @@ -543,13 +557,8 @@ pub fn main_args(args: &[~str]) { println("unstable. If you encounter problems, please use the"); println("compiler instead. Type :help for help."); - do rl::complete |line, suggest| { - if line.starts_with(":") { - suggest(~":clear"); - suggest(~":exit"); - suggest(~":help"); - suggest(~":load"); - } + unsafe { + rl::complete(@Completer as @CompletionCb) } } diff --git a/src/librusti/utils.rs b/src/librusti/utils.rs index 400399253a5..904594fdfb8 100644 --- a/src/librusti/utils.rs +++ b/src/librusti/utils.rs @@ -15,11 +15,11 @@ use syntax::print::pprust; use syntax::parse::token; use syntax::visit; -struct EachBindingVisitor { - f: @fn(&ast::Path, ast::NodeId) +struct EachBindingVisitor<'self> { + f: &'self fn(&ast::Path, ast::NodeId) } -impl visit::Visitor<()> for EachBindingVisitor { +impl<'self> visit::Visitor<()> for EachBindingVisitor<'self> { fn visit_pat(&mut self, pat:@ast::Pat, _:()) { match pat.node { ast::PatIdent(_, ref path, _) => { @@ -32,7 +32,7 @@ impl visit::Visitor<()> for EachBindingVisitor { } } -pub fn each_binding(l: @ast::Local, f: @fn(&ast::Path, ast::NodeId)) { +pub fn each_binding(l: @ast::Local, f: &fn(&ast::Path, ast::NodeId)) { use syntax::visit::Visitor; let mut vt = EachBindingVisitor{ f: f };