From 6309b0f5bb558b844f45b2d313d2078fd7b7614c Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Mon, 14 Dec 2015 11:17:55 +1300 Subject: move error handling from libsyntax/diagnostics.rs to libsyntax/errors/* Also split out emitters into their own module. --- src/libsyntax/parse/lexer/comments.rs | 4 ++-- src/libsyntax/parse/lexer/mod.rs | 17 ++++++++--------- src/libsyntax/parse/mod.rs | 27 +++++++++++++++------------ src/libsyntax/parse/obsolete.rs | 3 +-- src/libsyntax/parse/parser.rs | 13 ++++++------- 5 files changed, 32 insertions(+), 32 deletions(-) (limited to 'src/libsyntax/parse') diff --git a/src/libsyntax/parse/lexer/comments.rs b/src/libsyntax/parse/lexer/comments.rs index e5e2c3a986d..d2156d7cb68 100644 --- a/src/libsyntax/parse/lexer/comments.rs +++ b/src/libsyntax/parse/lexer/comments.rs @@ -12,7 +12,7 @@ pub use self::CommentStyle::*; use ast; use codemap::{BytePos, CharPos, CodeMap, Pos}; -use diagnostic; +use errors; use parse::lexer::is_block_doc_comment; use parse::lexer::{StringReader, TokenAndSpan}; use parse::lexer::{is_whitespace, Reader}; @@ -334,7 +334,7 @@ pub struct Literal { // it appears this function is called only from pprust... that's // probably not a good thing. -pub fn gather_comments_and_literals(span_diagnostic: &diagnostic::SpanHandler, +pub fn gather_comments_and_literals(span_diagnostic: &errors::Handler, path: String, srdr: &mut Read) -> (Vec, Vec) { diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index cb2181a0831..570e0882a85 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -11,8 +11,7 @@ use ast; use codemap::{BytePos, CharPos, CodeMap, Pos, Span}; use codemap; -use diagnostic::FatalError; -use diagnostic::SpanHandler; +use errors::{FatalError, Handler}; use ext::tt::transcribe::tt_next_token; use parse::token::str_to_ident; use parse::token; @@ -58,7 +57,7 @@ pub struct TokenAndSpan { } pub struct StringReader<'a> { - pub span_diagnostic: &'a SpanHandler, + pub span_diagnostic: &'a Handler, /// The absolute offset within the codemap of the next character to read pub pos: BytePos, /// The absolute offset within the codemap of the last character read(curr) @@ -128,10 +127,10 @@ impl<'a> Reader for TtReader<'a> { impl<'a> StringReader<'a> { /// For comments.rs, which hackily pokes into pos and curr - pub fn new_raw<'b>(span_diagnostic: &'b SpanHandler, + pub fn new_raw<'b>(span_diagnostic: &'b Handler, filemap: Rc) -> StringReader<'b> { if filemap.src.is_none() { - span_diagnostic.handler.bug(&format!("Cannot lex filemap without source: {}", + span_diagnostic.bug(&format!("Cannot lex filemap without source: {}", filemap.name)[..]); } @@ -153,7 +152,7 @@ impl<'a> StringReader<'a> { sr } - pub fn new<'b>(span_diagnostic: &'b SpanHandler, + pub fn new<'b>(span_diagnostic: &'b Handler, filemap: Rc) -> StringReader<'b> { let mut sr = StringReader::new_raw(span_diagnostic, filemap); sr.advance_token(); @@ -1428,15 +1427,15 @@ mod tests { use parse::token::{str_to_ident}; use std::io; - fn mk_sh() -> diagnostic::SpanHandler { + fn mk_sh() -> diagnostic::Handler { // FIXME (#22405): Replace `Box::new` with `box` here when/if possible. let emitter = diagnostic::EmitterWriter::new(Box::new(io::sink()), None); let handler = diagnostic::Handler::with_emitter(true, Box::new(emitter)); - diagnostic::SpanHandler::new(handler, CodeMap::new()) + diagnostic::Handler::new(handler, CodeMap::new()) } // open a string reader for the given string - fn setup<'a>(span_handler: &'a diagnostic::SpanHandler, + fn setup<'a>(span_handler: &'a diagnostic::Handler, teststr: String) -> StringReader<'a> { let fm = span_handler.cm.new_filemap("zebra.rs".to_string(), teststr); StringReader::new(span_handler, fm) diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index e9c8173a4d9..f74e9023ed1 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -12,7 +12,7 @@ use ast; use codemap::{self, Span, CodeMap, FileMap}; -use diagnostic::{SpanHandler, Handler, Auto, FatalError}; +use errors::{Handler, ColorConfig, FatalError}; use parse::parser::Parser; use parse::token::InternedString; use ptr::P; @@ -40,26 +40,29 @@ pub mod obsolete; /// Info about a parsing session. pub struct ParseSess { - pub span_diagnostic: SpanHandler, // better be the same as the one in the reader! + pub span_diagnostic: Handler, // better be the same as the one in the reader! /// Used to determine and report recursive mod inclusions included_mod_stack: RefCell>, + code_map: Rc, } impl ParseSess { pub fn new() -> ParseSess { - let handler = SpanHandler::new(Handler::new(Auto, None, true), CodeMap::new()); - ParseSess::with_span_handler(handler) + let cm = Rc::new(CodeMap::new()); + let handler = Handler::new(ColorConfig::Auto, None, true, cm.clone()); + ParseSess::with_span_handler(handler, cm) } - pub fn with_span_handler(sh: SpanHandler) -> ParseSess { + pub fn with_span_handler(handler: Handler, code_map: Rc) -> ParseSess { ParseSess { - span_diagnostic: sh, - included_mod_stack: RefCell::new(vec![]) + span_diagnostic: handler, + included_mod_stack: RefCell::new(vec![]), + code_map: code_map } } pub fn codemap(&self) -> &CodeMap { - &self.span_diagnostic.cm + &self.code_map } } @@ -235,7 +238,7 @@ fn file_to_filemap(sess: &ParseSess, path: &Path, spanopt: Option) let msg = format!("couldn't read {:?}: {}", path.display(), e); match spanopt { Some(sp) => panic!(sess.span_diagnostic.span_fatal(sp, &msg)), - None => panic!(sess.span_diagnostic.handler().fatal(&msg)) + None => panic!(sess.span_diagnostic.fatal(&msg)) } } } @@ -438,7 +441,7 @@ fn looks_like_width_suffix(first_chars: &[char], s: &str) -> bool { } fn filtered_float_lit(data: token::InternedString, suffix: Option<&str>, - sd: &SpanHandler, sp: Span) -> ast::Lit_ { + sd: &Handler, sp: Span) -> ast::Lit_ { debug!("filtered_float_lit: {}, {:?}", data, suffix); match suffix.as_ref().map(|s| &**s) { Some("f32") => ast::LitFloat(data, ast::TyF32), @@ -459,7 +462,7 @@ fn filtered_float_lit(data: token::InternedString, suffix: Option<&str>, } } pub fn float_lit(s: &str, suffix: Option, - sd: &SpanHandler, sp: Span) -> ast::Lit_ { + sd: &Handler, sp: Span) -> ast::Lit_ { debug!("float_lit: {:?}, {:?}", s, suffix); // FIXME #2252: bounds checking float literals is deferred until trans let s = s.chars().filter(|&c| c != '_').collect::(); @@ -561,7 +564,7 @@ pub fn byte_str_lit(lit: &str) -> Rc> { pub fn integer_lit(s: &str, suffix: Option, - sd: &SpanHandler, + sd: &Handler, sp: Span) -> ast::Lit_ { // s can only be ascii, byte indexing is fine diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs index bc355f70fb3..5dba1e189ab 100644 --- a/src/libsyntax/parse/obsolete.rs +++ b/src/libsyntax/parse/obsolete.rs @@ -66,10 +66,9 @@ impl<'a> ParserObsoleteMethods for parser::Parser<'a> { } if !self.obsolete_set.contains(&kind) && - (error || self.sess.span_diagnostic.handler().can_emit_warnings) { + (error || self.sess.span_diagnostic.can_emit_warnings) { self.sess .span_diagnostic - .handler() .note(&format!("{}", desc)); self.obsolete_set.insert(kind); } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 9398f1a5733..04b0c0fa273 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -60,7 +60,7 @@ use attr::{ThinAttributes, ThinAttributesExt, AttributesExt}; use ast; use ast_util::{self, ident_to_path}; use codemap::{self, Span, BytePos, Spanned, spanned, mk_sp, CodeMap}; -use diagnostic; +use errors::{self, FatalError}; use ext::tt::macro_parser; use parse; use parse::classify; @@ -75,7 +75,6 @@ use print::pprust; use ptr::P; use owned_slice::OwnedSlice; use parse::PResult; -use diagnostic::FatalError; use std::collections::HashSet; use std::io::prelude::*; @@ -983,16 +982,16 @@ impl<'a> Parser<'a> { } f(&self.buffer[((self.buffer_start + dist - 1) & 3) as usize].tok) } - pub fn fatal(&self, m: &str) -> diagnostic::FatalError { + pub fn fatal(&self, m: &str) -> errors::FatalError { self.sess.span_diagnostic.span_fatal(self.span, m) } - pub fn span_fatal(&self, sp: Span, m: &str) -> diagnostic::FatalError { + pub fn span_fatal(&self, sp: Span, m: &str) -> errors::FatalError { self.sess.span_diagnostic.span_fatal(sp, m) } - pub fn span_fatal_help(&self, sp: Span, m: &str, help: &str) -> diagnostic::FatalError { + pub fn span_fatal_help(&self, sp: Span, m: &str, help: &str) -> errors::FatalError { self.span_err(sp, m); self.fileline_help(sp, help); - diagnostic::FatalError + errors::FatalError } pub fn span_note(&self, sp: Span, m: &str) { self.sess.span_diagnostic.span_note(sp, m) @@ -1022,7 +1021,7 @@ impl<'a> Parser<'a> { self.sess.span_diagnostic.span_bug(sp, m) } pub fn abort_if_errors(&self) { - self.sess.span_diagnostic.handler().abort_if_errors(); + self.sess.span_diagnostic.abort_if_errors(); } pub fn id_to_interned_str(&mut self, id: Ident) -> InternedString { -- cgit 1.4.1-3-g733a5 From a47881182237201f207a4b89166a6be6903a8228 Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Mon, 14 Dec 2015 18:15:39 +1300 Subject: Move a bunch of stuff from Session to syntax::errors The intention here is that Session is a very thin wrapper over the error handling infra. --- src/librustc/session/mod.rs | 71 +++++--------------------------- src/librustc_trans/back/write.rs | 2 +- src/librustc_trans/trans/callee.rs | 6 +-- src/librustc_trans/trans/monomorphize.rs | 6 +-- src/libsyntax/parse/mod.rs | 2 +- 5 files changed, 19 insertions(+), 68 deletions(-) (limited to 'src/libsyntax/parse') diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index 76d765c9626..7b96db4bf0a 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -64,14 +64,10 @@ pub struct Session { pub crate_metadata: RefCell>, pub features: RefCell, - pub delayed_span_bug: RefCell>, - /// The maximum recursion limit for potentially infinitely recursive /// operations such as auto-dereference and monomorphization. pub recursion_limit: Cell, - pub can_print_warnings: bool, - /// The metadata::creader module may inject an allocator dependency if it /// didn't already find one, and this tracks what was injected. pub injected_allocator: Cell>, @@ -85,21 +81,12 @@ pub struct Session { impl Session { pub fn span_fatal(&self, sp: Span, msg: &str) -> ! { - if self.opts.treat_err_as_bug { - self.span_bug(sp, msg); - } panic!(self.diagnostic().span_fatal(sp, msg)) } pub fn span_fatal_with_code(&self, sp: Span, msg: &str, code: &str) -> ! { - if self.opts.treat_err_as_bug { - self.span_bug(sp, msg); - } panic!(self.diagnostic().span_fatal_with_code(sp, msg, code)) } pub fn fatal(&self, msg: &str) -> ! { - if self.opts.treat_err_as_bug { - self.bug(msg); - } panic!(self.diagnostic().fatal(msg)) } pub fn span_err_or_warn(&self, is_warning: bool, sp: Span, msg: &str) { @@ -110,9 +97,6 @@ impl Session { } } pub fn span_err(&self, sp: Span, msg: &str) { - if self.opts.treat_err_as_bug { - self.span_bug(sp, msg); - } match split_msg_into_multilines(msg) { Some(msg) => self.diagnostic().span_err(sp, &msg[..]), None => self.diagnostic().span_err(sp, msg) @@ -126,18 +110,12 @@ impl Session { See RFC 1214 for details.")); } pub fn span_err_with_code(&self, sp: Span, msg: &str, code: &str) { - if self.opts.treat_err_as_bug { - self.span_bug(sp, msg); - } match split_msg_into_multilines(msg) { Some(msg) => self.diagnostic().span_err_with_code(sp, &msg[..], code), None => self.diagnostic().span_err_with_code(sp, msg, code) } } pub fn err(&self, msg: &str) { - if self.opts.treat_err_as_bug { - self.bug(msg); - } self.diagnostic().err(msg) } pub fn err_count(&self) -> usize { @@ -148,14 +126,6 @@ impl Session { } pub fn abort_if_errors(&self) { self.diagnostic().abort_if_errors(); - - let delayed_bug = self.delayed_span_bug.borrow(); - match *delayed_bug { - Some((span, ref errmsg)) => { - self.diagnostic().span_bug(span, errmsg); - }, - _ => {} - } } pub fn abort_if_new_errors(&self, mut f: F) where F: FnMut() @@ -167,19 +137,13 @@ impl Session { } } pub fn span_warn(&self, sp: Span, msg: &str) { - if self.can_print_warnings { - self.diagnostic().span_warn(sp, msg) - } + self.diagnostic().span_warn(sp, msg) } pub fn span_warn_with_code(&self, sp: Span, msg: &str, code: &str) { - if self.can_print_warnings { - self.diagnostic().span_warn_with_code(sp, msg, code) - } + self.diagnostic().span_warn_with_code(sp, msg, code) } pub fn warn(&self, msg: &str) { - if self.can_print_warnings { - self.diagnostic().warn(msg) - } + self.diagnostic().warn(msg) } pub fn opt_span_warn(&self, opt_sp: Option, msg: &str) { match opt_sp { @@ -223,8 +187,7 @@ impl Session { } /// Delay a span_bug() call until abort_if_errors() pub fn delay_span_bug(&self, sp: Span, msg: &str) { - let mut delayed = self.delayed_span_bug.borrow_mut(); - *delayed = Some((sp, msg.to_string())); + self.diagnostic().delay_span_bug(sp, msg) } pub fn span_bug(&self, sp: Span, msg: &str) -> ! { self.diagnostic().span_bug(sp, msg) @@ -270,8 +233,7 @@ impl Session { // This exists to help with refactoring to eliminate impossible // cases later on pub fn impossible_case(&self, sp: Span, msg: &str) -> ! { - self.span_bug(sp, - &format!("impossible case reached: {}", msg)); + self.span_bug(sp, &format!("impossible case reached: {}", msg)); } pub fn verbose(&self) -> bool { self.opts.debugging_opts.verbose } pub fn time_passes(&self) -> bool { self.opts.debugging_opts.time_passes } @@ -414,10 +376,15 @@ pub fn build_session(sopts: config::Options, .map(|&(_, ref level)| *level != lint::Allow) .last() .unwrap_or(true); + let treat_err_as_bug = sopts.treat_err_as_bug; let codemap = Rc::new(codemap::CodeMap::new()); let diagnostic_handler = - errors::Handler::new(sopts.color, Some(registry), can_print_warnings, codemap.clone()); + errors::Handler::new(sopts.color, + Some(registry), + can_print_warnings, + treat_err_as_bug, + codemap.clone()); build_session_(sopts, local_crate_source_file, diagnostic_handler, codemap, cstore) } @@ -450,13 +417,6 @@ pub fn build_session_(sopts: config::Options, } ); - let can_print_warnings = sopts.lint_opts - .iter() - .filter(|&&(ref key, _)| *key == "warnings") - .map(|&(_, ref level)| *level != lint::Allow) - .last() - .unwrap_or(true); - let sess = Session { target: target_cfg, host: host, @@ -477,10 +437,8 @@ pub fn build_session_(sopts: config::Options, crate_types: RefCell::new(Vec::new()), dependency_formats: RefCell::new(FnvHashMap()), crate_metadata: RefCell::new(Vec::new()), - delayed_span_bug: RefCell::new(None), features: RefCell::new(feature_gate::Features::new()), recursion_limit: Cell::new(64), - can_print_warnings: can_print_warnings, next_node_id: Cell::new(1), injected_allocator: Cell::new(None), available_macros: RefCell::new(HashSet::new()), @@ -489,13 +447,6 @@ pub fn build_session_(sopts: config::Options, sess } -// Seems out of place, but it uses session, so I'm putting it here -pub fn expect(sess: &Session, opt: Option, msg: M) -> T where - M: FnOnce() -> String, -{ - errors::expect(sess.diagnostic(), opt, msg) -} - pub fn early_error(color: errors::ColorConfig, msg: &str) -> ! { let mut emitter = BasicEmitter::stderr(color); emitter.emit(None, msg, None, errors::Level::Fatal); diff --git a/src/librustc_trans/back/write.rs b/src/librustc_trans/back/write.rs index 26813d89915..dc20b99f9a6 100644 --- a/src/librustc_trans/back/write.rs +++ b/src/librustc_trans/back/write.rs @@ -862,7 +862,7 @@ fn run_work_multithreaded(sess: &Session, futures.push(rx); thread::Builder::new().name(format!("codegen-{}", i)).spawn(move || { - let diag_handler = Handler::with_emitter(true, box diag_emitter); + let diag_handler = Handler::with_emitter(true, false, box diag_emitter); // Must construct cgcx inside the proc because it has non-Send // fields. diff --git a/src/librustc_trans/trans/callee.rs b/src/librustc_trans/trans/callee.rs index a22c12588e5..cf82a3b72d5 100644 --- a/src/librustc_trans/trans/callee.rs +++ b/src/librustc_trans/trans/callee.rs @@ -20,7 +20,6 @@ pub use self::CallArgs::*; use arena::TypedArena; use back::link; -use session; use llvm::{self, ValueRef, get_params}; use middle::cstore::LOCAL_CRATE; use middle::def; @@ -57,6 +56,7 @@ use rustc_front::hir; use syntax::abi as synabi; use syntax::ast; +use syntax::errors; use syntax::ptr::P; #[derive(Copy, Clone)] @@ -412,8 +412,8 @@ pub fn trans_fn_ref_with_substs<'a, 'tcx>( Some(n) => n, None => { return false; } }; - let map_node = session::expect( - &tcx.sess, + let map_node = errors::expect( + &tcx.sess.diagnostic(), tcx.map.find(node_id), || "local item should be in ast map".to_string()); diff --git a/src/librustc_trans/trans/monomorphize.rs b/src/librustc_trans/trans/monomorphize.rs index 9c1fcaff7c8..4b6a0d1a509 100644 --- a/src/librustc_trans/trans/monomorphize.rs +++ b/src/librustc_trans/trans/monomorphize.rs @@ -9,7 +9,6 @@ // except according to those terms. use back::link::exported_name; -use session; use llvm::ValueRef; use llvm; use middle::def_id::DefId; @@ -32,6 +31,7 @@ use rustc_front::hir; use syntax::abi; use syntax::ast; use syntax::attr; +use syntax::errors; use std::hash::{Hasher, Hash, SipHasher}; pub fn monomorphic_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, @@ -83,8 +83,8 @@ pub fn monomorphic_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, hash_id); - let map_node = session::expect( - ccx.sess(), + let map_node = errors::expect( + ccx.sess().diagnostic(), ccx.tcx().map.find(fn_node_id), || { format!("while monomorphizing {:?}, couldn't find it in \ diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index f74e9023ed1..ed87961e7f3 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -49,7 +49,7 @@ pub struct ParseSess { impl ParseSess { pub fn new() -> ParseSess { let cm = Rc::new(CodeMap::new()); - let handler = Handler::new(ColorConfig::Auto, None, true, cm.clone()); + let handler = Handler::new(ColorConfig::Auto, None, true, false, cm.clone()); ParseSess::with_span_handler(handler, cm) } -- cgit 1.4.1-3-g733a5 From ff0c74f7d47f5261ebda7cb3b9a637e0cfc69104 Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Tue, 15 Dec 2015 16:51:13 +1300 Subject: test errors --- src/librustc/session/config.rs | 6 +- src/librustc_driver/test.rs | 30 +++------ src/librustdoc/test.rs | 4 +- src/libsyntax/errors/emitter.rs | 61 +++++++++++++++++- src/libsyntax/errors/mod.rs | 58 ------------------ src/libsyntax/parse/lexer/mod.rs | 78 ++++++++++++++++-------- src/libsyntax_ext/lib.rs | 2 +- src/test/run-pass-fulldeps/ast_stmt_expr_attr.rs | 2 +- src/test/run-pass-fulldeps/compiler-calls.rs | 4 +- 9 files changed, 131 insertions(+), 114 deletions(-) (limited to 'src/libsyntax/parse') diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 75761dbc15a..e33fe9570c0 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -1224,7 +1224,7 @@ mod tests { let sessopts = build_session_options(&matches); let sess = build_session(sessopts, None, registry, Rc::new(DummyCrateStore)); - assert!(!sess.can_print_warnings); + assert!(!sess.diagnostic().can_emit_warnings); } { @@ -1236,7 +1236,7 @@ mod tests { let sessopts = build_session_options(&matches); let sess = build_session(sessopts, None, registry, Rc::new(DummyCrateStore)); - assert!(sess.can_print_warnings); + assert!(sess.diagnostic().can_emit_warnings); } { @@ -1247,7 +1247,7 @@ mod tests { let sessopts = build_session_options(&matches); let sess = build_session(sessopts, None, registry, Rc::new(DummyCrateStore)); - assert!(sess.can_print_warnings); + assert!(sess.diagnostic().can_emit_warnings); } } } diff --git a/src/librustc_driver/test.rs b/src/librustc_driver/test.rs index 2fb23c943c7..df9294a9d5b 100644 --- a/src/librustc_driver/test.rs +++ b/src/librustc_driver/test.rs @@ -10,8 +10,6 @@ //! # Standalone Tests for the Inference Module -use diagnostic; -use diagnostic::Emitter; use driver; use rustc_lint; use rustc_resolve as resolve; @@ -34,9 +32,10 @@ use rustc::front::map as hir_map; use rustc::session::{self, config}; use std::rc::Rc; use syntax::{abi, ast}; -use syntax::codemap; use syntax::codemap::{Span, CodeMap, DUMMY_SP}; -use syntax::diagnostic::{Level, RenderSpan, Bug, Fatal, Error, Warning, Note, Help}; +use syntax::errors; +use syntax::errors::emitter::Emitter; +use syntax::errors::{Level, RenderSpan}; use syntax::parse::token; use syntax::feature_gate::UnstableFeatures; @@ -60,8 +59,8 @@ struct ExpectErrorEmitter { fn remove_message(e: &mut ExpectErrorEmitter, msg: &str, lvl: Level) { match lvl { - Bug | Fatal | Error => {} - Warning | Note | Help => { + Level::Bug | Level::Fatal | Level::Error => {} + Level::Warning | Level::Note | Level::Help => { return; } } @@ -79,14 +78,14 @@ fn remove_message(e: &mut ExpectErrorEmitter, msg: &str, lvl: Level) { impl Emitter for ExpectErrorEmitter { fn emit(&mut self, - _cmsp: Option<(&codemap::CodeMap, Span)>, + _sp: Option, msg: &str, _: Option<&str>, lvl: Level) { remove_message(self, msg, lvl); } - fn custom_emit(&mut self, _cm: &codemap::CodeMap, _sp: RenderSpan, msg: &str, lvl: Level) { + fn custom_emit(&mut self, _sp: RenderSpan, msg: &str, lvl: Level) { remove_message(self, msg, lvl); } } @@ -105,13 +104,11 @@ fn test_env(source_string: &str, let mut options = config::basic_options(); options.debugging_opts.verbose = true; options.unstable_features = UnstableFeatures::Allow; - let codemap = CodeMap::new(); - let diagnostic_handler = diagnostic::Handler::with_emitter(true, emitter); - let span_diagnostic_handler = diagnostic::SpanHandler::new(diagnostic_handler, codemap); + let diagnostic_handler = errors::Handler::with_emitter(true, false, emitter); let cstore = Rc::new(CStore::new(token::get_ident_interner())); - let sess = session::build_session_(options, None, span_diagnostic_handler, - cstore.clone()); + let sess = session::build_session_(options, None, diagnostic_handler, + Rc::new(CodeMap::new()), cstore.clone()); rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess)); let krate_config = Vec::new(); let input = config::Input::Str(source_string.to_string()); @@ -366,13 +363,6 @@ impl<'a, 'tcx> Env<'a, 'tcx> { self.infcx.glb(true, trace) } - pub fn make_lub_ty(&self, t1: Ty<'tcx>, t2: Ty<'tcx>) -> Ty<'tcx> { - match self.lub().relate(&t1, &t2) { - Ok(t) => t, - Err(ref e) => panic!("unexpected error computing LUB: {}", e), - } - } - /// Checks that `t1 <: t2` is true (this may register additional /// region checks). pub fn check_sub(&self, t1: Ty<'tcx>, t2: Ty<'tcx>) { diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index 4ac20ba001b..fde8299d2d2 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -225,7 +225,9 @@ fn runtest(test: &str, cratename: &str, cfgs: Vec, libs: SearchPaths, } let data = Arc::new(Mutex::new(Vec::new())); let codemap = Rc::new(CodeMap::new()); - let emitter = errors::emitter::EmitterWriter::new(box Sink(data.clone()), None, codemap.clone()); + let emitter = errors::emitter::EmitterWriter::new(box Sink(data.clone()), + None, + codemap.clone()); let old = io::set_panic(box Sink(data.clone())); let _bomb = Bomb(data, old.unwrap_or(box io::stdout())); diff --git a/src/libsyntax/errors/emitter.rs b/src/libsyntax/errors/emitter.rs index e65eab58d9a..7fef85a833e 100644 --- a/src/libsyntax/errors/emitter.rs +++ b/src/libsyntax/errors/emitter.rs @@ -45,7 +45,7 @@ impl ColorConfig { ColorConfig::Always => true, ColorConfig::Never => false, ColorConfig::Auto => stderr_isatty(), - } + } } } @@ -619,3 +619,62 @@ impl Write for Destination { } } + +#[cfg(test)] +mod test { + use errors::Level; + use super::EmitterWriter; + use codemap::{mk_sp, CodeMap}; + use std::sync::{Arc, Mutex}; + use std::io::{self, Write}; + use std::str::from_utf8; + use std::rc::Rc; + + // Diagnostic doesn't align properly in span where line number increases by one digit + #[test] + fn test_hilight_suggestion_issue_11715() { + struct Sink(Arc>>); + impl Write for Sink { + fn write(&mut self, data: &[u8]) -> io::Result { + Write::write(&mut *self.0.lock().unwrap(), data) + } + fn flush(&mut self) -> io::Result<()> { Ok(()) } + } + let data = Arc::new(Mutex::new(Vec::new())); + let cm = Rc::new(CodeMap::new()); + let mut ew = EmitterWriter::new(Box::new(Sink(data.clone())), None, cm.clone()); + let content = "abcdefg + koksi + line3 + line4 + cinq + line6 + line7 + line8 + line9 + line10 + e-lä-vän + tolv + dreizehn + "; + let file = cm.new_filemap_and_lines("dummy.txt", content); + let start = file.lines.borrow()[7]; + let end = file.lines.borrow()[11]; + let sp = mk_sp(start, end); + let lvl = Level::Error; + println!("span_to_lines"); + let lines = cm.span_to_lines(sp); + println!("highlight_lines"); + ew.highlight_lines(sp, lvl, lines).unwrap(); + println!("done"); + let vec = data.lock().unwrap().clone(); + let vec: &[u8] = &vec; + let str = from_utf8(vec).unwrap(); + println!("{}", str); + assert_eq!(str, "dummy.txt: 8 line8\n\ + dummy.txt: 9 line9\n\ + dummy.txt:10 line10\n\ + dummy.txt:11 e-lä-vän\n\ + dummy.txt:12 tolv\n"); + } +} diff --git a/src/libsyntax/errors/mod.rs b/src/libsyntax/errors/mod.rs index 920fd2fdb00..f2e61090ba2 100644 --- a/src/libsyntax/errors/mod.rs +++ b/src/libsyntax/errors/mod.rs @@ -336,61 +336,3 @@ pub fn expect(diag: &Handler, opt: Option, msg: M) -> T where None => diag.bug(&msg()), } } - -#[cfg(test)] -mod test { - use super::Level; - use emitter::EmitterWriter; - use codemap::{mk_sp, CodeMap}; - use std::sync::{Arc, Mutex}; - use std::io::{self, Write}; - use std::str::from_utf8; - - // Diagnostic doesn't align properly in span where line number increases by one digit - #[test] - fn test_hilight_suggestion_issue_11715() { - struct Sink(Arc>>); - impl Write for Sink { - fn write(&mut self, data: &[u8]) -> io::Result { - Write::write(&mut *self.0.lock().unwrap(), data) - } - fn flush(&mut self) -> io::Result<()> { Ok(()) } - } - let data = Arc::new(Mutex::new(Vec::new())); - let mut ew = EmitterWriter::new(Box::new(Sink(data.clone())), None); - let cm = CodeMap::new(); - let content = "abcdefg - koksi - line3 - line4 - cinq - line6 - line7 - line8 - line9 - line10 - e-lä-vän - tolv - dreizehn - "; - let file = cm.new_filemap_and_lines("dummy.txt", content); - let start = file.lines.borrow()[7]; - let end = file.lines.borrow()[11]; - let sp = mk_sp(start, end); - let lvl = Level::Error; - println!("span_to_lines"); - let lines = cm.span_to_lines(sp); - println!("highlight_lines"); - ew.highlight_lines(&cm, sp, lvl, lines).unwrap(); - println!("done"); - let vec = data.lock().unwrap().clone(); - let vec: &[u8] = &vec; - let str = from_utf8(vec).unwrap(); - println!("{}", str); - assert_eq!(str, "dummy.txt: 8 line8\n\ - dummy.txt: 9 line9\n\ - dummy.txt:10 line10\n\ - dummy.txt:11 e-lä-vän\n\ - dummy.txt:12 tolv\n"); - } -} diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index 570e0882a85..4619410ada7 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -1422,28 +1422,30 @@ mod tests { use super::*; use codemap::{BytePos, CodeMap, Span, NO_EXPANSION}; - use diagnostic; + use errors; use parse::token; use parse::token::{str_to_ident}; use std::io; + use std::rc::Rc; - fn mk_sh() -> diagnostic::Handler { + fn mk_sh(cm: Rc) -> errors::Handler { // FIXME (#22405): Replace `Box::new` with `box` here when/if possible. - let emitter = diagnostic::EmitterWriter::new(Box::new(io::sink()), None); - let handler = diagnostic::Handler::with_emitter(true, Box::new(emitter)); - diagnostic::Handler::new(handler, CodeMap::new()) + let emitter = errors::emitter::EmitterWriter::new(Box::new(io::sink()), None, cm); + errors::Handler::with_emitter(true, false, Box::new(emitter)) } // open a string reader for the given string - fn setup<'a>(span_handler: &'a diagnostic::Handler, + fn setup<'a>(cm: &CodeMap, + span_handler: &'a errors::Handler, teststr: String) -> StringReader<'a> { - let fm = span_handler.cm.new_filemap("zebra.rs".to_string(), teststr); + let fm = cm.new_filemap("zebra.rs".to_string(), teststr); StringReader::new(span_handler, fm) } #[test] fn t1 () { - let span_handler = mk_sh(); - let mut string_reader = setup(&span_handler, + let cm = Rc::new(CodeMap::new()); + let sh = mk_sh(cm.clone()); + let mut string_reader = setup(&cm, &sh, "/* my source file */ \ fn main() { println!(\"zebra\"); }\n".to_string()); let id = str_to_ident("fn"); @@ -1481,21 +1483,27 @@ mod tests { } #[test] fn doublecolonparsing () { - check_tokenization(setup(&mk_sh(), "a b".to_string()), + let cm = Rc::new(CodeMap::new()); + let sh = mk_sh(cm.clone()); + check_tokenization(setup(&cm, &sh, "a b".to_string()), vec![mk_ident("a", token::Plain), token::Whitespace, mk_ident("b", token::Plain)]); } #[test] fn dcparsing_2 () { - check_tokenization(setup(&mk_sh(), "a::b".to_string()), + let cm = Rc::new(CodeMap::new()); + let sh = mk_sh(cm.clone()); + check_tokenization(setup(&cm, &sh, "a::b".to_string()), vec![mk_ident("a",token::ModName), token::ModSep, mk_ident("b", token::Plain)]); } #[test] fn dcparsing_3 () { - check_tokenization(setup(&mk_sh(), "a ::b".to_string()), + let cm = Rc::new(CodeMap::new()); + let sh = mk_sh(cm.clone()); + check_tokenization(setup(&cm, &sh, "a ::b".to_string()), vec![mk_ident("a", token::Plain), token::Whitespace, token::ModSep, @@ -1503,7 +1511,9 @@ mod tests { } #[test] fn dcparsing_4 () { - check_tokenization(setup(&mk_sh(), "a:: b".to_string()), + let cm = Rc::new(CodeMap::new()); + let sh = mk_sh(cm.clone()); + check_tokenization(setup(&cm, &sh, "a:: b".to_string()), vec![mk_ident("a",token::ModName), token::ModSep, token::Whitespace, @@ -1511,40 +1521,52 @@ mod tests { } #[test] fn character_a() { - assert_eq!(setup(&mk_sh(), "'a'".to_string()).next_token().tok, + let cm = Rc::new(CodeMap::new()); + let sh = mk_sh(cm.clone()); + assert_eq!(setup(&cm, &sh, "'a'".to_string()).next_token().tok, token::Literal(token::Char(token::intern("a")), None)); } #[test] fn character_space() { - assert_eq!(setup(&mk_sh(), "' '".to_string()).next_token().tok, + let cm = Rc::new(CodeMap::new()); + let sh = mk_sh(cm.clone()); + assert_eq!(setup(&cm, &sh, "' '".to_string()).next_token().tok, token::Literal(token::Char(token::intern(" ")), None)); } #[test] fn character_escaped() { - assert_eq!(setup(&mk_sh(), "'\\n'".to_string()).next_token().tok, + let cm = Rc::new(CodeMap::new()); + let sh = mk_sh(cm.clone()); + assert_eq!(setup(&cm, &sh, "'\\n'".to_string()).next_token().tok, token::Literal(token::Char(token::intern("\\n")), None)); } #[test] fn lifetime_name() { - assert_eq!(setup(&mk_sh(), "'abc".to_string()).next_token().tok, + let cm = Rc::new(CodeMap::new()); + let sh = mk_sh(cm.clone()); + assert_eq!(setup(&cm, &sh, "'abc".to_string()).next_token().tok, token::Lifetime(token::str_to_ident("'abc"))); } #[test] fn raw_string() { - assert_eq!(setup(&mk_sh(), + let cm = Rc::new(CodeMap::new()); + let sh = mk_sh(cm.clone()); + assert_eq!(setup(&cm, &sh, "r###\"\"#a\\b\x00c\"\"###".to_string()).next_token() .tok, token::Literal(token::StrRaw(token::intern("\"#a\\b\x00c\""), 3), None)); } #[test] fn literal_suffixes() { + let cm = Rc::new(CodeMap::new()); + let sh = mk_sh(cm.clone()); macro_rules! test { ($input: expr, $tok_type: ident, $tok_contents: expr) => {{ - assert_eq!(setup(&mk_sh(), format!("{}suffix", $input)).next_token().tok, + assert_eq!(setup(&cm, &sh, format!("{}suffix", $input)).next_token().tok, token::Literal(token::$tok_type(token::intern($tok_contents)), Some(token::intern("suffix")))); // with a whitespace separator: - assert_eq!(setup(&mk_sh(), format!("{} suffix", $input)).next_token().tok, + assert_eq!(setup(&cm, &sh, format!("{} suffix", $input)).next_token().tok, token::Literal(token::$tok_type(token::intern($tok_contents)), None)); }} @@ -1560,13 +1582,13 @@ mod tests { test!("1.0", Float, "1.0"); test!("1.0e10", Float, "1.0e10"); - assert_eq!(setup(&mk_sh(), "2us".to_string()).next_token().tok, + assert_eq!(setup(&cm, &sh, "2us".to_string()).next_token().tok, token::Literal(token::Integer(token::intern("2")), Some(token::intern("us")))); - assert_eq!(setup(&mk_sh(), "r###\"raw\"###suffix".to_string()).next_token().tok, + assert_eq!(setup(&cm, &sh, "r###\"raw\"###suffix".to_string()).next_token().tok, token::Literal(token::StrRaw(token::intern("raw"), 3), Some(token::intern("suffix")))); - assert_eq!(setup(&mk_sh(), "br###\"raw\"###suffix".to_string()).next_token().tok, + assert_eq!(setup(&cm, &sh, "br###\"raw\"###suffix".to_string()).next_token().tok, token::Literal(token::ByteStrRaw(token::intern("raw"), 3), Some(token::intern("suffix")))); } @@ -1578,8 +1600,9 @@ mod tests { } #[test] fn nested_block_comments() { - let sh = mk_sh(); - let mut lexer = setup(&sh, "/* /* */ */'a'".to_string()); + let cm = Rc::new(CodeMap::new()); + let sh = mk_sh(cm.clone()); + let mut lexer = setup(&cm, &sh, "/* /* */ */'a'".to_string()); match lexer.next_token().tok { token::Comment => { }, _ => panic!("expected a comment!") @@ -1588,8 +1611,9 @@ mod tests { } #[test] fn crlf_comments() { - let sh = mk_sh(); - let mut lexer = setup(&sh, "// test\r\n/// test\r\n".to_string()); + let cm = Rc::new(CodeMap::new()); + let sh = mk_sh(cm.clone()); + let mut lexer = setup(&cm, &sh, "// test\r\n/// test\r\n".to_string()); let comment = lexer.next_token(); assert_eq!(comment.tok, token::Comment); assert_eq!(comment.sp, ::codemap::mk_sp(BytePos(0), BytePos(7))); diff --git a/src/libsyntax_ext/lib.rs b/src/libsyntax_ext/lib.rs index f4dd621c97e..01dc9662588 100644 --- a/src/libsyntax_ext/lib.rs +++ b/src/libsyntax_ext/lib.rs @@ -39,7 +39,7 @@ use syntax::parse::token::intern; macro_rules! panictry { ($e:expr) => ({ use std::result::Result::{Ok, Err}; - use syntax::diagnostic::FatalError; + use syntax::errors::FatalError; match $e { Ok(e) => e, Err(FatalError) => panic!(FatalError) diff --git a/src/test/run-pass-fulldeps/ast_stmt_expr_attr.rs b/src/test/run-pass-fulldeps/ast_stmt_expr_attr.rs index e40abe05023..7c1a45d020b 100644 --- a/src/test/run-pass-fulldeps/ast_stmt_expr_attr.rs +++ b/src/test/run-pass-fulldeps/ast_stmt_expr_attr.rs @@ -44,7 +44,7 @@ fn with_error_checking_parse(s: String, f: F) -> PResult where let mut p = string_to_parser(&ps, s); let x = f(&mut p); - if ps.span_diagnostic.handler().has_errors() || p.token != token::Eof { + if ps.span_diagnostic.has_errors() || p.token != token::Eof { return Err(p.fatal("parse error")); } diff --git a/src/test/run-pass-fulldeps/compiler-calls.rs b/src/test/run-pass-fulldeps/compiler-calls.rs index 8850f6e6d2a..e3eeeb86356 100644 --- a/src/test/run-pass-fulldeps/compiler-calls.rs +++ b/src/test/run-pass-fulldeps/compiler-calls.rs @@ -23,7 +23,7 @@ extern crate syntax; use rustc::session::Session; use rustc::session::config::{self, Input}; use rustc_driver::{driver, CompilerCalls, Compilation}; -use syntax::{diagnostics, diagnostic}; +use syntax::{diagnostics, errors}; use std::path::PathBuf; @@ -35,7 +35,7 @@ impl<'a> CompilerCalls<'a> for TestCalls { fn early_callback(&mut self, _: &getopts::Matches, _: &diagnostics::registry::Registry, - _: diagnostic::ColorConfig) + _: errors::emitter::ColorConfig) -> Compilation { self.count *= 2; Compilation::Continue -- cgit 1.4.1-3-g733a5 From 0d298f9904468b8f668cb9b505c19d64fdeb7633 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Wed, 16 Dec 2015 21:44:33 +0300 Subject: Deprecate name `OwnedSlice` and don't use it --- src/librustc/middle/infer/error_reporting.rs | 11 +++++----- src/librustc/middle/ty/structural_impls.rs | 6 ++--- src/librustc_front/fold.rs | 17 +++++++------- src/librustc_front/hir.rs | 15 ++++++------- src/librustc_front/lowering.rs | 13 +++++------ src/librustc_front/print/pprust.rs | 5 ++--- src/librustc_front/util.rs | 7 +++--- src/librustc_trans/save/dump_csv.rs | 3 +-- src/librustc_typeck/check/mod.rs | 3 +-- src/librustdoc/clean/mod.rs | 2 +- src/libsyntax/ast.rs | 17 +++++++------- src/libsyntax/ast_util.rs | 5 ++--- src/libsyntax/ext/build.rs | 25 ++++++++++----------- src/libsyntax/fold.rs | 19 ++++++++-------- src/libsyntax/owned_slice.rs | 2 ++ src/libsyntax/parse/mod.rs | 3 +-- src/libsyntax/parse/parser.rs | 33 ++++++++++++++-------------- src/libsyntax/print/pprust.rs | 5 ++--- src/libsyntax/test.rs | 1 - src/libsyntax/util/move_map.rs | 6 ++--- src/libsyntax_ext/deriving/generic/mod.rs | 9 ++++---- src/libsyntax_ext/deriving/generic/ty.rs | 3 +-- 22 files changed, 96 insertions(+), 114 deletions(-) (limited to 'src/libsyntax/parse') diff --git a/src/librustc/middle/infer/error_reporting.rs b/src/librustc/middle/infer/error_reporting.rs index e894878e43c..d5ecb3f2e86 100644 --- a/src/librustc/middle/infer/error_reporting.rs +++ b/src/librustc/middle/infer/error_reporting.rs @@ -90,7 +90,6 @@ use std::cell::{Cell, RefCell}; use std::char::from_u32; use std::fmt; use syntax::ast; -use syntax::owned_slice::OwnedSlice; use syntax::codemap::{self, Pos, Span}; use syntax::parse::token; use syntax::ptr::P; @@ -1154,10 +1153,10 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> { } fn rebuild_ty_params(&self, - ty_params: OwnedSlice, + ty_params: P<[hir::TyParam]>, lifetime: hir::Lifetime, region_names: &HashSet) - -> OwnedSlice { + -> P<[hir::TyParam]> { ty_params.map(|ty_param| { let bounds = self.rebuild_ty_param_bounds(ty_param.bounds.clone(), lifetime, @@ -1173,10 +1172,10 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> { } fn rebuild_ty_param_bounds(&self, - ty_param_bounds: OwnedSlice, + ty_param_bounds: hir::TyParamBounds, lifetime: hir::Lifetime, region_names: &HashSet) - -> OwnedSlice { + -> hir::TyParamBounds { ty_param_bounds.map(|tpb| { match tpb { &hir::RegionTyParamBound(lt) => { @@ -1249,7 +1248,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> { add: &Vec, keep: &HashSet, remove: &HashSet, - ty_params: OwnedSlice, + ty_params: P<[hir::TyParam]>, where_clause: hir::WhereClause) -> hir::Generics { let mut lifetimes = Vec::new(); diff --git a/src/librustc/middle/ty/structural_impls.rs b/src/librustc/middle/ty/structural_impls.rs index e6007809af5..ecb2b85fd77 100644 --- a/src/librustc/middle/ty/structural_impls.rs +++ b/src/librustc/middle/ty/structural_impls.rs @@ -16,7 +16,7 @@ use middle::ty::fold::{TypeFoldable, TypeFolder}; use std::rc::Rc; use syntax::abi; -use syntax::owned_slice::OwnedSlice; +use syntax::ptr::P; use rustc_front::hir; @@ -555,8 +555,8 @@ impl<'tcx, T:TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::Binder { } } -impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for OwnedSlice { - fn fold_with>(&self, folder: &mut F) -> OwnedSlice { +impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for P<[T]> { + fn fold_with>(&self, folder: &mut F) -> P<[T]> { self.iter().map(|t| t.fold_with(folder)).collect() } } diff --git a/src/librustc_front/fold.rs b/src/librustc_front/fold.rs index 88a34b27c31..0978c3f78e8 100644 --- a/src/librustc_front/fold.rs +++ b/src/librustc_front/fold.rs @@ -17,7 +17,6 @@ use syntax::ast::{MetaWord, MetaList, MetaNameValue}; use syntax::attr::ThinAttributesExt; use hir; use syntax::codemap::{respan, Span, Spanned}; -use syntax::owned_slice::OwnedSlice; use syntax::ptr::P; use syntax::parse::token; use syntax::util::move_map::MoveMap; @@ -211,7 +210,7 @@ pub trait Folder : Sized { noop_fold_ty_param(tp, self) } - fn fold_ty_params(&mut self, tps: OwnedSlice) -> OwnedSlice { + fn fold_ty_params(&mut self, tps: P<[TyParam]>) -> P<[TyParam]> { noop_fold_ty_params(tps, self) } @@ -220,12 +219,12 @@ pub trait Folder : Sized { } fn fold_opt_bounds(&mut self, - b: Option>) - -> Option> { + b: Option) + -> Option { noop_fold_opt_bounds(b, self) } - fn fold_bounds(&mut self, b: OwnedSlice) -> OwnedSlice { + fn fold_bounds(&mut self, b: TyParamBounds) -> TyParamBounds { noop_fold_bounds(b, self) } @@ -576,9 +575,9 @@ pub fn noop_fold_ty_param(tp: TyParam, fld: &mut T) -> TyParam { } } -pub fn noop_fold_ty_params(tps: OwnedSlice, +pub fn noop_fold_ty_params(tps: P<[TyParam]>, fld: &mut T) - -> OwnedSlice { + -> P<[TyParam]> { tps.move_map(|tp| fld.fold_ty_param(tp)) } @@ -726,9 +725,9 @@ pub fn noop_fold_mt(MutTy { ty, mutbl }: MutTy, folder: &mut T) -> Mu } } -pub fn noop_fold_opt_bounds(b: Option>, +pub fn noop_fold_opt_bounds(b: Option, folder: &mut T) - -> Option> { + -> Option { b.map(|bounds| folder.fold_bounds(bounds)) } diff --git a/src/librustc_front/hir.rs b/src/librustc_front/hir.rs index d1cb82dbecc..1491ecc89af 100644 --- a/src/librustc_front/hir.rs +++ b/src/librustc_front/hir.rs @@ -42,7 +42,6 @@ use syntax::abi::Abi; use syntax::ast::{Name, NodeId, DUMMY_NODE_ID, TokenTree, AsmDialect}; use syntax::ast::{Attribute, Lit, StrStyle, FloatTy, IntTy, UintTy, CrateConfig}; use syntax::attr::ThinAttributes; -use syntax::owned_slice::OwnedSlice; use syntax::parse::token::InternedString; use syntax::ptr::P; @@ -193,8 +192,8 @@ impl PathParameters { pub fn none() -> PathParameters { AngleBracketedParameters(AngleBracketedParameterData { lifetimes: Vec::new(), - types: OwnedSlice::empty(), - bindings: OwnedSlice::empty(), + types: P::empty(), + bindings: P::empty(), }) } @@ -267,10 +266,10 @@ pub struct AngleBracketedParameterData { /// The lifetime parameters for this path segment. pub lifetimes: Vec, /// The type parameters for this path segment, if present. - pub types: OwnedSlice>, + pub types: P<[P]>, /// Bindings (equality constraints) on associated types, if present. /// E.g., `Foo`. - pub bindings: OwnedSlice, + pub bindings: P<[TypeBinding]>, } impl AngleBracketedParameterData { @@ -310,7 +309,7 @@ pub enum TraitBoundModifier { Maybe, } -pub type TyParamBounds = OwnedSlice; +pub type TyParamBounds = P<[TyParamBound]>; #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct TyParam { @@ -326,7 +325,7 @@ pub struct TyParam { #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct Generics { pub lifetimes: Vec, - pub ty_params: OwnedSlice, + pub ty_params: P<[TyParam]>, pub where_clause: WhereClause, } @@ -369,7 +368,7 @@ pub struct WhereBoundPredicate { /// The type being bounded pub bounded_ty: P, /// Trait and lifetime bounds (`Clone+Send+'static`) - pub bounds: OwnedSlice, + pub bounds: TyParamBounds, } /// A lifetime predicate, e.g. `'a: 'b+'c` diff --git a/src/librustc_front/lowering.rs b/src/librustc_front/lowering.rs index c0b10fb8912..614f6f0bd36 100644 --- a/src/librustc_front/lowering.rs +++ b/src/librustc_front/lowering.rs @@ -70,7 +70,6 @@ use syntax::attr::{ThinAttributes, ThinAttributesExt}; use syntax::ext::mtwt; use syntax::ptr::P; use syntax::codemap::{respan, Spanned, Span}; -use syntax::owned_slice::OwnedSlice; use syntax::parse::token; use syntax::std_inject; use syntax::visit::{self, Visitor}; @@ -430,8 +429,8 @@ pub fn lower_ty_param(lctx: &LoweringContext, tp: &TyParam) -> hir::TyParam { } pub fn lower_ty_params(lctx: &LoweringContext, - tps: &OwnedSlice) - -> OwnedSlice { + tps: &P<[TyParam]>) + -> P<[hir::TyParam]> { tps.iter().map(|tp| lower_ty_param(lctx, tp)).collect() } @@ -583,8 +582,8 @@ pub fn lower_mt(lctx: &LoweringContext, mt: &MutTy) -> hir::MutTy { } pub fn lower_opt_bounds(lctx: &LoweringContext, - b: &Option>) - -> Option> { + b: &Option) + -> Option { b.as_ref().map(|ref bounds| lower_bounds(lctx, bounds)) } @@ -1795,8 +1794,8 @@ fn path_all(sp: Span, identifier: last_identifier, parameters: hir::AngleBracketedParameters(hir::AngleBracketedParameterData { lifetimes: lifetimes, - types: OwnedSlice::from_vec(types), - bindings: OwnedSlice::from_vec(bindings), + types: P::from_vec(types), + bindings: P::from_vec(bindings), }), }); hir::Path { diff --git a/src/librustc_front/print/pprust.rs b/src/librustc_front/print/pprust.rs index 81076b6e402..a3bb005dfbd 100644 --- a/src/librustc_front/print/pprust.rs +++ b/src/librustc_front/print/pprust.rs @@ -12,7 +12,6 @@ pub use self::AnnNode::*; use syntax::abi; use syntax::ast; -use syntax::owned_slice::OwnedSlice; use syntax::codemap::{self, CodeMap, BytePos, Spanned}; use syntax::diagnostic; use syntax::parse::token::{self, BinOpToken}; @@ -519,7 +518,7 @@ impl<'a> State<'a> { hir::TyBareFn(ref f) => { let generics = hir::Generics { lifetimes: f.lifetimes.clone(), - ty_params: OwnedSlice::empty(), + ty_params: P::empty(), where_clause: hir::WhereClause { id: ast::DUMMY_NODE_ID, predicates: Vec::new(), @@ -2258,7 +2257,7 @@ impl<'a> State<'a> { } let generics = hir::Generics { lifetimes: Vec::new(), - ty_params: OwnedSlice::empty(), + ty_params: P::empty(), where_clause: hir::WhereClause { id: ast::DUMMY_NODE_ID, predicates: Vec::new(), diff --git a/src/librustc_front/util.rs b/src/librustc_front/util.rs index 4dc08f7a048..f85eb2bb401 100644 --- a/src/librustc_front/util.rs +++ b/src/librustc_front/util.rs @@ -15,7 +15,6 @@ use syntax::ast_util; use syntax::ast::{Name, NodeId, DUMMY_NODE_ID}; use syntax::codemap::Span; use syntax::ptr::P; -use syntax::owned_slice::OwnedSlice; pub fn walk_pat(pat: &Pat, mut it: F) -> bool where F: FnMut(&Pat) -> bool @@ -336,7 +335,7 @@ pub fn is_path(e: P) -> bool { pub fn empty_generics() -> Generics { Generics { lifetimes: Vec::new(), - ty_params: OwnedSlice::empty(), + ty_params: P::empty(), where_clause: WhereClause { id: DUMMY_NODE_ID, predicates: Vec::new(), @@ -354,8 +353,8 @@ pub fn ident_to_path(s: Span, ident: Ident) -> Path { identifier: ident, parameters: hir::AngleBracketedParameters(hir::AngleBracketedParameterData { lifetimes: Vec::new(), - types: OwnedSlice::empty(), - bindings: OwnedSlice::empty(), + types: P::empty(), + bindings: P::empty(), }), }), } diff --git a/src/librustc_trans/save/dump_csv.rs b/src/librustc_trans/save/dump_csv.rs index 747b76ae57f..9c6b54e1379 100644 --- a/src/librustc_trans/save/dump_csv.rs +++ b/src/librustc_trans/save/dump_csv.rs @@ -41,7 +41,6 @@ use std::fs::File; use syntax::ast::{self, NodeId}; use syntax::codemap::*; use syntax::parse::token::{self, keywords}; -use syntax::owned_slice::OwnedSlice; use syntax::visit::{self, Visitor}; use syntax::print::pprust::{path_to_string, ty_to_string}; use syntax::ptr::P; @@ -572,7 +571,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> { fn process_trait(&mut self, item: &ast::Item, generics: &ast::Generics, - trait_refs: &OwnedSlice, + trait_refs: &ast::TyParamBounds, methods: &[P]) { let qualname = format!("::{}", self.tcx.map.path_to_string(item.id)); let val = self.span.snippet(item.span); diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 9f453362d24..bddf0e9ffb0 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -119,7 +119,6 @@ use syntax::ast; use syntax::attr; use syntax::attr::AttrMetaMethods; use syntax::codemap::{self, Span, Spanned}; -use syntax::owned_slice::OwnedSlice; use syntax::parse::token::{self, InternedString}; use syntax::ptr::P; use syntax::util::lev_distance::lev_distance; @@ -4907,7 +4906,7 @@ pub fn may_break(cx: &ty::ctxt, id: ast::NodeId, b: &hir::Block) -> bool { } pub fn check_bounds_are_used<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, - tps: &OwnedSlice, + tps: &P<[hir::TyParam]>, ty: Ty<'tcx>) { debug!("check_bounds_are_used(n_tps={}, ty={:?})", tps.len(), ty); diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 52eeb781b31..e217e7afad7 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -112,7 +112,7 @@ impl Clean for ty::Binder where T: Clean { } } -impl, U> Clean> for syntax::owned_slice::OwnedSlice { +impl, U> Clean> for P<[T]> { fn clean(&self, cx: &DocContext) -> Vec { self.iter().map(|x| x.clean(cx)).collect() } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index de5595eebee..4b0ec8578c1 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -50,7 +50,6 @@ use codemap::{Span, Spanned, DUMMY_SP, ExpnId}; use abi::Abi; use ext::base; use ext::tt::macro_parser; -use owned_slice::OwnedSlice; use parse::token::InternedString; use parse::token; use parse::lexer; @@ -261,8 +260,8 @@ impl PathParameters { pub fn none() -> PathParameters { AngleBracketedParameters(AngleBracketedParameterData { lifetimes: Vec::new(), - types: OwnedSlice::empty(), - bindings: OwnedSlice::empty(), + types: P::empty(), + bindings: P::empty(), }) } @@ -334,10 +333,10 @@ pub struct AngleBracketedParameterData { /// The lifetime parameters for this path segment. pub lifetimes: Vec, /// The type parameters for this path segment, if present. - pub types: OwnedSlice>, + pub types: P<[P]>, /// Bindings (equality constraints) on associated types, if present. /// E.g., `Foo`. - pub bindings: OwnedSlice>, + pub bindings: P<[P]>, } impl AngleBracketedParameterData { @@ -394,7 +393,7 @@ pub enum TraitBoundModifier { Maybe, } -pub type TyParamBounds = OwnedSlice; +pub type TyParamBounds = P<[TyParamBound]>; #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct TyParam { @@ -410,7 +409,7 @@ pub struct TyParam { #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct Generics { pub lifetimes: Vec, - pub ty_params: OwnedSlice, + pub ty_params: P<[TyParam]>, pub where_clause: WhereClause, } @@ -430,7 +429,7 @@ impl Default for Generics { fn default() -> Generics { Generics { lifetimes: Vec::new(), - ty_params: OwnedSlice::empty(), + ty_params: P::empty(), where_clause: WhereClause { id: DUMMY_NODE_ID, predicates: Vec::new(), @@ -466,7 +465,7 @@ pub struct WhereBoundPredicate { /// The type being bounded pub bounded_ty: P, /// Trait and lifetime bounds (`Clone+Send+'static`) - pub bounds: OwnedSlice, + pub bounds: TyParamBounds, } /// A lifetime predicate, e.g. `'a: 'b+'c` diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 3d3d5347749..d38b771814c 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -12,7 +12,6 @@ use ast::*; use ast; use codemap; use codemap::Span; -use owned_slice::OwnedSlice; use parse::token; use print::pprust; use ptr::P; @@ -43,8 +42,8 @@ pub fn ident_to_path(s: Span, identifier: Ident) -> Path { identifier: identifier, parameters: ast::AngleBracketedParameters(ast::AngleBracketedParameterData { lifetimes: Vec::new(), - types: OwnedSlice::empty(), - bindings: OwnedSlice::empty(), + types: P::empty(), + bindings: P::empty(), }) } ), diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index cdc9cb02453..46a39b98058 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -14,7 +14,6 @@ use ast; use attr; use codemap::{Span, respan, Spanned, DUMMY_SP, Pos}; use ext::base::ExtCtxt; -use owned_slice::OwnedSlice; use parse::token::special_idents; use parse::token::InternedString; use parse::token; @@ -56,7 +55,7 @@ pub trait AstBuilder { fn ty(&self, span: Span, ty: ast::Ty_) -> P; fn ty_path(&self, ast::Path) -> P; - fn ty_sum(&self, ast::Path, OwnedSlice) -> P; + fn ty_sum(&self, ast::Path, ast::TyParamBounds) -> P; fn ty_ident(&self, span: Span, idents: ast::Ident) -> P; fn ty_rptr(&self, span: Span, @@ -70,13 +69,13 @@ pub trait AstBuilder { fn ty_option(&self, ty: P) -> P; fn ty_infer(&self, sp: Span) -> P; - fn ty_vars(&self, ty_params: &OwnedSlice) -> Vec> ; - fn ty_vars_global(&self, ty_params: &OwnedSlice) -> Vec> ; + fn ty_vars(&self, ty_params: &P<[ast::TyParam]>) -> Vec> ; + fn ty_vars_global(&self, ty_params: &P<[ast::TyParam]>) -> Vec> ; fn typaram(&self, span: Span, id: ast::Ident, - bounds: OwnedSlice, + bounds: ast::TyParamBounds, default: Option>) -> ast::TyParam; fn trait_ref(&self, path: ast::Path) -> ast::TraitRef; @@ -331,8 +330,8 @@ impl<'a> AstBuilder for ExtCtxt<'a> { identifier: last_identifier, parameters: ast::AngleBracketedParameters(ast::AngleBracketedParameterData { lifetimes: lifetimes, - types: OwnedSlice::from_vec(types), - bindings: OwnedSlice::from_vec(bindings), + types: P::from_vec(types), + bindings: P::from_vec(bindings), }) }); ast::Path { @@ -369,8 +368,8 @@ impl<'a> AstBuilder for ExtCtxt<'a> { identifier: ident, parameters: ast::AngleBracketedParameters(ast::AngleBracketedParameterData { lifetimes: lifetimes, - types: OwnedSlice::from_vec(types), - bindings: OwnedSlice::from_vec(bindings), + types: P::from_vec(types), + bindings: P::from_vec(bindings), }) }); @@ -399,7 +398,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { self.ty(path.span, ast::TyPath(None, path)) } - fn ty_sum(&self, path: ast::Path, bounds: OwnedSlice) -> P { + fn ty_sum(&self, path: ast::Path, bounds: ast::TyParamBounds) -> P { self.ty(path.span, ast::TyObjectSum(self.ty_path(path), bounds)) @@ -448,7 +447,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { fn typaram(&self, span: Span, id: ast::Ident, - bounds: OwnedSlice, + bounds: ast::TyParamBounds, default: Option>) -> ast::TyParam { ast::TyParam { ident: id, @@ -462,11 +461,11 @@ impl<'a> AstBuilder for ExtCtxt<'a> { // these are strange, and probably shouldn't be used outside of // pipes. Specifically, the global version possible generates // incorrect code. - fn ty_vars(&self, ty_params: &OwnedSlice) -> Vec> { + fn ty_vars(&self, ty_params: &P<[ast::TyParam]>) -> Vec> { ty_params.iter().map(|p| self.ty_ident(DUMMY_SP, p.ident)).collect() } - fn ty_vars_global(&self, ty_params: &OwnedSlice) -> Vec> { + fn ty_vars_global(&self, ty_params: &P<[ast::TyParam]>) -> Vec> { ty_params .iter() .map(|p| self.ty_path(self.path_global(DUMMY_SP, vec!(p.ident)))) diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index cd976884d2f..cd2210c71b8 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -23,7 +23,6 @@ use ast; use attr::{ThinAttributes, ThinAttributesExt}; use ast_util; use codemap::{respan, Span, Spanned}; -use owned_slice::OwnedSlice; use parse::token; use ptr::P; use util::small_vector::SmallVector; @@ -233,7 +232,7 @@ pub trait Folder : Sized { noop_fold_ty_param(tp, self) } - fn fold_ty_params(&mut self, tps: OwnedSlice) -> OwnedSlice { + fn fold_ty_params(&mut self, tps: P<[TyParam]>) -> P<[TyParam]> { noop_fold_ty_params(tps, self) } @@ -257,13 +256,13 @@ pub trait Folder : Sized { noop_fold_opt_lifetime(o_lt, self) } - fn fold_opt_bounds(&mut self, b: Option>) - -> Option> { + fn fold_opt_bounds(&mut self, b: Option) + -> Option { noop_fold_opt_bounds(b, self) } - fn fold_bounds(&mut self, b: OwnedSlice) - -> OwnedSlice { + fn fold_bounds(&mut self, b: TyParamBounds) + -> TyParamBounds { noop_fold_bounds(b, self) } @@ -714,8 +713,8 @@ pub fn noop_fold_ty_param(tp: TyParam, fld: &mut T) -> TyParam { } } -pub fn noop_fold_ty_params(tps: OwnedSlice, fld: &mut T) - -> OwnedSlice { +pub fn noop_fold_ty_params(tps: P<[TyParam]>, fld: &mut T) + -> P<[TyParam]> { tps.move_map(|tp| fld.fold_ty_param(tp)) } @@ -871,8 +870,8 @@ pub fn noop_fold_mt(MutTy {ty, mutbl}: MutTy, folder: &mut T) -> MutT } } -pub fn noop_fold_opt_bounds(b: Option>, folder: &mut T) - -> Option> { +pub fn noop_fold_opt_bounds(b: Option, folder: &mut T) + -> Option { b.map(|bounds| folder.fold_bounds(bounds)) } diff --git a/src/libsyntax/owned_slice.rs b/src/libsyntax/owned_slice.rs index 820c7e7e4a6..33a3d578598 100644 --- a/src/libsyntax/owned_slice.rs +++ b/src/libsyntax/owned_slice.rs @@ -9,4 +9,6 @@ // except according to those terms. /// A non-growable owned slice. +#[unstable(feature = "rustc_private", issue = "0")] +#[rustc_deprecated(since = "1.7.0", reason = "use `ptr::P<[T]>` instead")] pub type OwnedSlice = ::ptr::P<[T]>; diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index e9c8173a4d9..df2a9f30c7a 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -668,7 +668,6 @@ mod tests { use super::*; use std::rc::Rc; use codemap::{Span, BytePos, Pos, Spanned, NO_EXPANSION}; - use owned_slice::OwnedSlice; use ast::{self, TokenTree}; use abi; use attr::{first_attr_value_str_by_name, AttrMetaMethods}; @@ -944,7 +943,7 @@ mod tests { abi::Rust, ast::Generics{ // no idea on either of these: lifetimes: Vec::new(), - ty_params: OwnedSlice::empty(), + ty_params: P::empty(), where_clause: ast::WhereClause { id: ast::DUMMY_NODE_ID, predicates: Vec::new(), diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 712f4e38012..8cf8533c3aa 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -50,7 +50,7 @@ use ast::{SelfExplicit, SelfRegion, SelfStatic, SelfValue}; use ast::{Delimited, SequenceRepetition, TokenTree, TraitItem, TraitRef}; use ast::{Ty, Ty_, TypeBinding, TyMac}; use ast::{TyFixedLengthVec, TyBareFn, TyTypeof, TyInfer}; -use ast::{TyParam, TyParamBound, TyParen, TyPath, TyPtr}; +use ast::{TyParam, TyParamBounds, TyParen, TyPath, TyPtr}; use ast::{TyRptr, TyTup, TyU32, TyVec}; use ast::TypeTraitItem; use ast::{UnnamedField, UnsafeBlock}; @@ -73,7 +73,6 @@ use parse::{new_sub_parser_from_file, ParseSess}; use util::parser::{AssocOp, Fixity}; use print::pprust; use ptr::P; -use owned_slice::OwnedSlice; use parse::PResult; use diagnostic::FatalError; @@ -752,7 +751,7 @@ impl<'a> Parser<'a> { pub fn parse_seq_to_before_gt_or_return(&mut self, sep: Option, mut f: F) - -> PResult<(OwnedSlice, bool)> where + -> PResult<(P<[T]>, bool)> where F: FnMut(&mut Parser) -> PResult>, { let mut v = Vec::new(); @@ -773,7 +772,7 @@ impl<'a> Parser<'a> { if i % 2 == 0 { match try!(f(self)) { Some(result) => v.push(result), - None => return Ok((OwnedSlice::from_vec(v), true)) + None => return Ok((P::from_vec(v), true)) } } else { if let Some(t) = sep.as_ref() { @@ -782,7 +781,7 @@ impl<'a> Parser<'a> { } } - return Ok((OwnedSlice::from_vec(v), false)); + return Ok((P::from_vec(v), false)); } /// Parse a sequence bracketed by '<' and '>', stopping @@ -790,7 +789,7 @@ impl<'a> Parser<'a> { pub fn parse_seq_to_before_gt(&mut self, sep: Option, mut f: F) - -> PResult> where + -> PResult> where F: FnMut(&mut Parser) -> PResult, { let (result, returned) = try!(self.parse_seq_to_before_gt_or_return(sep, @@ -802,7 +801,7 @@ impl<'a> Parser<'a> { pub fn parse_seq_to_gt(&mut self, sep: Option, f: F) - -> PResult> where + -> PResult> where F: FnMut(&mut Parser) -> PResult, { let v = try!(self.parse_seq_to_before_gt(sep, f)); @@ -813,7 +812,7 @@ impl<'a> Parser<'a> { pub fn parse_seq_to_gt_or_return(&mut self, sep: Option, f: F) - -> PResult<(OwnedSlice, bool)> where + -> PResult<(P<[T]>, bool)> where F: FnMut(&mut Parser) -> PResult>, { let (v, returned) = try!(self.parse_seq_to_before_gt_or_return(sep, f)); @@ -1077,7 +1076,7 @@ impl<'a> Parser<'a> { let other_bounds = if try!(self.eat(&token::BinOp(token::Plus)) ){ try!(self.parse_ty_param_bounds(BoundParsingMode::Bare)) } else { - OwnedSlice::empty() + P::empty() }; let all_bounds = Some(TraitTyParamBound(poly_trait_ref, TraitBoundModifier::None)).into_iter() @@ -1710,8 +1709,8 @@ impl<'a> Parser<'a> { ast::AngleBracketedParameters(ast::AngleBracketedParameterData { lifetimes: lifetimes, - types: OwnedSlice::from_vec(types), - bindings: OwnedSlice::from_vec(bindings), + types: P::from_vec(types), + bindings: P::from_vec(bindings), }) } else if try!(self.eat(&token::OpenDelim(token::Paren)) ){ let lo = self.last_span.lo; @@ -1774,8 +1773,8 @@ impl<'a> Parser<'a> { identifier: identifier, parameters: ast::AngleBracketedParameters(ast::AngleBracketedParameterData { lifetimes: lifetimes, - types: OwnedSlice::from_vec(types), - bindings: OwnedSlice::from_vec(bindings), + types: P::from_vec(types), + bindings: P::from_vec(bindings), }), }); @@ -3883,10 +3882,10 @@ impl<'a> Parser<'a> { // otherwise returns empty list. fn parse_colon_then_ty_param_bounds(&mut self, mode: BoundParsingMode) - -> PResult> + -> PResult { if !try!(self.eat(&token::Colon) ){ - Ok(OwnedSlice::empty()) + Ok(P::empty()) } else { self.parse_ty_param_bounds(mode) } @@ -3898,7 +3897,7 @@ impl<'a> Parser<'a> { // and bound = 'region | trait_ref fn parse_ty_param_bounds(&mut self, mode: BoundParsingMode) - -> PResult> + -> PResult { let mut result = vec!(); loop { @@ -3940,7 +3939,7 @@ impl<'a> Parser<'a> { } } - return Ok(OwnedSlice::from_vec(result)); + return Ok(P::from_vec(result)); } /// Matches typaram = IDENT (`?` unbound)? optbounds ( EQ ty )? diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 4e2289cb7f4..457d7d150dd 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -17,7 +17,6 @@ use ast::Attribute; use attr::ThinAttributesExt; use util::parser::AssocOp; use attr; -use owned_slice::OwnedSlice; use attr::{AttrMetaMethods, AttributeMethods}; use codemap::{self, CodeMap, BytePos}; use diagnostic; @@ -1001,7 +1000,7 @@ impl<'a> State<'a> { ast::TyBareFn(ref f) => { let generics = ast::Generics { lifetimes: f.lifetimes.clone(), - ty_params: OwnedSlice::empty(), + ty_params: P::empty(), where_clause: ast::WhereClause { id: ast::DUMMY_NODE_ID, predicates: Vec::new(), @@ -3024,7 +3023,7 @@ impl<'a> State<'a> { } let generics = ast::Generics { lifetimes: Vec::new(), - ty_params: OwnedSlice::empty(), + ty_params: P::empty(), where_clause: ast::WhereClause { id: ast::DUMMY_NODE_ID, predicates: Vec::new(), diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs index 63fbe284a09..e9581b9e05c 100644 --- a/src/libsyntax/test.rs +++ b/src/libsyntax/test.rs @@ -32,7 +32,6 @@ use ext::expand::ExpansionConfig; use fold::Folder; use util::move_map::MoveMap; use fold; -use owned_slice::OwnedSlice; use parse::token::{intern, InternedString}; use parse::{token, ParseSess}; use print::pprust; diff --git a/src/libsyntax/util/move_map.rs b/src/libsyntax/util/move_map.rs index 95c24c66630..e1078b719bf 100644 --- a/src/libsyntax/util/move_map.rs +++ b/src/libsyntax/util/move_map.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use owned_slice::OwnedSlice; - use std::ptr; pub trait MoveMap: Sized { @@ -69,11 +67,11 @@ impl MoveMap for Vec { } } -impl MoveMap for OwnedSlice { +impl MoveMap for ::ptr::P<[T]> { fn move_flat_map(self, f: F) -> Self where F: FnMut(T) -> I, I: IntoIterator { - OwnedSlice::from_vec(self.into_vec().move_flat_map(f)) + ::ptr::P::from_vec(self.into_vec().move_flat_map(f)) } } diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index 5977144dae7..85245842268 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -205,7 +205,6 @@ use syntax::codemap::{self, DUMMY_SP}; use syntax::codemap::Span; use syntax::diagnostic::SpanHandler; use syntax::util::move_map::MoveMap; -use syntax::owned_slice::OwnedSlice; use syntax::parse::token::{intern, InternedString}; use syntax::parse::token::special_idents; use syntax::ptr::P; @@ -516,7 +515,7 @@ impl<'a> TraitDef<'a> { cx.typaram(self.span, ty_param.ident, - OwnedSlice::from_vec(bounds), + P::from_vec(bounds), None) })); @@ -528,7 +527,7 @@ impl<'a> TraitDef<'a> { span: self.span, bound_lifetimes: wb.bound_lifetimes.clone(), bounded_ty: wb.bounded_ty.clone(), - bounds: OwnedSlice::from_vec(wb.bounds.iter().cloned().collect()) + bounds: P::from_vec(wb.bounds.iter().cloned().collect()) }) } ast::WherePredicate::RegionPredicate(ref rb) => { @@ -579,7 +578,7 @@ impl<'a> TraitDef<'a> { span: self.span, bound_lifetimes: vec![], bounded_ty: ty, - bounds: OwnedSlice::from_vec(bounds), + bounds: P::from_vec(bounds), }; let predicate = ast::WherePredicate::BoundPredicate(predicate); @@ -590,7 +589,7 @@ impl<'a> TraitDef<'a> { let trait_generics = Generics { lifetimes: lifetimes, - ty_params: OwnedSlice::from_vec(ty_params), + ty_params: P::from_vec(ty_params), where_clause: where_clause }; diff --git a/src/libsyntax_ext/deriving/generic/ty.rs b/src/libsyntax_ext/deriving/generic/ty.rs index 0c4a81361ae..10564b5f698 100644 --- a/src/libsyntax_ext/deriving/generic/ty.rs +++ b/src/libsyntax_ext/deriving/generic/ty.rs @@ -19,7 +19,6 @@ use syntax::ast::{Expr,Generics,Ident}; use syntax::ext::base::ExtCtxt; use syntax::ext::build::AstBuilder; use syntax::codemap::{Span,respan}; -use syntax::owned_slice::OwnedSlice; use syntax::parse::token::special_idents; use syntax::ptr::P; @@ -209,7 +208,7 @@ fn mk_generics(lifetimes: Vec, ty_params: Vec) -> Generics { Generics { lifetimes: lifetimes, - ty_params: OwnedSlice::from_vec(ty_params), + ty_params: P::from_vec(ty_params), where_clause: ast::WhereClause { id: ast::DUMMY_NODE_ID, predicates: Vec::new(), -- cgit 1.4.1-3-g733a5