diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 69cf5baa26fec..393045bf93efb 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -51,10 +51,9 @@ use std::collections::BTreeMap; use std::iter; use syntax::ast::*; use syntax::attr::{ThinAttributes, ThinAttributesExt}; -use syntax::ext::mtwt; use syntax::ptr::P; use syntax::codemap::{respan, Spanned, Span}; -use syntax::parse::token::{self, keywords}; +use syntax::parse::token; use syntax::std_inject; use syntax::visit::{self, Visitor}; @@ -184,16 +183,8 @@ impl<'a> LoweringContext<'a> { result } - fn lower_ident(&mut self, ident: Ident) -> Name { - if ident.name != keywords::Invalid.name() { - mtwt::resolve(ident) - } else { - ident.name - } - } - fn lower_opt_sp_ident(&mut self, o_id: Option>) -> Option> { - o_id.map(|sp_ident| respan(sp_ident.span, self.lower_ident(sp_ident.node))) + o_id.map(|sp_ident| respan(sp_ident.span, sp_ident.node.name)) } fn lower_attrs(&mut self, attrs: &Vec) -> hir::HirVec { @@ -338,18 +329,14 @@ impl<'a> LoweringContext<'a> { } } - fn lower_path_full(&mut self, p: &Path, rename: bool) -> hir::Path { + fn lower_path(&mut self, p: &Path) -> hir::Path { hir::Path { global: p.global, segments: p.segments .iter() .map(|&PathSegment { identifier, ref parameters }| { hir::PathSegment { - name: if rename { - self.lower_ident(identifier) - } else { - identifier.name - }, + name: identifier.name, parameters: self.lower_path_parameters(parameters), } }) @@ -358,10 +345,6 @@ impl<'a> LoweringContext<'a> { } } - fn lower_path(&mut self, p: &Path) -> hir::Path { - self.lower_path_full(p, false) - } - fn lower_path_parameters(&mut self, path_parameters: &PathParameters) -> hir::PathParameters { match *path_parameters { PathParameters::AngleBracketed(ref data) => @@ -870,8 +853,7 @@ impl<'a> LoweringContext<'a> { // `None` can occur in body-less function signatures None | Some(Def::Local(..)) => { hir::PatKind::Binding(this.lower_binding_mode(binding_mode), - respan(pth1.span, - this.lower_ident(pth1.node)), + respan(pth1.span, pth1.node.name), sub.as_ref().map(|x| this.lower_pat(x))) } _ => hir::PatKind::Path(hir::Path::from_name(pth1.span, pth1.node.name)) @@ -1238,12 +1220,7 @@ impl<'a> LoweringContext<'a> { position: position, } }); - // Only local variables are renamed - let rename = match self.resolver.get_resolution(e.id).map(|d| d.base_def) { - Some(Def::Local(..)) | Some(Def::Upvar(..)) => true, - _ => false, - }; - hir::ExprPath(hir_qself, self.lower_path_full(path, rename)) + hir::ExprPath(hir_qself, self.lower_path(path)) } ExprKind::Break(opt_ident) => hir::ExprBreak(self.lower_opt_sp_ident(opt_ident)), ExprKind::Again(opt_ident) => hir::ExprAgain(self.lower_opt_sp_ident(opt_ident)), diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index c36c88c7990d3..8faa1cc1174e8 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -1138,7 +1138,7 @@ pub type ExplicitSelf = Spanned; impl Arg { pub fn to_self(&self) -> Option { if let PatKind::Binding(BindByValue(mutbl), name, _) = self.pat.node { - if name.node.unhygienize() == keywords::SelfValue.name() { + if name.node == keywords::SelfValue.name() { return match self.ty.node { TyInfer => Some(respan(self.pat.span, SelfKind::Value(mutbl))), TyRptr(lt, MutTy{ref ty, mutbl}) if ty.node == TyInfer => { @@ -1154,7 +1154,7 @@ impl Arg { pub fn is_self(&self) -> bool { if let PatKind::Binding(_, name, _) = self.pat.node { - name.node.unhygienize() == keywords::SelfValue.name() + name.node == keywords::SelfValue.name() } else { false } diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index ceaf348117e17..b6b7aa6ce7de7 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -1728,12 +1728,9 @@ impl<'a> State<'a> { } } self.print_name(path1.node)?; - match *sub { - Some(ref p) => { - word(&mut self.s, "@")?; - self.print_pat(&p)?; - } - None => (), + if let Some(ref p) = *sub { + word(&mut self.s, "@")?; + self.print_pat(&p)?; } } PatKind::TupleStruct(ref path, ref elts, ddpos) => { @@ -2246,25 +2243,21 @@ impl<'a> State<'a> { Some(cm) => cm, _ => return Ok(()), }; - match self.next_comment() { - Some(ref cmnt) => { - if (*cmnt).style != comments::Trailing { - return Ok(()); - } - let span_line = cm.lookup_char_pos(span.hi); - let comment_line = cm.lookup_char_pos((*cmnt).pos); - let mut next = (*cmnt).pos + BytePos(1); - match next_pos { - None => (), - Some(p) => next = p, - } - if span.hi < (*cmnt).pos && (*cmnt).pos < next && - span_line.line == comment_line.line { - self.print_comment(cmnt)?; - self.cur_cmnt_and_lit.cur_cmnt += 1; - } + if let Some(ref cmnt) = self.next_comment() { + if (*cmnt).style != comments::Trailing { + return Ok(()); + } + let span_line = cm.lookup_char_pos(span.hi); + let comment_line = cm.lookup_char_pos((*cmnt).pos); + let mut next = (*cmnt).pos + BytePos(1); + if let Some(p) = next_pos { + next = p; + } + if span.hi < (*cmnt).pos && (*cmnt).pos < next && + span_line.line == comment_line.line { + self.print_comment(cmnt)?; + self.cur_cmnt_and_lit.cur_cmnt += 1; } - _ => (), } Ok(()) } diff --git a/src/librustc/infer/error_reporting.rs b/src/librustc/infer/error_reporting.rs index 27896b0998121..86bc4355b2d3c 100644 --- a/src/librustc/infer/error_reporting.rs +++ b/src/librustc/infer/error_reporting.rs @@ -1856,11 +1856,10 @@ fn lifetimes_in_scope<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>, }, None => None }; - if method_id_opt.is_some() { - let method_id = method_id_opt.unwrap(); + if let Some(method_id) = method_id_opt { let parent = tcx.map.get_parent(method_id); - match tcx.map.find(parent) { - Some(node) => match node { + if let Some(node) = tcx.map.find(parent) { + match node { ast_map::NodeItem(item) => match item.node { hir::ItemImpl(_, _, ref gen, _, _, _) => { taken.extend_from_slice(&gen.lifetimes); @@ -1868,8 +1867,7 @@ fn lifetimes_in_scope<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>, _ => () }, _ => () - }, - None => () + } } } return taken; @@ -1938,4 +1936,3 @@ fn name_to_dummy_lifetime(name: ast::Name) -> hir::Lifetime { span: codemap::DUMMY_SP, name: name } } - diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index e65074a4f07b3..17da8ddbbc30c 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -160,12 +160,9 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> { } scanned.insert(id); - match self.tcx.map.find(id) { - Some(ref node) => { - self.live_symbols.insert(id); - self.visit_node(node); - } - None => (), + if let Some(ref node) = self.tcx.map.find(id) { + self.live_symbols.insert(id); + self.visit_node(node); } } } @@ -372,9 +369,8 @@ fn create_and_seed_worklist<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, } // Seed entry point - match *tcx.sess.entry_fn.borrow() { - Some((id, _)) => worklist.push(id), - None => () + if let Some((id, _)) = *tcx.sess.entry_fn.borrow() { + worklist.push(id); } // Seed implemented trait items @@ -464,16 +460,14 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> { // method of a private type is used, but the type itself is never // called directly. let impl_items = self.tcx.impl_items.borrow(); - match self.tcx.inherent_impls.borrow().get(&self.tcx.map.local_def_id(id)) { - None => (), - Some(impl_list) => { - for impl_did in impl_list.iter() { - for item_did in impl_items.get(impl_did).unwrap().iter() { - if let Some(item_node_id) = - self.tcx.map.as_local_node_id(item_did.def_id()) { - if self.live_symbols.contains(&item_node_id) { - return true; - } + if let Some(impl_list) = + self.tcx.inherent_impls.borrow().get(&self.tcx.map.local_def_id(id)) { + for impl_did in impl_list.iter() { + for item_did in impl_items.get(impl_did).unwrap().iter() { + if let Some(item_node_id) = + self.tcx.map.as_local_node_id(item_did.def_id()) { + if self.live_symbols.contains(&item_node_id) { + return true; } } } diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index dcc84fb04399f..78d9f5c9b7c29 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -456,8 +456,7 @@ fn extract_labels(ctxt: &mut LifetimeContext, b: &hir::Block) { fn expression_label(ex: &hir::Expr) -> Option<(ast::Name, Span)> { match ex.node { hir::ExprWhile(_, _, Some(label)) | - hir::ExprLoop(_, Some(label)) => Some((label.node.unhygienize(), - label.span)), + hir::ExprLoop(_, Some(label)) => Some((label.node, label.span)), _ => None, } } diff --git a/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs b/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs index 8682661d35a84..64f35aed23f5c 100644 --- a/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs +++ b/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs @@ -122,15 +122,12 @@ fn gather_move<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, let potentially_illegal_move = check_and_get_illegal_move_origin(bccx, &move_info.cmt); - match potentially_illegal_move { - Some(illegal_move_origin) => { - debug!("illegal_move_origin={:?}", illegal_move_origin); - let error = MoveError::with_move_info(illegal_move_origin, - move_info.span_path_opt); - move_error_collector.add_error(error); - return - } - None => () + if let Some(illegal_move_origin) = potentially_illegal_move { + debug!("illegal_move_origin={:?}", illegal_move_origin); + let error = MoveError::with_move_info(illegal_move_origin, + move_info.span_path_opt); + move_error_collector.add_error(error); + return; } match opt_loan_path(&move_info.cmt) { diff --git a/src/librustc_const_eval/check_match.rs b/src/librustc_const_eval/check_match.rs index f183736b9ed57..dbca15ffd34b9 100644 --- a/src/librustc_const_eval/check_match.rs +++ b/src/librustc_const_eval/check_match.rs @@ -247,8 +247,7 @@ fn check_for_bindings_named_the_same_as_variants(cx: &MatchCheckCtxt, pat: &Pat) if let ty::TyEnum(edef, _) = pat_ty.sty { if let Def::Local(..) = cx.tcx.expect_def(p.id) { if edef.variants.iter().any(|variant| - variant.name == name.node.unhygienize() - && variant.kind() == VariantKind::Unit + variant.name == name.node && variant.kind() == VariantKind::Unit ) { let ty_path = cx.tcx.item_path_str(edef.did); let mut err = struct_span_warn!(cx.tcx.sess, p.span, E0170, diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 2bd2997566e0d..3ceca9218bdf5 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -163,7 +163,7 @@ impl LateLintPass for NonShorthandFieldPatterns { continue; } if let PatKind::Binding(_, ident, None) = fieldpat.node.pat.node { - if ident.node.unhygienize() == fieldpat.node.name { + if ident.node == fieldpat.node.name { cx.span_lint(NON_SHORTHAND_FIELD_PATTERNS, fieldpat.span, &format!("the `{}:` in this pattern is redundant and can \ be removed", ident.node)) diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs index 2025045cc8f56..8bf057095ac56 100644 --- a/src/librustc_metadata/creader.rs +++ b/src/librustc_metadata/creader.rs @@ -929,29 +929,26 @@ impl<'a> LocalCrateReader<'a> { return; } - match self.creader.extract_crate_info(i) { - Some(info) => { - let (cnum, _, _) = self.creader.resolve_crate(&None, - &info.ident, - &info.name, - None, - i.span, - PathKind::Crate, - true); - - let def_id = self.definitions.opt_local_def_id(i.id).unwrap(); - let len = self.definitions.def_path(def_id.index).data.len(); - - self.creader.update_extern_crate(cnum, - ExternCrate { - def_id: def_id, - span: i.span, - direct: true, - path_len: len, - }); - self.cstore.add_extern_mod_stmt_cnum(info.id, cnum); - } - None => () + if let Some(info) = self.creader.extract_crate_info(i) { + let (cnum, _, _) = self.creader.resolve_crate(&None, + &info.ident, + &info.name, + None, + i.span, + PathKind::Crate, + true); + + let def_id = self.definitions.opt_local_def_id(i.id).unwrap(); + let len = self.definitions.def_path(def_id.index).data.len(); + + self.creader.update_extern_crate(cnum, + ExternCrate { + def_id: def_id, + span: i.span, + direct: true, + path_len: len, + }); + self.cstore.add_extern_mod_stmt_cnum(info.id, cnum); } } ast::ItemKind::ForeignMod(ref fm) => self.process_foreign_mod(i, fm), diff --git a/src/librustc_trans/base.rs b/src/librustc_trans/base.rs index 381bd24d9a4ae..5250361cd17ae 100644 --- a/src/librustc_trans/base.rs +++ b/src/librustc_trans/base.rs @@ -2252,17 +2252,14 @@ pub fn update_linkage(ccx: &CrateContext, } fn set_global_section(ccx: &CrateContext, llval: ValueRef, i: &hir::Item) { - match attr::first_attr_value_str_by_name(&i.attrs, "link_section") { - Some(sect) => { - if contains_null(§) { - ccx.sess().fatal(&format!("Illegal null byte in link_section value: `{}`", §)); - } - unsafe { - let buf = CString::new(sect.as_bytes()).unwrap(); - llvm::LLVMSetSection(llval, buf.as_ptr()); - } - }, - None => () + if let Some(sect) = attr::first_attr_value_str_by_name(&i.attrs, "link_section") { + if contains_null(§) { + ccx.sess().fatal(&format!("Illegal null byte in link_section value: `{}`", §)); + } + unsafe { + let buf = CString::new(sect.as_bytes()).unwrap(); + llvm::LLVMSetSection(llval, buf.as_ptr()); + } } } diff --git a/src/librustc_trans/debuginfo/create_scope_map.rs b/src/librustc_trans/debuginfo/create_scope_map.rs index f1d9e2c5a5710..33bdccbf06728 100644 --- a/src/librustc_trans/debuginfo/create_scope_map.rs +++ b/src/librustc_trans/debuginfo/create_scope_map.rs @@ -51,7 +51,7 @@ pub fn create_scope_map(cx: &CrateContext, for arg in args { pat_util::pat_bindings(&arg.pat, |_, node_id, _, path1| { scope_stack.push(ScopeStackEntry { scope_metadata: fn_metadata, - name: Some(path1.node.unhygienize()) }); + name: Some(path1.node) }); scope_map.insert(node_id, fn_metadata); }) } @@ -260,7 +260,7 @@ fn walk_pattern(cx: &CrateContext, // N.B.: this comparison must be UNhygienic... because // gdb knows nothing about the context, so any two // variables with the same name will cause the problem. - let name = path1.node.unhygienize(); + let name = path1.node; let need_new_scope = scope_stack .iter() .any(|entry| entry.name == Some(name)); diff --git a/src/librustc_trans/debuginfo/metadata.rs b/src/librustc_trans/debuginfo/metadata.rs index ab4860dff1510..0d13a1377b831 100644 --- a/src/librustc_trans/debuginfo/metadata.rs +++ b/src/librustc_trans/debuginfo/metadata.rs @@ -874,9 +874,8 @@ pub fn unknown_file_metadata(cx: &CrateContext) -> DIFile { } fn file_metadata_(cx: &CrateContext, key: &str, file_name: &str, work_dir: &str) -> DIFile { - match debug_context(cx).created_files.borrow().get(key) { - Some(file_metadata) => return *file_metadata, - None => () + if let Some(file_metadata) = debug_context(cx).created_files.borrow().get(key) { + return *file_metadata; } debug!("file_metadata: file_name: {}, work_dir: {}", file_name, work_dir); diff --git a/src/librustc_trans/monomorphize.rs b/src/librustc_trans/monomorphize.rs index a0355dcc66e61..dad82167a76b3 100644 --- a/src/librustc_trans/monomorphize.rs +++ b/src/librustc_trans/monomorphize.rs @@ -50,12 +50,9 @@ pub fn monomorphic_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, let mono_ty = apply_param_substs(ccx.tcx(), psubsts, &item_ty); debug!("mono_ty = {:?} (post-substitution)", mono_ty); - match ccx.instances().borrow().get(&instance) { - Some(&val) => { - debug!("leaving monomorphic fn {:?}", instance); - return (val, mono_ty); - } - None => () + if let Some(&val) = ccx.instances().borrow().get(&instance) { + debug!("leaving monomorphic fn {:?}", instance); + return (val, mono_ty); } debug!("monomorphic_fn({:?})", instance); diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs index 0180c3118a586..668fa1fb30360 100644 --- a/src/libstd/fs.rs +++ b/src/libstd/fs.rs @@ -512,7 +512,7 @@ impl OpenOptions { /// No file is allowed to exist at the target location, also no (dangling) /// symlink. /// - /// This option is useful because it as atomic. Otherwise between checking + /// This option is useful because it is atomic. Otherwise between checking /// whether a file exists and creating a new one, the file may have been /// created by another process (a TOCTOU race condition / attack). /// @@ -1770,6 +1770,15 @@ mod tests { check!(fs::remove_dir(dir)); } + #[test] + fn file_create_new_already_exists_error() { + let tmpdir = tmpdir(); + let file = &tmpdir.join("file_create_new_error_exists"); + check!(fs::File::create(file)); + let e = fs::OpenOptions::new().write(true).create_new(true).open(file).unwrap_err(); + assert_eq!(e.kind(), ErrorKind::AlreadyExists); + } + #[test] fn mkdir_path_already_exists_error() { let tmpdir = tmpdir(); diff --git a/src/libstd/sys/windows/c.rs b/src/libstd/sys/windows/c.rs index 2acf6485eb3da..ce563dc7b16d3 100644 --- a/src/libstd/sys/windows/c.rs +++ b/src/libstd/sys/windows/c.rs @@ -181,6 +181,7 @@ pub const ERROR_ACCESS_DENIED: DWORD = 5; pub const ERROR_INVALID_HANDLE: DWORD = 6; pub const ERROR_NO_MORE_FILES: DWORD = 18; pub const ERROR_HANDLE_EOF: DWORD = 38; +pub const ERROR_FILE_EXISTS: DWORD = 80; pub const ERROR_BROKEN_PIPE: DWORD = 109; pub const ERROR_CALL_NOT_IMPLEMENTED: DWORD = 120; pub const ERROR_INSUFFICIENT_BUFFER: DWORD = 122; diff --git a/src/libstd/sys/windows/mod.rs b/src/libstd/sys/windows/mod.rs index 384940e4dc446..6dd4f4c3e750e 100644 --- a/src/libstd/sys/windows/mod.rs +++ b/src/libstd/sys/windows/mod.rs @@ -68,6 +68,7 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind { match errno as c::DWORD { c::ERROR_ACCESS_DENIED => return ErrorKind::PermissionDenied, c::ERROR_ALREADY_EXISTS => return ErrorKind::AlreadyExists, + c::ERROR_FILE_EXISTS => return ErrorKind::AlreadyExists, c::ERROR_BROKEN_PIPE => return ErrorKind::BrokenPipe, c::ERROR_FILE_NOT_FOUND => return ErrorKind::NotFound, c::ERROR_PATH_NOT_FOUND => return ErrorKind::NotFound, diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 40c98206c16e9..8537fcc221c95 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -60,10 +60,6 @@ impl Name { pub fn as_str(self) -> token::InternedString { token::InternedString::new_from_name(self) } - - pub fn unhygienize(self) -> Name { - token::intern(&self.as_str()) - } } impl fmt::Debug for Name { diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 22cc20b8f8c44..341b076e7cf30 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -5430,18 +5430,15 @@ impl<'a> Parser<'a> { name: String, id_sp: Span) -> PResult<'a, (ast::ItemKind, Vec )> { let mut included_mod_stack = self.sess.included_mod_stack.borrow_mut(); - match included_mod_stack.iter().position(|p| *p == path) { - Some(i) => { - let mut err = String::from("circular modules: "); - let len = included_mod_stack.len(); - for p in &included_mod_stack[i.. len] { - err.push_str(&p.to_string_lossy()); - err.push_str(" -> "); - } - err.push_str(&path.to_string_lossy()); - return Err(self.span_fatal(id_sp, &err[..])); - } - None => () + if let Some(i) = included_mod_stack.iter().position(|p| *p == path) { + let mut err = String::from("circular modules: "); + let len = included_mod_stack.len(); + for p in &included_mod_stack[i.. len] { + err.push_str(&p.to_string_lossy()); + err.push_str(" -> "); + } + err.push_str(&path.to_string_lossy()); + return Err(self.span_fatal(id_sp, &err[..])); } included_mod_stack.push(path.clone()); drop(included_mod_stack); diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 5b9ec924de953..8818acf9aeff0 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -2459,12 +2459,9 @@ impl<'a> State<'a> { } } self.print_ident(path1.node)?; - match *sub { - Some(ref p) => { - word(&mut self.s, "@")?; - self.print_pat(&p)?; - } - None => () + if let Some(ref p) = *sub { + word(&mut self.s, "@")?; + self.print_pat(&p)?; } } PatKind::TupleStruct(ref path, ref elts, ddpos) => { @@ -3008,20 +3005,19 @@ impl<'a> State<'a> { Some(cm) => cm, _ => return Ok(()) }; - match self.next_comment() { - Some(ref cmnt) => { - if (*cmnt).style != comments::Trailing { return Ok(()) } - let span_line = cm.lookup_char_pos(span.hi); - let comment_line = cm.lookup_char_pos((*cmnt).pos); - let mut next = (*cmnt).pos + BytePos(1); - match next_pos { None => (), Some(p) => next = p } - if span.hi < (*cmnt).pos && (*cmnt).pos < next && - span_line.line == comment_line.line { - self.print_comment(cmnt)?; - self.cur_cmnt_and_lit.cur_cmnt += 1; - } + if let Some(ref cmnt) = self.next_comment() { + if (*cmnt).style != comments::Trailing { return Ok(()) } + let span_line = cm.lookup_char_pos(span.hi); + let comment_line = cm.lookup_char_pos((*cmnt).pos); + let mut next = (*cmnt).pos + BytePos(1); + if let Some(p) = next_pos { + next = p; + } + if span.hi < (*cmnt).pos && (*cmnt).pos < next && + span_line.line == comment_line.line { + self.print_comment(cmnt)?; + self.cur_cmnt_and_lit.cur_cmnt += 1; } - _ => () } Ok(()) } diff --git a/src/libsyntax/util/interner.rs b/src/libsyntax/util/interner.rs index 8e20358027b22..7295b36af0fe9 100644 --- a/src/libsyntax/util/interner.rs +++ b/src/libsyntax/util/interner.rs @@ -47,9 +47,8 @@ impl Interner { pub fn intern(&self, val: T) -> Name { let mut map = self.map.borrow_mut(); - match (*map).get(&val) { - Some(&idx) => return idx, - None => (), + if let Some(&idx) = (*map).get(&val) { + return idx; } let mut vect = self.vect.borrow_mut(); @@ -161,9 +160,8 @@ impl StrInterner { pub fn intern(&self, val: &str) -> Name { let mut map = self.map.borrow_mut(); - match map.get(val) { - Some(&idx) => return idx, - None => (), + if let Some(&idx) = map.get(val) { + return idx; } let new_idx = Name(self.len() as u32);