From 4e352892c8ca76f49332fb74d9903677dea2c5fe Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Wed, 29 Oct 2014 18:03:40 -0400 Subject: Restructure parsing of paths, which is quite tortured --- src/libsyntax/parse/parser.rs | 150 ++++++++++++++++++++++++++++++------------ 1 file changed, 108 insertions(+), 42 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 10bb9ef3625..fd244a443a8 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1706,50 +1706,18 @@ impl<'a> Parser<'a> { // Parse any number of segments and bound sets. A segment is an // identifier followed by an optional lifetime and a set of types. // A bound set is a set of type parameter bounds. - let mut segments = Vec::new(); - loop { - // First, parse an identifier. - let identifier = self.parse_ident(); - - // Parse the '::' before type parameters if it's required. If - // it is required and wasn't present, then we're done. - if mode == LifetimeAndTypesWithColons && - !self.eat(&token::ModSep) { - segments.push(ast::PathSegment { - identifier: identifier, - lifetimes: Vec::new(), - types: OwnedSlice::empty(), - }); - break + let segments = match mode { + LifetimeAndTypesWithoutColons | + LifetimeAndTypesAndBounds => { + self.parse_path_segments_without_colons() } - - // Parse the `<` before the lifetime and types, if applicable. - let (any_lifetime_or_types, lifetimes, types) = { - if mode != NoTypesAllowed && self.eat_lt(false) { - let (lifetimes, types) = - self.parse_generic_values_after_lt(); - (true, lifetimes, OwnedSlice::from_vec(types)) - } else { - (false, Vec::new(), OwnedSlice::empty()) - } - }; - - // Assemble and push the result. - segments.push(ast::PathSegment { - identifier: identifier, - lifetimes: lifetimes, - types: types, - }); - - // We're done if we don't see a '::', unless the mode required - // a double colon to get here in the first place. - if !(mode == LifetimeAndTypesWithColons && - !any_lifetime_or_types) { - if !self.eat(&token::ModSep) { - break - } + LifetimeAndTypesWithColons => { + self.parse_path_segments_with_colons() } - } + NoTypesAllowed => { + self.parse_path_segments_without_types() + } + }; // Next, parse a plus and bounded type parameters, if // applicable. We need to remember whether the separate was @@ -1792,6 +1760,104 @@ impl<'a> Parser<'a> { } } + /// Examples: + /// - `a::b::c` + /// - `a::b::c(V) -> W` + /// - `a::b::c(V)` + pub fn parse_path_segments_without_colons(&mut self) -> Vec { + let mut segments = Vec::new(); + loop { + // First, parse an identifier. + let identifier = self.parse_ident(); + + // Parse types, optionally. + let (lifetimes, types) = if self.eat_lt(false) { + self.parse_generic_values_after_lt() + } else if false && self.eat(&token::LParen) { + let mut types = self.parse_seq_to_end( + &token::RParen, + seq_sep_trailing_allowed(token::Comma), + |p| p.parse_ty(true)); + + if self.eat(&token::RArrow) { + types.push(self.parse_ty(true)) + } + + (Vec::new(), types) + } else { + (Vec::new(), Vec::new()) + }; + + // Assemble and push the result. + segments.push(ast::PathSegment { identifier: identifier, + lifetimes: lifetimes, + types: OwnedSlice::from_vec(types), }); + + // Continue only if we see a `::` + if !self.eat(&token::ModSep) { + return segments; + } + } + } + + /// Examples: + /// - `a::b::::c` + pub fn parse_path_segments_with_colons(&mut self) -> Vec { + let mut segments = Vec::new(); + loop { + // First, parse an identifier. + let identifier = self.parse_ident(); + + // If we do not see a `::`, stop. + if !self.eat(&token::ModSep) { + segments.push(ast::PathSegment { identifier: identifier, + lifetimes: Vec::new(), + types: OwnedSlice::empty() }); + return segments; + } + + // Check for a type segment. + if self.eat_lt(false) { + // Consumed `a::b::<`, go look for types + let (lifetimes, types) = self.parse_generic_values_after_lt(); + segments.push(ast::PathSegment { identifier: identifier, + lifetimes: lifetimes, + types: OwnedSlice::from_vec(types) }); + + // Consumed `a::b::`, check for `::` before proceeding + if !self.eat(&token::ModSep) { + return segments; + } + } else { + // Consumed `a::`, go look for `b` + segments.push(ast::PathSegment { identifier: identifier, + lifetimes: Vec::new(), + types: OwnedSlice::empty() }); + } + } + } + + + /// Examples: + /// - `a::b::c` + pub fn parse_path_segments_without_types(&mut self) -> Vec { + let mut segments = Vec::new(); + loop { + // First, parse an identifier. + let identifier = self.parse_ident(); + + // Assemble and push the result. + segments.push(ast::PathSegment { identifier: identifier, + lifetimes: Vec::new(), + types: OwnedSlice::empty(), }); + + // If we do not see a `::`, stop. + if !self.eat(&token::ModSep) { + return segments; + } + } + } + /// parses 0 or 1 lifetime pub fn parse_opt_lifetime(&mut self) -> Option { match self.token { -- cgit 1.4.1-3-g733a5 From 221edbae3843848047825701e25b6f9d8b096075 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 3 Nov 2014 21:52:52 -0500 Subject: Support parenthesized paths `Foo(A,B) -> C` that expand to `Foo<(A,B),C>`. These paths also bind anonymous regions (or will, once HRTB is fully working). Fixes #18423. --- src/librustc/diagnostics.rs | 5 +- src/librustc/middle/check_const.rs | 2 +- src/librustc/middle/pat_util.rs | 4 +- src/librustc/middle/privacy.rs | 4 +- src/librustc/middle/resolve.rs | 8 +- src/librustc/middle/trans/base.rs | 6 +- src/librustc/middle/trans/consts.rs | 2 +- src/librustc/middle/ty.rs | 8 + src/librustc/middle/typeck/astconv.rs | 230 +++++++++++++-------- src/librustc/middle/typeck/check/mod.rs | 90 ++++++-- src/librustc/middle/typeck/collect.rs | 3 +- .../middle/typeck/infer/error_reporting.rs | 71 ++++--- src/librustdoc/clean/mod.rs | 17 +- src/libsyntax/ast.rs | 97 ++++++++- src/libsyntax/ast_util.rs | 18 +- src/libsyntax/ext/build.rs | 9 +- src/libsyntax/ext/concat_idents.rs | 4 +- src/libsyntax/fold.rs | 50 ++++- src/libsyntax/parse/mod.rs | 24 +-- src/libsyntax/parse/parser.rs | 98 +++++---- src/libsyntax/print/pprust.rs | 56 ++++- src/libsyntax/std_inject.rs | 7 +- src/libsyntax/test.rs | 3 +- src/libsyntax/visit.rs | 22 +- src/test/compile-fail/issue-14092.rs | 2 +- src/test/compile-fail/issue-18423.rs | 18 ++ .../compile-fail/unboxed-closure-sugar-default.rs | 37 ++++ .../compile-fail/unboxed-closure-sugar-equiv.rs | 39 ++++ .../unboxed-closure-sugar-nonexistent-trait.rs | 2 +- .../compile-fail/unboxed-closure-sugar-region.rs | 45 ++++ ...-sugar-wrong-number-number-type-parameters-1.rs | 16 ++ ...-sugar-wrong-number-number-type-parameters-3.rs | 16 ++ ...re-sugar-wrong-number-number-type-parameters.rs | 16 ++ .../unboxed-closure-sugar-wrong-trait.rs | 2 +- src/test/run-pass/unboxed-closures-prelude.rs | 2 +- src/test/run-pass/unboxed-closures-sugar-1.rs | 34 +++ src/test/run-pass/unboxed-closures-sugar-object.rs | 34 +++ .../run-pass/unboxed-closures-unboxing-shim.rs | 2 +- 38 files changed, 840 insertions(+), 263 deletions(-) create mode 100644 src/test/compile-fail/issue-18423.rs create mode 100644 src/test/compile-fail/unboxed-closure-sugar-default.rs create mode 100644 src/test/compile-fail/unboxed-closure-sugar-equiv.rs create mode 100644 src/test/compile-fail/unboxed-closure-sugar-region.rs create mode 100644 src/test/compile-fail/unboxed-closure-sugar-wrong-number-number-type-parameters-1.rs create mode 100644 src/test/compile-fail/unboxed-closure-sugar-wrong-number-number-type-parameters-3.rs create mode 100644 src/test/compile-fail/unboxed-closure-sugar-wrong-number-number-type-parameters.rs create mode 100644 src/test/run-pass/unboxed-closures-sugar-1.rs create mode 100644 src/test/run-pass/unboxed-closures-sugar-object.rs (limited to 'src/libsyntax') diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index c4e21379088..d5e9c1ef99f 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -57,7 +57,6 @@ register_diagnostics!( E0044, E0045, E0046, - E0047, E0049, E0050, E0051, @@ -111,7 +110,6 @@ register_diagnostics!( E0108, E0109, E0110, - E0113, E0116, E0117, E0118, @@ -145,5 +143,6 @@ register_diagnostics!( E0163, E0164, E0165, - E0166 + E0166, + E0167 ) diff --git a/src/librustc/middle/check_const.rs b/src/librustc/middle/check_const.rs index 6cf1a93b40b..28384566303 100644 --- a/src/librustc/middle/check_const.rs +++ b/src/librustc/middle/check_const.rs @@ -138,7 +138,7 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr) -> bool { // to handle on-demand instantiation of functions via // foo:: in a const. Currently that is only done on // a path in trans::callee that only works in block contexts. - if !pth.segments.iter().all(|segment| segment.types.is_empty()) { + if !pth.segments.iter().all(|segment| segment.parameters.is_empty()) { span_err!(v.tcx.sess, e.span, E0013, "paths in constants may only refer to items without \ type parameters"); diff --git a/src/librustc/middle/pat_util.rs b/src/librustc/middle/pat_util.rs index 357f4cdf0eb..f1d8c550d04 100644 --- a/src/librustc/middle/pat_util.rs +++ b/src/librustc/middle/pat_util.rs @@ -16,7 +16,6 @@ use std::collections::HashMap; use syntax::ast::*; use syntax::ast_util::{walk_pat}; use syntax::codemap::{Span, DUMMY_SP}; -use syntax::owned_slice::OwnedSlice; pub type PatIdMap = HashMap; @@ -133,8 +132,7 @@ pub fn def_to_path(tcx: &ty::ctxt, id: DefId) -> Path { global: false, segments: path.last().map(|elem| PathSegment { identifier: Ident::new(elem.name()), - lifetimes: vec!(), - types: OwnedSlice::empty() + parameters: PathParameters::none(), }).into_iter().collect(), span: DUMMY_SP, }) diff --git a/src/librustc/middle/privacy.rs b/src/librustc/middle/privacy.rs index 4fbffa2a819..7124488f7c1 100644 --- a/src/librustc/middle/privacy.rs +++ b/src/librustc/middle/privacy.rs @@ -27,7 +27,6 @@ use syntax::ast_map; use syntax::ast_util::{is_local, local_def, PostExpansionMethod}; use syntax::codemap::Span; use syntax::parse::token; -use syntax::owned_slice::OwnedSlice; use syntax::visit; use syntax::visit::Visitor; @@ -945,8 +944,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> { debug!("privacy - ident item {}", id); let seg = ast::PathSegment { identifier: name, - lifetimes: Vec::new(), - types: OwnedSlice::empty(), + parameters: ast::PathParameters::none(), }; let segs = vec![seg]; let path = ast::Path { diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index ed7d9296c70..34f0cb7c198 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -4951,12 +4951,12 @@ impl<'a> Resolver<'a> { if path.segments .iter() - .any(|s| !s.lifetimes.is_empty()) { + .any(|s| s.parameters.has_lifetimes()) { span_err!(self.session, path.span, E0157, "lifetime parameters are not allowed on this type"); } else if path.segments .iter() - .any(|s| s.types.len() > 0) { + .any(|s| !s.parameters.is_empty()) { span_err!(self.session, path.span, E0153, "type parameters are not allowed on this type"); } @@ -5234,7 +5234,7 @@ impl<'a> Resolver<'a> { // Check the types in the path pattern. for ty in path.segments .iter() - .flat_map(|s| s.types.iter()) { + .flat_map(|s| s.parameters.types().into_iter()) { self.resolve_type(&**ty); } } @@ -5340,7 +5340,7 @@ impl<'a> Resolver<'a> { namespace: Namespace, check_ribs: bool) -> Option<(Def, LastPrivate)> { // First, resolve the types. - for ty in path.segments.iter().flat_map(|s| s.types.iter()) { + for ty in path.segments.iter().flat_map(|s| s.parameters.types().into_iter()) { self.resolve_type(&**ty); } diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index b80425e7ac8..c73268317bd 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -1836,11 +1836,7 @@ pub fn trans_closure(ccx: &CrateContext, NotUnboxedClosure => monomorphized_arg_types, // Tuple up closure argument types for the "rust-call" ABI. - IsUnboxedClosure => vec![if monomorphized_arg_types.is_empty() { - ty::mk_nil() - } else { - ty::mk_tup(ccx.tcx(), monomorphized_arg_types) - }] + IsUnboxedClosure => vec![ty::mk_tup_or_nil(ccx.tcx(), monomorphized_arg_types)] }; for monomorphized_arg_type in monomorphized_arg_types.iter() { debug!("trans_closure: monomorphized_arg_type: {}", diff --git a/src/librustc/middle/trans/consts.rs b/src/librustc/middle/trans/consts.rs index 6ba6ff6fb21..bd43aa47906 100644 --- a/src/librustc/middle/trans/consts.rs +++ b/src/librustc/middle/trans/consts.rs @@ -625,7 +625,7 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr) -> ValueRef { } ast::ExprPath(ref pth) => { // Assert that there are no type parameters in this path. - assert!(pth.segments.iter().all(|seg| seg.types.is_empty())); + assert!(pth.segments.iter().all(|seg| !seg.parameters.has_types())); let opt_def = cx.tcx().def_map.borrow().find_copy(&e.id); match opt_def { diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 76caa42b850..9c717b98f35 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -1838,6 +1838,14 @@ pub fn mk_slice(cx: &ctxt, r: Region, tm: mt) -> t { pub fn mk_tup(cx: &ctxt, ts: Vec) -> t { mk_t(cx, ty_tup(ts)) } +pub fn mk_tup_or_nil(cx: &ctxt, ts: Vec) -> t { + if ts.len() == 0 { + ty::mk_nil() + } else { + mk_t(cx, ty_tup(ts)) + } +} + pub fn mk_closure(cx: &ctxt, fty: ClosureTy) -> t { mk_t(cx, ty_closure(box fty)) } diff --git a/src/librustc/middle/typeck/astconv.rs b/src/librustc/middle/typeck/astconv.rs index 7c8d9309df3..f2cc3bfd29b 100644 --- a/src/librustc/middle/typeck/astconv.rs +++ b/src/librustc/middle/typeck/astconv.rs @@ -59,7 +59,7 @@ use middle::subst::{VecPerParamSpace}; use middle::ty; use middle::typeck::lookup_def_tcx; use middle::typeck::infer; -use middle::typeck::rscope::{UnelidableRscope, RegionScope, SpecificRscope}; +use middle::typeck::rscope::{UnelidableRscope, RegionScope, SpecificRscope, BindingRscope}; use middle::typeck::rscope; use middle::typeck::TypeAndSubsts; use middle::typeck; @@ -207,15 +207,16 @@ pub fn opt_ast_region_to_region<'tcx, AC: AstConv<'tcx>, RS: RegionScope>( } fn ast_path_substs<'tcx,AC,RS>( - this: &AC, - rscope: &RS, - decl_def_id: ast::DefId, - decl_generics: &ty::Generics, - self_ty: Option, - associated_ty: Option, - path: &ast::Path) - -> Substs - where AC: AstConv<'tcx>, RS: RegionScope + this: &AC, + rscope: &RS, + decl_def_id: ast::DefId, + decl_generics: &ty::Generics, + self_ty: Option, + associated_ty: Option, + path: &ast::Path, + binder_id: ast::NodeId) + -> Substs + where AC: AstConv<'tcx>, RS: RegionScope { /*! * Given a path `path` that refers to an item `I` with the @@ -236,45 +237,51 @@ fn ast_path_substs<'tcx,AC,RS>( assert!(decl_generics.regions.all(|d| d.space == TypeSpace)); assert!(decl_generics.types.all(|d| d.space != FnSpace)); + let (regions, types) = match path.segments.last().unwrap().parameters { + ast::AngleBracketedParameters(ref data) => + angle_bracketed_parameters(this, rscope, data), + ast::ParenthesizedParameters(ref data) => + parenthesized_parameters(this, binder_id, data), + }; + // If the type is parameterized by the this region, then replace this // region with the current anon region binding (in other words, // whatever & would get replaced with). let expected_num_region_params = decl_generics.regions.len(TypeSpace); - let supplied_num_region_params = path.segments.last().unwrap().lifetimes.len(); + let supplied_num_region_params = regions.len(); let regions = if expected_num_region_params == supplied_num_region_params { - path.segments.last().unwrap().lifetimes.iter().map( - |l| ast_region_to_region(this.tcx(), l)).collect::>() + regions } else { let anon_regions = rscope.anon_regions(path.span, expected_num_region_params); if supplied_num_region_params != 0 || anon_regions.is_err() { span_err!(tcx.sess, path.span, E0107, - "wrong number of lifetime parameters: expected {}, found {}", - expected_num_region_params, supplied_num_region_params); + "wrong number of lifetime parameters: expected {}, found {}", + expected_num_region_params, supplied_num_region_params); } match anon_regions { Ok(v) => v.into_iter().collect(), Err(_) => Vec::from_fn(expected_num_region_params, - |_| ty::ReStatic) // hokey + |_| ty::ReStatic) // hokey } }; // Convert the type parameters supplied by the user. let ty_param_defs = decl_generics.types.get_slice(TypeSpace); - let supplied_ty_param_count = path.segments.iter().flat_map(|s| s.types.iter()).count(); + let supplied_ty_param_count = types.len(); let formal_ty_param_count = ty_param_defs.iter() - .take_while(|x| !ty::is_associated_type(tcx, x.def_id)) - .count(); + .take_while(|x| !ty::is_associated_type(tcx, x.def_id)) + .count(); let required_ty_param_count = ty_param_defs.iter() - .take_while(|x| { - x.default.is_none() && - !ty::is_associated_type(tcx, x.def_id) - }) - .count(); + .take_while(|x| { + x.default.is_none() && + !ty::is_associated_type(tcx, x.def_id) + }) + .count(); if supplied_ty_param_count < required_ty_param_count { let expected = if required_ty_param_count < formal_ty_param_count { "expected at least" @@ -282,10 +289,10 @@ fn ast_path_substs<'tcx,AC,RS>( "expected" }; this.tcx().sess.span_fatal(path.span, - format!("wrong number of type arguments: {} {}, found {}", - expected, - required_ty_param_count, - supplied_ty_param_count).as_slice()); + format!("wrong number of type arguments: {} {}, found {}", + expected, + required_ty_param_count, + supplied_ty_param_count).as_slice()); } else if supplied_ty_param_count > formal_ty_param_count { let expected = if required_ty_param_count < formal_ty_param_count { "expected at most" @@ -293,10 +300,10 @@ fn ast_path_substs<'tcx,AC,RS>( "expected" }; this.tcx().sess.span_fatal(path.span, - format!("wrong number of type arguments: {} {}, found {}", - expected, - formal_ty_param_count, - supplied_ty_param_count).as_slice()); + format!("wrong number of type arguments: {} {}, found {}", + expected, + formal_ty_param_count, + supplied_ty_param_count).as_slice()); } if supplied_ty_param_count > required_ty_param_count @@ -307,13 +314,7 @@ fn ast_path_substs<'tcx,AC,RS>( "add #![feature(default_type_params)] to the crate attributes to enable"); } - let tps = path.segments - .iter() - .flat_map(|s| s.types.iter()) - .map(|a_t| ast_ty_to_ty(this, rscope, &**a_t)) - .collect(); - - let mut substs = Substs::new_type(tps, regions); + let mut substs = Substs::new_type(types, regions); match self_ty { None => { @@ -354,7 +355,47 @@ fn ast_path_substs<'tcx,AC,RS>( param.def_id)) } - substs + return substs; + + fn angle_bracketed_parameters<'tcx, AC, RS>(this: &AC, + rscope: &RS, + data: &ast::AngleBracketedParameterData) + -> (Vec, Vec) + where AC: AstConv<'tcx>, RS: RegionScope + { + let regions: Vec<_> = + data.lifetimes.iter() + .map(|l| ast_region_to_region(this.tcx(), l)) + .collect(); + + let types: Vec<_> = + data.types.iter() + .map(|t| ast_ty_to_ty(this, rscope, &**t)) + .collect(); + + (regions, types) + } + + fn parenthesized_parameters<'tcx,AC>(this: &AC, + binder_id: ast::NodeId, + data: &ast::ParenthesizedParameterData) + -> (Vec, Vec) + where AC: AstConv<'tcx> + { + let binding_rscope = BindingRscope::new(binder_id); + + let inputs = data.inputs.iter() + .map(|a_t| ast_ty_to_ty(this, &binding_rscope, &**a_t)) + .collect(); + let input_ty = ty::mk_tup_or_nil(this.tcx(), inputs); + + let output = match data.output { + Some(ref output_ty) => ast_ty_to_ty(this, &binding_rscope, &**output_ty), + None => ty::mk_nil() + }; + + (Vec::new(), vec![input_ty, output]) + } } pub fn ast_path_to_trait_ref<'tcx,AC,RS>(this: &AC, @@ -362,7 +403,8 @@ pub fn ast_path_to_trait_ref<'tcx,AC,RS>(this: &AC, trait_def_id: ast::DefId, self_ty: Option, associated_type: Option, - path: &ast::Path) + path: &ast::Path, + binder_id: ast::NodeId) -> Rc where AC: AstConv<'tcx>, RS: RegionScope { @@ -375,7 +417,8 @@ pub fn ast_path_to_trait_ref<'tcx,AC,RS>(this: &AC, &trait_def.generics, self_ty, associated_type, - path) + path, + binder_id) }) } @@ -383,8 +426,10 @@ pub fn ast_path_to_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>( this: &AC, rscope: &RS, did: ast::DefId, - path: &ast::Path) - -> TypeAndSubsts { + path: &ast::Path, + binder_id: ast::NodeId) + -> TypeAndSubsts +{ let tcx = this.tcx(); let ty::Polytype { generics, @@ -397,7 +442,8 @@ pub fn ast_path_to_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>( &generics, None, None, - path); + path, + binder_id); let ty = decl_ty.subst(tcx, &substs); TypeAndSubsts { substs: substs, ty: ty } } @@ -407,24 +453,29 @@ pub fn ast_path_to_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>( /// and/or region variables are substituted. /// /// This is used when checking the constructor in struct literals. -pub fn ast_path_to_ty_relaxed<'tcx, AC: AstConv<'tcx>, - RS:RegionScope>( - this: &AC, - rscope: &RS, - did: ast::DefId, - path: &ast::Path) - -> TypeAndSubsts { +pub fn ast_path_to_ty_relaxed<'tcx,AC,RS>( + this: &AC, + rscope: &RS, + did: ast::DefId, + path: &ast::Path, + binder_id: ast::NodeId) + -> TypeAndSubsts + where AC : AstConv<'tcx>, RS : RegionScope +{ let tcx = this.tcx(); let ty::Polytype { generics, ty: decl_ty } = this.get_item_ty(did); - let substs = if (generics.has_type_params(TypeSpace) || - generics.has_region_params(TypeSpace)) && - path.segments.iter().all(|s| { - s.lifetimes.len() == 0 && s.types.len() == 0 - }) { + let wants_params = + generics.has_type_params(TypeSpace) || generics.has_region_params(TypeSpace); + + let needs_defaults = + wants_params && + path.segments.iter().all(|s| s.parameters.is_empty()); + + let substs = if needs_defaults { let type_params = Vec::from_fn(generics.types.len(TypeSpace), |_| this.ty_infer(path.span)); let region_params = @@ -433,7 +484,7 @@ pub fn ast_path_to_ty_relaxed<'tcx, AC: AstConv<'tcx>, Substs::new(VecPerParamSpace::params_from_type(type_params), VecPerParamSpace::params_from_type(region_params)) } else { - ast_path_substs(this, rscope, did, &generics, None, None, path) + ast_path_substs(this, rscope, did, &generics, None, None, path, binder_id) }; let ty = decl_ty.subst(tcx, &substs); @@ -450,14 +501,14 @@ fn check_path_args(tcx: &ty::ctxt, path: &ast::Path, flags: uint) { if (flags & NO_TPS) != 0u { - if !path.segments.iter().all(|s| s.types.is_empty()) { + if path.segments.iter().any(|s| s.parameters.has_types()) { span_err!(tcx.sess, path.span, E0109, "type parameters are not allowed on this type"); } } if (flags & NO_REGIONS) != 0u { - if !path.segments.last().unwrap().lifetimes.is_empty() { + if path.segments.iter().any(|s| s.parameters.has_lifetimes()) { span_err!(tcx.sess, path.span, E0110, "region parameters are not allowed on this type"); } @@ -538,29 +589,23 @@ pub fn ast_ty_to_builtin_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>( // FIXME(#12938): This is a hack until we have full support for // DST. match a_def { - def::DefTy(did, _) | def::DefStruct(did) - if Some(did) == this.tcx().lang_items.owned_box() => { - if path.segments - .iter() - .flat_map(|s| s.types.iter()) - .count() > 1 { - span_err!(this.tcx().sess, path.span, E0047, - "`Box` has only one type parameter"); - } - - for inner_ast_type in path.segments - .iter() - .flat_map(|s| s.types.iter()) { - return Some(mk_pointer(this, - rscope, - ast::MutImmutable, - &**inner_ast_type, - Uniq, - |typ| ty::mk_uniq(this.tcx(), typ))); + def::DefTy(did, _) | + def::DefStruct(did) if Some(did) == this.tcx().lang_items.owned_box() => { + let ty = ast_path_to_ty(this, rscope, did, path, id).ty; + match ty::get(ty).sty { + ty::ty_struct(struct_def_id, ref substs) => { + assert_eq!(struct_def_id, did); + assert_eq!(substs.types.len(TypeSpace), 1); + let referent_ty = *substs.types.get(TypeSpace, 0); + Some(ty::mk_uniq(this.tcx(), referent_ty)) + } + _ => { + this.tcx().sess.span_bug( + path.span, + format!("converting `Box` to `{}`", + ty.repr(this.tcx()))[]); + } } - span_err!(this.tcx().sess, path.span, E0113, - "not enough type parameters supplied to `Box`"); - Some(ty::mk_err()) } _ => None } @@ -603,11 +648,7 @@ pub fn trait_ref_for_unboxed_function<'tcx, AC: AstConv<'tcx>, .map(|input| { ast_ty_to_ty(this, rscope, &*input.ty) }).collect::>(); - let input_tuple = if input_types.len() == 0 { - ty::mk_nil() - } else { - ty::mk_tup(this.tcx(), input_types) - }; + let input_tuple = ty::mk_tup_or_nil(this.tcx(), input_types); let output_type = ast_ty_to_ty(this, rscope, &*decl.output); let mut substs = Substs::new_type(vec!(input_tuple, output_type), Vec::new()); @@ -693,7 +734,8 @@ fn mk_pointer<'tcx, AC: AstConv<'tcx>, RS: RegionScope>( trait_def_id, None, None, - path); + path, + id); let bounds = match *opt_bounds { None => { conv_existential_bounds(this, @@ -771,7 +813,12 @@ fn associated_ty_to_ty<'tcx,AC,RS>(this: &AC, trait_did, None, Some(for_type), - trait_path); + trait_path, + ast::DUMMY_NODE_ID); // *see below + + // * The trait in a qualified path cannot be "higher-ranked" and + // hence cannot use the parenthetical sugar, so the binder-id is + // irrelevant. debug!("associated_ty_to_ty(trait_ref={})", trait_ref.repr(this.tcx())); @@ -925,7 +972,8 @@ pub fn ast_ty_to_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>( trait_def_id, None, None, - path); + path, + id); let empty_bounds: &[ast::TyParamBound] = &[]; let ast_bounds = match *bounds { Some(ref b) => b.as_slice(), @@ -942,7 +990,7 @@ pub fn ast_ty_to_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>( bounds) } def::DefTy(did, _) | def::DefStruct(did) => { - ast_path_to_ty(this, rscope, did, path).ty + ast_path_to_ty(this, rscope, did, path, id).ty } def::DefTyParam(space, id, n) => { check_path_args(tcx, path, NO_TPS | NO_REGIONS); diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index bcb875a6aa8..322275218e1 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -3481,11 +3481,7 @@ fn check_expr_with_unifier(fcx: &FnCtxt, // Tuple up the arguments and insert the resulting function type into // the `unboxed_closures` table. - fn_ty.sig.inputs = if fn_ty.sig.inputs.len() == 0 { - vec![ty::mk_nil()] - } else { - vec![ty::mk_tup(fcx.tcx(), fn_ty.sig.inputs)] - }; + fn_ty.sig.inputs = vec![ty::mk_tup_or_nil(fcx.tcx(), fn_ty.sig.inputs)]; let kind = match kind { ast::FnUnboxedClosureKind => ty::FnUnboxedClosureKind, @@ -4478,7 +4474,8 @@ fn check_expr_with_unifier(fcx: &FnCtxt, let type_and_substs = astconv::ast_path_to_ty_relaxed(fcx, fcx.infcx(), struct_id, - path); + path, + expr.id); match fcx.mk_subty(false, infer::Misc(path.span), actual_structure_type, @@ -5339,6 +5336,7 @@ pub fn instantiate_path(fcx: &FnCtxt, Some(space) => { push_explicit_parameters_from_segment_to_substs(fcx, space, + path.span, type_defs, region_defs, segment, @@ -5374,13 +5372,13 @@ pub fn instantiate_path(fcx: &FnCtxt, fcx: &FnCtxt, segment: &ast::PathSegment) { - for typ in segment.types.iter() { + for typ in segment.parameters.types().iter() { span_err!(fcx.tcx().sess, typ.span, E0085, "type parameters may not appear here"); break; } - for lifetime in segment.lifetimes.iter() { + for lifetime in segment.parameters.lifetimes().iter() { span_err!(fcx.tcx().sess, lifetime.span, E0086, "lifetime parameters may not appear here"); break; @@ -5390,6 +5388,7 @@ pub fn instantiate_path(fcx: &FnCtxt, fn push_explicit_parameters_from_segment_to_substs( fcx: &FnCtxt, space: subst::ParamSpace, + span: Span, type_defs: &VecPerParamSpace, region_defs: &VecPerParamSpace, segment: &ast::PathSegment, @@ -5412,10 +5411,31 @@ pub fn instantiate_path(fcx: &FnCtxt, * span of the N+1'th parameter. */ + match segment.parameters { + ast::AngleBracketedParameters(ref data) => { + push_explicit_angle_bracketed_parameters_from_segment_to_substs( + fcx, space, type_defs, region_defs, data, substs); + } + + ast::ParenthesizedParameters(ref data) => { + push_explicit_parenthesized_parameters_from_segment_to_substs( + fcx, space, span, type_defs, data, substs); + } + } + } + + fn push_explicit_angle_bracketed_parameters_from_segment_to_substs( + fcx: &FnCtxt, + space: subst::ParamSpace, + type_defs: &VecPerParamSpace, + region_defs: &VecPerParamSpace, + data: &ast::AngleBracketedParameterData, + substs: &mut Substs) + { { let type_count = type_defs.len(space); assert_eq!(substs.types.len(space), 0); - for (i, typ) in segment.types.iter().enumerate() { + for (i, typ) in data.types.iter().enumerate() { let t = fcx.to_ty(&**typ); if i < type_count { substs.types.push(space, t); @@ -5424,7 +5444,7 @@ pub fn instantiate_path(fcx: &FnCtxt, "too many type parameters provided: \ expected at most {} parameter(s), \ found {} parameter(s)", - type_count, segment.types.len()); + type_count, data.types.len()); substs.types.truncate(space, 0); } } @@ -5433,7 +5453,7 @@ pub fn instantiate_path(fcx: &FnCtxt, { let region_count = region_defs.len(space); assert_eq!(substs.regions().len(space), 0); - for (i, lifetime) in segment.lifetimes.iter().enumerate() { + for (i, lifetime) in data.lifetimes.iter().enumerate() { let r = ast_region_to_region(fcx.tcx(), lifetime); if i < region_count { substs.mut_regions().push(space, r); @@ -5442,13 +5462,59 @@ pub fn instantiate_path(fcx: &FnCtxt, "too many lifetime parameters provided: \ expected {} parameter(s), found {} parameter(s)", region_count, - segment.lifetimes.len()); + data.lifetimes.len()); substs.mut_regions().truncate(space, 0); } } } } + fn push_explicit_parenthesized_parameters_from_segment_to_substs( + fcx: &FnCtxt, + space: subst::ParamSpace, + span: Span, + type_defs: &VecPerParamSpace, + data: &ast::ParenthesizedParameterData, + substs: &mut Substs) + { + /*! + * As with + * `push_explicit_angle_bracketed_parameters_from_segment_to_substs`, + * but intended for `Foo(A,B) -> C` form. This expands to + * roughly the same thing as `Foo<(A,B),C>`. One important + * difference has to do with the treatment of anonymous + * regions, which are translated into bound regions (NYI). + */ + + let type_count = type_defs.len(space); + if type_count < 2 { + span_err!(fcx.tcx().sess, span, E0167, + "parenthesized form always supplies 2 type parameters, \ + but only {} parameter(s) were expected", + type_count); + } + + let input_tys: Vec = + data.inputs.iter().map(|ty| fcx.to_ty(&**ty)).collect(); + + let tuple_ty = + ty::mk_tup_or_nil(fcx.tcx(), input_tys); + + if type_count >= 1 { + substs.types.push(space, tuple_ty); + } + + let output_ty: Option = + data.output.as_ref().map(|ty| fcx.to_ty(&**ty)); + + let output_ty = + output_ty.unwrap_or(ty::mk_nil()); + + if type_count >= 2 { + substs.types.push(space, output_ty); + } + } + fn adjust_type_parameters( fcx: &FnCtxt, span: Span, diff --git a/src/librustc/middle/typeck/collect.rs b/src/librustc/middle/typeck/collect.rs index 0374a64261f..7a26cc51114 100644 --- a/src/librustc/middle/typeck/collect.rs +++ b/src/librustc/middle/typeck/collect.rs @@ -1340,7 +1340,8 @@ pub fn instantiate_trait_ref<'tcx,AC>(this: &AC, trait_did, Some(self_ty), associated_type, - &ast_trait_ref.path); + &ast_trait_ref.path, + ast_trait_ref.ref_id); this.tcx().trait_refs.borrow_mut().insert(ast_trait_ref.ref_id, trait_ref.clone()); diff --git a/src/librustc/middle/typeck/infer/error_reporting.rs b/src/librustc/middle/typeck/infer/error_reporting.rs index bfa0f94a747..64efae486b7 100644 --- a/src/librustc/middle/typeck/infer/error_reporting.rs +++ b/src/librustc/middle/typeck/infer/error_reporting.rs @@ -1108,7 +1108,8 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> { &ast::TraitTyParamBound(ref tr) => { let last_seg = tr.path.segments.last().unwrap(); let mut insert = Vec::new(); - for (i, lt) in last_seg.lifetimes.iter().enumerate() { + let lifetimes = last_seg.parameters.lifetimes(); + for (i, lt) in lifetimes.iter().enumerate() { if region_names.contains(<.name) { insert.push(i); } @@ -1116,7 +1117,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> { let rebuild_info = RebuildPathInfo { path: &tr.path, indexes: insert, - expected: last_seg.lifetimes.len(), + expected: lifetimes.len(), anon_nums: &HashSet::new(), region_names: region_names }; @@ -1257,7 +1258,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> { let expected = generics.regions.len(subst::TypeSpace); let lifetimes = - &path.segments.last().unwrap().lifetimes; + path.segments.last().unwrap().parameters.lifetimes(); let mut insert = Vec::new(); if lifetimes.len() == 0 { let anon = self.cur_anon.get(); @@ -1357,7 +1358,8 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> { fn rebuild_path(&self, rebuild_info: RebuildPathInfo, lifetime: ast::Lifetime) - -> ast::Path { + -> ast::Path + { let RebuildPathInfo { path, indexes, @@ -1367,37 +1369,48 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> { } = rebuild_info; let last_seg = path.segments.last().unwrap(); - let mut new_lts = Vec::new(); - if last_seg.lifetimes.len() == 0 { - // traverse once to see if there's a need to insert lifetime - let need_insert = range(0, expected).any(|i| { - indexes.contains(&i) - }); - if need_insert { - for i in range(0, expected) { - if indexes.contains(&i) { - new_lts.push(lifetime); - } else { - new_lts.push(self.life_giver.give_lifetime()); + let new_parameters = match last_seg.parameters { + ast::ParenthesizedParameters(..) => { + last_seg.parameters.clone() + } + + ast::AngleBracketedParameters(ref data) => { + let mut new_lts = Vec::new(); + if data.lifetimes.len() == 0 { + // traverse once to see if there's a need to insert lifetime + let need_insert = range(0, expected).any(|i| { + indexes.contains(&i) + }); + if need_insert { + for i in range(0, expected) { + if indexes.contains(&i) { + new_lts.push(lifetime); + } else { + new_lts.push(self.life_giver.give_lifetime()); + } + } } - } - } - } else { - for (i, lt) in last_seg.lifetimes.iter().enumerate() { - if indexes.contains(&i) { - new_lts.push(lifetime); } else { - new_lts.push(*lt); + for (i, lt) in data.lifetimes.iter().enumerate() { + if indexes.contains(&i) { + new_lts.push(lifetime); + } else { + new_lts.push(*lt); + } + } } + let new_types = data.types.map(|t| { + self.rebuild_arg_ty_or_output(&**t, lifetime, anon_nums, region_names) + }); + ast::AngleBracketedParameters(ast::AngleBracketedParameterData { + lifetimes: new_lts, + types: new_types + }) } - } - let new_types = last_seg.types.map(|t| { - self.rebuild_arg_ty_or_output(&**t, lifetime, anon_nums, region_names) - }); + }; let new_seg = ast::PathSegment { identifier: last_seg.identifier, - lifetimes: new_lts, - types: new_types, + parameters: new_parameters }; let mut new_segs = Vec::new(); new_segs.push_all(path.segments.init()); diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index f96b3916f06..cfd183b4c45 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1641,10 +1641,23 @@ pub struct PathSegment { impl Clean for ast::PathSegment { fn clean(&self, cx: &DocContext) -> PathSegment { + let (lifetimes, types) = match self.parameters { + ast::AngleBracketedParameters(ref data) => { + (data.lifetimes.clean(cx), data.types.clean(cx)) + } + + ast::ParenthesizedParameters(ref data) => { + // FIXME -- rustdoc should be taught about Foo() notation + let inputs = Tuple(data.inputs.clean(cx)); + let output = data.output.as_ref().map(|t| t.clean(cx)).unwrap_or(Tuple(Vec::new())); + (Vec::new(), vec![inputs, output]) + } + }; + PathSegment { name: self.identifier.clean(cx), - lifetimes: self.lifetimes.clean(cx), - types: self.types.clean(cx), + lifetimes: lifetimes, + types: types, } } } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 078e393eb28..a2089a3e2a3 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -171,7 +171,7 @@ pub struct Path { /// module (like paths in an import). pub global: bool, /// The segments in the path: the things separated by `::`. - pub segments: Vec , + pub segments: Vec, } /// A segment of a path: an identifier, an optional lifetime, and a set of @@ -180,12 +180,107 @@ pub struct Path { pub struct PathSegment { /// The identifier portion of this path segment. pub identifier: Ident, + + /// Type/lifetime parameters attached to this path. They come in + /// two flavors: `Path` and `Path(A,B) -> C`. Note that + /// this is more than just simple syntactic sugar; the use of + /// parens affects the region binding rules, so we preserve the + /// distinction. + pub parameters: PathParameters, +} + +#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +pub enum PathParameters { + AngleBracketedParameters(AngleBracketedParameterData), + ParenthesizedParameters(ParenthesizedParameterData), +} + +impl PathParameters { + pub fn none() -> PathParameters { + AngleBracketedParameters(AngleBracketedParameterData { + lifetimes: Vec::new(), + types: OwnedSlice::empty(), + }) + } + + pub fn is_empty(&self) -> bool { + match *self { + AngleBracketedParameters(ref data) => data.is_empty(), + + // Even if the user supplied no types, something like + // `X()` is equivalent to `X<(),()>`. + ParenthesizedParameters(..) => false, + } + } + + pub fn has_lifetimes(&self) -> bool { + match *self { + AngleBracketedParameters(ref data) => !data.lifetimes.is_empty(), + ParenthesizedParameters(_) => false, + } + } + + pub fn has_types(&self) -> bool { + match *self { + AngleBracketedParameters(ref data) => !data.types.is_empty(), + ParenthesizedParameters(..) => true, + } + } + + pub fn types(&self) -> Vec<&P> { + /*! + * Returns the types that the user wrote. Note that these do not + * necessarily map to the type parameters in the parenthesized case. + */ + match *self { + AngleBracketedParameters(ref data) => { + data.types.iter().collect() + } + ParenthesizedParameters(ref data) => { + data.inputs.iter() + .chain(data.output.iter()) + .collect() + } + } + } + + pub fn lifetimes(&self) -> Vec<&Lifetime> { + match *self { + AngleBracketedParameters(ref data) => { + data.lifetimes.iter().collect() + } + ParenthesizedParameters(_) => { + Vec::new() + } + } + } +} + +/// A path like `Foo<'a, T>` +#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +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>, } +impl AngleBracketedParameterData { + fn is_empty(&self) -> bool { + self.lifetimes.is_empty() && self.types.is_empty() + } +} + +/// A path like `Foo(A,B) -> C` +#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +pub struct ParenthesizedParameterData { + /// `(A,B)` + pub inputs: Vec>, + + /// `C` + pub output: Option>, +} + pub type CrateNum = u32; pub type NodeId = u32; diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 3aa60236d70..2e3a15bfd4b 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -171,8 +171,10 @@ pub fn ident_to_path(s: Span, identifier: Ident) -> Path { segments: vec!( ast::PathSegment { identifier: identifier, - lifetimes: Vec::new(), - types: OwnedSlice::empty(), + parameters: ast::AngleBracketedParameters(ast::AngleBracketedParameterData { + lifetimes: Vec::new(), + types: OwnedSlice::empty(), + }) } ), } @@ -681,11 +683,11 @@ pub fn segments_name_eq(a : &[ast::PathSegment], b : &[ast::PathSegment]) -> boo false } else { for (idx,seg) in a.iter().enumerate() { - if (seg.identifier.name != b[idx].identifier.name) + if seg.identifier.name != b[idx].identifier.name // FIXME #7743: ident -> name problems in lifetime comparison? - || (seg.lifetimes != b[idx].lifetimes) // can types contain idents? - || (seg.types != b[idx].types) { + || seg.parameters != b[idx].parameters + { return false; } } @@ -747,12 +749,10 @@ impl PostExpansionMethod for Method { mod test { use ast::*; use super::*; - use owned_slice::OwnedSlice; fn ident_to_segment(id : &Ident) -> PathSegment { - PathSegment {identifier:id.clone(), - lifetimes: Vec::new(), - types: OwnedSlice::empty()} + PathSegment {identifier: id.clone(), + parameters: PathParameters::none()} } #[test] fn idents_name_eq_test() { diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index dc4eaf7d7ad..5921d630b89 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -313,14 +313,15 @@ impl<'a> AstBuilder for ExtCtxt<'a> { .map(|ident| { ast::PathSegment { identifier: ident, - lifetimes: Vec::new(), - types: OwnedSlice::empty(), + parameters: ast::PathParameters::none(), } }).collect(); segments.push(ast::PathSegment { identifier: last_identifier, - lifetimes: lifetimes, - types: OwnedSlice::from_vec(types), + parameters: ast::AngleBracketedParameters(ast::AngleBracketedParameterData { + lifetimes: lifetimes, + types: OwnedSlice::from_vec(types), + }) }); ast::Path { span: sp, diff --git a/src/libsyntax/ext/concat_idents.rs b/src/libsyntax/ext/concat_idents.rs index e5e93a7d8b3..aa18b1be31a 100644 --- a/src/libsyntax/ext/concat_idents.rs +++ b/src/libsyntax/ext/concat_idents.rs @@ -12,7 +12,6 @@ use ast; use codemap::Span; use ext::base::*; use ext::base; -use owned_slice::OwnedSlice; use parse::token; use parse::token::{str_to_ident}; use ptr::P; @@ -52,8 +51,7 @@ pub fn expand_syntax_ext<'cx>(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree] segments: vec!( ast::PathSegment { identifier: res, - lifetimes: Vec::new(), - types: OwnedSlice::empty(), + parameters: ast::PathParameters::none(), } ) } diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 6535c8e89fd..79e2c656e41 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -166,6 +166,22 @@ pub trait Folder { noop_fold_path(p, self) } + fn fold_path_parameters(&mut self, p: PathParameters) -> PathParameters { + noop_fold_path_parameters(p, self) + } + + fn fold_angle_bracketed_parameter_data(&mut self, p: AngleBracketedParameterData) + -> AngleBracketedParameterData + { + noop_fold_angle_bracketed_parameter_data(p, self) + } + + fn fold_parenthesized_parameter_data(&mut self, p: ParenthesizedParameterData) + -> ParenthesizedParameterData + { + noop_fold_parenthesized_parameter_data(p, self) + } + fn fold_local(&mut self, l: P) -> P { noop_fold_local(l, self) } @@ -480,15 +496,43 @@ pub fn noop_fold_uint(i: uint, _: &mut T) -> uint { pub fn noop_fold_path(Path {global, segments, span}: Path, fld: &mut T) -> Path { Path { global: global, - segments: segments.move_map(|PathSegment {identifier, lifetimes, types}| PathSegment { + segments: segments.move_map(|PathSegment {identifier, parameters}| PathSegment { identifier: fld.fold_ident(identifier), - lifetimes: fld.fold_lifetimes(lifetimes), - types: types.move_map(|typ| fld.fold_ty(typ)), + parameters: fld.fold_path_parameters(parameters), }), span: fld.new_span(span) } } +pub fn noop_fold_path_parameters(path_parameters: PathParameters, fld: &mut T) + -> PathParameters +{ + match path_parameters { + AngleBracketedParameters(data) => + AngleBracketedParameters(fld.fold_angle_bracketed_parameter_data(data)), + ParenthesizedParameters(data) => + ParenthesizedParameters(fld.fold_parenthesized_parameter_data(data)), + } +} + +pub fn noop_fold_angle_bracketed_parameter_data(data: AngleBracketedParameterData, + fld: &mut T) + -> AngleBracketedParameterData +{ + let AngleBracketedParameterData { lifetimes, types } = data; + AngleBracketedParameterData { lifetimes: fld.fold_lifetimes(lifetimes), + types: types.move_map(|ty| fld.fold_ty(ty)) } +} + +pub fn noop_fold_parenthesized_parameter_data(data: ParenthesizedParameterData, + fld: &mut T) + -> ParenthesizedParameterData +{ + let ParenthesizedParameterData { inputs, output } = data; + ParenthesizedParameterData { inputs: inputs.move_map(|ty| fld.fold_ty(ty)), + output: output.map(|ty| fld.fold_ty(ty)) } +} + pub fn noop_fold_local(l: P, fld: &mut T) -> P { l.map(|Local {id, pat, ty, init, source, span}| Local { id: fld.new_id(id), diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 83499ec54c6..996708b2174 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -749,8 +749,7 @@ mod test { segments: vec!( ast::PathSegment { identifier: str_to_ident("a"), - lifetimes: Vec::new(), - types: OwnedSlice::empty(), + parameters: ast::PathParameters::none(), } ), }), @@ -768,13 +767,11 @@ mod test { segments: vec!( ast::PathSegment { identifier: str_to_ident("a"), - lifetimes: Vec::new(), - types: OwnedSlice::empty(), + parameters: ast::PathParameters::none(), }, ast::PathSegment { identifier: str_to_ident("b"), - lifetimes: Vec::new(), - types: OwnedSlice::empty(), + parameters: ast::PathParameters::none(), } ) }), @@ -952,8 +949,7 @@ mod test { segments: vec!( ast::PathSegment { identifier: str_to_ident("d"), - lifetimes: Vec::new(), - types: OwnedSlice::empty(), + parameters: ast::PathParameters::none(), } ), }), @@ -974,8 +970,7 @@ mod test { segments: vec!( ast::PathSegment { identifier: str_to_ident("b"), - lifetimes: Vec::new(), - types: OwnedSlice::empty(), + parameters: ast::PathParameters::none(), } ), }), @@ -1022,8 +1017,7 @@ mod test { ast::PathSegment { identifier: str_to_ident("int"), - lifetimes: Vec::new(), - types: OwnedSlice::empty(), + parameters: ast::PathParameters::none(), } ), }, None, ast::DUMMY_NODE_ID), @@ -1072,10 +1066,8 @@ mod test { identifier: str_to_ident( "b"), - lifetimes: - Vec::new(), - types: - OwnedSlice::empty() + parameters: + ast::PathParameters::none(), } ), }), diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index fd244a443a8..1c65a47350e 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1487,9 +1487,9 @@ impl<'a> Parser<'a> { trait_name: trait_name.path, item_name: item_name, })) - } else if self.token == token::ModSep - || self.token.is_ident() - || self.token.is_path() { + } else if self.token == token::ModSep || + self.token.is_ident() || + self.token.is_path() { // NAMED TYPE let mode = if plus_allowed { LifetimeAndTypesAndBounds @@ -1771,27 +1771,36 @@ impl<'a> Parser<'a> { let identifier = self.parse_ident(); // Parse types, optionally. - let (lifetimes, types) = if self.eat_lt(false) { - self.parse_generic_values_after_lt() - } else if false && self.eat(&token::LParen) { - let mut types = self.parse_seq_to_end( - &token::RParen, + let parameters = if self.eat_lt(false) { + let (lifetimes, types) = self.parse_generic_values_after_lt(); + + ast::AngleBracketedParameters(ast::AngleBracketedParameterData { + lifetimes: lifetimes, + types: OwnedSlice::from_vec(types), + }) + } else if self.eat(&token::OpenDelim(token::Paren)) { + let inputs = self.parse_seq_to_end( + &token::CloseDelim(token::Paren), seq_sep_trailing_allowed(token::Comma), |p| p.parse_ty(true)); - if self.eat(&token::RArrow) { - types.push(self.parse_ty(true)) - } + let output_ty = if self.eat(&token::RArrow) { + Some(self.parse_ty(true)) + } else { + None + }; - (Vec::new(), types) + ast::ParenthesizedParameters(ast::ParenthesizedParameterData { + inputs: inputs, + output: output_ty + }) } else { - (Vec::new(), Vec::new()) + ast::PathParameters::none() }; // Assemble and push the result. segments.push(ast::PathSegment { identifier: identifier, - lifetimes: lifetimes, - types: OwnedSlice::from_vec(types), }); + parameters: parameters }); // Continue only if we see a `::` if !self.eat(&token::ModSep) { @@ -1810,9 +1819,13 @@ impl<'a> Parser<'a> { // If we do not see a `::`, stop. if !self.eat(&token::ModSep) { - segments.push(ast::PathSegment { identifier: identifier, - lifetimes: Vec::new(), - types: OwnedSlice::empty() }); + segments.push(ast::PathSegment { + identifier: identifier, + parameters: ast::AngleBracketedParameters(ast::AngleBracketedParameterData { + lifetimes: Vec::new(), + types: OwnedSlice::empty(), + }) + }); return segments; } @@ -1820,9 +1833,13 @@ impl<'a> Parser<'a> { if self.eat_lt(false) { // Consumed `a::b::<`, go look for types let (lifetimes, types) = self.parse_generic_values_after_lt(); - segments.push(ast::PathSegment { identifier: identifier, - lifetimes: lifetimes, - types: OwnedSlice::from_vec(types) }); + segments.push(ast::PathSegment { + identifier: identifier, + parameters: ast::AngleBracketedParameters(ast::AngleBracketedParameterData { + lifetimes: lifetimes, + types: OwnedSlice::from_vec(types), + }), + }); // Consumed `a::b::`, check for `::` before proceeding if !self.eat(&token::ModSep) { @@ -1830,9 +1847,10 @@ impl<'a> Parser<'a> { } } else { // Consumed `a::`, go look for `b` - segments.push(ast::PathSegment { identifier: identifier, - lifetimes: Vec::new(), - types: OwnedSlice::empty() }); + segments.push(ast::PathSegment { + identifier: identifier, + parameters: ast::PathParameters::none(), + }); } } } @@ -1847,9 +1865,10 @@ impl<'a> Parser<'a> { let identifier = self.parse_ident(); // Assemble and push the result. - segments.push(ast::PathSegment { identifier: identifier, - lifetimes: Vec::new(), - types: OwnedSlice::empty(), }); + segments.push(ast::PathSegment { + identifier: identifier, + parameters: ast::PathParameters::none() + }); // If we do not see a `::`, stop. if !self.eat(&token::ModSep) { @@ -3455,13 +3474,9 @@ impl<'a> Parser<'a> { }, _ => { if !enum_path.global && - enum_path.segments.len() == 1 && - enum_path.segments[0] - .lifetimes - .len() == 0 && - enum_path.segments[0] - .types - .len() == 0 { + enum_path.segments.len() == 1 && + enum_path.segments[0].parameters.is_empty() + { // it could still be either an enum // or an identifier pattern, resolve // will sort it out: @@ -3960,8 +3975,7 @@ impl<'a> Parser<'a> { fn trait_ref_from_ident(ident: Ident, span: Span) -> ast::TraitRef { let segment = ast::PathSegment { identifier: ident, - lifetimes: Vec::new(), - types: OwnedSlice::empty(), + parameters: ast::PathParameters::none() }; let path = ast::Path { span: span, @@ -5677,8 +5691,7 @@ impl<'a> Parser<'a> { segments: path.into_iter().map(|identifier| { ast::PathSegment { identifier: identifier, - lifetimes: Vec::new(), - types: OwnedSlice::empty(), + parameters: ast::PathParameters::none(), } }).collect() }; @@ -5712,8 +5725,7 @@ impl<'a> Parser<'a> { segments: path.into_iter().map(|identifier| { ast::PathSegment { identifier: identifier, - lifetimes: Vec::new(), - types: OwnedSlice::empty(), + parameters: ast::PathParameters::none(), } }).collect() }; @@ -5730,8 +5742,7 @@ impl<'a> Parser<'a> { segments: path.into_iter().map(|identifier| { ast::PathSegment { identifier: identifier, - lifetimes: Vec::new(), - types: OwnedSlice::empty(), + parameters: ast::PathParameters::none(), } }).collect() }; @@ -5752,8 +5763,7 @@ impl<'a> Parser<'a> { segments: path.into_iter().map(|identifier| { ast::PathSegment { identifier: identifier, - lifetimes: Vec::new(), - types: OwnedSlice::empty(), + parameters: ast::PathParameters::none(), } }).collect() }; diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 106e3f1faae..d83ea5f76b1 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1995,14 +1995,34 @@ impl<'a> State<'a> { try!(self.print_ident(segment.identifier)); - if !segment.lifetimes.is_empty() || !segment.types.is_empty() { - if colons_before_params { - try!(word(&mut self.s, "::")) - } + try!(self.print_path_parameters(&segment.parameters, colons_before_params)); + } + + match *opt_bounds { + None => Ok(()), + Some(ref bounds) => self.print_bounds("+", bounds) + } + } + + fn print_path_parameters(&mut self, + parameters: &ast::PathParameters, + colons_before_params: bool) + -> IoResult<()> + { + if parameters.is_empty() { + return Ok(()); + } + + if colons_before_params { + try!(word(&mut self.s, "::")) + } + + match *parameters { + ast::AngleBracketedParameters(ref data) => { try!(word(&mut self.s, "<")); let mut comma = false; - for lifetime in segment.lifetimes.iter() { + for lifetime in data.lifetimes.iter() { if comma { try!(self.word_space(",")) } @@ -2010,24 +2030,38 @@ impl<'a> State<'a> { comma = true; } - if !segment.types.is_empty() { + if !data.types.is_empty() { if comma { try!(self.word_space(",")) } try!(self.commasep( Inconsistent, - segment.types.as_slice(), + data.types.as_slice(), |s, ty| s.print_type(&**ty))); } try!(word(&mut self.s, ">")) } - } - match *opt_bounds { - None => Ok(()), - Some(ref bounds) => self.print_bounds("+", bounds) + ast::ParenthesizedParameters(ref data) => { + try!(word(&mut self.s, "(")); + try!(self.commasep( + Inconsistent, + data.inputs.as_slice(), + |s, ty| s.print_type(&**ty))); + try!(word(&mut self.s, ")")); + + match data.output { + None => { } + Some(ref ty) => { + try!(self.word_space("->")); + try!(self.print_type(&**ty)); + } + } + } } + + Ok(()) } fn print_path(&mut self, path: &ast::Path, diff --git a/src/libsyntax/std_inject.rs b/src/libsyntax/std_inject.rs index 0f86fb751da..6a4ab365a50 100644 --- a/src/libsyntax/std_inject.rs +++ b/src/libsyntax/std_inject.rs @@ -14,7 +14,6 @@ use codemap::DUMMY_SP; use codemap; use fold::Folder; use fold; -use owned_slice::OwnedSlice; use parse::token::InternedString; use parse::token::special_idents; use parse::token; @@ -181,13 +180,11 @@ impl<'a> fold::Folder for PreludeInjector<'a> { segments: vec!( ast::PathSegment { identifier: token::str_to_ident("std"), - lifetimes: Vec::new(), - types: OwnedSlice::empty(), + parameters: ast::PathParameters::none(), }, ast::PathSegment { identifier: token::str_to_ident("prelude"), - lifetimes: Vec::new(), - types: OwnedSlice::empty(), + parameters: ast::PathParameters::none(), }), }; diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs index 37586f6abd7..a7db8e800a9 100644 --- a/src/libsyntax/test.rs +++ b/src/libsyntax/test.rs @@ -453,8 +453,7 @@ fn path_node(ids: Vec ) -> ast::Path { global: false, segments: ids.into_iter().map(|identifier| ast::PathSegment { identifier: identifier, - lifetimes: Vec::new(), - types: OwnedSlice::empty(), + parameters: ast::PathParameters::none(), }).collect() } } diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 86ee23d71a6..b4141af0733 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -407,11 +407,23 @@ pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path) { for segment in path.segments.iter() { visitor.visit_ident(path.span, segment.identifier); - for typ in segment.types.iter() { - visitor.visit_ty(&**typ); - } - for lifetime in segment.lifetimes.iter() { - visitor.visit_lifetime_ref(lifetime); + match segment.parameters { + ast::AngleBracketedParameters(ref data) => { + for typ in data.types.iter() { + visitor.visit_ty(&**typ); + } + for lifetime in data.lifetimes.iter() { + visitor.visit_lifetime_ref(lifetime); + } + } + ast::ParenthesizedParameters(ref data) => { + for typ in data.inputs.iter() { + visitor.visit_ty(&**typ); + } + for typ in data.output.iter() { + visitor.visit_ty(&**typ); + } + } } } } diff --git a/src/test/compile-fail/issue-14092.rs b/src/test/compile-fail/issue-14092.rs index 4d663d00fb2..0ab37a88826 100644 --- a/src/test/compile-fail/issue-14092.rs +++ b/src/test/compile-fail/issue-14092.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn fn1(0: Box) {} //~ ERROR: not enough type parameters supplied to `Box` +fn fn1(0: Box) {} //~ ERROR: wrong number of type arguments: expected 1, found 0 fn main() {} diff --git a/src/test/compile-fail/issue-18423.rs b/src/test/compile-fail/issue-18423.rs new file mode 100644 index 00000000000..63b110b5579 --- /dev/null +++ b/src/test/compile-fail/issue-18423.rs @@ -0,0 +1,18 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test that `Box` cannot be used with a lifetime parameter. + +struct Foo<'a> { + x: Box<'a, int> //~ ERROR wrong number of lifetime parameters +} + +pub fn main() { +} diff --git a/src/test/compile-fail/unboxed-closure-sugar-default.rs b/src/test/compile-fail/unboxed-closure-sugar-default.rs new file mode 100644 index 00000000000..9866a200045 --- /dev/null +++ b/src/test/compile-fail/unboxed-closure-sugar-default.rs @@ -0,0 +1,37 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test interaction between unboxed closure sugar and default type +// parameters (should be exactly as if angle brackets were used). + +#![feature(default_type_params)] +#![allow(dead_code)] + +struct Foo { + t: T, u: U +} + +trait Eq { } +impl Eq for X { } +fn eq>() { } + +fn test<'a,'b>() { + // Parens are equivalent to omitting default in angle. + eq::< Foo<(int,),()>, Foo(int) >(); + + // In angle version, we supply something other than the default + eq::< Foo<(int,),(),int>, Foo(int) >(); + //~^ ERROR not implemented + + // Supply default explicitly. + eq::< Foo<(int,),(),(int,)>, Foo(int) >(); +} + +fn main() { } diff --git a/src/test/compile-fail/unboxed-closure-sugar-equiv.rs b/src/test/compile-fail/unboxed-closure-sugar-equiv.rs new file mode 100644 index 00000000000..c38010c1ee2 --- /dev/null +++ b/src/test/compile-fail/unboxed-closure-sugar-equiv.rs @@ -0,0 +1,39 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test that the unboxed closure sugar can be used with an arbitrary +// struct type and that it is equivalent to the same syntax using +// angle brackets. This test covers only simple types and in +// particular doesn't test bound regions. + +#![allow(dead_code)] + +struct Foo { + t: T, u: U +} + +trait Eq { } +impl Eq for X { } +fn eq>() { } + +fn test<'a,'b>() { + // No errors expected: + eq::< Foo<(),()>, Foo() >(); + eq::< Foo<(int,),()>, Foo(int) >(); + eq::< Foo<(int,uint),()>, Foo(int,uint) >(); + eq::< Foo<(int,uint),uint>, Foo(int,uint) -> uint >(); + eq::< Foo<(&'a int,&'b uint),uint>, Foo(&'a int,&'b uint) -> uint >(); + + // Errors expected: + eq::< Foo<(),()>, Foo(char) >(); + //~^ ERROR not implemented +} + +fn main() { } diff --git a/src/test/compile-fail/unboxed-closure-sugar-nonexistent-trait.rs b/src/test/compile-fail/unboxed-closure-sugar-nonexistent-trait.rs index f51160a1b23..d89c3802508 100644 --- a/src/test/compile-fail/unboxed-closure-sugar-nonexistent-trait.rs +++ b/src/test/compile-fail/unboxed-closure-sugar-nonexistent-trait.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn f int>(x: F) {} //~ ERROR unresolved trait +fn f int>(x: F) {} //~ ERROR nonexistent trait `Nonexist` type Typedef = int; diff --git a/src/test/compile-fail/unboxed-closure-sugar-region.rs b/src/test/compile-fail/unboxed-closure-sugar-region.rs new file mode 100644 index 00000000000..962e233dea6 --- /dev/null +++ b/src/test/compile-fail/unboxed-closure-sugar-region.rs @@ -0,0 +1,45 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test interaction between unboxed closure sugar and region +// parameters (should be exactly as if angle brackets were used +// and regions omitted). + +#![feature(default_type_params)] +#![allow(dead_code)] + +use std::kinds::marker; + +struct Foo<'a,T,U> { + t: T, + u: U, + m: marker::InvariantLifetime<'a> +} + +trait Eq { } +impl Eq for X { } +fn eq>() { } +fn same_type>(a: A, b: B) { } + +fn test<'a,'b>() { + // Parens are equivalent to omitting default in angle. + eq::< Foo<(int,),()>, Foo(int) >(); + + // Here we specify 'static explicitly in angle-bracket version. + // Parenthesized winds up getting inferred. + eq::< Foo<'static, (int,),()>, Foo(int) >(); +} + +fn test2(x: Foo<(int,),()>, y: Foo(int)) { + // Here, the omitted lifetimes are expanded to distinct things. + same_type(x, y) //~ ERROR cannot infer +} + +fn main() { } diff --git a/src/test/compile-fail/unboxed-closure-sugar-wrong-number-number-type-parameters-1.rs b/src/test/compile-fail/unboxed-closure-sugar-wrong-number-number-type-parameters-1.rs new file mode 100644 index 00000000000..e122b87b1e0 --- /dev/null +++ b/src/test/compile-fail/unboxed-closure-sugar-wrong-number-number-type-parameters-1.rs @@ -0,0 +1,16 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +struct One; + +fn foo(_: One()) //~ ERROR wrong number of type arguments +{} + +fn main() { } diff --git a/src/test/compile-fail/unboxed-closure-sugar-wrong-number-number-type-parameters-3.rs b/src/test/compile-fail/unboxed-closure-sugar-wrong-number-number-type-parameters-3.rs new file mode 100644 index 00000000000..7a66abb39df --- /dev/null +++ b/src/test/compile-fail/unboxed-closure-sugar-wrong-number-number-type-parameters-3.rs @@ -0,0 +1,16 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +struct Three; + +fn foo(_: Three()) //~ ERROR wrong number of type arguments +{} + +fn main() { } diff --git a/src/test/compile-fail/unboxed-closure-sugar-wrong-number-number-type-parameters.rs b/src/test/compile-fail/unboxed-closure-sugar-wrong-number-number-type-parameters.rs new file mode 100644 index 00000000000..e265a3d56b8 --- /dev/null +++ b/src/test/compile-fail/unboxed-closure-sugar-wrong-number-number-type-parameters.rs @@ -0,0 +1,16 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +struct Zero; + +fn foo(_: Zero()) //~ ERROR wrong number of type arguments +{} + +fn main() { } diff --git a/src/test/compile-fail/unboxed-closure-sugar-wrong-trait.rs b/src/test/compile-fail/unboxed-closure-sugar-wrong-trait.rs index a751ae1c518..1394f8fa65f 100644 --- a/src/test/compile-fail/unboxed-closure-sugar-wrong-trait.rs +++ b/src/test/compile-fail/unboxed-closure-sugar-wrong-trait.rs @@ -11,7 +11,7 @@ trait Trait {} fn f int>(x: F) {} -//~^ ERROR unboxed function trait must be one of `Fn`, `FnMut`, or `FnOnce` +//~^ ERROR wrong number of type arguments: expected 0, found 2 fn main() {} diff --git a/src/test/run-pass/unboxed-closures-prelude.rs b/src/test/run-pass/unboxed-closures-prelude.rs index 4226ed427e7..f9d2ba02123 100644 --- a/src/test/run-pass/unboxed-closures-prelude.rs +++ b/src/test/run-pass/unboxed-closures-prelude.rs @@ -13,7 +13,7 @@ #![feature(unboxed_closures, unboxed_closure_sugar)] fn main() { - let task: Box<|: int| -> int> = box |: x| x; + let task: Box int> = box |: x| x; task.call_once((0i, )); } diff --git a/src/test/run-pass/unboxed-closures-sugar-1.rs b/src/test/run-pass/unboxed-closures-sugar-1.rs new file mode 100644 index 00000000000..b358e7ce288 --- /dev/null +++ b/src/test/run-pass/unboxed-closures-sugar-1.rs @@ -0,0 +1,34 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test that the unboxed closure sugar can be used with an arbitrary +// struct type and that it is equivalent to the same syntax using +// angle brackets. This test covers only simple types and in +// particular doesn't test bound regions. + +#![allow(dead_code)] + +struct Foo { + t: T, u: U +} + +trait Eq { } +impl Eq for X { } +fn eq>() { } + +fn test<'a,'b>() { + eq::< Foo<(),()>, Foo() >(); + eq::< Foo<(int,),()>, Foo(int) >(); + eq::< Foo<(int,uint),()>, Foo(int,uint) >(); + eq::< Foo<(int,uint),uint>, Foo(int,uint) -> uint >(); + eq::< Foo<(&'a int,&'b uint),uint>, Foo(&'a int,&'b uint) -> uint >(); +} + +fn main() { } diff --git a/src/test/run-pass/unboxed-closures-sugar-object.rs b/src/test/run-pass/unboxed-closures-sugar-object.rs new file mode 100644 index 00000000000..3b38f72432f --- /dev/null +++ b/src/test/run-pass/unboxed-closures-sugar-object.rs @@ -0,0 +1,34 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test unboxed closure sugar used in object types. + +#![allow(dead_code)] + +struct Foo { + t: T, u: U +} + +trait Getter { + fn get(&self, arg: A) -> R; +} + +struct Identity; +impl Getter for Identity { + fn get(&self, arg: X) -> X { + arg + } +} + +fn main() { + let x: &Getter(int) -> (int,) = &Identity; + let (y,) = x.get((22,)); + assert_eq!(y, 22); +} diff --git a/src/test/run-pass/unboxed-closures-unboxing-shim.rs b/src/test/run-pass/unboxed-closures-unboxing-shim.rs index 0a7baa3ba36..426352cadd8 100644 --- a/src/test/run-pass/unboxed-closures-unboxing-shim.rs +++ b/src/test/run-pass/unboxed-closures-unboxing-shim.rs @@ -13,7 +13,7 @@ use std::ops::FnOnce; fn main() { - let task: Box<|: int| -> int> = box |: x| x; + let task: Box int> = box |: x| x; assert!(task.call_once((1234i,)) == 1234i); } -- cgit 1.4.1-3-g733a5 From d0fa4c6239accc08aae11d9db3e13d4153add432 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Tue, 4 Nov 2014 16:25:15 -0500 Subject: Remove the unboxed closure `|:|` notation from types and trait references completely. --- src/librustc/middle/resolve.rs | 37 +----------- src/librustc/middle/resolve_lifetime.rs | 15 ----- src/librustc/middle/save/mod.rs | 2 +- src/librustc/middle/typeck/astconv.rs | 55 +----------------- src/librustc/middle/typeck/collect.rs | 57 +------------------ .../middle/typeck/infer/error_reporting.rs | 3 - src/librustdoc/clean/inline.rs | 1 - src/librustdoc/clean/mod.rs | 17 ------ src/librustdoc/html/format.rs | 6 +- src/libsyntax/ast.rs | 16 ------ src/libsyntax/ast_map/mod.rs | 3 - src/libsyntax/feature_gate.rs | 5 -- src/libsyntax/fold.rs | 23 -------- src/libsyntax/parse/parser.rs | 66 ++++++---------------- src/libsyntax/print/pprust.rs | 56 ++---------------- src/libsyntax/visit.rs | 13 ----- src/test/run-pass/unboxed-closures-manual-impl.rs | 2 +- 17 files changed, 29 insertions(+), 348 deletions(-) (limited to 'src/libsyntax') diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 34f0cb7c198..0420506d001 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -40,7 +40,7 @@ use syntax::ast::{TupleVariantKind, Ty, TyBool, TyChar, TyClosure, TyF32}; use syntax::ast::{TyF64, TyFloat, TyI, TyI8, TyI16, TyI32, TyI64, TyInt}; use syntax::ast::{TyParam, TyParamBound, TyPath, TyPtr, TyProc, TyQPath}; use syntax::ast::{TyRptr, TyStr, TyU, TyU8, TyU16, TyU32, TyU64, TyUint}; -use syntax::ast::{TypeImplItem, UnboxedFnTyParamBound, UnnamedField}; +use syntax::ast::{TypeImplItem, UnnamedField}; use syntax::ast::{Variant, ViewItem, ViewItemExternCrate}; use syntax::ast::{ViewItemUse, ViewPathGlob, ViewPathList, ViewPathSimple}; use syntax::ast::{Visibility}; @@ -4523,41 +4523,6 @@ impl<'a> Resolver<'a> { TraitTyParamBound(ref tref) => { self.resolve_trait_reference(id, tref, reference_type) } - UnboxedFnTyParamBound(ref unboxed_function) => { - match self.resolve_path(unboxed_function.ref_id, - &unboxed_function.path, - TypeNS, - true) { - None => { - let path_str = self.path_names_to_string( - &unboxed_function.path); - self.resolve_error(unboxed_function.path.span, - format!("unresolved trait `{}`", - path_str).as_slice()) - } - Some(def) => { - match def { - (DefTrait(_), _) => { - self.record_def(unboxed_function.ref_id, def); - } - _ => { - let msg = - format!("`{}` is not a trait", - self.path_names_to_string( - &unboxed_function.path)); - self.resolve_error(unboxed_function.path.span, - msg.as_slice()); - } - } - } - } - - for argument in unboxed_function.decl.inputs.iter() { - self.resolve_type(&*argument.ty); - } - - self.resolve_type(&*unboxed_function.decl.output); - } RegionTyParamBound(..) => {} } } diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index eda4c241f86..8246970c24a 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -204,9 +204,6 @@ impl<'a> LifetimeContext<'a> { ast::TraitTyParamBound(ref trait_ref) => { self.visit_trait_ref(trait_ref); } - ast::UnboxedFnTyParamBound(ref fn_decl) => { - self.visit_unboxed_fn_ty_param_bound(&**fn_decl); - } ast::RegionTyParamBound(ref lifetime) => { self.visit_lifetime_ref(lifetime); } @@ -226,18 +223,6 @@ impl<'a> LifetimeContext<'a> { }) } - fn visit_unboxed_fn_ty_param_bound(&mut self, - bound: &ast::UnboxedFnBound) { - self.with(|scope, f| { - f(LateScope(bound.ref_id, &bound.lifetimes, scope)) - }, |v| { - for argument in bound.decl.inputs.iter() { - v.visit_ty(&*argument.ty); - } - v.visit_ty(&*bound.decl.output); - }) - } - /// Visits self by adding a scope and handling recursive walk over the contents with `walk`. fn visit_fn_decl(&mut self, n: ast::NodeId, diff --git a/src/librustc/middle/save/mod.rs b/src/librustc/middle/save/mod.rs index 90a21d47903..b64a160ab1f 100644 --- a/src/librustc/middle/save/mod.rs +++ b/src/librustc/middle/save/mod.rs @@ -705,7 +705,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { ast::TraitTyParamBound(ref trait_ref) => { trait_ref } - ast::UnboxedFnTyParamBound(..) | ast::RegionTyParamBound(..) => { + ast::RegionTyParamBound(..) => { continue; } }; diff --git a/src/librustc/middle/typeck/astconv.rs b/src/librustc/middle/typeck/astconv.rs index f2cc3bfd29b..05d315e5fec 100644 --- a/src/librustc/middle/typeck/astconv.rs +++ b/src/librustc/middle/typeck/astconv.rs @@ -620,15 +620,6 @@ enum PointerTy { Uniq } -impl PointerTy { - fn default_region(&self) -> ty::Region { - match *self { - Uniq => ty::ReStatic, - RPtr(r) => r, - } - } -} - pub fn trait_ref_for_unboxed_function<'tcx, AC: AstConv<'tcx>, RS:RegionScope>( this: &AC, @@ -687,31 +678,6 @@ fn mk_pointer<'tcx, AC: AstConv<'tcx>, RS: RegionScope>( let ty = ast_ty_to_ty(this, rscope, &**ty); return constr(ty::mk_vec(tcx, ty, None)); } - ast::TyUnboxedFn(ref unboxed_function) => { - let ty::TraitRef { - def_id, - substs - } = trait_ref_for_unboxed_function(this, - rscope, - unboxed_function.kind, - &*unboxed_function.decl, - None); - let r = ptr_ty.default_region(); - let tr = ty::mk_trait(this.tcx(), - def_id, - substs, - ty::region_existential_bound(r)); - match ptr_ty { - Uniq => { - return ty::mk_uniq(this.tcx(), tr); - } - RPtr(r) => { - return ty::mk_rptr(this.tcx(), - r, - ty::mt {mutbl: a_seq_mutbl, ty: tr}); - } - } - } ast::TyPath(ref path, ref opt_bounds, id) => { // Note that the "bounds must be empty if path is not a trait" // restriction is enforced in the below case for ty_path, which @@ -941,11 +907,6 @@ pub fn ast_ty_to_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>( ty::mk_closure(tcx, fn_decl) } - ast::TyUnboxedFn(..) => { - tcx.sess.span_err(ast_ty.span, - "cannot use unboxed functions here"); - ty::mk_err() - } ast::TyPath(ref path, ref bounds, id) => { let a_def = match tcx.def_map.borrow().find(&id) { None => { @@ -1425,8 +1386,7 @@ pub fn conv_existential_bounds<'tcx, AC: AstConv<'tcx>, RS:RegionScope>( let PartitionedBounds { builtin_bounds, trait_bounds, - region_bounds, - unboxed_fn_ty_bounds } = + region_bounds } = partition_bounds(this.tcx(), span, ast_bound_refs.as_slice()); if !trait_bounds.is_empty() { @@ -1437,13 +1397,6 @@ pub fn conv_existential_bounds<'tcx, AC: AstConv<'tcx>, RS:RegionScope>( as closure or object bounds").as_slice()); } - if !unboxed_fn_ty_bounds.is_empty() { - this.tcx().sess.span_err( - span, - format!("only the builtin traits can be used \ - as closure or object bounds").as_slice()); - } - // The "main trait refs", rather annoyingly, have no type // specified for the `Self` parameter of the trait. The reason for // this is that they are, after all, *existential* types, and @@ -1572,7 +1525,6 @@ fn compute_region_bound<'tcx, AC: AstConv<'tcx>, RS:RegionScope>( pub struct PartitionedBounds<'a> { pub builtin_bounds: ty::BuiltinBounds, pub trait_bounds: Vec<&'a ast::TraitRef>, - pub unboxed_fn_ty_bounds: Vec<&'a ast::UnboxedFnBound>, pub region_bounds: Vec<&'a ast::Lifetime>, } @@ -1590,7 +1542,6 @@ pub fn partition_bounds<'a>(tcx: &ty::ctxt, let mut builtin_bounds = ty::empty_builtin_bounds(); let mut region_bounds = Vec::new(); let mut trait_bounds = Vec::new(); - let mut unboxed_fn_ty_bounds = Vec::new(); let mut trait_def_ids = HashMap::new(); for &ast_bound in ast_bounds.iter() { match *ast_bound { @@ -1635,9 +1586,6 @@ pub fn partition_bounds<'a>(tcx: &ty::ctxt, ast::RegionTyParamBound(ref l) => { region_bounds.push(l); } - ast::UnboxedFnTyParamBound(ref unboxed_function) => { - unboxed_fn_ty_bounds.push(&**unboxed_function); - } } } @@ -1645,7 +1593,6 @@ pub fn partition_bounds<'a>(tcx: &ty::ctxt, builtin_bounds: builtin_bounds, trait_bounds: trait_bounds, region_bounds: region_bounds, - unboxed_fn_ty_bounds: unboxed_fn_ty_bounds } } diff --git a/src/librustc/middle/typeck/collect.rs b/src/librustc/middle/typeck/collect.rs index 7a26cc51114..38de50f6831 100644 --- a/src/librustc/middle/typeck/collect.rs +++ b/src/librustc/middle/typeck/collect.rs @@ -638,7 +638,7 @@ pub fn ensure_no_ty_param_bounds(ccx: &CrateCtxt, let mut bounds = bounds.chain(ty_param.unbound.iter()); for bound in bounds { match *bound { - ast::TraitTyParamBound(..) | ast::UnboxedFnTyParamBound(..) => { + ast::TraitTyParamBound(..) => { // According to accepted RFC #XXX, we should // eventually accept these, but it will not be // part of this PR. Still, convert to warning to @@ -1356,20 +1356,6 @@ pub fn instantiate_trait_ref<'tcx,AC>(this: &AC, } } -pub fn instantiate_unboxed_fn_ty<'tcx,AC>(this: &AC, - unboxed_function: &ast::UnboxedFnTy, - param_ty: ty::ParamTy) - -> Rc - where AC: AstConv<'tcx> { - let rscope = ExplicitRscope; - let param_ty = param_ty.to_ty(this.tcx()); - Rc::new(astconv::trait_ref_for_unboxed_function(this, - &rscope, - unboxed_function.kind, - &*unboxed_function.decl, - Some(param_ty))) -} - fn get_trait_def(ccx: &CrateCtxt, trait_id: ast::DefId) -> Rc { if trait_id.krate != ast::LOCAL_CRATE { return ty::lookup_trait_def(ccx.tcx, trait_id) @@ -1879,7 +1865,6 @@ fn ty_generics<'tcx,AC>(this: &AC, // In the above example, `ast_trait_ref` is `Iterator`. let ast_trait_ref = match *bound { ast::TraitTyParamBound(ref r) => r, - ast::UnboxedFnTyParamBound(..) => { continue; } ast::RegionTyParamBound(..) => { continue; } }; @@ -2057,45 +2042,8 @@ fn conv_param_bounds<'tcx,AC>(this: &AC, merge_param_bounds(this.tcx(), param_ty, ast_bounds, where_clause); let astconv::PartitionedBounds { builtin_bounds, trait_bounds, - region_bounds, - unboxed_fn_ty_bounds } = + region_bounds } = astconv::partition_bounds(this.tcx(), span, all_bounds.as_slice()); - - let unboxed_fn_ty_bounds = unboxed_fn_ty_bounds.into_iter().map(|b| { - let trait_id = (*this.tcx().def_map.borrow())[b.ref_id].def_id(); - let mut kind = None; - for &(lang_item, this_kind) in [ - (this.tcx().lang_items.fn_trait(), ast::FnUnboxedClosureKind), - (this.tcx().lang_items.fn_mut_trait(), - ast::FnMutUnboxedClosureKind), - (this.tcx().lang_items.fn_once_trait(), - ast::FnOnceUnboxedClosureKind) - ].iter() { - if Some(trait_id) == lang_item { - kind = Some(this_kind); - break - } - } - - let kind = match kind { - Some(kind) => kind, - None => { - this.tcx().sess.span_err(b.path.span, - "unboxed function trait must be one \ - of `Fn`, `FnMut`, or `FnOnce`"); - ast::FnMutUnboxedClosureKind - } - }; - - let rscope = ExplicitRscope; - let param_ty = param_ty.to_ty(this.tcx()); - Rc::new(astconv::trait_ref_for_unboxed_function(this, - &rscope, - kind, - &*b.decl, - Some(param_ty))) - }); - let trait_bounds: Vec> = trait_bounds.into_iter() .map(|b| { @@ -2104,7 +2052,6 @@ fn conv_param_bounds<'tcx,AC>(this: &AC, param_ty.to_ty(this.tcx()), Some(param_ty.to_ty(this.tcx()))) }) - .chain(unboxed_fn_ty_bounds) .collect(); let region_bounds: Vec = region_bounds.into_iter() diff --git a/src/librustc/middle/typeck/infer/error_reporting.rs b/src/librustc/middle/typeck/infer/error_reporting.rs index 64efae486b7..4882059e91b 100644 --- a/src/librustc/middle/typeck/infer/error_reporting.rs +++ b/src/librustc/middle/typeck/infer/error_reporting.rs @@ -1102,9 +1102,6 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> { // be passing down a map. ast::RegionTyParamBound(lt) } - &ast::UnboxedFnTyParamBound(ref unboxed_function_type) => { - ast::UnboxedFnTyParamBound((*unboxed_function_type).clone()) - } &ast::TraitTyParamBound(ref tr) => { let last_seg = tr.path.segments.last().unwrap(); let mut insert = Vec::new(); diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index d87d8776d4a..a3bf0160471 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -323,7 +323,6 @@ fn build_impl(cx: &DocContext, tcx: &ty::ctxt, trait_: associated_trait.clean(cx).map(|bound| { match bound { clean::TraitBound(ty) => ty, - clean::UnboxedFnBound(..) | clean::RegionBound(..) => unreachable!(), } }), diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index cfd183b4c45..d3bfe42dcb2 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -476,7 +476,6 @@ impl Clean for ty::TypeParameterDef { #[deriving(Clone, Encodable, Decodable, PartialEq)] pub enum TyParamBound { RegionBound(Lifetime), - UnboxedFnBound(UnboxedFnType), TraitBound(Type) } @@ -484,7 +483,6 @@ impl Clean for ast::TyParamBound { fn clean(&self, cx: &DocContext) -> TyParamBound { match *self { ast::RegionTyParamBound(lt) => RegionBound(lt.clean(cx)), - ast::UnboxedFnTyParamBound(ref ty) => { UnboxedFnBound(ty.clean(cx)) }, ast::TraitTyParamBound(ref t) => TraitBound(t.clean(cx)), } } @@ -599,21 +597,6 @@ impl Clean>> for subst::Substs { } } -#[deriving(Clone, Encodable, Decodable, PartialEq)] -pub struct UnboxedFnType { - pub path: Path, - pub decl: FnDecl -} - -impl Clean for ast::UnboxedFnBound { - fn clean(&self, cx: &DocContext) -> UnboxedFnType { - UnboxedFnType { - path: self.path.clean(cx), - decl: self.decl.clean(cx) - } - } -} - #[deriving(Clone, Encodable, Decodable, PartialEq)] pub struct Lifetime(String); diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index f9177c8d615..ea6cbbb6b83 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -143,9 +143,6 @@ impl fmt::Show for clean::TyParamBound { clean::RegionBound(ref lt) => { write!(f, "{}", *lt) } - clean::UnboxedFnBound(ref ty) => { - write!(f, "{}{}", ty.path, ty.decl) - } clean::TraitBound(ref ty) => { write!(f, "{}", *ty) } @@ -404,8 +401,7 @@ impl fmt::Show for clean::Type { let mut ret = String::new(); for bound in decl.bounds.iter() { match *bound { - clean::RegionBound(..) | - clean::UnboxedFnBound(..) => {} + clean::RegionBound(..) => {} clean::TraitBound(ref t) => { if ret.len() == 0 { ret.push_str(": "); diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index a2089a3e2a3..6a354fa20e1 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -308,20 +308,11 @@ pub const DUMMY_NODE_ID: NodeId = -1; #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub enum TyParamBound { TraitTyParamBound(TraitRef), - UnboxedFnTyParamBound(P), RegionTyParamBound(Lifetime) } pub type TyParamBounds = OwnedSlice; -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] -pub struct UnboxedFnBound { - pub path: Path, - pub decl: P, - pub lifetimes: Vec, - pub ref_id: NodeId, -} - #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub struct TyParam { pub ident: Ident, @@ -1089,12 +1080,6 @@ pub struct BareFnTy { pub decl: P } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] -pub struct UnboxedFnTy { - pub kind: UnboxedClosureKind, - pub decl: P, -} - #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub enum Ty_ { TyNil, @@ -1107,7 +1092,6 @@ pub enum Ty_ { TyClosure(P), TyProc(P), TyBareFn(P), - TyUnboxedFn(P), TyTup(Vec> ), TyPath(Path, Option, NodeId), // for #7264; see above /// A "qualified path", e.g. ` as SomeTrait>::SomeType` diff --git a/src/libsyntax/ast_map/mod.rs b/src/libsyntax/ast_map/mod.rs index f049b964ff3..3adb062864e 100644 --- a/src/libsyntax/ast_map/mod.rs +++ b/src/libsyntax/ast_map/mod.rs @@ -848,9 +848,6 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> { TyBareFn(ref fd) => { self.visit_fn_decl(&*fd.decl); } - TyUnboxedFn(ref fd) => { - self.visit_fn_decl(&*fd.decl); - } _ => {} } visit::walk_ty(self, ty); diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 7701f495f72..80b158a54d3 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -313,11 +313,6 @@ impl<'a, 'v> Visitor<'v> for Context<'a> { experimental and likely to be removed"); }, - ast::TyUnboxedFn(..) => { - self.gate_feature("unboxed_closure_sugar", - t.span, - "unboxed closure trait sugar is experimental"); - } _ => {} } diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 79e2c656e41..cd4a3d10c48 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -424,12 +424,6 @@ pub fn noop_fold_ty(t: P, fld: &mut T) -> P { decl: fld.fold_fn_decl(decl) })) } - TyUnboxedFn(f) => { - TyUnboxedFn(f.map(|UnboxedFnTy {decl, kind}| UnboxedFnTy { - decl: fld.fold_fn_decl(decl), - kind: kind, - })) - } TyTup(tys) => TyTup(tys.move_map(|ty| fld.fold_ty(ty))), TyParen(ty) => TyParen(fld.fold_ty(ty)), TyPath(path, bounds, id) => { @@ -715,23 +709,6 @@ pub fn noop_fold_ty_param_bound(tpb: TyParamBound, fld: &mut T) match tpb { TraitTyParamBound(ty) => TraitTyParamBound(fld.fold_trait_ref(ty)), RegionTyParamBound(lifetime) => RegionTyParamBound(fld.fold_lifetime(lifetime)), - UnboxedFnTyParamBound(bound) => { - match *bound { - UnboxedFnBound { - ref path, - ref decl, - ref lifetimes, - ref_id - } => { - UnboxedFnTyParamBound(P(UnboxedFnBound { - path: fld.fold_path(path.clone()), - decl: fld.fold_fn_decl(decl.clone()), - lifetimes: fld.fold_lifetime_defs(lifetimes.clone()), - ref_id: fld.new_id(ref_id), - })) - } - } - } } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 1c65a47350e..18dd7074d28 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -53,9 +53,8 @@ use ast::{TtNonterminal, TupleVariantKind, Ty, Ty_, TyBot}; use ast::{TypeField, TyFixedLengthVec, TyClosure, TyProc, TyBareFn}; use ast::{TyTypeof, TyInfer, TypeMethod}; use ast::{TyNil, TyParam, TyParamBound, TyParen, TyPath, TyPtr, TyQPath}; -use ast::{TyRptr, TyTup, TyU32, TyUnboxedFn, TyUniq, TyVec, UnUniq}; +use ast::{TyRptr, TyTup, TyU32, TyUniq, TyVec, UnUniq}; use ast::{TypeImplItem, TypeTraitItem, Typedef, UnboxedClosureKind}; -use ast::{UnboxedFnBound, UnboxedFnTy, UnboxedFnTyParamBound}; use ast::{UnnamedField, UnsafeBlock}; use ast::{UnsafeFn, ViewItem, ViewItem_, ViewItemExternCrate, ViewItemUse}; use ast::{ViewPath, ViewPathGlob, ViewPathList, ViewPathSimple}; @@ -1127,19 +1126,16 @@ impl<'a> Parser<'a> { Vec::new() }; - let (optional_unboxed_closure_kind, inputs) = if self.eat(&token::OrOr) { - (None, Vec::new()) + let inputs = if self.eat(&token::OrOr) { + Vec::new() } else { self.expect_or(); - let optional_unboxed_closure_kind = - self.parse_optional_unboxed_closure_kind(); - let inputs = self.parse_seq_to_before_or( &token::Comma, |p| p.parse_arg_general(false)); self.expect_or(); - (optional_unboxed_closure_kind, inputs) + inputs }; let bounds = self.parse_colon_then_ty_param_bounds(); @@ -1152,23 +1148,13 @@ impl<'a> Parser<'a> { variadic: false }); - match optional_unboxed_closure_kind { - Some(unboxed_closure_kind) => { - TyUnboxedFn(P(UnboxedFnTy { - kind: unboxed_closure_kind, - decl: decl, - })) - } - None => { - TyClosure(P(ClosureTy { - fn_style: fn_style, - onceness: onceness, - bounds: bounds, - decl: decl, - lifetimes: lifetime_defs, - })) - } - } + TyClosure(P(ClosureTy { + fn_style: fn_style, + onceness: onceness, + bounds: bounds, + decl: decl, + lifetimes: lifetime_defs, + })) } pub fn parse_unsafety(&mut self) -> FnStyle { @@ -3935,31 +3921,11 @@ impl<'a> Parser<'a> { token::ModSep | token::Ident(..) => { let path = self.parse_path(LifetimeAndTypesWithoutColons).path; - if self.token == token::OpenDelim(token::Paren) { - self.bump(); - let inputs = self.parse_seq_to_end( - &token::CloseDelim(token::Paren), - seq_sep_trailing_allowed(token::Comma), - |p| p.parse_arg_general(false)); - let (return_style, output) = self.parse_ret_ty(); - result.push(UnboxedFnTyParamBound(P(UnboxedFnBound { - path: path, - decl: P(FnDecl { - inputs: inputs, - output: output, - cf: return_style, - variadic: false, - }), - lifetimes: lifetime_defs, - ref_id: ast::DUMMY_NODE_ID, - }))); - } else { - result.push(TraitTyParamBound(ast::TraitRef { - path: path, - ref_id: ast::DUMMY_NODE_ID, - lifetimes: lifetime_defs, - })) - } + result.push(TraitTyParamBound(ast::TraitRef { + path: path, + ref_id: ast::DUMMY_NODE_ID, + lifetimes: lifetime_defs, + })) } _ => break, } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index d83ea5f76b1..2448eacbb39 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -13,7 +13,7 @@ use ast::{FnUnboxedClosureKind, FnMutUnboxedClosureKind}; use ast::{FnOnceUnboxedClosureKind}; use ast::{MethodImplItem, RegionTyParamBound, TraitTyParamBound}; use ast::{RequiredMethod, ProvidedMethod, TypeImplItem, TypeTraitItem}; -use ast::{UnboxedClosureKind, UnboxedFnTyParamBound}; +use ast::{UnboxedClosureKind}; use ast; use ast_util; use owned_slice::OwnedSlice; @@ -699,7 +699,6 @@ impl<'a> State<'a> { None, &OwnedSlice::empty(), Some(&generics), - None, None)); } ast::TyClosure(ref f) => { @@ -719,7 +718,6 @@ impl<'a> State<'a> { None, &f.bounds, Some(&generics), - None, None)); } ast::TyProc(ref f) => { @@ -739,21 +737,8 @@ impl<'a> State<'a> { None, &f.bounds, Some(&generics), - None, None)); } - ast::TyUnboxedFn(ref f) => { - try!(self.print_ty_fn(None, - None, - ast::NormalFn, - ast::Many, - &*f.decl, - None, - &OwnedSlice::empty(), - None, - None, - Some(f.kind))); - } ast::TyPath(ref path, ref bounds, _) => { try!(self.print_bounded_path(path, bounds)); } @@ -1212,8 +1197,7 @@ impl<'a> State<'a> { Some(m.ident), &OwnedSlice::empty(), Some(&m.generics), - Some(&m.explicit_self.node), - None)); + Some(&m.explicit_self.node))); word(&mut self.s, ";") } @@ -2407,15 +2391,6 @@ impl<'a> State<'a> { RegionTyParamBound(ref lt) => { self.print_lifetime(lt) } - UnboxedFnTyParamBound(ref unboxed_function_type) => { - try!(self.print_path(&unboxed_function_type.path, - false)); - try!(self.popen()); - try!(self.print_fn_args(&*unboxed_function_type.decl, - None)); - try!(self.pclose()); - self.print_fn_output(&*unboxed_function_type.decl) - } }) } Ok(()) @@ -2675,9 +2650,7 @@ impl<'a> State<'a> { id: Option, bounds: &OwnedSlice, generics: Option<&ast::Generics>, - opt_explicit_self: Option<&ast::ExplicitSelf_>, - opt_unboxed_closure_kind: - Option) + opt_explicit_self: Option<&ast::ExplicitSelf_>) -> IoResult<()> { try!(self.ibox(indent_unit)); @@ -2694,9 +2667,7 @@ impl<'a> State<'a> { try!(self.print_fn_style(fn_style)); try!(self.print_opt_abi_and_extern_if_nondefault(opt_abi)); try!(self.print_onceness(onceness)); - if opt_unboxed_closure_kind.is_none() { - try!(word(&mut self.s, "fn")); - } + try!(word(&mut self.s, "fn")); } match id { @@ -2710,30 +2681,15 @@ impl<'a> State<'a> { match generics { Some(g) => try!(self.print_generics(g)), _ => () } try!(zerobreak(&mut self.s)); - if opt_unboxed_closure_kind.is_some() || opt_sigil == Some('&') { + if opt_sigil == Some('&') { try!(word(&mut self.s, "|")); } else { try!(self.popen()); } - match opt_unboxed_closure_kind { - Some(ast::FnUnboxedClosureKind) => { - try!(word(&mut self.s, "&")); - try!(self.word_space(":")); - } - Some(ast::FnMutUnboxedClosureKind) => { - try!(word(&mut self.s, "&mut")); - try!(self.word_space(":")); - } - Some(ast::FnOnceUnboxedClosureKind) => { - try!(self.word_space(":")); - } - None => {} - } - try!(self.print_fn_args(decl, opt_explicit_self)); - if opt_unboxed_closure_kind.is_some() || opt_sigil == Some('&') { + if opt_sigil == Some('&') { try!(word(&mut self.s, "|")); } else { if decl.variadic { diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index b4141af0733..9751abacbd3 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -365,12 +365,6 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) { visitor.visit_ty(&*function_declaration.decl.output); walk_lifetime_decls(visitor, &function_declaration.lifetimes); } - TyUnboxedFn(ref function_declaration) => { - for argument in function_declaration.decl.inputs.iter() { - visitor.visit_ty(&*argument.ty) - } - visitor.visit_ty(&*function_declaration.decl.output); - } TyPath(ref path, ref opt_bounds, id) => { visitor.visit_path(path, id); match *opt_bounds { @@ -505,13 +499,6 @@ pub fn walk_ty_param_bounds<'v, V: Visitor<'v>>(visitor: &mut V, TraitTyParamBound(ref typ) => { walk_trait_ref_helper(visitor, typ) } - UnboxedFnTyParamBound(ref function_declaration) => { - for argument in function_declaration.decl.inputs.iter() { - visitor.visit_ty(&*argument.ty) - } - visitor.visit_ty(&*function_declaration.decl.output); - walk_lifetime_decls(visitor, &function_declaration.lifetimes); - } RegionTyParamBound(ref lifetime) => { visitor.visit_lifetime_ref(lifetime); } diff --git a/src/test/run-pass/unboxed-closures-manual-impl.rs b/src/test/run-pass/unboxed-closures-manual-impl.rs index b0947f46a86..8f6cfe04997 100644 --- a/src/test/run-pass/unboxed-closures-manual-impl.rs +++ b/src/test/run-pass/unboxed-closures-manual-impl.rs @@ -25,7 +25,7 @@ fn call_itint>(mut f: F, x: int) -> int { f.call_mut((x,)) + 3 } -fn call_box(f: &mut |&mut: int|->int, x: int) -> int { +fn call_box(f: &mut FnMut(int) -> int, x: int) -> int { f.call_mut((x,)) + 3 } -- cgit 1.4.1-3-g733a5 From eec145be3f5e5f763e61749a6737f90df8504e05 Mon Sep 17 00:00:00 2001 From: Alexis Beingessner Date: Thu, 6 Nov 2014 12:25:16 -0500 Subject: Fallout from collection conventions --- src/libgreen/lib.rs | 2 +- src/libgreen/sched.rs | 2 +- src/librustc/back/link.rs | 2 +- src/librustc/driver/session.rs | 2 +- src/librustc/lint/builtin.rs | 14 ++--- src/librustc/lint/context.rs | 12 ++--- src/librustc/metadata/cstore.rs | 2 +- src/librustc/metadata/decoder.rs | 4 +- src/librustc/metadata/encoder.rs | 14 ++--- src/librustc/metadata/tydecode.rs | 8 +-- src/librustc/metadata/tyencode.rs | 2 +- src/librustc/middle/astencode.rs | 26 ++++----- src/librustc/middle/borrowck/move_data.rs | 4 +- src/librustc/middle/cfg/construct.rs | 4 +- src/librustc/middle/check_const.rs | 4 +- src/librustc/middle/check_match.rs | 6 +-- src/librustc/middle/check_static_recursion.rs | 2 +- src/librustc/middle/const_eval.rs | 6 +-- src/librustc/middle/dataflow.rs | 4 +- src/librustc/middle/dead.rs | 6 +-- src/librustc/middle/dependency_format.rs | 4 +- src/librustc/middle/expr_use_visitor.rs | 6 +-- src/librustc/middle/lang_items.rs | 2 +- src/librustc/middle/liveness.rs | 16 +++--- src/librustc/middle/mem_categorization.rs | 8 +-- src/librustc/middle/pat_util.rs | 6 +-- src/librustc/middle/privacy.rs | 10 ++-- src/librustc/middle/reachable.rs | 2 +- src/librustc/middle/region.rs | 14 ++--- src/librustc/middle/resolve.rs | 52 +++++++++--------- src/librustc/middle/traits/select.rs | 16 +++--- src/librustc/middle/trans/_match.rs | 4 +- src/librustc/middle/trans/adt.rs | 2 +- src/librustc/middle/trans/base.rs | 10 ++-- src/librustc/middle/trans/builder.rs | 2 +- src/librustc/middle/trans/closure.rs | 4 +- src/librustc/middle/trans/common.rs | 8 +-- src/librustc/middle/trans/consts.rs | 4 +- src/librustc/middle/trans/controlflow.rs | 2 +- src/librustc/middle/trans/debuginfo.rs | 8 +-- src/librustc/middle/trans/expr.rs | 14 ++--- src/librustc/middle/trans/glue.rs | 4 +- src/librustc/middle/trans/inline.rs | 2 +- src/librustc/middle/trans/meth.rs | 8 +-- src/librustc/middle/trans/monomorphize.rs | 4 +- src/librustc/middle/trans/type_.rs | 2 +- src/librustc/middle/trans/type_of.rs | 2 +- src/librustc/middle/ty.rs | 56 +++++++++---------- src/librustc/middle/typeck/astconv.rs | 16 +++--- src/librustc/middle/typeck/check/_match.rs | 2 +- src/librustc/middle/typeck/check/method.rs | 10 ++-- src/librustc/middle/typeck/check/mod.rs | 22 ++++---- src/librustc/middle/typeck/check/regionck.rs | 22 ++++---- src/librustc/middle/typeck/check/writeback.rs | 6 +-- src/librustc/middle/typeck/coherence/mod.rs | 2 +- src/librustc/middle/typeck/coherence/overlap.rs | 2 +- src/librustc/middle/typeck/collect.rs | 16 +++--- .../middle/typeck/infer/error_reporting.rs | 2 +- .../middle/typeck/infer/region_inference/mod.rs | 8 +-- src/librustc/middle/typeck/infer/sub.rs | 2 +- src/librustc/middle/typeck/mod.rs | 2 +- src/librustc/middle/typeck/variance.rs | 12 ++--- src/librustc/util/common.rs | 4 +- src/librustc/util/ppaux.rs | 6 +-- src/librustdoc/clean/inline.rs | 4 +- src/librustdoc/clean/mod.rs | 6 +-- src/librustdoc/html/format.rs | 4 +- src/librustdoc/html/markdown.rs | 2 +- src/librustdoc/html/render.rs | 18 +++---- src/librustdoc/lib.rs | 4 +- src/librustrt/local_data.rs | 4 +- src/libserialize/collection_impls.rs | 8 +-- src/libserialize/json.rs | 10 ++-- src/libstd/io/mod.rs | 4 +- src/libstd/io/process.rs | 2 +- src/libsyntax/diagnostics/plugin.rs | 4 +- src/libsyntax/ext/base.rs | 2 +- src/libsyntax/ext/format.rs | 8 +-- src/libsyntax/ext/mtwt.rs | 2 +- src/libsyntax/util/interner.rs | 2 +- src/libtest/lib.rs | 46 ++++++++-------- src/test/bench/core-map.rs | 12 ++--- src/test/bench/shootout-chameneos-redux.rs | 4 +- src/test/bench/shootout-fasta-redux.rs | 2 +- src/test/bench/shootout-k-nucleotide.rs | 4 +- src/test/bench/shootout-meteor.rs | 4 +- src/test/bench/shootout-regex-dna.rs | 2 +- src/test/bench/shootout-reverse-complement.rs | 5 +- src/test/bench/sudoku.rs | 6 +-- src/test/compile-fail/borrowck-assign-comp-idx.rs | 6 +-- .../compile-fail/borrowck-for-loop-head-linkage.rs | 2 +- src/test/compile-fail/borrowck-loan-vec-content.rs | 2 +- src/test/run-pass/foreach-nested.rs | 2 +- src/test/run-pass/hashmap-memory.rs | 2 +- src/test/run-pass/issue-3563-3.rs | 4 +- src/test/run-pass/issue-3991.rs | 2 +- src/test/run-pass/overloaded-deref.rs | 4 +- src/test/run-pass/send_str_hashmap.rs | 44 +++++++-------- src/test/run-pass/send_str_treemap.rs | 62 +++++++++++----------- src/test/run-pass/swap-2.rs | 2 +- src/test/run-pass/unique-in-vec-copy.rs | 2 +- 101 files changed, 418 insertions(+), 417 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libgreen/lib.rs b/src/libgreen/lib.rs index fcebfeac292..ed394fc0de5 100644 --- a/src/libgreen/lib.rs +++ b/src/libgreen/lib.rs @@ -417,7 +417,7 @@ impl SchedPool { } // Jettison the task away! - self.handles.get_mut(idx).send(TaskFromFriend(task)); + self.handles[idx].send(TaskFromFriend(task)); } /// Spawns a new scheduler into this M:N pool. A handle is returned to the diff --git a/src/libgreen/sched.rs b/src/libgreen/sched.rs index b1c2695ac7d..50b10873faf 100644 --- a/src/libgreen/sched.rs +++ b/src/libgreen/sched.rs @@ -502,7 +502,7 @@ impl Scheduler { let len = work_queues.len(); let start_index = self.rng.gen_range(0, len); for index in range(0, len).map(|i| (i + start_index) % len) { - match work_queues.get_mut(index).steal() { + match work_queues[index].steal() { deque::Data(task) => { rtdebug!("found task by stealing"); return Some(task) diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs index 81f856c29d5..7488cb59830 100644 --- a/src/librustc/back/link.rs +++ b/src/librustc/back/link.rs @@ -220,7 +220,7 @@ fn symbol_hash(tcx: &ty::ctxt, } fn get_symbol_hash(ccx: &CrateContext, t: ty::t) -> String { - match ccx.type_hashcodes().borrow().find(&t) { + match ccx.type_hashcodes().borrow().get(&t) { Some(h) => return h.to_string(), None => {} } diff --git a/src/librustc/driver/session.rs b/src/librustc/driver/session.rs index 57c65ccebc5..35ccbb4c7b4 100644 --- a/src/librustc/driver/session.rs +++ b/src/librustc/driver/session.rs @@ -127,7 +127,7 @@ impl Session { msg: String) { let lint_id = lint::LintId::of(lint); let mut lints = self.lints.borrow_mut(); - match lints.find_mut(&id) { + match lints.get_mut(&id) { Some(arr) => { arr.push((lint_id, sp, msg)); return; } None => {} } diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index b60b2ba984e..d42a9c69dc1 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -403,7 +403,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { libc::c_uint or libc::c_ulong should be used"); } def::DefTy(..) => { - let tty = match self.cx.tcx.ast_ty_to_ty_cache.borrow().find(&ty_id) { + let tty = match self.cx.tcx.ast_ty_to_ty_cache.borrow().get(&ty_id) { Some(&ty::atttce_resolved(t)) => t, _ => panic!("ast_ty_to_ty_cache was incomplete after typeck!") }; @@ -994,7 +994,7 @@ impl LintPass for NonSnakeCase { fn check_pat(&mut self, cx: &Context, p: &ast::Pat) { match &p.node { &ast::PatIdent(_, ref path1, _) => { - match cx.tcx.def_map.borrow().find(&p.id) { + match cx.tcx.def_map.borrow().get(&p.id) { Some(&def::DefLocal(_)) => { self.check_snake_case(cx, "variable", path1.node, p.span); } @@ -1051,7 +1051,7 @@ impl LintPass for NonUpperCaseGlobals { fn check_pat(&mut self, cx: &Context, p: &ast::Pat) { // Lint for constants that look like binding identifiers (#7526) - match (&p.node, cx.tcx.def_map.borrow().find(&p.id)) { + match (&p.node, cx.tcx.def_map.borrow().get(&p.id)) { (&ast::PatIdent(_, ref path1, _), Some(&def::DefConst(..))) => { let s = token::get_ident(path1.node); if s.get().chars().any(|c| c.is_lowercase()) { @@ -1211,7 +1211,7 @@ impl LintPass for NonShorthandFieldPatterns { ast::PatStruct(_, ref v, _) => { for fieldpat in v.iter() .filter(|fieldpat| !fieldpat.node.is_shorthand) - .filter(|fieldpat| def_map.find(&fieldpat.node.pat.id) + .filter(|fieldpat| def_map.get(&fieldpat.node.pat.id) == Some(&def::DefLocal(fieldpat.node.pat.id))) { match fieldpat.node.pat.node { ast::PatIdent(_, ident, None) if ident.node.as_str() @@ -1368,7 +1368,7 @@ impl LintPass for UnusedAllocation { _ => return } - match cx.tcx.adjustments.borrow().find(&e.id) { + match cx.tcx.adjustments.borrow().get(&e.id) { Some(adjustment) => { match *adjustment { ty::AdjustDerefRef(ty::AutoDerefRef { ref autoref, .. }) => { @@ -1637,7 +1637,7 @@ impl LintPass for Stability { let id = match e.node { ast::ExprPath(..) | ast::ExprStruct(..) => { - match cx.tcx.def_map.borrow().find(&e.id) { + match cx.tcx.def_map.borrow().get(&e.id) { Some(&def) => def.def_id(), None => return } @@ -1645,7 +1645,7 @@ impl LintPass for Stability { ast::ExprMethodCall(i, _, _) => { span = i.span; let method_call = typeck::MethodCall::expr(e.id); - match cx.tcx.method_map.borrow().find(&method_call) { + match cx.tcx.method_map.borrow().get(&method_call) { Some(method) => { match method.origin { typeck::MethodStatic(def_id) => { diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 6da74eee8a3..76187f192c2 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -84,7 +84,7 @@ enum TargetLint { impl LintStore { fn get_level_source(&self, lint: LintId) -> LevelSource { - match self.levels.find(&lint) { + match self.levels.get(&lint) { Some(&s) => s, None => (Allow, Default), } @@ -124,7 +124,7 @@ impl LintStore { self.lints.push((*lint, from_plugin)); let id = LintId::of(*lint); - if !self.by_name.insert(lint.name_lower(), Id(id)) { + if self.by_name.insert(lint.name_lower(), Id(id)).is_some() { let msg = format!("duplicate specification of lint {}", lint.name_lower()); match (sess, from_plugin) { // We load builtin lints first, so a duplicate is a compiler bug. @@ -147,7 +147,7 @@ impl LintStore { pub fn register_group(&mut self, sess: Option<&Session>, from_plugin: bool, name: &'static str, to: Vec) { - let new = self.lint_groups.insert(name, (to, from_plugin)); + let new = self.lint_groups.insert(name, (to, from_plugin)).is_none(); if !new { let msg = format!("duplicate specification of lint group {}", name); @@ -437,11 +437,11 @@ impl<'a, 'tcx> Context<'a, 'tcx> { /// Get the level of `lint` at the current position of the lint /// traversal. pub fn current_level(&self, lint: &'static Lint) -> Level { - self.lints.levels.find(&LintId::of(lint)).map_or(Allow, |&(lvl, _)| lvl) + self.lints.levels.get(&LintId::of(lint)).map_or(Allow, |&(lvl, _)| lvl) } fn lookup_and_emit(&self, lint: &'static Lint, span: Option, msg: &str) { - let (level, src) = match self.lints.levels.find(&LintId::of(lint)) { + let (level, src) = match self.lints.levels.get(&LintId::of(lint)) { None => return, Some(&(Warn, src)) => { let lint_id = LintId::of(builtin::WARNINGS); @@ -750,7 +750,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Context<'a, 'tcx> { // Output any lints that were previously added to the session. impl<'a, 'tcx> IdVisitingOperation for Context<'a, 'tcx> { fn visit_id(&mut self, id: ast::NodeId) { - match self.tcx.sess.lints.borrow_mut().pop(&id) { + match self.tcx.sess.lints.borrow_mut().remove(&id) { None => {} Some(lints) => { for (lint_id, span, msg) in lints.into_iter() { diff --git a/src/librustc/metadata/cstore.rs b/src/librustc/metadata/cstore.rs index e8c5f6f4910..36456b3c4a9 100644 --- a/src/librustc/metadata/cstore.rs +++ b/src/librustc/metadata/cstore.rs @@ -213,7 +213,7 @@ impl CStore { pub fn find_extern_mod_stmt_cnum(&self, emod_id: ast::NodeId) -> Option { - self.extern_mod_crate_map.borrow().find(&emod_id).map(|x| *x) + self.extern_mod_crate_map.borrow().get(&emod_id).map(|x| *x) } } diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs index 92f3b888dcd..2fd6e2b4787 100644 --- a/src/librustc/metadata/decoder.rs +++ b/src/librustc/metadata/decoder.rs @@ -1209,7 +1209,7 @@ pub fn translate_def_id(cdata: Cmd, did: ast::DefId) -> ast::DefId { return ast::DefId { krate: cdata.cnum, node: did.node }; } - match cdata.cnum_map.find(&did.krate) { + match cdata.cnum_map.get(&did.krate) { Some(&n) => { ast::DefId { krate: n, @@ -1321,7 +1321,7 @@ pub fn get_dylib_dependency_formats(cdata: Cmd) let cnum = spec.split(':').nth(0).unwrap(); let link = spec.split(':').nth(1).unwrap(); let cnum = from_str(cnum).unwrap(); - let cnum = match cdata.cnum_map.find(&cnum) { + let cnum = match cdata.cnum_map.get(&cnum) { Some(&n) => n, None => panic!("didn't find a crate in the cnum_map") }; diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index da7e78d272f..66b647fabdc 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -253,7 +253,7 @@ fn encode_symbol(ecx: &EncodeContext, rbml_w: &mut Encoder, id: NodeId) { rbml_w.start_tag(tag_items_data_item_symbol); - match ecx.item_symbols.borrow().find(&id) { + match ecx.item_symbols.borrow().get(&id) { Some(x) => { debug!("encode_symbol(id={}, str={})", id, *x); rbml_w.writer.write(x.as_bytes()); @@ -397,7 +397,7 @@ fn encode_reexported_static_base_methods(ecx: &EncodeContext, exp: &middle::resolve::Export2) -> bool { let impl_items = ecx.tcx.impl_items.borrow(); - match ecx.tcx.inherent_impls.borrow().find(&exp.def_id) { + match ecx.tcx.inherent_impls.borrow().get(&exp.def_id) { Some(implementations) => { for base_impl_did in implementations.iter() { for &method_did in (*impl_items)[*base_impl_did].iter() { @@ -426,7 +426,7 @@ fn encode_reexported_static_trait_methods(ecx: &EncodeContext, rbml_w: &mut Encoder, exp: &middle::resolve::Export2) -> bool { - match ecx.tcx.trait_items_cache.borrow().find(&exp.def_id) { + match ecx.tcx.trait_items_cache.borrow().get(&exp.def_id) { Some(trait_items) => { for trait_item in trait_items.iter() { match *trait_item { @@ -531,7 +531,7 @@ fn encode_reexports(ecx: &EncodeContext, id: NodeId, path: PathElems) { debug!("(encoding info for module) encoding reexports for {}", id); - match ecx.reexports2.find(&id) { + match ecx.reexports2.get(&id) { Some(ref exports) => { debug!("(encoding info for module) found reexports for {}", id); for exp in exports.iter() { @@ -978,7 +978,7 @@ fn should_inline(attrs: &[Attribute]) -> bool { fn encode_inherent_implementations(ecx: &EncodeContext, rbml_w: &mut Encoder, def_id: DefId) { - match ecx.tcx.inherent_impls.borrow().find(&def_id) { + match ecx.tcx.inherent_impls.borrow().get(&def_id) { None => {} Some(implementations) => { for &impl_def_id in implementations.iter() { @@ -994,7 +994,7 @@ fn encode_inherent_implementations(ecx: &EncodeContext, fn encode_extension_implementations(ecx: &EncodeContext, rbml_w: &mut Encoder, trait_def_id: DefId) { - match ecx.tcx.trait_impls.borrow().find(&trait_def_id) { + match ecx.tcx.trait_impls.borrow().get(&trait_def_id) { None => {} Some(implementations) => { for &impl_def_id in implementations.borrow().iter() { @@ -1987,7 +1987,7 @@ fn encode_crate_triple(rbml_w: &mut Encoder, triple: &str) { fn encode_dylib_dependency_formats(rbml_w: &mut Encoder, ecx: &EncodeContext) { rbml_w.start_tag(tag_dylib_dependency_formats); - match ecx.tcx.dependency_formats.borrow().find(&config::CrateTypeDylib) { + match ecx.tcx.dependency_formats.borrow().get(&config::CrateTypeDylib) { Some(arr) => { let s = arr.iter().enumerate().filter_map(|(i, slot)| { slot.map(|kind| (format!("{}:{}", i + 1, match kind { diff --git a/src/librustc/metadata/tydecode.rs b/src/librustc/metadata/tydecode.rs index b9660dbd466..227a6f71bfd 100644 --- a/src/librustc/metadata/tydecode.rs +++ b/src/librustc/metadata/tydecode.rs @@ -675,16 +675,16 @@ fn parse_builtin_bounds(st: &mut PState, _conv: conv_did) -> ty::BuiltinBounds { loop { match next(st) { 'S' => { - builtin_bounds.add(ty::BoundSend); + builtin_bounds.insert(ty::BoundSend); } 'Z' => { - builtin_bounds.add(ty::BoundSized); + builtin_bounds.insert(ty::BoundSized); } 'P' => { - builtin_bounds.add(ty::BoundCopy); + builtin_bounds.insert(ty::BoundCopy); } 'T' => { - builtin_bounds.add(ty::BoundSync); + builtin_bounds.insert(ty::BoundSync); } '.' => { return builtin_bounds; diff --git a/src/librustc/metadata/tyencode.rs b/src/librustc/metadata/tyencode.rs index 5fb1fec5340..027b9980a32 100644 --- a/src/librustc/metadata/tyencode.rs +++ b/src/librustc/metadata/tyencode.rs @@ -50,7 +50,7 @@ pub struct ty_abbrev { pub type abbrev_map = RefCell>; pub fn enc_ty(w: &mut SeekableMemWriter, cx: &ctxt, t: ty::t) { - match cx.abbrevs.borrow_mut().find(&t) { + match cx.abbrevs.borrow_mut().get(&t) { Some(a) => { w.write(a.s.as_bytes()); return; } None => {} } diff --git a/src/librustc/middle/astencode.rs b/src/librustc/middle/astencode.rs index 5410417ec3f..9268418ef94 100644 --- a/src/librustc/middle/astencode.rs +++ b/src/librustc/middle/astencode.rs @@ -1151,14 +1151,14 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext, debug!("Encoding side tables for id {}", id); - for def in tcx.def_map.borrow().find(&id).iter() { + for def in tcx.def_map.borrow().get(&id).iter() { rbml_w.tag(c::tag_table_def, |rbml_w| { rbml_w.id(id); rbml_w.tag(c::tag_table_val, |rbml_w| (*def).encode(rbml_w).unwrap()); }) } - for &ty in tcx.node_types.borrow().find(&(id as uint)).iter() { + for &ty in tcx.node_types.borrow().get(&(id as uint)).iter() { rbml_w.tag(c::tag_table_node_type, |rbml_w| { rbml_w.id(id); rbml_w.tag(c::tag_table_val, |rbml_w| { @@ -1167,7 +1167,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext, }) } - for &item_substs in tcx.item_substs.borrow().find(&id).iter() { + for &item_substs in tcx.item_substs.borrow().get(&id).iter() { rbml_w.tag(c::tag_table_item_subst, |rbml_w| { rbml_w.id(id); rbml_w.tag(c::tag_table_val, |rbml_w| { @@ -1176,7 +1176,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext, }) } - for &fv in tcx.freevars.borrow().find(&id).iter() { + for &fv in tcx.freevars.borrow().get(&id).iter() { rbml_w.tag(c::tag_table_freevars, |rbml_w| { rbml_w.id(id); rbml_w.tag(c::tag_table_val, |rbml_w| { @@ -1209,7 +1209,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext, } } - for &cm in tcx.capture_modes.borrow().find(&id).iter() { + for &cm in tcx.capture_modes.borrow().get(&id).iter() { rbml_w.tag(c::tag_table_capture_modes, |rbml_w| { rbml_w.id(id); rbml_w.tag(c::tag_table_val, |rbml_w| { @@ -1219,7 +1219,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext, } let lid = ast::DefId { krate: ast::LOCAL_CRATE, node: id }; - for &pty in tcx.tcache.borrow().find(&lid).iter() { + for &pty in tcx.tcache.borrow().get(&lid).iter() { rbml_w.tag(c::tag_table_tcache, |rbml_w| { rbml_w.id(id); rbml_w.tag(c::tag_table_val, |rbml_w| { @@ -1228,7 +1228,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext, }) } - for &type_param_def in tcx.ty_param_defs.borrow().find(&id).iter() { + for &type_param_def in tcx.ty_param_defs.borrow().get(&id).iter() { rbml_w.tag(c::tag_table_param_defs, |rbml_w| { rbml_w.id(id); rbml_w.tag(c::tag_table_val, |rbml_w| { @@ -1238,7 +1238,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext, } let method_call = MethodCall::expr(id); - for &method in tcx.method_map.borrow().find(&method_call).iter() { + for &method in tcx.method_map.borrow().get(&method_call).iter() { rbml_w.tag(c::tag_table_method_map, |rbml_w| { rbml_w.id(id); rbml_w.tag(c::tag_table_val, |rbml_w| { @@ -1247,7 +1247,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext, }) } - for &trait_ref in tcx.object_cast_map.borrow().find(&id).iter() { + for &trait_ref in tcx.object_cast_map.borrow().get(&id).iter() { rbml_w.tag(c::tag_table_object_cast_map, |rbml_w| { rbml_w.id(id); rbml_w.tag(c::tag_table_val, |rbml_w| { @@ -1256,11 +1256,11 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext, }) } - for &adjustment in tcx.adjustments.borrow().find(&id).iter() { + for &adjustment in tcx.adjustments.borrow().get(&id).iter() { match *adjustment { _ if ty::adjust_is_object(adjustment) => { let method_call = MethodCall::autoobject(id); - for &method in tcx.method_map.borrow().find(&method_call).iter() { + for &method in tcx.method_map.borrow().get(&method_call).iter() { rbml_w.tag(c::tag_table_method_map, |rbml_w| { rbml_w.id(id); rbml_w.tag(c::tag_table_val, |rbml_w| { @@ -1273,7 +1273,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext, assert!(!ty::adjust_is_object(adjustment)); for autoderef in range(0, adj.autoderefs) { let method_call = MethodCall::autoderef(id, autoderef); - for &method in tcx.method_map.borrow().find(&method_call).iter() { + for &method in tcx.method_map.borrow().get(&method_call).iter() { rbml_w.tag(c::tag_table_method_map, |rbml_w| { rbml_w.id(id); rbml_w.tag(c::tag_table_val, |rbml_w| { @@ -1299,7 +1299,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext, for unboxed_closure in tcx.unboxed_closures .borrow() - .find(&ast_util::local_def(id)) + .get(&ast_util::local_def(id)) .iter() { rbml_w.tag(c::tag_table_unboxed_closures, |rbml_w| { rbml_w.id(id); diff --git a/src/librustc/middle/borrowck/move_data.rs b/src/librustc/middle/borrowck/move_data.rs index 98376726913..2a92db3e7d4 100644 --- a/src/librustc/middle/borrowck/move_data.rs +++ b/src/librustc/middle/borrowck/move_data.rs @@ -242,7 +242,7 @@ impl MoveData { * base paths that do not yet have an index. */ - match self.path_map.borrow().find(&lp) { + match self.path_map.borrow().get(&lp) { Some(&index) => { return index; } @@ -577,7 +577,7 @@ impl<'a, 'tcx> FlowedMoveData<'a, 'tcx> { //! Returns the kind of a move of `loan_path` by `id`, if one exists. let mut ret = None; - for loan_path_index in self.move_data.path_map.borrow().find(&*loan_path).iter() { + for loan_path_index in self.move_data.path_map.borrow().get(&*loan_path).iter() { self.dfcx_moves.each_gen_bit(id, |move_index| { let the_move = self.move_data.moves.borrow(); let the_move = (*the_move)[move_index]; diff --git a/src/librustc/middle/cfg/construct.rs b/src/librustc/middle/cfg/construct.rs index 146891825d6..1e38250ceb3 100644 --- a/src/librustc/middle/cfg/construct.rs +++ b/src/librustc/middle/cfg/construct.rs @@ -512,7 +512,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { func_or_rcvr: &ast::Expr, args: I) -> CFGIndex { let method_call = typeck::MethodCall::expr(call_expr.id); - let return_ty = ty::ty_fn_ret(match self.tcx.method_map.borrow().find(&method_call) { + let return_ty = ty::ty_fn_ret(match self.tcx.method_map.borrow().get(&method_call) { Some(method) => method.ty, None => ty::expr_ty(self.tcx, func_or_rcvr) }); @@ -610,7 +610,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { } Some(_) => { - match self.tcx.def_map.borrow().find(&expr.id) { + match self.tcx.def_map.borrow().get(&expr.id) { Some(&def::DefLabel(loop_id)) => { for l in self.loop_scopes.iter() { if l.loop_id == loop_id { diff --git a/src/librustc/middle/check_const.rs b/src/librustc/middle/check_const.rs index 6cf1a93b40b..b03fe0f3f6f 100644 --- a/src/librustc/middle/check_const.rs +++ b/src/librustc/middle/check_const.rs @@ -143,7 +143,7 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr) -> bool { "paths in constants may only refer to items without \ type parameters"); } - match v.tcx.def_map.borrow().find(&e.id) { + match v.tcx.def_map.borrow().get(&e.id) { Some(&DefStatic(..)) | Some(&DefConst(..)) | Some(&DefFn(..)) | @@ -162,7 +162,7 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr) -> bool { } } ExprCall(ref callee, _) => { - match v.tcx.def_map.borrow().find(&callee.id) { + match v.tcx.def_map.borrow().get(&callee.id) { Some(&DefStruct(..)) | Some(&DefVariant(..)) => {} // OK. diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index fe38669ea6c..4dcd5d8873e 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -639,7 +639,7 @@ fn pat_constructors(cx: &MatchCheckCtxt, p: &Pat, let pat = raw_pat(p); match pat.node { PatIdent(..) => - match cx.tcx.def_map.borrow().find(&pat.id) { + match cx.tcx.def_map.borrow().get(&pat.id) { Some(&DefConst(..)) => cx.tcx.sess.span_bug(pat.span, "const pattern should've \ been rewritten"), @@ -648,7 +648,7 @@ fn pat_constructors(cx: &MatchCheckCtxt, p: &Pat, _ => vec!() }, PatEnum(..) => - match cx.tcx.def_map.borrow().find(&pat.id) { + match cx.tcx.def_map.borrow().get(&pat.id) { Some(&DefConst(..)) => cx.tcx.sess.span_bug(pat.span, "const pattern should've \ been rewritten"), @@ -656,7 +656,7 @@ fn pat_constructors(cx: &MatchCheckCtxt, p: &Pat, _ => vec!(Single) }, PatStruct(..) => - match cx.tcx.def_map.borrow().find(&pat.id) { + match cx.tcx.def_map.borrow().get(&pat.id) { Some(&DefConst(..)) => cx.tcx.sess.span_bug(pat.span, "const pattern should've \ been rewritten"), diff --git a/src/librustc/middle/check_static_recursion.rs b/src/librustc/middle/check_static_recursion.rs index 1c83bf19919..a3738f031a9 100644 --- a/src/librustc/middle/check_static_recursion.rs +++ b/src/librustc/middle/check_static_recursion.rs @@ -95,7 +95,7 @@ impl<'a, 'ast, 'v> Visitor<'v> for CheckItemRecursionVisitor<'a, 'ast> { fn visit_expr(&mut self, e: &ast::Expr) { match e.node { ast::ExprPath(..) => { - match self.def_map.borrow().find(&e.id) { + match self.def_map.borrow().get(&e.id) { Some(&DefStatic(def_id, _)) | Some(&DefConst(def_id)) if ast_util::is_local(def_id) => { diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index ce91bd1b153..fdda5f1a860 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -123,7 +123,7 @@ fn lookup_variant_by_id<'a>(tcx: &'a ty::ctxt, Some(_) => None } } else { - match tcx.extern_const_variants.borrow().find(&variant_def) { + match tcx.extern_const_variants.borrow().get(&variant_def) { Some(&ast::DUMMY_NODE_ID) => return None, Some(&expr_id) => { return Some(tcx.map.expect_expr(expr_id)); @@ -163,7 +163,7 @@ pub fn lookup_const_by_id<'a>(tcx: &'a ty::ctxt, def_id: ast::DefId) Some(_) => None } } else { - match tcx.extern_const_statics.borrow().find(&def_id) { + match tcx.extern_const_statics.borrow().get(&def_id) { Some(&ast::DUMMY_NODE_ID) => return None, Some(&expr_id) => { return Some(tcx.map.expect_expr(expr_id)); @@ -192,7 +192,7 @@ struct ConstEvalVisitor<'a, 'tcx: 'a> { impl<'a, 'tcx> ConstEvalVisitor<'a, 'tcx> { fn classify(&mut self, e: &Expr) -> constness { let did = ast_util::local_def(e.id); - match self.ccache.find(&did) { + match self.ccache.get(&did) { Some(&x) => return x, None => {} } diff --git a/src/librustc/middle/dataflow.rs b/src/librustc/middle/dataflow.rs index 612c9a00bbe..97dfa4ecd36 100644 --- a/src/librustc/middle/dataflow.rs +++ b/src/librustc/middle/dataflow.rs @@ -86,7 +86,7 @@ struct PropagationContext<'a, 'b: 'a, 'tcx: 'b, O: 'a> { } fn to_cfgidx_or_die(id: ast::NodeId, index: &NodeMap) -> CFGIndex { - let opt_cfgindex = index.find(&id).map(|&i|i); + let opt_cfgindex = index.get(&id).map(|&i|i); opt_cfgindex.unwrap_or_else(|| { panic!("nodeid_to_index does not have entry for NodeId {}", id); }) @@ -397,7 +397,7 @@ impl<'a, 'tcx, O:DataFlowOperator> DataFlowContext<'a, 'tcx, O> { let mut changed = false; for &node_id in edge.data.exiting_scopes.iter() { - let opt_cfg_idx = self.nodeid_to_index.find(&node_id).map(|&i|i); + let opt_cfg_idx = self.nodeid_to_index.get(&node_id).map(|&i|i); match opt_cfg_idx { Some(cfg_idx) => { let (start, end) = self.compute_id_range(cfg_idx); diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index ec09706f97e..2ae2f9bfe7a 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -74,7 +74,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> { } fn lookup_and_handle_definition(&mut self, id: &ast::NodeId) { - self.tcx.def_map.borrow().find(id).map(|def| { + self.tcx.def_map.borrow().get(id).map(|def| { match def { &def::DefConst(_) => { self.check_def_id(def.def_id()) @@ -95,7 +95,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> { fn lookup_and_handle_method(&mut self, id: ast::NodeId, span: codemap::Span) { let method_call = typeck::MethodCall::expr(id); - match self.tcx.method_map.borrow().find(&method_call) { + match self.tcx.method_map.borrow().get(&method_call) { Some(method) => { match method.origin { typeck::MethodStatic(def_id) => { @@ -493,7 +493,7 @@ 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().find(&local_def(id)) { + match self.tcx.inherent_impls.borrow().get(&local_def(id)) { None => (), Some(impl_list) => { for impl_did in impl_list.iter() { diff --git a/src/librustc/middle/dependency_format.rs b/src/librustc/middle/dependency_format.rs index 20be7406204..bfabcc958d7 100644 --- a/src/librustc/middle/dependency_format.rs +++ b/src/librustc/middle/dependency_format.rs @@ -158,7 +158,7 @@ fn calculate_type(sess: &session::Session, // Collect what we've got so far in the return vector. let mut ret = range(1, sess.cstore.next_crate_num()).map(|i| { - match formats.find(&i).map(|v| *v) { + match formats.get(&i).map(|v| *v) { v @ Some(cstore::RequireDynamic) => v, _ => None, } @@ -209,7 +209,7 @@ fn add_library(sess: &session::Session, cnum: ast::CrateNum, link: cstore::LinkagePreference, m: &mut HashMap) { - match m.find(&cnum) { + match m.get(&cnum) { Some(&link2) => { // If the linkages differ, then we'd have two copies of the library // if we continued linking. If the linkages are both static, then we diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index e8a85b89b58..d12b612b033 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -162,7 +162,7 @@ impl OverloadedCallType { let trait_did = tcx.unboxed_closures .borrow() - .find(&closure_did) + .get(&closure_did) .expect("OverloadedCallType::from_unboxed_closure: didn't \ find closure id") .kind @@ -535,7 +535,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,TYPER> { match self.tcx() .method_map .borrow() - .find(&MethodCall::expr(call.id)) { + .get(&MethodCall::expr(call.id)) { Some(ref method_callee) => { OverloadedCallType::from_method_origin( self.tcx(), @@ -686,7 +686,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,TYPER> { // process. fn walk_adjustment(&mut self, expr: &ast::Expr) { let typer = self.typer; - match typer.adjustments().borrow().find(&expr.id) { + match typer.adjustments().borrow().get(&expr.id) { None => { } Some(adjustment) => { match *adjustment { diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index 08202897558..1f3473c159f 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -173,7 +173,7 @@ impl<'a> LanguageItemCollector<'a> { } // Matched. - *self.items.items.get_mut(item_index) = Some(item_def_id); + self.items.items[item_index] = Some(item_def_id); } pub fn collect_local_language_items(&mut self, krate: &ast::Crate) { diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index b5847a94b8d..dff9c45611a 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -322,7 +322,7 @@ impl<'a, 'tcx> IrMaps<'a, 'tcx> { } fn variable(&self, node_id: NodeId, span: Span) -> Variable { - match self.variable_map.find(&node_id) { + match self.variable_map.get(&node_id) { Some(&var) => var, None => { self.tcx @@ -591,7 +591,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { } fn live_node(&self, node_id: NodeId, span: Span) -> LiveNode { - match self.ir.live_node_map.find(&node_id) { + match self.ir.live_node_map.get(&node_id) { Some(&ln) => ln, None => { // This must be a mismatch between the ir_map construction @@ -719,7 +719,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { Some(_) => { // Refers to a labeled loop. Use the results of resolve // to find with one - match self.ir.tcx.def_map.borrow().find(&id) { + match self.ir.tcx.def_map.borrow().get(&id) { Some(&DefLabel(loop_id)) => loop_id, _ => self.ir.tcx.sess.span_bug(sp, "label on break/loop \ doesn't refer to a loop") @@ -988,7 +988,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { // the construction of a closure itself is not important, // but we have to consider the closed over variables. - let caps = match this.ir.capture_info_map.find(&expr.id) { + let caps = match this.ir.capture_info_map.get(&expr.id) { Some(caps) => caps.clone(), None => { this.ir.tcx.sess.span_bug(expr.span, "no registered caps"); @@ -1096,7 +1096,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { // Now that we know the label we're going to, // look it up in the break loop nodes table - match self.break_ln.find(&sc) { + match self.break_ln.get(&sc) { Some(&b) => b, None => self.ir.tcx.sess.span_bug(expr.span, "break to unknown label") @@ -1110,7 +1110,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { // Now that we know the label we're going to, // look it up in the continue loop nodes table - match self.cont_ln.find(&sc) { + match self.cont_ln.get(&sc) { Some(&b) => b, None => self.ir.tcx.sess.span_bug(expr.span, "loop to unknown label") @@ -1167,7 +1167,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { ExprMethodCall(_, _, ref args) => { let method_call = typeck::MethodCall::expr(expr.id); - let method_ty = self.ir.tcx.method_map.borrow().find(&method_call).unwrap().ty; + let method_ty = self.ir.tcx.method_map.borrow().get(&method_call).unwrap().ty; let diverges = ty::ty_fn_ret(method_ty) == ty::FnDiverging; let succ = if diverges { self.s.exit_ln @@ -1520,7 +1520,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { ty::ty_unboxed_closure(closure_def_id, _, _) => self.ir.tcx.unboxed_closures() .borrow() - .find(&closure_def_id) + .get(&closure_def_id) .unwrap() .closure_type .sig diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index c0188cac259..4c396a5a205 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -389,7 +389,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { fn expr_ty_adjusted(&self, expr: &ast::Expr) -> McResult { let unadjusted_ty = if_ok!(self.expr_ty(expr)); Ok(ty::adjust_ty(self.tcx(), expr.span, expr.id, unadjusted_ty, - self.typer.adjustments().borrow().find(&expr.id), + self.typer.adjustments().borrow().get(&expr.id), |method_call| self.typer.node_method_ty(method_call))) } @@ -402,7 +402,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { } pub fn cat_expr(&self, expr: &ast::Expr) -> McResult { - match self.typer.adjustments().borrow().find(&expr.id) { + match self.typer.adjustments().borrow().get(&expr.id) { None => { // No adjustments. self.cat_expr_unadjusted(expr) @@ -861,7 +861,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { deref_cnt: uint, implicit: bool) -> cmt { - let adjustment = match self.typer.adjustments().borrow().find(&node.id()) { + let adjustment = match self.typer.adjustments().borrow().get(&node.id()) { Some(adj) if ty::adjust_is_object(adj) => typeck::AutoObject, _ if deref_cnt != 0 => typeck::AutoDeref(deref_cnt), _ => typeck::NoAdjustment @@ -1170,7 +1170,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { // variant(..) } ast::PatEnum(_, Some(ref subpats)) => { - match self.tcx().def_map.borrow().find(&pat.id) { + match self.tcx().def_map.borrow().get(&pat.id) { Some(&def::DefVariant(enum_did, _, _)) => { // variant(x, y, z) diff --git a/src/librustc/middle/pat_util.rs b/src/librustc/middle/pat_util.rs index 357f4cdf0eb..958f65d7efb 100644 --- a/src/librustc/middle/pat_util.rs +++ b/src/librustc/middle/pat_util.rs @@ -34,7 +34,7 @@ pub fn pat_is_refutable(dm: &resolve::DefMap, pat: &Pat) -> bool { match pat.node { PatLit(_) | PatRange(_, _) => true, PatEnum(_, _) | PatIdent(_, _, None) | PatStruct(..) => { - match dm.borrow().find(&pat.id) { + match dm.borrow().get(&pat.id) { Some(&DefVariant(..)) => true, _ => false } @@ -47,7 +47,7 @@ pub fn pat_is_refutable(dm: &resolve::DefMap, pat: &Pat) -> bool { pub fn pat_is_variant_or_struct(dm: &resolve::DefMap, pat: &Pat) -> bool { match pat.node { PatEnum(_, _) | PatIdent(_, _, None) | PatStruct(..) => { - match dm.borrow().find(&pat.id) { + match dm.borrow().get(&pat.id) { Some(&DefVariant(..)) | Some(&DefStruct(..)) => true, _ => false } @@ -59,7 +59,7 @@ pub fn pat_is_variant_or_struct(dm: &resolve::DefMap, pat: &Pat) -> bool { pub fn pat_is_const(dm: &resolve::DefMap, pat: &Pat) -> bool { match pat.node { PatIdent(_, _, None) | PatEnum(..) => { - match dm.borrow().find(&pat.id) { + match dm.borrow().get(&pat.id) { Some(&DefConst(..)) => true, _ => false } diff --git a/src/librustc/middle/privacy.rs b/src/librustc/middle/privacy.rs index 4fbffa2a819..24c653e415e 100644 --- a/src/librustc/middle/privacy.rs +++ b/src/librustc/middle/privacy.rs @@ -399,7 +399,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> { } debug!("privacy - is {} a public method", did); - return match self.tcx.impl_or_trait_items.borrow().find(&did) { + return match self.tcx.impl_or_trait_items.borrow().get(&did) { Some(&ty::MethodTraitItem(ref meth)) => { debug!("privacy - well at least it's a method: {}", *meth); @@ -462,7 +462,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> { debug!("privacy - local {} not public all the way down", self.tcx.map.node_to_string(did.node)); // return quickly for things in the same module - if self.parents.find(&did.node) == self.parents.find(&self.curitem) { + if self.parents.get(&did.node) == self.parents.get(&self.curitem) { debug!("privacy - same parent, we're done here"); return Allowable; } @@ -855,7 +855,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> { } ast::ExprMethodCall(ident, _, _) => { let method_call = MethodCall::expr(expr.id); - match self.tcx.method_map.borrow().find(&method_call) { + match self.tcx.method_map.borrow().get(&method_call) { None => { self.tcx.sess.span_bug(expr.span, "method call not in \ @@ -909,7 +909,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> { with private fields"); } }; - match self.tcx.def_map.borrow().find(&expr.id) { + match self.tcx.def_map.borrow().get(&expr.id) { Some(&def::DefStruct(did)) => { guard(if is_local(did) { local_def(self.tcx.map.get_parent(did.node)) @@ -986,7 +986,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> { } } ty::ty_enum(_, _) => { - match self.tcx.def_map.borrow().find(&pattern.id) { + match self.tcx.def_map.borrow().get(&pattern.id) { Some(&def::DefVariant(_, variant_id, _)) => { for field in fields.iter() { self.check_field(pattern.span, variant_id, diff --git a/src/librustc/middle/reachable.rs b/src/librustc/middle/reachable.rs index 4506cd7e463..dbeb2e289fb 100644 --- a/src/librustc/middle/reachable.rs +++ b/src/librustc/middle/reachable.rs @@ -106,7 +106,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for ReachableContext<'a, 'tcx> { match expr.node { ast::ExprPath(_) => { - let def = match self.tcx.def_map.borrow().find(&expr.id) { + let def = match self.tcx.def_map.borrow().get(&expr.id) { Some(&def) => def, None => { self.tcx.sess.span_bug(expr.span, diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index 32e373f5851..d380c35580d 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -103,7 +103,7 @@ struct RegionResolutionVisitor<'a> { impl RegionMaps { pub fn relate_free_regions(&self, sub: FreeRegion, sup: FreeRegion) { - match self.free_region_map.borrow_mut().find_mut(&sub) { + match self.free_region_map.borrow_mut().get_mut(&sub) { Some(sups) => { if !sups.iter().any(|x| x == &sup) { sups.push(sup); @@ -149,13 +149,13 @@ impl RegionMaps { pub fn opt_encl_scope(&self, id: ast::NodeId) -> Option { //! Returns the narrowest scope that encloses `id`, if any. - self.scope_map.borrow().find(&id).map(|x| *x) + self.scope_map.borrow().get(&id).map(|x| *x) } #[allow(dead_code)] // used in middle::cfg pub fn encl_scope(&self, id: ast::NodeId) -> ast::NodeId { //! Returns the narrowest scope that encloses `id`, if any. - match self.scope_map.borrow().find(&id) { + match self.scope_map.borrow().get(&id) { Some(&r) => r, None => { panic!("no enclosing scope for id {}", id); } } @@ -165,7 +165,7 @@ impl RegionMaps { /*! * Returns the lifetime of the local variable `var_id` */ - match self.var_map.borrow().find(&var_id) { + match self.var_map.borrow().get(&var_id) { Some(&r) => r, None => { panic!("no enclosing scope for id {}", var_id); } } @@ -175,7 +175,7 @@ impl RegionMaps { //! Returns the scope when temp created by expr_id will be cleaned up // check for a designated rvalue scope - match self.rvalue_scopes.borrow().find(&expr_id) { + match self.rvalue_scopes.borrow().get(&expr_id) { Some(&s) => { debug!("temporary_scope({}) = {} [custom]", expr_id, s); return Some(s); @@ -232,7 +232,7 @@ impl RegionMaps { let mut s = subscope; while superscope != s { - match self.scope_map.borrow().find(&s) { + match self.scope_map.borrow().get(&s) { None => { debug!("is_subscope_of({}, {}, s={})=false", subscope, superscope, s); @@ -356,7 +356,7 @@ impl RegionMaps { let mut result = vec!(scope); let mut scope = scope; loop { - match this.scope_map.borrow().find(&scope) { + match this.scope_map.borrow().get(&scope) { None => return result, Some(&superscope) => { result.push(superscope); diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index ed7d9296c70..a8adbbe8fec 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -2234,7 +2234,7 @@ impl<'a> Resolver<'a> { let mut import_resolutions = module_.import_resolutions .borrow_mut(); - match import_resolutions.find_mut(&target) { + match import_resolutions.get_mut(&target) { Some(resolution) => { debug!("(building import directive) bumping \ reference"); @@ -2552,7 +2552,7 @@ impl<'a> Resolver<'a> { // Search for direct children of the containing module. self.populate_module_if_necessary(&containing_module); - match containing_module.children.borrow().find(&source) { + match containing_module.children.borrow().get(&source) { None => { // Continue. } @@ -2588,7 +2588,7 @@ impl<'a> Resolver<'a> { } // Now search the exported imports within the containing module. - match containing_module.import_resolutions.borrow().find(&source) { + match containing_module.import_resolutions.borrow().get(&source) { None => { debug!("(resolving single import) no import"); // The containing module definitely doesn't have an @@ -2853,7 +2853,7 @@ impl<'a> Resolver<'a> { // Here we merge two import resolutions. let mut import_resolutions = module_.import_resolutions.borrow_mut(); - match import_resolutions.find_mut(ident) { + match import_resolutions.get_mut(ident) { Some(dest_import_resolution) => { // Merge the two import resolutions at a finer-grained // level. @@ -3046,7 +3046,7 @@ impl<'a> Resolver<'a> { // Check for item conflicts. let children = module.children.borrow(); - let name_bindings = match children.find(&name) { + let name_bindings = match children.get(&name) { None => { // There can't be any conflicts. return @@ -3432,7 +3432,7 @@ impl<'a> Resolver<'a> { // its immediate children. self.populate_module_if_necessary(&module_); - match module_.children.borrow().find(&name) { + match module_.children.borrow().get(&name) { Some(name_bindings) if name_bindings.defined_in_namespace(namespace) => { debug!("top name bindings succeeded"); @@ -3448,7 +3448,7 @@ impl<'a> Resolver<'a> { // all its imports in the usual way; this is because chains of // adjacent import statements are processed as though they mutated the // current scope. - match module_.import_resolutions.borrow().find(&name) { + match module_.import_resolutions.borrow().get(&name) { None => { // Not found; continue. } @@ -3705,7 +3705,7 @@ impl<'a> Resolver<'a> { // First, check the direct children of the module. self.populate_module_if_necessary(&module_); - match module_.children.borrow().find(&name) { + match module_.children.borrow().get(&name) { Some(name_bindings) if name_bindings.defined_in_namespace(namespace) => { debug!("(resolving name in module) found node as child"); @@ -3728,7 +3728,7 @@ impl<'a> Resolver<'a> { } // Check the list of resolved imports. - match module_.import_resolutions.borrow().find(&name) { + match module_.import_resolutions.borrow().get(&name) { Some(import_resolution) if allow_private_imports || import_resolution.is_public => { @@ -3967,7 +3967,7 @@ impl<'a> Resolver<'a> { Some(name) => { self.populate_module_if_necessary(&orig_module); - match orig_module.children.borrow().find(&name) { + match orig_module.children.borrow().get(&name) { None => { debug!("!!! (with scope) didn't find `{}` in `{}`", token::get_name(name), @@ -4691,7 +4691,7 @@ impl<'a> Resolver<'a> { Some(ref trait_ref) => { self.resolve_trait_reference(id, trait_ref, TraitImplementation); - match self.def_map.borrow().find(&trait_ref.ref_id) { + match self.def_map.borrow().get(&trait_ref.ref_id) { Some(def) => { let did = def.def_id(); Some((did, trait_ref.clone())) @@ -4767,7 +4767,7 @@ impl<'a> Resolver<'a> { // a type (shadowing any imported modules or types with this name), leading // to weird user-visible bugs. So we ward this off here. See #15060. TyPath(ref path, _, path_id) => { - match self.def_map.borrow().find(&path_id) { + match self.def_map.borrow().get(&path_id) { // FIXME: should we catch other options and give more precise errors? Some(&DefMod(_)) => { self.resolve_error(path.span, "inherent implementations are not \ @@ -4785,7 +4785,7 @@ impl<'a> Resolver<'a> { fn check_trait_item(&self, name: Name, span: Span) { // If there is a TraitRef in scope for an impl, then the method must be in the trait. for &(did, ref trait_ref) in self.current_trait_ref.iter() { - if self.trait_item_map.find(&(name, did)).is_none() { + if self.trait_item_map.get(&(name, did)).is_none() { let path_str = self.path_names_to_string(&trait_ref.path); self.resolve_error(span, format!("method `{}` is not a member of trait `{}`", @@ -4849,7 +4849,7 @@ impl<'a> Resolver<'a> { let map_i = self.binding_mode_map(&**p); for (&key, &binding_0) in map_0.iter() { - match map_i.find(&key) { + match map_i.get(&key) { None => { self.resolve_error( p.span, @@ -4908,7 +4908,7 @@ impl<'a> Resolver<'a> { // Move down in the graph, if there's an anonymous module rooted here. let orig_module = self.current_module.clone(); - match orig_module.anonymous_children.borrow().find(&block.id) { + match orig_module.anonymous_children.borrow().get(&block.id) { None => { /* Nothing to do. */ } Some(anonymous_module) => { debug!("(resolving block) found anonymous module, moving \ @@ -4943,7 +4943,7 @@ impl<'a> Resolver<'a> { match self.primitive_type_table .primitive_types - .find(&id.name) { + .get(&id.name) { Some(&primitive_type) => { result_def = @@ -5181,7 +5181,7 @@ impl<'a> Resolver<'a> { token::get_ident( ident)) .as_slice()) - } else if bindings_list.find(&renamed) == + } else if bindings_list.get(&renamed) == Some(&pat_id) { // Then this is a duplicate variable in the // same disjunction, which is an error. @@ -5407,7 +5407,7 @@ impl<'a> Resolver<'a> { // First, search children. self.populate_module_if_necessary(&containing_module); - match containing_module.children.borrow().find(&name) { + match containing_module.children.borrow().get(&name) { Some(child_name_bindings) => { match child_name_bindings.def_for_namespace(namespace) { Some(def) => { @@ -5426,7 +5426,7 @@ impl<'a> Resolver<'a> { } // Next, search import resolutions. - match containing_module.import_resolutions.borrow().find(&name) { + match containing_module.import_resolutions.borrow().get(&name) { Some(import_resolution) if import_resolution.is_public => { match (*import_resolution).target_for_namespace(namespace) { Some(target) => { @@ -5715,10 +5715,10 @@ impl<'a> Resolver<'a> { let last_name = name_path.last().unwrap(); if name_path.len() == 1 { - match this.primitive_type_table.primitive_types.find(last_name) { + match this.primitive_type_table.primitive_types.get(last_name) { Some(_) => None, None => { - match this.current_module.children.borrow().find(last_name) { + match this.current_module.children.borrow().get(last_name) { Some(child) => child.get_module_if_available(), None => None } @@ -5746,10 +5746,10 @@ impl<'a> Resolver<'a> { if allowed == Everything { // Look for a field with the same name in the current self_type. - match self.def_map.borrow().find(&node_id) { + match self.def_map.borrow().get(&node_id) { Some(&DefTy(did, _)) | Some(&DefStruct(did)) - | Some(&DefVariant(_, did, _)) => match self.structs.find(&did) { + | Some(&DefVariant(_, did, _)) => match self.structs.get(&did) { None => {} Some(fields) => { if fields.iter().any(|&field_name| name == field_name) { @@ -5765,7 +5765,7 @@ impl<'a> Resolver<'a> { // Look for a method in the current self type's impl module. match get_module(self, path.span, name_path.as_slice()) { - Some(module) => match module.children.borrow().find(&name) { + Some(module) => match module.children.borrow().get(&name) { Some(binding) => { let p_str = self.path_names_to_string(&path); match binding.def_for_namespace(ValueNS) { @@ -5790,7 +5790,7 @@ impl<'a> Resolver<'a> { Some((did, ref trait_ref)) => { let path_str = self.path_names_to_string(&trait_ref.path); - match self.trait_item_map.find(&(name, did)) { + match self.trait_item_map.get(&(name, did)) { Some(&StaticMethodTraitItemKind) => { return TraitMethod(path_str) } @@ -6270,7 +6270,7 @@ impl<'a> Resolver<'a> { "unused import".to_string()); } - let (v_priv, t_priv) = match self.last_private.find(&id) { + let (v_priv, t_priv) = match self.last_private.get(&id) { Some(&LastImport { value_priv: v, value_used: _, diff --git a/src/librustc/middle/traits/select.rs b/src/librustc/middle/traits/select.rs index 09bd0f52985..7fcc58d8f4e 100644 --- a/src/librustc/middle/traits/select.rs +++ b/src/librustc/middle/traits/select.rs @@ -906,7 +906,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { { let cache = self.pick_candidate_cache(&cache_skol_trait_ref); let hashmap = cache.hashmap.borrow(); - hashmap.find(&cache_skol_trait_ref).map(|c| (*c).clone()) + hashmap.get(&cache_skol_trait_ref).map(|c| (*c).clone()) } fn insert_candidate_cache(&mut self, @@ -1032,7 +1032,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { self_ty.repr(self.tcx()), obligation.repr(self.tcx())); - let closure_kind = match self.typer.unboxed_closures().borrow().find(&closure_def_id) { + let closure_kind = match self.typer.unboxed_closures().borrow().get(&closure_def_id) { Some(closure) => closure.kind, None => { self.tcx().sess.span_bug( @@ -1282,7 +1282,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { ty::BoundSync | ty::BoundSend => { - if c.bounds.builtin_bounds.contains_elem(bound) { + if c.bounds.builtin_bounds.contains(&bound) { Ok(If(Vec::new())) } else { Err(Unimplemented) @@ -1306,7 +1306,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { ty::BoundSync | ty::BoundSend => { - if c.bounds.builtin_bounds.contains_elem(bound) { + if c.bounds.builtin_bounds.contains(&bound) { Ok(If(Vec::new())) } else { Err(Unimplemented) @@ -1323,7 +1323,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { Err(Unimplemented) } ty::BoundCopy | ty::BoundSync | ty::BoundSend => { - if bounds.builtin_bounds.contains_elem(bound) { + if bounds.builtin_bounds.contains(&bound) { Ok(If(Vec::new())) } else { Err(Unimplemented) @@ -1428,7 +1428,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // is reserve judgement and then intertwine this // analysis with closure inference. assert_eq!(def_id.krate, ast::LOCAL_CRATE); - match self.tcx().freevars.borrow().find(&def_id.node) { + match self.tcx().freevars.borrow().get(&def_id.node) { None => { // No upvars. Ok(If(Vec::new())) @@ -1690,7 +1690,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { closure_def_id.repr(self.tcx()), substs.repr(self.tcx())); - let closure_type = match self.typer.unboxed_closures().borrow().find(&closure_def_id) { + let closure_type = match self.typer.unboxed_closures().borrow().get(&closure_def_id) { Some(closure) => closure.closure_type.clone(), None => { self.tcx().sess.span_bug( @@ -1973,7 +1973,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { ty::populate_implementations_for_trait_if_necessary(self.tcx(), trait_def_id); - match self.tcx().trait_impls.borrow().find(&trait_def_id) { + match self.tcx().trait_impls.borrow().get(&trait_def_id) { None => Vec::new(), Some(impls) => impls.borrow().clone() } diff --git a/src/librustc/middle/trans/_match.rs b/src/librustc/middle/trans/_match.rs index 70aef4504f0..e148261b1bf 100644 --- a/src/librustc/middle/trans/_match.rs +++ b/src/librustc/middle/trans/_match.rs @@ -696,13 +696,13 @@ fn any_irrefutable_adt_pat(tcx: &ty::ctxt, m: &[Match], col: uint) -> bool { match pat.node { ast::PatTup(_) => true, ast::PatStruct(..) => { - match tcx.def_map.borrow().find(&pat.id) { + match tcx.def_map.borrow().get(&pat.id) { Some(&def::DefVariant(..)) => false, _ => true, } } ast::PatEnum(..) | ast::PatIdent(_, _, None) => { - match tcx.def_map.borrow().find(&pat.id) { + match tcx.def_map.borrow().get(&pat.id) { Some(&def::DefStruct(..)) => true, _ => false } diff --git a/src/librustc/middle/trans/adt.rs b/src/librustc/middle/trans/adt.rs index d3658e89a2a..7ff94c28d93 100644 --- a/src/librustc/middle/trans/adt.rs +++ b/src/librustc/middle/trans/adt.rs @@ -147,7 +147,7 @@ pub fn represent_node(bcx: Block, node: ast::NodeId) -> Rc { /// Decides how to represent a given type. pub fn represent_type(cx: &CrateContext, t: ty::t) -> Rc { debug!("Representing: {}", ty_to_string(cx.tcx(), t)); - match cx.adt_reprs().borrow().find(&t) { + match cx.adt_reprs().borrow().get(&t) { Some(repr) => return repr.clone(), None => {} } diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index b80425e7ac8..3b3b886c6d0 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -316,7 +316,7 @@ pub fn get_extern_const(ccx: &CrateContext, did: ast::DefId, t: ty::t) -> ValueRef { let name = csearch::get_symbol(&ccx.sess().cstore, did); let ty = type_of(ccx, t); - match ccx.externs().borrow_mut().find(&name) { + match ccx.externs().borrow_mut().get(&name) { Some(n) => return *n, None => () } @@ -409,7 +409,7 @@ pub fn malloc_raw_dyn_proc<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, t: ty::t) -> Resu // Type descriptor and type glue stuff pub fn get_tydesc(ccx: &CrateContext, t: ty::t) -> Rc { - match ccx.tydescs().borrow().find(&t) { + match ccx.tydescs().borrow().get(&t) { Some(inf) => return inf.clone(), _ => { } } @@ -2100,7 +2100,7 @@ fn enum_variant_size_lint(ccx: &CrateContext, enum_def: &ast::EnumDef, sp: Span, let levels = ccx.tcx().node_lint_levels.borrow(); let lint_id = lint::LintId::of(lint::builtin::VARIANT_SIZE_DIFFERENCES); - let lvlsrc = match levels.find(&(id, lint_id)) { + let lvlsrc = match levels.get(&(id, lint_id)) { None | Some(&(lint::Allow, _)) => return, Some(&lvlsrc) => lvlsrc, }; @@ -2645,7 +2645,7 @@ pub fn create_entry_wrapper(ccx: &CrateContext, fn exported_name(ccx: &CrateContext, id: ast::NodeId, ty: ty::t, attrs: &[ast::Attribute]) -> String { - match ccx.external_srcs().borrow().find(&id) { + match ccx.external_srcs().borrow().get(&id) { Some(&did) => { let sym = csearch::get_symbol(&ccx.sess().cstore, did); debug!("found item {} in other crate...", sym); @@ -3123,7 +3123,7 @@ pub fn trans_crate<'tcx>(analysis: CrateAnalysis<'tcx>) .collect(); let mut reachable: Vec = shared_ccx.reachable().iter().filter_map(|id| { - shared_ccx.item_symbols().borrow().find(id).map(|s| s.to_string()) + shared_ccx.item_symbols().borrow().get(id).map(|s| s.to_string()) }).collect(); // For the purposes of LTO, we add to the reachable set all of the upstream diff --git a/src/librustc/middle/trans/builder.rs b/src/librustc/middle/trans/builder.rs index 81428937e4b..b692b01f765 100644 --- a/src/librustc/middle/trans/builder.rs +++ b/src/librustc/middle/trans/builder.rs @@ -81,7 +81,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { s.push('/'); s.push_str(category); - let n = match h.find(&s) { + let n = match h.get(&s) { Some(&n) => n, _ => 0u }; diff --git a/src/librustc/middle/trans/closure.rs b/src/librustc/middle/trans/closure.rs index decd238627c..16db4daba46 100644 --- a/src/librustc/middle/trans/closure.rs +++ b/src/librustc/middle/trans/closure.rs @@ -438,7 +438,7 @@ pub fn get_or_create_declaration_if_unboxed_closure<'blk, 'tcx>(bcx: Block<'blk, params: params }; - match ccx.unboxed_closure_vals().borrow().find(&mono_id) { + match ccx.unboxed_closure_vals().borrow().get(&mono_id) { Some(llfn) => { debug!("get_or_create_declaration_if_unboxed_closure(): found \ closure"); @@ -564,7 +564,7 @@ pub fn get_wrapper_for_bare_fn(ccx: &CrateContext, } }; - match ccx.closure_bare_wrapper_cache().borrow().find(&fn_ptr) { + match ccx.closure_bare_wrapper_cache().borrow().get(&fn_ptr) { Some(&llval) => return llval, None => {} } diff --git a/src/librustc/middle/trans/common.rs b/src/librustc/middle/trans/common.rs index 8b5e82ecf90..18501dd9e34 100644 --- a/src/librustc/middle/trans/common.rs +++ b/src/librustc/middle/trans/common.rs @@ -466,7 +466,7 @@ impl<'blk, 'tcx> BlockS<'blk, 'tcx> { } pub fn def(&self, nid: ast::NodeId) -> def::Def { - match self.tcx().def_map.borrow().find(&nid) { + match self.tcx().def_map.borrow().get(&nid) { Some(v) => v.clone(), None => { self.tcx().sess.bug(format!( @@ -505,7 +505,7 @@ impl<'blk, 'tcx> mc::Typer<'tcx> for BlockS<'blk, 'tcx> { self.tcx() .method_map .borrow() - .find(&method_call) + .get(&method_call) .map(|method| monomorphize_type(self, method.ty)) } @@ -647,7 +647,7 @@ pub fn C_u8(ccx: &CrateContext, i: uint) -> ValueRef { // our boxed-and-length-annotated strings. pub fn C_cstr(cx: &CrateContext, s: InternedString, null_terminated: bool) -> ValueRef { unsafe { - match cx.const_cstr_cache().borrow().find(&s) { + match cx.const_cstr_cache().borrow().get(&s) { Some(&llval) => return llval, None => () } @@ -813,7 +813,7 @@ pub fn fulfill_obligation(ccx: &CrateContext, let trait_ref = ty_fold::erase_regions(tcx, trait_ref); // First check the cache. - match ccx.trait_cache().borrow().find(&trait_ref) { + match ccx.trait_cache().borrow().get(&trait_ref) { Some(vtable) => { info!("Cache hit: {}", trait_ref.repr(ccx.tcx())); return (*vtable).clone(); diff --git a/src/librustc/middle/trans/consts.rs b/src/librustc/middle/trans/consts.rs index 6ba6ff6fb21..ced6c2f4949 100644 --- a/src/librustc/middle/trans/consts.rs +++ b/src/librustc/middle/trans/consts.rs @@ -90,7 +90,7 @@ pub fn const_lit(cx: &CrateContext, e: &ast::Expr, lit: &ast::Lit) pub fn const_ptrcast(cx: &CrateContext, a: ValueRef, t: Type) -> ValueRef { unsafe { let b = llvm::LLVMConstPointerCast(a, t.ptr_to().to_ref()); - assert!(cx.const_globals().borrow_mut().insert(b as int, a)); + assert!(cx.const_globals().borrow_mut().insert(b as int, a).is_none()); b } } @@ -125,7 +125,7 @@ pub fn const_addr_of(cx: &CrateContext, cv: ValueRef, mutbl: ast::Mutability) -> } fn const_deref_ptr(cx: &CrateContext, v: ValueRef) -> ValueRef { - let v = match cx.const_globals().borrow().find(&(v as int)) { + let v = match cx.const_globals().borrow().get(&(v as int)) { Some(&v) => v, None => v }; diff --git a/src/librustc/middle/trans/controlflow.rs b/src/librustc/middle/trans/controlflow.rs index 911ae42e142..714d5ab248d 100644 --- a/src/librustc/middle/trans/controlflow.rs +++ b/src/librustc/middle/trans/controlflow.rs @@ -421,7 +421,7 @@ pub fn trans_break_cont<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, let loop_id = match opt_label { None => fcx.top_loop_scope(), Some(_) => { - match bcx.tcx().def_map.borrow().find(&expr_id) { + match bcx.tcx().def_map.borrow().get(&expr_id) { Some(&def::DefLabel(loop_id)) => loop_id, ref r => { bcx.tcx().sess.bug(format!("{} in def-map for label", diff --git a/src/librustc/middle/trans/debuginfo.rs b/src/librustc/middle/trans/debuginfo.rs index ea7f28796f0..c84543773a4 100644 --- a/src/librustc/middle/trans/debuginfo.rs +++ b/src/librustc/middle/trans/debuginfo.rs @@ -282,7 +282,7 @@ impl TypeMap { cx: &CrateContext, type_: ty::t, metadata: DIType) { - if !self.type_to_metadata.insert(ty::type_id(type_), metadata) { + if self.type_to_metadata.insert(ty::type_id(type_), metadata).is_some() { cx.sess().bug(format!("Type metadata for ty::t '{}' is already in the TypeMap!", ppaux::ty_to_string(cx.tcx(), type_)).as_slice()); } @@ -294,7 +294,7 @@ impl TypeMap { cx: &CrateContext, unique_type_id: UniqueTypeId, metadata: DIType) { - if !self.unique_id_to_metadata.insert(unique_type_id, metadata) { + if self.unique_id_to_metadata.insert(unique_type_id, metadata).is_some() { let unique_type_id_str = self.get_unique_type_id_as_string(unique_type_id); cx.sess().bug(format!("Type metadata for unique id '{}' is already in the TypeMap!", unique_type_id_str.as_slice()).as_slice()); @@ -468,7 +468,7 @@ impl TypeMap { }, ty::ty_unboxed_closure(ref def_id, _, ref substs) => { let closure_ty = cx.tcx().unboxed_closures.borrow() - .find(def_id).unwrap().closure_type.subst(cx.tcx(), substs); + .get(def_id).unwrap().closure_type.subst(cx.tcx(), substs); self.get_unique_type_id_of_closure_type(cx, closure_ty, &mut unique_type_id); @@ -2939,7 +2939,7 @@ fn type_metadata(cx: &CrateContext, } ty::ty_unboxed_closure(ref def_id, _, ref substs) => { let sig = cx.tcx().unboxed_closures.borrow() - .find(def_id).unwrap().closure_type.sig.subst(cx.tcx(), substs); + .get(def_id).unwrap().closure_type.sig.subst(cx.tcx(), substs); subroutine_type_metadata(cx, unique_type_id, &sig, usage_site_span) } ty::ty_struct(def_id, ref substs) => { diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs index a0ba2996334..b01d891270b 100644 --- a/src/librustc/middle/trans/expr.rs +++ b/src/librustc/middle/trans/expr.rs @@ -212,7 +212,7 @@ fn apply_adjustments<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, // Don't skip a conversion from Box to &T, etc. ty::ty_rptr(..) => { let method_call = MethodCall::autoderef(expr.id, adj.autoderefs-1); - let method = bcx.tcx().method_map.borrow().find(&method_call).is_some(); + let method = bcx.tcx().method_map.borrow().get(&method_call).is_some(); if method { // Don't skip an overloaded deref. (adj.autoderefs, true) @@ -601,7 +601,7 @@ fn trans_datum_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, let method_ty = ccx.tcx() .method_map .borrow() - .find(&method_call) + .get(&method_call) .map(|method| method.ty); let base_datum = unpack_datum!(bcx, trans(bcx, &**base)); @@ -736,7 +736,7 @@ fn trans_index<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, let method_ty = ccx.tcx() .method_map .borrow() - .find(&method_call) + .get(&method_call) .map(|method| method.ty); let elt_datum = match method_ty { Some(method_ty) => { @@ -1114,7 +1114,7 @@ fn trans_rvalue_dps_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, if ty::type_is_trait(node_id_type(bcx, expr.id)) { let trait_ref = bcx.tcx().object_cast_map.borrow() - .find(&expr.id) + .get(&expr.id) .map(|t| (*t).clone()) .unwrap(); let trait_ref = @@ -1232,7 +1232,7 @@ pub fn trans_local_var<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, def::DefUpvar(nid, _, _) => { // Can't move upvars, so this is never a ZeroMemLastUse. let local_ty = node_id_type(bcx, nid); - match bcx.fcx.llupvars.borrow().find(&nid) { + match bcx.fcx.llupvars.borrow().get(&nid) { Some(&val) => Datum::new(val, local_ty, Lvalue), None => { bcx.sess().bug(format!( @@ -1242,7 +1242,7 @@ pub fn trans_local_var<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, } } def::DefLocal(nid) => { - let datum = match bcx.fcx.lllocals.borrow().find(&nid) { + let datum = match bcx.fcx.lllocals.borrow().get(&nid) { Some(&v) => v, None => { bcx.sess().bug(format!( @@ -2089,7 +2089,7 @@ fn deref_once<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, // Check for overloaded deref. let method_ty = ccx.tcx().method_map.borrow() - .find(&method_call).map(|method| method.ty); + .get(&method_call).map(|method| method.ty); let datum = match method_ty { Some(method_ty) => { // Overloaded. Evaluate `trans_overloaded_op`, which will diff --git a/src/librustc/middle/trans/glue.rs b/src/librustc/middle/trans/glue.rs index fb85e619866..eb6e67efd49 100644 --- a/src/librustc/middle/trans/glue.rs +++ b/src/librustc/middle/trans/glue.rs @@ -144,7 +144,7 @@ pub fn get_drop_glue(ccx: &CrateContext, t: ty::t) -> ValueRef { debug!("make drop glue for {}", ppaux::ty_to_string(ccx.tcx(), t)); let t = get_drop_glue_type(ccx, t); debug!("drop glue type {}", ppaux::ty_to_string(ccx.tcx(), t)); - match ccx.drop_glues().borrow().find(&t) { + match ccx.drop_glues().borrow().get(&t) { Some(&glue) => return glue, _ => { } } @@ -157,7 +157,7 @@ pub fn get_drop_glue(ccx: &CrateContext, t: ty::t) -> ValueRef { let llfnty = Type::glue_fn(ccx, llty); - let (glue, new_sym) = match ccx.available_drop_glues().borrow().find(&t) { + let (glue, new_sym) = match ccx.available_drop_glues().borrow().get(&t) { Some(old_sym) => { let glue = decl_cdecl_fn(ccx, old_sym.as_slice(), llfnty, ty::mk_nil()); (glue, None) diff --git a/src/librustc/middle/trans/inline.rs b/src/librustc/middle/trans/inline.rs index 048402782a6..65d7749b489 100644 --- a/src/librustc/middle/trans/inline.rs +++ b/src/librustc/middle/trans/inline.rs @@ -21,7 +21,7 @@ use syntax::ast_util::{local_def, PostExpansionMethod}; fn instantiate_inline(ccx: &CrateContext, fn_id: ast::DefId) -> Option { let _icx = push_ctxt("maybe_instantiate_inline"); - match ccx.external().borrow().find(&fn_id) { + match ccx.external().borrow().get(&fn_id) { Some(&Some(node_id)) => { // Already inline debug!("maybe_instantiate_inline({}): already inline as node id {}", diff --git a/src/librustc/middle/trans/meth.rs b/src/librustc/middle/trans/meth.rs index fbd4db959ce..0ae728c71ee 100644 --- a/src/librustc/middle/trans/meth.rs +++ b/src/librustc/middle/trans/meth.rs @@ -116,7 +116,7 @@ pub fn trans_method_callee<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, let (origin, method_ty) = bcx.tcx().method_map .borrow() - .find(&method_call) + .get(&method_call) .map(|method| (method.origin.clone(), method.ty)) .unwrap(); @@ -308,7 +308,7 @@ fn method_with_name(ccx: &CrateContext, impl_id: ast::DefId, name: ast::Name) let impl_items = ccx.tcx().impl_items.borrow(); let impl_items = - impl_items.find(&impl_id) + impl_items.get(&impl_id) .expect("could not find impl while translating"); let meth_did = impl_items.iter() .find(|&did| { @@ -559,7 +559,7 @@ pub fn get_vtable(bcx: Block, // Check the cache. let cache_key = (box_ty, trait_ref.clone()); - match ccx.vtables().borrow().find(&cache_key) { + match ccx.vtables().borrow().get(&cache_key) { Some(&val) => { return val } None => { } } @@ -599,7 +599,7 @@ pub fn get_vtable(bcx: Block, .unboxed_closures .borrow(); let closure_info = - unboxed_closures.find(&closure_def_id) + unboxed_closures.get(&closure_def_id) .expect("get_vtable(): didn't find \ unboxed closure"); if closure_info.kind == ty::FnOnceUnboxedClosureKind { diff --git a/src/librustc/middle/trans/monomorphize.rs b/src/librustc/middle/trans/monomorphize.rs index 258d12e631f..f9d42240f35 100644 --- a/src/librustc/middle/trans/monomorphize.rs +++ b/src/librustc/middle/trans/monomorphize.rs @@ -54,7 +54,7 @@ pub fn monomorphic_fn(ccx: &CrateContext, params: real_substs.types.clone() }; - match ccx.monomorphized().borrow().find(&hash_id) { + match ccx.monomorphized().borrow().get(&hash_id) { Some(&val) => { debug!("leaving monomorphic fn {}", ty::item_path_str(ccx.tcx(), fn_id)); @@ -106,7 +106,7 @@ pub fn monomorphic_fn(ccx: &CrateContext, let depth; { let mut monomorphizing = ccx.monomorphizing().borrow_mut(); - depth = match monomorphizing.find(&fn_id) { + depth = match monomorphizing.get(&fn_id) { Some(&d) => d, None => 0 }; diff --git a/src/librustc/middle/trans/type_.rs b/src/librustc/middle/trans/type_.rs index 7b8eb4e02b2..175b0d7adde 100644 --- a/src/librustc/middle/trans/type_.rs +++ b/src/librustc/middle/trans/type_.rs @@ -332,7 +332,7 @@ impl TypeNames { pub fn associate_type(&self, s: &str, t: &Type) { assert!(self.named_types.borrow_mut().insert(s.to_string(), - t.to_ref())); + t.to_ref()).is_none()); } pub fn find_type(&self, s: &str) -> Option { diff --git a/src/librustc/middle/trans/type_of.rs b/src/librustc/middle/trans/type_of.rs index 649dbbacc69..d1b8f767bc8 100644 --- a/src/librustc/middle/trans/type_of.rs +++ b/src/librustc/middle/trans/type_of.rs @@ -272,7 +272,7 @@ pub fn type_of(cx: &CrateContext, t: ty::t) -> Type { } // Check the cache. - match cx.lltypes().borrow().find(&t) { + match cx.lltypes().borrow().get(&t) { Some(&llty) => return llty, None => () } diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 76caa42b850..421042a8648 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -1080,14 +1080,14 @@ pub enum BuiltinBound { } pub fn empty_builtin_bounds() -> BuiltinBounds { - EnumSet::empty() + EnumSet::new() } pub fn all_builtin_bounds() -> BuiltinBounds { - let mut set = EnumSet::empty(); - set.add(BoundSend); - set.add(BoundSized); - set.add(BoundSync); + let mut set = EnumSet::new(); + set.insert(BoundSend); + set.insert(BoundSized); + set.insert(BoundSync); set } @@ -1584,7 +1584,7 @@ pub fn mk_t(cx: &ctxt, st: sty) -> t { let key = intern_key { sty: &st }; - match cx.interner.borrow().find(&key) { + match cx.interner.borrow().get(&key) { Some(t) => unsafe { return mem::transmute(&t.sty); }, _ => () } @@ -2418,11 +2418,11 @@ pub fn type_contents(cx: &ctxt, ty: t) -> TypeContents { // value for the type contents of list. The correct value is // TC::OwnsOwned. This manifested as issue #4821. let ty_id = type_id(ty); - match cache.find(&ty_id) { + match cache.get(&ty_id) { Some(tc) => { return *tc; } None => {} } - match cx.tc_cache.borrow().find(&ty_id) { // Must check both caches! + match cx.tc_cache.borrow().get(&ty_id) { // Must check both caches! Some(tc) => { return *tc; } None => {} } @@ -3192,7 +3192,7 @@ pub fn array_element_ty(t: t) -> Option { } pub fn node_id_to_trait_ref(cx: &ctxt, id: ast::NodeId) -> Rc { - match cx.trait_refs.borrow().find(&id) { + match cx.trait_refs.borrow().get(&id) { Some(t) => t.clone(), None => cx.sess.bug( format!("node_id_to_trait_ref: no trait ref for node `{}`", @@ -3214,14 +3214,14 @@ pub fn node_id_to_type(cx: &ctxt, id: ast::NodeId) -> t { } pub fn node_id_to_type_opt(cx: &ctxt, id: ast::NodeId) -> Option { - match cx.node_types.borrow().find(&(id as uint)) { + match cx.node_types.borrow().get(&(id as uint)) { Some(&t) => Some(t), None => None } } pub fn node_id_item_substs(cx: &ctxt, id: ast::NodeId) -> ItemSubsts { - match cx.item_substs.borrow().find(&id) { + match cx.item_substs.borrow().get(&id) { None => ItemSubsts::empty(), Some(ts) => ts.clone(), } @@ -3361,8 +3361,8 @@ pub fn expr_ty_adjusted(cx: &ctxt, expr: &ast::Expr) -> t { */ adjust_ty(cx, expr.span, expr.id, expr_ty(cx, expr), - cx.adjustments.borrow().find(&expr.id), - |method_call| cx.method_map.borrow().find(&method_call).map(|method| method.ty)) + cx.adjustments.borrow().get(&expr.id), + |method_call| cx.method_map.borrow().get(&method_call).map(|method| method.ty)) } pub fn expr_span(cx: &ctxt, id: NodeId) -> Span { @@ -3553,7 +3553,7 @@ pub fn unsize_ty(cx: &ctxt, } pub fn resolve_expr(tcx: &ctxt, expr: &ast::Expr) -> def::Def { - match tcx.def_map.borrow().find(&expr.id) { + match tcx.def_map.borrow().get(&expr.id) { Some(&def) => def, None => { tcx.sess.span_bug(expr.span, format!( @@ -3690,7 +3690,7 @@ pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind { } ast::ExprCast(..) => { - match tcx.node_types.borrow().find(&(expr.id as uint)) { + match tcx.node_types.borrow().get(&(expr.id as uint)) { Some(&t) => { if type_is_trait(t) { RvalueDpsExpr @@ -3736,7 +3736,7 @@ pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind { ast::ExprBox(ref place, _) => { // Special case `Box` for now: - let definition = match tcx.def_map.borrow().find(&place.id) { + let definition = match tcx.def_map.borrow().get(&place.id) { Some(&def) => def, None => panic!("no def for place"), }; @@ -4003,7 +4003,7 @@ pub fn note_and_explain_type_err(cx: &ctxt, err: &type_err) { } pub fn provided_source(cx: &ctxt, id: ast::DefId) -> Option { - cx.provided_method_sources.borrow().find(&id).map(|x| *x) + cx.provided_method_sources.borrow().get(&id).map(|x| *x) } pub fn provided_trait_methods(cx: &ctxt, id: ast::DefId) -> Vec> { @@ -4113,7 +4113,7 @@ pub fn impl_or_trait_item(cx: &ctxt, id: ast::DefId) -> ImplOrTraitItem { pub fn is_associated_type(cx: &ctxt, id: ast::DefId) -> bool { memoized(&cx.associated_types, id, |id: ast::DefId| { if id.krate == ast::LOCAL_CRATE { - match cx.impl_or_trait_items.borrow().find(&id) { + match cx.impl_or_trait_items.borrow().get(&id) { Some(ref item) => { match **item { TypeTraitItem(_) => true, @@ -4198,7 +4198,7 @@ pub fn impl_trait_ref(cx: &ctxt, id: ast::DefId) -> Option> { pub fn trait_ref_to_def_id(tcx: &ctxt, tr: &ast::TraitRef) -> ast::DefId { let def = *tcx.def_map.borrow() - .find(&tr.ref_id) + .get(&tr.ref_id) .expect("no def-map entry for trait"); def.def_id() } @@ -4215,7 +4215,7 @@ pub fn try_add_builtin_trait( //! is a builtin trait. match tcx.lang_items.to_builtin_kind(trait_def_id) { - Some(bound) => { builtin_bounds.add(bound); true } + Some(bound) => { builtin_bounds.insert(bound); true } None => false } } @@ -4346,7 +4346,7 @@ impl DtorKind { /* If struct_id names a struct with a dtor, return Some(the dtor's id). Otherwise return none. */ pub fn ty_dtor(cx: &ctxt, struct_id: DefId) -> DtorKind { - match cx.destructor_for_type.borrow().find(&struct_id) { + match cx.destructor_for_type.borrow().get(&struct_id) { Some(&method_def_id) => { let flag = !has_attr(cx, struct_id, "unsafe_no_drop_flag"); @@ -4569,7 +4569,7 @@ pub fn lookup_field_type(tcx: &ctxt, pub fn lookup_struct_fields(cx: &ctxt, did: ast::DefId) -> Vec { if did.krate == ast::LOCAL_CRATE { let struct_fields = cx.struct_fields.borrow(); - match struct_fields.find(&did) { + match struct_fields.get(&did) { Some(fields) => (**fields).clone(), _ => { cx.sess.bug( @@ -4632,7 +4632,7 @@ pub fn unboxed_closure_upvars(tcx: &ctxt, closure_id: ast::DefId, substs: &Subst // implemented. assert!(closure_id.krate == ast::LOCAL_CRATE); let capture_mode = tcx.capture_modes.borrow().get_copy(&closure_id.node); - match tcx.freevars.borrow().find(&closure_id.node) { + match tcx.freevars.borrow().get(&closure_id.node) { None => vec![], Some(ref freevars) => { freevars.iter().map(|freevar| { @@ -4898,7 +4898,7 @@ pub fn required_region_bounds(tcx: &ctxt, all_bounds: &mut Vec) { all_bounds.push_all(region_bounds.as_slice()); - if builtin_bounds.contains_elem(ty::BoundSend) { + if builtin_bounds.contains(&ty::BoundSend) { all_bounds.push(ty::ReStatic); } } @@ -4921,7 +4921,7 @@ pub fn item_variances(tcx: &ctxt, item_id: ast::DefId) -> Rc { pub fn record_trait_implementation(tcx: &ctxt, trait_def_id: DefId, impl_def_id: DefId) { - match tcx.trait_impls.borrow().find(&trait_def_id) { + match tcx.trait_impls.borrow().get(&trait_def_id) { Some(impls_for_trait) => { impls_for_trait.borrow_mut().push(impl_def_id); return; @@ -5094,7 +5094,7 @@ pub fn trait_of_item(tcx: &ctxt, def_id: ast::DefId) -> Option { /// Otherwise, return `None`. pub fn trait_item_of_item(tcx: &ctxt, def_id: ast::DefId) -> Option { - let impl_item = match tcx.impl_or_trait_items.borrow().find(&def_id) { + let impl_item = match tcx.impl_or_trait_items.borrow().get(&def_id) { Some(m) => m.clone(), None => return None, }; @@ -5449,7 +5449,7 @@ impl<'tcx> mc::Typer<'tcx> for ty::ctxt<'tcx> { } fn node_method_ty(&self, method_call: typeck::MethodCall) -> Option { - self.method_map.borrow().find(&method_call).map(|method| method.ty) + self.method_map.borrow().get(&method_call).map(|method| method.ty) } fn adjustments<'a>(&'a self) -> &'a RefCell> { @@ -5561,7 +5561,7 @@ pub type FreevarMap = NodeMap>; pub type CaptureModeMap = NodeMap; pub fn with_freevars(tcx: &ty::ctxt, fid: ast::NodeId, f: |&[Freevar]| -> T) -> T { - match tcx.freevars.borrow().find(&fid) { + match tcx.freevars.borrow().get(&fid) { None => f(&[]), Some(d) => f(d.as_slice()) } diff --git a/src/librustc/middle/typeck/astconv.rs b/src/librustc/middle/typeck/astconv.rs index 7c8d9309df3..32fd385aa5d 100644 --- a/src/librustc/middle/typeck/astconv.rs +++ b/src/librustc/middle/typeck/astconv.rs @@ -99,7 +99,7 @@ pub trait AstConv<'tcx> { pub fn ast_region_to_region(tcx: &ty::ctxt, lifetime: &ast::Lifetime) -> ty::Region { - let r = match tcx.named_region_map.find(&lifetime.id) { + let r = match tcx.named_region_map.get(&lifetime.id) { None => { // should have been recorded by the `resolve_lifetime` pass tcx.sess.span_bug(lifetime.span, "unresolved lifetime"); @@ -467,7 +467,7 @@ fn check_path_args(tcx: &ty::ctxt, pub fn ast_ty_to_prim_ty(tcx: &ty::ctxt, ast_ty: &ast::Ty) -> Option { match ast_ty.node { ast::TyPath(ref path, _, id) => { - let a_def = match tcx.def_map.borrow().find(&id) { + let a_def = match tcx.def_map.borrow().get(&id) { None => { tcx.sess.span_bug(ast_ty.span, format!("unbound path {}", @@ -524,7 +524,7 @@ pub fn ast_ty_to_builtin_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>( match ast_ty.node { ast::TyPath(ref path, _, id) => { - let a_def = match this.tcx().def_map.borrow().find(&id) { + let a_def = match this.tcx().def_map.borrow().get(&id) { None => { this.tcx() .sess @@ -675,7 +675,7 @@ fn mk_pointer<'tcx, AC: AstConv<'tcx>, RS: RegionScope>( // Note that the "bounds must be empty if path is not a trait" // restriction is enforced in the below case for ty_path, which // will run after this as long as the path isn't a trait. - match tcx.def_map.borrow().find(&id) { + match tcx.def_map.borrow().get(&id) { Some(&def::DefPrimTy(ast::TyStr)) => { check_path_args(tcx, path, NO_TPS | NO_REGIONS); match ptr_ty { @@ -802,7 +802,7 @@ pub fn ast_ty_to_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>( let tcx = this.tcx(); let mut ast_ty_to_ty_cache = tcx.ast_ty_to_ty_cache.borrow_mut(); - match ast_ty_to_ty_cache.find(&ast_ty.id) { + match ast_ty_to_ty_cache.get(&ast_ty.id) { Some(&ty::atttce_resolved(ty)) => return ty, Some(&ty::atttce_unresolved) => { tcx.sess.span_fatal(ast_ty.span, @@ -900,7 +900,7 @@ pub fn ast_ty_to_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>( ty::mk_err() } ast::TyPath(ref path, ref bounds, id) => { - let a_def = match tcx.def_map.borrow().find(&id) { + let a_def = match tcx.def_map.borrow().get(&id) { None => { tcx.sess .span_bug(ast_ty.span, @@ -990,7 +990,7 @@ pub fn ast_ty_to_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>( } } ast::TyQPath(ref qpath) => { - match tcx.def_map.borrow().find(&ast_ty.id) { + match tcx.def_map.borrow().get(&ast_ty.id) { None => { tcx.sess.span_bug(ast_ty.span, "unbound qualified path") @@ -1549,7 +1549,7 @@ pub fn partition_bounds<'a>(tcx: &ty::ctxt, ast::TraitTyParamBound(ref b) => { match lookup_def_tcx(tcx, b.path.span, b.ref_id) { def::DefTrait(trait_did) => { - match trait_def_ids.find(&trait_did) { + match trait_def_ids.get(&trait_did) { // Already seen this trait. We forbid // duplicates in the list (for some // reason). diff --git a/src/librustc/middle/typeck/check/_match.rs b/src/librustc/middle/typeck/check/_match.rs index a686a5e72a0..7070f16da3b 100644 --- a/src/librustc/middle/typeck/check/_match.rs +++ b/src/librustc/middle/typeck/check/_match.rs @@ -324,7 +324,7 @@ pub fn check_pat_struct(pcx: &pat_ctxt, pat: &ast::Pat, let item_substs = fcx .item_substs() - .find(&pat.id) + .get(&pat.id) .map(|substs| substs.substs.clone()) .unwrap_or_else(|| Substs::empty()); diff --git a/src/librustc/middle/typeck/check/method.rs b/src/librustc/middle/typeck/check/method.rs index f854bc52acd..557b92d439d 100644 --- a/src/librustc/middle/typeck/check/method.rs +++ b/src/librustc/middle/typeck/check/method.rs @@ -678,7 +678,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> { debug!("push_extension_candidates(expr_id={})", expr_id); let mut duplicates = HashSet::new(); - let opt_applicable_traits = self.fcx.ccx.trait_map.find(&expr_id); + let opt_applicable_traits = self.fcx.ccx.trait_map.get(&expr_id); for applicable_traits in opt_applicable_traits.into_iter() { for &trait_did in applicable_traits.iter() { if duplicates.insert(trait_did) { @@ -912,7 +912,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> { // metadata if necessary. ty::populate_implementations_for_type_if_necessary(self.tcx(), did); - for impl_infos in self.tcx().inherent_impls.borrow().find(&did).iter() { + for impl_infos in self.tcx().inherent_impls.borrow().get(&did).iter() { for impl_did in impl_infos.iter() { self.push_candidates_from_inherent_impl(*impl_did); } @@ -1627,7 +1627,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> { .inh .adjustments .borrow() - .find(&expr.id) { + .get(&expr.id) { Some(&ty::AdjustDerefRef(ty::AutoDerefRef { autoderefs: autoderef_count, autoref: _ @@ -1658,7 +1658,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> { match expr.node { ast::ExprIndex(ref base_expr, _) => { let mut base_adjustment = - match self.fcx.inh.adjustments.borrow().find(&base_expr.id) { + match self.fcx.inh.adjustments.borrow().get(&base_expr.id) { Some(&ty::AdjustDerefRef(ref adr)) => (*adr).clone(), None => ty::AutoDerefRef { autoderefs: 0, autoref: None }, Some(_) => { @@ -1839,7 +1839,7 @@ fn impl_method(tcx: &ty::ctxt, -> Option> { let impl_items = tcx.impl_items.borrow(); - let impl_items = impl_items.find(&impl_def_id).unwrap(); + let impl_items = impl_items.get(&impl_def_id).unwrap(); impl_items .iter() .map(|&did| ty::impl_or_trait_item(tcx, did.def_id())) diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index bcb875a6aa8..b83c81cd986 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -298,7 +298,7 @@ impl<'a, 'tcx> mem_categorization::Typer<'tcx> for FnCtxt<'a, 'tcx> { } fn node_method_ty(&self, method_call: typeck::MethodCall) -> Option { - self.inh.method_map.borrow().find(&method_call).map(|m| m.ty) + self.inh.method_map.borrow().get(&method_call).map(|m| m.ty) } fn adjustments<'a>(&'a self) -> &'a RefCell> { &self.inh.adjustments @@ -1556,7 +1556,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } pub fn local_ty(&self, span: Span, nid: ast::NodeId) -> ty::t { - match self.inh.locals.borrow().find(&nid) { + match self.inh.locals.borrow().get(&nid) { Some(&t) => t, None => { self.tcx().sess.span_bug( @@ -1808,7 +1808,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } pub fn expr_ty(&self, ex: &ast::Expr) -> ty::t { - match self.inh.node_types.borrow().find(&ex.id) { + match self.inh.node_types.borrow().get(&ex.id) { Some(&t) => t, None => { self.tcx().sess.bug(format!("no type for expr in fcx {}", @@ -1824,7 +1824,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { */ let adjustments = self.inh.adjustments.borrow(); - let adjustment = adjustments.find(&expr.id); + let adjustment = adjustments.get(&expr.id); self.adjust_expr_ty(expr, adjustment) } @@ -1845,12 +1845,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { raw_ty, adjustment, |method_call| self.inh.method_map.borrow() - .find(&method_call) + .get(&method_call) .map(|method| method.ty)) } pub fn node_ty(&self, id: ast::NodeId) -> ty::t { - match self.inh.node_types.borrow().find(&id) { + match self.inh.node_types.borrow().get(&id) { Some(&t) => t, None => { self.tcx().sess.bug( @@ -1868,7 +1868,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub fn opt_node_ty_substs(&self, id: ast::NodeId, f: |&ty::ItemSubsts|) { - match self.inh.item_substs.borrow().find(&id) { + match self.inh.item_substs.borrow().get(&id) { Some(s) => { f(s) } None => { } } @@ -3554,7 +3554,7 @@ fn check_expr_with_unifier(fcx: &FnCtxt, let (bounds, onceness) = match expr.node { ast::ExprProc(..) => { let mut bounds = ty::region_existential_bound(ty::ReStatic); - bounds.builtin_bounds.add(ty::BoundSend); // FIXME + bounds.builtin_bounds.insert(ty::BoundSend); // FIXME (bounds, ast::Once) } _ => { @@ -3763,7 +3763,7 @@ fn check_expr_with_unifier(fcx: &FnCtxt, for field in ast_fields.iter() { let mut expected_field_type = ty::mk_err(); - let pair = class_field_map.find(&field.ident.node.name).map(|x| *x); + let pair = class_field_map.get(&field.ident.node.name).map(|x| *x); match pair { None => { fcx.type_error_message( @@ -4422,7 +4422,7 @@ fn check_expr_with_unifier(fcx: &FnCtxt, } ast::ExprStruct(ref path, ref fields, ref base_expr) => { // Resolve the path. - let def = tcx.def_map.borrow().find(&id).map(|i| *i); + let def = tcx.def_map.borrow().get(&id).map(|i| *i); let struct_id = match def { Some(def::DefVariant(enum_id, variant_id, true)) => { check_struct_enum_variant(fcx, id, expr.span, enum_id, @@ -5603,7 +5603,7 @@ pub fn may_break(cx: &ty::ctxt, id: ast::NodeId, b: &ast::Block) -> bool { (block_query(b, |e| { match e.node { ast::ExprBreak(Some(_)) => { - match cx.def_map.borrow().find(&e.id) { + match cx.def_map.borrow().get(&e.id) { Some(&def::DefLabel(loop_id)) if id == loop_id => true, _ => false, } diff --git a/src/librustc/middle/typeck/check/regionck.rs b/src/librustc/middle/typeck/check/regionck.rs index acc3cf0307b..014180a1155 100644 --- a/src/librustc/middle/typeck/check/regionck.rs +++ b/src/librustc/middle/typeck/check/regionck.rs @@ -327,7 +327,7 @@ impl<'a, 'tcx> Rcx<'a, 'tcx> { fn resolve_method_type(&self, method_call: MethodCall) -> Option { let method_ty = self.fcx.inh.method_map.borrow() - .find(&method_call).map(|method| method.ty); + .get(&method_call).map(|method| method.ty); method_ty.map(|method_ty| self.resolve_type(method_ty)) } @@ -339,7 +339,7 @@ impl<'a, 'tcx> Rcx<'a, 'tcx> { } else { let tcx = self.fcx.tcx(); ty::adjust_ty(tcx, expr.span, expr.id, ty_unadjusted, - self.fcx.inh.adjustments.borrow().find(&expr.id), + self.fcx.inh.adjustments.borrow().get(&expr.id), |method_call| self.resolve_method_type(method_call)) } } @@ -351,7 +351,7 @@ impl<'a, 'tcx> Rcx<'a, 'tcx> { // When we enter a function, we can derive let fn_sig_map = self.fcx.inh.fn_sig_map.borrow(); - let fn_sig = match fn_sig_map.find(&id) { + let fn_sig = match fn_sig_map.get(&id) { Some(f) => f, None => { self.tcx().sess.bug( @@ -370,7 +370,7 @@ impl<'a, 'tcx> Rcx<'a, 'tcx> { { debug!("visit_region_obligations: node_id={}", node_id); let region_obligations = self.fcx.inh.region_obligations.borrow(); - match region_obligations.find(&node_id) { + match region_obligations.get(&node_id) { None => { } Some(vec) => { for r_o in vec.iter() { @@ -594,7 +594,7 @@ fn visit_expr(rcx: &mut Rcx, expr: &ast::Expr) { let has_method_map = rcx.fcx.inh.method_map.borrow().contains_key(&method_call); // Check any autoderefs or autorefs that appear. - for &adjustment in rcx.fcx.inh.adjustments.borrow().find(&expr.id).iter() { + for &adjustment in rcx.fcx.inh.adjustments.borrow().get(&expr.id).iter() { debug!("adjustment={}", adjustment); match *adjustment { ty::AdjustDerefRef(ty::AutoDerefRef {autoderefs, autoref: ref opt_autoref}) => { @@ -686,7 +686,7 @@ fn visit_expr(rcx: &mut Rcx, expr: &ast::Expr) { ast::ExprUnary(ast::UnDeref, ref base) => { // For *a, the lifetime of a must enclose the deref let method_call = MethodCall::expr(expr.id); - let base_ty = match rcx.fcx.inh.method_map.borrow().find(&method_call) { + let base_ty = match rcx.fcx.inh.method_map.borrow().get(&method_call) { Some(method) => { constrain_call(rcx, expr, Some(&**base), None::.iter(), true); @@ -950,7 +950,7 @@ fn check_expr_fn_block(rcx: &mut Rcx, let raw_var_ty = rcx.resolve_node_type(var_node_id); let upvar_id = ty::UpvarId { var_id: var_node_id, closure_expr_id: expr.id }; - let var_ty = match rcx.fcx.inh.upvar_borrow_map.borrow().find(&upvar_id) { + let var_ty = match rcx.fcx.inh.upvar_borrow_map.borrow().get(&upvar_id) { Some(upvar_borrow) => { ty::mk_rptr(rcx.tcx(), upvar_borrow.region, @@ -1195,7 +1195,7 @@ fn constrain_autoderefs(rcx: &mut Rcx, i, derefs); let method_call = MethodCall::autoderef(deref_expr.id, i); - derefd_ty = match rcx.fcx.inh.method_map.borrow().find(&method_call) { + derefd_ty = match rcx.fcx.inh.method_map.borrow().get(&method_call) { Some(method) => { // Treat overloaded autoderefs as if an AutoRef adjustment // was applied on the base type, as that is always the case. @@ -1301,7 +1301,7 @@ fn type_of_node_must_outlive( // report errors later on in the writeback phase. let ty0 = rcx.resolve_node_type(id); let ty = ty::adjust_ty(tcx, origin.span(), id, ty0, - rcx.fcx.inh.adjustments.borrow().find(&id), + rcx.fcx.inh.adjustments.borrow().get(&id), |method_call| rcx.resolve_method_type(method_call)); debug!("constrain_regions_in_type_of_node(\ ty={}, ty0={}, id={}, minimum_lifetime={})", @@ -1582,7 +1582,7 @@ fn link_reborrowed_region(rcx: &Rcx, mc::NoteUpvarRef(ref upvar_id) => { let mut upvar_borrow_map = rcx.fcx.inh.upvar_borrow_map.borrow_mut(); - match upvar_borrow_map.find_mut(upvar_id) { + match upvar_borrow_map.get_mut(upvar_id) { Some(upvar_borrow) => { // Adjust mutability that we infer for the upvar // so it can accommodate being borrowed with @@ -1845,7 +1845,7 @@ fn link_upvar_borrow_kind_for_nested_closures(rcx: &mut Rcx, let mut upvar_borrow_map = rcx.fcx.inh.upvar_borrow_map.borrow_mut(); let inner_borrow = upvar_borrow_map.get_copy(&inner_upvar_id); - match upvar_borrow_map.find_mut(&outer_upvar_id) { + match upvar_borrow_map.get_mut(&outer_upvar_id) { Some(outer_borrow) => { adjust_upvar_borrow_kind(rcx, outer_upvar_id, outer_borrow, inner_borrow.kind); } diff --git a/src/librustc/middle/typeck/check/writeback.rs b/src/librustc/middle/typeck/check/writeback.rs index d011e807ce7..cf78ef16219 100644 --- a/src/librustc/middle/typeck/check/writeback.rs +++ b/src/librustc/middle/typeck/check/writeback.rs @@ -263,7 +263,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { } fn visit_adjustments(&self, reason: ResolveReason, id: ast::NodeId) { - match self.fcx.inh.adjustments.borrow_mut().pop(&id) { + match self.fcx.inh.adjustments.borrow_mut().remove(&id) { None => { debug!("No adjustments for node {}", id); } @@ -275,7 +275,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { // FIXME(eddyb) #2190 Allow only statically resolved // bare functions to coerce to a closure to avoid // constructing (slower) indirect call wrappers. - match self.tcx().def_map.borrow().find(&id) { + match self.tcx().def_map.borrow().get(&id) { Some(&def::DefFn(..)) | Some(&def::DefStaticMethod(..)) | Some(&def::DefVariant(..)) | @@ -320,7 +320,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { reason: ResolveReason, method_call: MethodCall) { // Resolve any method map entry - match self.fcx.inh.method_map.borrow_mut().pop(&method_call) { + match self.fcx.inh.method_map.borrow_mut().remove(&method_call) { Some(method) => { debug!("writeback::resolve_method_map_entry(call={}, entry={})", method_call, diff --git a/src/librustc/middle/typeck/coherence/mod.rs b/src/librustc/middle/typeck/coherence/mod.rs index ac18f53de04..19ff82469b5 100644 --- a/src/librustc/middle/typeck/coherence/mod.rs +++ b/src/librustc/middle/typeck/coherence/mod.rs @@ -294,7 +294,7 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> { } fn add_inherent_impl(&self, base_def_id: DefId, impl_def_id: DefId) { - match self.inherent_impls.borrow().find(&base_def_id) { + match self.inherent_impls.borrow().get(&base_def_id) { Some(implementation_list) => { implementation_list.borrow_mut().push(impl_def_id); return; diff --git a/src/librustc/middle/typeck/coherence/overlap.rs b/src/librustc/middle/typeck/coherence/overlap.rs index ccfa31df826..933c2c81ac2 100644 --- a/src/librustc/middle/typeck/coherence/overlap.rs +++ b/src/librustc/middle/typeck/coherence/overlap.rs @@ -114,7 +114,7 @@ impl<'cx, 'tcx> OverlapChecker<'cx, 'tcx> { fn push_impls_of_trait(&self, trait_def_id: ast::DefId, out: &mut Vec) { - match self.tcx.trait_impls.borrow().find(&trait_def_id) { + match self.tcx.trait_impls.borrow().get(&trait_def_id) { Some(impls) => { out.push_all(impls.borrow().as_slice()); } None => { /* no impls */ } } diff --git a/src/librustc/middle/typeck/collect.rs b/src/librustc/middle/typeck/collect.rs index 0374a64261f..d137e5536a5 100644 --- a/src/librustc/middle/typeck/collect.rs +++ b/src/librustc/middle/typeck/collect.rs @@ -1243,7 +1243,7 @@ pub fn convert_struct(ccx: &CrateCtxt, let result = convert_field(ccx, &pty.generics, f, local_def(id)); if result.name != special_idents::unnamed_field.name { - let dup = match seen_fields.find(&result.name) { + let dup = match seen_fields.get(&result.name) { Some(prev_span) => { span_err!(tcx.sess, f.span, E0124, "field `{}` is already declared", @@ -1386,7 +1386,7 @@ fn get_trait_def(ccx: &CrateCtxt, trait_id: ast::DefId) -> Rc { pub fn trait_def_of_item(ccx: &CrateCtxt, it: &ast::Item) -> Rc { let def_id = local_def(it.id); let tcx = ccx.tcx; - match tcx.trait_defs.borrow().find(&def_id) { + match tcx.trait_defs.borrow().get(&def_id) { Some(def) => return def.clone(), _ => {} } @@ -1486,7 +1486,7 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::Item) -> ty::Polytype { let def_id = local_def(it.id); let tcx = ccx.tcx; - match tcx.tcache.borrow().find(&def_id) { + match tcx.tcache.borrow().get(&def_id) { Some(pty) => return pty.clone(), _ => {} } @@ -1528,7 +1528,7 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::Item) return pty; } ast::ItemTy(ref t, ref generics) => { - match tcx.tcache.borrow_mut().find(&local_def(it.id)) { + match tcx.tcache.borrow_mut().get(&local_def(it.id)) { Some(pty) => return pty.clone(), None => { } } @@ -1933,7 +1933,7 @@ fn get_or_create_type_parameter_def<'tcx,AC>(this: &AC, -> ty::TypeParameterDef where AC: AstConv<'tcx> { - match this.tcx().ty_param_defs.borrow().find(¶m.id) { + match this.tcx().ty_param_defs.borrow().get(¶m.id) { Some(d) => { return (*d).clone(); } None => { } } @@ -2027,13 +2027,13 @@ fn check_bounds_compatible(tcx: &ty::ctxt, span: Span) { // Currently the only bound which is incompatible with other bounds is // Sized/Unsized. - if !param_bounds.builtin_bounds.contains_elem(ty::BoundSized) { + if !param_bounds.builtin_bounds.contains(&ty::BoundSized) { ty::each_bound_trait_and_supertraits( tcx, param_bounds.trait_bounds.as_slice(), |trait_ref| { let trait_def = ty::lookup_trait_def(tcx, trait_ref.def_id); - if trait_def.bounds.builtin_bounds.contains_elem(ty::BoundSized) { + if trait_def.bounds.builtin_bounds.contains(&ty::BoundSized) { span_err!(tcx.sess, span, E0129, "incompatible bounds on type parameter `{}`, \ bound `{}` does not allow unsized type", @@ -2136,7 +2136,7 @@ fn merge_param_bounds<'a>(tcx: &ty::ctxt, let predicate_param_id = tcx.def_map .borrow() - .find(&predicate.id) + .get(&predicate.id) .expect("compute_bounds(): resolve didn't resolve the type \ parameter identifier in a `where` clause") .def_id(); diff --git a/src/librustc/middle/typeck/infer/error_reporting.rs b/src/librustc/middle/typeck/infer/error_reporting.rs index bfa0f94a747..20c14580b3b 100644 --- a/src/librustc/middle/typeck/infer/error_reporting.rs +++ b/src/librustc/middle/typeck/infer/error_reporting.rs @@ -1240,7 +1240,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> { ty_queue.push(&*mut_ty.ty); } ast::TyPath(ref path, ref bounds, id) => { - let a_def = match self.tcx.def_map.borrow().find(&id) { + let a_def = match self.tcx.def_map.borrow().get(&id) { None => { self.tcx .sess diff --git a/src/librustc/middle/typeck/infer/region_inference/mod.rs b/src/librustc/middle/typeck/infer/region_inference/mod.rs index cdc45890c09..70c4a245b2c 100644 --- a/src/librustc/middle/typeck/infer/region_inference/mod.rs +++ b/src/librustc/middle/typeck/infer/region_inference/mod.rs @@ -367,7 +367,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> { debug!("RegionVarBindings: add_constraint({})", constraint.repr(self.tcx)); - if self.constraints.borrow_mut().insert(constraint, origin) { + if self.constraints.borrow_mut().insert(constraint, origin).is_none() { if self.in_snapshot() { self.undo_log.borrow_mut().push(AddConstraint(constraint)); } @@ -559,7 +559,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> { new_r: Region|) -> Region { let vars = TwoRegions { a: a, b: b }; - match self.combine_map(t).borrow().find(&vars) { + match self.combine_map(t).borrow().get(&vars) { Some(&c) => { return ReInfer(ReVar(c)); } @@ -991,7 +991,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> { debug!("expansion: constraint={} origin={}", constraint.repr(self.tcx), self.constraints.borrow() - .find(constraint) + .get(constraint) .unwrap() .repr(self.tcx)); match *constraint { @@ -1075,7 +1075,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> { debug!("contraction: constraint={} origin={}", constraint.repr(self.tcx), self.constraints.borrow() - .find(constraint) + .get(constraint) .unwrap() .repr(self.tcx)); match *constraint { diff --git a/src/librustc/middle/typeck/infer/sub.rs b/src/librustc/middle/typeck/infer/sub.rs index f44fa1ac1c6..d2f315f2a4b 100644 --- a/src/librustc/middle/typeck/infer/sub.rs +++ b/src/librustc/middle/typeck/infer/sub.rs @@ -113,7 +113,7 @@ impl<'f, 'tcx> Combine<'tcx> for Sub<'f, 'tcx> { // e.g., fn:Copy() <: fn(), because the former is a function // that only closes over copyable things, but the latter is // any function at all. - if a.contains(b) { + if a.is_superset(&b) { Ok(a) } else { Err(ty::terr_builtin_bounds(expected_found(self, a, b))) diff --git a/src/librustc/middle/typeck/mod.rs b/src/librustc/middle/typeck/mod.rs index 22898221d9b..5ca0de47ad5 100644 --- a/src/librustc/middle/typeck/mod.rs +++ b/src/librustc/middle/typeck/mod.rs @@ -301,7 +301,7 @@ pub fn write_substs_to_tcx(tcx: &ty::ctxt, } } pub fn lookup_def_tcx(tcx:&ty::ctxt, sp: Span, id: ast::NodeId) -> def::Def { - match tcx.def_map.borrow().find(&id) { + match tcx.def_map.borrow().get(&id) { Some(x) => x.clone(), _ => { tcx.sess.span_fatal(sp, "internal error looking up a definition") diff --git a/src/librustc/middle/typeck/variance.rs b/src/librustc/middle/typeck/variance.rs index 9a90381854a..4227cc521b4 100644 --- a/src/librustc/middle/typeck/variance.rs +++ b/src/librustc/middle/typeck/variance.rs @@ -322,7 +322,7 @@ impl<'a, 'tcx> TermsContext<'a, 'tcx> { index: index, param_id: param_id, term: term }); - let newly_added = self.inferred_map.insert(param_id, inf_index); + let newly_added = self.inferred_map.insert(param_id, inf_index).is_none(); assert!(newly_added); debug!("add_inferred(item_id={}, \ @@ -376,7 +376,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for TermsContext<'a, 'tcx> { if self.num_inferred() == inferreds_on_entry { let newly_added = self.tcx.item_variance_map.borrow_mut().insert( ast_util::local_def(item.id), - self.empty_variances.clone()); + self.empty_variances.clone()).is_none(); assert!(newly_added); } @@ -556,7 +556,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { } fn inferred_index(&self, param_id: ast::NodeId) -> InferredIndex { - match self.terms_cx.inferred_map.find(¶m_id) { + match self.terms_cx.inferred_map.get(¶m_id) { Some(&index) => index, None => { self.tcx().sess.bug(format!( @@ -569,7 +569,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { fn find_binding_for_lifetime(&self, param_id: ast::NodeId) -> ast::NodeId { let tcx = self.terms_cx.tcx; assert!(is_lifetime(&tcx.map, param_id)); - match tcx.named_region_map.find(¶m_id) { + match tcx.named_region_map.get(¶m_id) { Some(&rl::DefEarlyBoundRegion(_, _, lifetime_decl_id)) => lifetime_decl_id, Some(_) => panic!("should not encounter non early-bound cases"), @@ -810,7 +810,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { ty::ty_param(ty::ParamTy { ref def_id, .. }) => { assert_eq!(def_id.krate, ast::LOCAL_CRATE); - match self.terms_cx.inferred_map.find(&def_id.node) { + match self.terms_cx.inferred_map.get(&def_id.node) { Some(&index) => { self.add_constraint(index, variance); } @@ -1060,7 +1060,7 @@ impl<'a, 'tcx> SolveContext<'a, 'tcx> { } let newly_added = tcx.item_variance_map.borrow_mut() - .insert(item_def_id, Rc::new(item_variances)); + .insert(item_def_id, Rc::new(item_variances)).is_none(); assert!(newly_added); } } diff --git a/src/librustc/util/common.rs b/src/librustc/util/common.rs index cf807cb22bc..577d92744e6 100644 --- a/src/librustc/util/common.rs +++ b/src/librustc/util/common.rs @@ -139,7 +139,7 @@ pub fn can_reach,T:Eq+Clone+Hash>( let mut queue = vec!(source); let mut i = 0; while i < queue.len() { - match edges_map.find(&queue[i]) { + match edges_map.get(&queue[i]) { Some(edges) => { for target in edges.iter() { if *target == destination { @@ -200,7 +200,7 @@ pub fn memoized_with_key + Eq, U: Clone, S, H: Hasher>( k: |&T| -> K ) -> U { let key = k(&arg); - let result = cache.borrow().find(&key).map(|result| result.clone()); + let result = cache.borrow().get(&key).map(|result| result.clone()); match result { Some(result) => result, None => { diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 33e14197532..9080b12c543 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -451,7 +451,7 @@ pub fn ty_to_string(cx: &ctxt, typ: t) -> String { ty_str => "str".to_string(), ty_unboxed_closure(ref did, _, ref substs) => { let unboxed_closures = cx.unboxed_closures.borrow(); - unboxed_closures.find(did).map(|cl| { + unboxed_closures.get(did).map(|cl| { closure_to_string(cx, &cl.closure_type.subst(cx, substs)) }).unwrap_or_else(|| "closure".to_string()) } @@ -1108,7 +1108,7 @@ impl UserString for ty::ParamBounds { impl UserString for ty::ExistentialBounds { fn user_string(&self, tcx: &ctxt) -> String { - if self.builtin_bounds.contains_elem(ty::BoundSend) && + if self.builtin_bounds.contains(&ty::BoundSend) && self.region_bound == ty::ReStatic { // Region bound is implied by builtin bounds: return self.builtin_bounds.repr(tcx); @@ -1277,7 +1277,7 @@ impl UserString for ParamTy { fn user_string(&self, tcx: &ctxt) -> String { let id = self.idx; let did = self.def_id; - let ident = match tcx.ty_param_defs.borrow().find(&did.node) { + let ident = match tcx.ty_param_defs.borrow().get(&did.node) { Some(def) => token::get_name(def.name).get().to_string(), // This can only happen when a type mismatch error happens and diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index d87d8776d4a..545eeaf7406 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -45,7 +45,7 @@ pub fn try_inline(cx: &DocContext, id: ast::NodeId, into: Option) Some(tcx) => tcx, None => return None, }; - let def = match tcx.def_map.borrow().find(&id) { + let def = match tcx.def_map.borrow().get(&id) { Some(def) => *def, None => return None, }; @@ -223,7 +223,7 @@ fn build_impls(cx: &DocContext, tcx: &ty::ctxt, ty::populate_implementations_for_type_if_necessary(tcx, did); let mut impls = Vec::new(); - match tcx.inherent_impls.borrow().find(&did) { + match tcx.inherent_impls.borrow().get(&did) { None => {} Some(i) => { impls.extend(i.iter().map(|&did| { build_impl(cx, tcx, did) })); diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index f96b3916f06..bd6c696ad74 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1395,7 +1395,7 @@ impl Clean for ty::field_ty { let (name, attrs) = if self.name == unnamed_field.name { (None, None) } else { - (Some(self.name), Some(attr_map.find(&self.id.node).unwrap())) + (Some(self.name), Some(attr_map.get(&self.id.node).unwrap())) }; let ty = ty::lookup_item_type(cx.tcx(), self.id); @@ -2090,7 +2090,7 @@ fn resolve_type(cx: &DocContext, path: Path, None => return Primitive(Bool), }; debug!("searching for {} in defmap", id); - let def = match tcx.def_map.borrow().find(&id) { + let def = match tcx.def_map.borrow().get(&id) { Some(&k) => k, None => panic!("unresolved id not in defmap") }; @@ -2159,7 +2159,7 @@ fn resolve_use_source(cx: &DocContext, path: Path, id: ast::NodeId) -> ImportSou fn resolve_def(cx: &DocContext, id: ast::NodeId) -> Option { cx.tcx_opt().and_then(|tcx| { - tcx.def_map.borrow().find(&id).map(|&def| register_def(cx, def)) + tcx.def_map.borrow().get(&id).map(|&def| register_def(cx, def)) }) } diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index f9177c8d615..320f84adea7 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -208,7 +208,7 @@ fn resolved_path(w: &mut fmt::Formatter, did: ast::DefId, p: &clean::Path, } }, |cache| { - match cache.paths.find(&did) { + match cache.paths.get(&did) { None => None, Some(&(ref fqp, shortty)) => Some((fqp.clone(), shortty)) } @@ -313,7 +313,7 @@ fn primitive_link(f: &mut fmt::Formatter, name: &str) -> fmt::Result { let m = cache_key.get().unwrap(); let mut needs_termination = false; - match m.primitive_locations.find(&prim) { + match m.primitive_locations.get(&prim) { Some(&ast::LOCAL_CRATE) => { let loc = current_location_key.get().unwrap(); let len = if loc.len() == 0 {0} else {loc.len() - 1}; diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index 3f1590773aa..9dacee1652a 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -242,7 +242,7 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result { // Make sure our hyphenated ID is unique for this page let map = used_header_map.get().unwrap(); - let id = match map.borrow_mut().find_mut(&id) { + let id = match map.borrow_mut().get_mut(&id) { None => id, Some(a) => { *a += 1; format!("{}-{}", id, *a - 1) } }; diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 9af2b22adea..fbd2611acb9 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -389,7 +389,7 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> io::IoResult // has since been learned. for &(pid, ref item) in orphan_methods.iter() { let did = ast_util::local_def(pid); - match paths.find(&did) { + match paths.get(&did) { Some(&(ref fqp, _)) => { search_index.push(IndexItem { ty: shortty(item), @@ -443,7 +443,7 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> io::IoResult item.desc.to_json().to_string())); match item.parent { Some(nodeid) => { - let pathid = *nodeid_to_pathid.find(&nodeid).unwrap(); + let pathid = *nodeid_to_pathid.get(&nodeid).unwrap(); try!(write!(&mut w, ",{}", pathid)); } None => {} @@ -454,7 +454,7 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> io::IoResult try!(write!(&mut w, r#"],"paths":["#)); for (i, &did) in pathid_to_nodeid.iter().enumerate() { - let &(ref fqp, short) = cache.paths.find(&did).unwrap(); + let &(ref fqp, short) = cache.paths.get(&did).unwrap(); if i > 0 { try!(write!(&mut w, ",")); } @@ -543,7 +543,7 @@ fn write_shared(cx: &Context, // // FIXME: this is a vague explanation for why this can't be a `get`, in // theory it should be... - let &(ref remote_path, remote_item_type) = match cache.paths.find(&did) { + let &(ref remote_path, remote_item_type) = match cache.paths.get(&did) { Some(p) => p, None => continue, }; @@ -838,7 +838,7 @@ impl DocFolder for Cache { } else { let last = self.parent_stack.last().unwrap(); let did = *last; - let path = match self.paths.find(&did) { + let path = match self.paths.get(&did) { Some(&(_, item_type::Trait)) => Some(self.stack[..self.stack.len() - 1]), // The current stack not necessarily has correlation for @@ -1170,7 +1170,7 @@ impl Context { &Item{ cx: cx, item: it })); } else { let mut url = "../".repeat(cx.current.len()); - match cache_key.get().unwrap().paths.find(&it.def_id) { + match cache_key.get().unwrap().paths.get(&it.def_id) { Some(&(ref names, _)) => { for name in names[..names.len() - 1].iter() { url.push_str(name.as_slice()); @@ -1735,7 +1735,7 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,

Implementors

    ")); - match cache.implementors.find(&it.def_id) { + match cache.implementors.get(&it.def_id) { Some(implementors) => { for i in implementors.iter() { try!(writeln!(w, "
  • {}impl{} {} for {}{}
  • ", @@ -1992,7 +1992,7 @@ fn render_struct(w: &mut fmt::Formatter, it: &clean::Item, } fn render_methods(w: &mut fmt::Formatter, it: &clean::Item) -> fmt::Result { - match cache_key.get().unwrap().impls.find(&it.def_id) { + match cache_key.get().unwrap().impls.get(&it.def_id) { Some(v) => { let (non_trait, traits) = v.partitioned(|i| i.impl_.trait_.is_none()); if non_trait.len() > 0 { @@ -2080,7 +2080,7 @@ fn render_impl(w: &mut fmt::Formatter, i: &Impl) -> fmt::Result { match i.impl_.trait_ { Some(clean::ResolvedPath { did, .. }) => { try!({ - match cache_key.get().unwrap().traits.find(&did) { + match cache_key.get().unwrap().traits.get(&did) { Some(t) => try!(render_default_methods(w, t, &i.impl_)), None => {} } diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index bd3c618a5ed..5e2f56e00fc 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -417,7 +417,7 @@ fn json_input(input: &str) -> Result { Ok(json::Object(obj)) => { let mut obj = obj; // Make sure the schema is what we expect - match obj.pop(&"schema".to_string()) { + match obj.remove(&"schema".to_string()) { Some(json::String(version)) => { if version.as_slice() != SCHEMA_VERSION { return Err(format!( @@ -428,7 +428,7 @@ fn json_input(input: &str) -> Result { Some(..) => return Err("malformed json".to_string()), None => return Err("expected a schema version".to_string()), } - let krate = match obj.pop(&"crate".to_string()) { + let krate = match obj.remove(&"crate".to_string()) { Some(json) => { let mut d = json::Decoder::new(json); Decodable::decode(&mut d).unwrap() diff --git a/src/librustrt/local_data.rs b/src/librustrt/local_data.rs index 7129f147209..4a16bcf939e 100644 --- a/src/librustrt/local_data.rs +++ b/src/librustrt/local_data.rs @@ -186,7 +186,7 @@ impl KeyValue { // The following match takes a mutable borrow on the map. In order to insert // our data if the key isn't present, we need to let the match end first. - let data = match (map.find_mut(&keyval), data) { + let data = match (map.get_mut(&keyval), data) { (None, Some(data)) => { // The key doesn't exist and we need to insert it. To make borrowck // happy, return it up a scope and insert it there. @@ -266,7 +266,7 @@ impl KeyValue { }; let keyval = key_to_key_value(self); - match map.find(&keyval) { + match map.get(&keyval) { Some(slot) => { let value_box = slot.box_ptr as *mut TLDValueBox; if unsafe { *(*value_box).refcount.get() } >= 1 { diff --git a/src/libserialize/collection_impls.rs b/src/libserialize/collection_impls.rs index 79166935a5e..d2d1f5fa8b0 100644 --- a/src/libserialize/collection_impls.rs +++ b/src/libserialize/collection_impls.rs @@ -39,7 +39,7 @@ impl,T:Decodable> Decodable for DList { d.read_seq(|d, len| { let mut list = DList::new(); for i in range(0u, len) { - list.push(try!(d.read_seq_elt(i, |d| Decodable::decode(d)))); + list.push_back(try!(d.read_seq_elt(i, |d| Decodable::decode(d)))); } Ok(list) }) @@ -66,7 +66,7 @@ impl,T:Decodable> Decodable for RingBuf { d.read_seq(|d, len| { let mut deque: RingBuf = RingBuf::new(); for i in range(0u, len) { - deque.push(try!(d.read_seq_elt(i, |d| Decodable::decode(d)))); + deque.push_back(try!(d.read_seq_elt(i, |d| Decodable::decode(d)))); } Ok(deque) }) @@ -165,10 +165,10 @@ impl< > Decodable for EnumSet { fn decode(d: &mut D) -> Result, E> { let bits = try!(d.read_uint()); - let mut set = EnumSet::empty(); + let mut set = EnumSet::new(); for bit in range(0, uint::BITS) { if bits & (1 << bit) != 0 { - set.add(CLike::from_uint(1 << bit)); + set.insert(CLike::from_uint(1 << bit)); } } Ok(set) diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index dbdfa17bfc2..9f40cd2d277 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -2113,7 +2113,7 @@ impl ::Decoder for Decoder { let name = match self.pop() { String(s) => s, Object(mut o) => { - let n = match o.pop(&"variant".to_string()) { + let n = match o.remove(&"variant".to_string()) { Some(String(s)) => s, Some(val) => { return Err(ExpectedError("String".to_string(), format!("{}", val))) @@ -2122,7 +2122,7 @@ impl ::Decoder for Decoder { return Err(MissingFieldError("variant".to_string())) } }; - match o.pop(&"fields".to_string()) { + match o.remove(&"fields".to_string()) { Some(List(l)) => { for field in l.into_iter().rev() { self.stack.push(field); @@ -2192,7 +2192,7 @@ impl ::Decoder for Decoder { debug!("read_struct_field(name={}, idx={})", name, idx); let mut obj = try!(expect!(self.pop(), Object)); - let value = match obj.pop(&name.to_string()) { + let value = match obj.remove(&name.to_string()) { None => { // Add a Null and try to parse it as an Option<_> // to get None as a default value. @@ -3072,8 +3072,8 @@ mod tests { \"fields\":[\"Henry\", 349]}}"; let mut map: TreeMap = super::decode(s).unwrap(); - assert_eq!(map.pop(&"a".to_string()), Some(Dog)); - assert_eq!(map.pop(&"b".to_string()), Some(Frog("Henry".to_string(), 349))); + assert_eq!(map.remove(&"a".to_string()), Some(Dog)); + assert_eq!(map.remove(&"b".to_string()), Some(Frog("Henry".to_string(), 349))); } #[test] diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index ebf541a63da..0e75e4610ab 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -627,7 +627,7 @@ pub trait Reader { /// as `Err(IoError)`. See `read()` for more details. fn push(&mut self, len: uint, buf: &mut Vec) -> IoResult { let start_len = buf.len(); - buf.reserve_additional(len); + buf.reserve(len); let n = { let s = unsafe { slice_vec_capacity(buf, start_len, start_len + len) }; @@ -658,7 +658,7 @@ pub trait Reader { } let start_len = buf.len(); - buf.reserve_additional(len); + buf.reserve(len); // we can't just use self.read_at_least(min, slice) because we need to push // successful reads onto the vector before any returned errors. diff --git a/src/libstd/io/process.rs b/src/libstd/io/process.rs index 493e1b559d7..698e0a3460f 100644 --- a/src/libstd/io/process.rs +++ b/src/libstd/io/process.rs @@ -1137,7 +1137,7 @@ mod tests { cmd.env("path", "foo"); cmd.env("Path", "bar"); let env = &cmd.env.unwrap(); - let val = env.find(&EnvKey("PATH".to_c_str())); + let val = env.get(&EnvKey("PATH".to_c_str())); assert!(val.unwrap() == &"bar".to_c_str()); } } diff --git a/src/libsyntax/diagnostics/plugin.rs b/src/libsyntax/diagnostics/plugin.rs index d9d549f6841..d077fbd7bf0 100644 --- a/src/libsyntax/diagnostics/plugin.rs +++ b/src/libsyntax/diagnostics/plugin.rs @@ -63,7 +63,7 @@ pub fn expand_diagnostic_used<'cx>(ecx: &'cx mut ExtCtxt, () }); with_used_diagnostics(|diagnostics| { - match diagnostics.swap(code.name, span) { + match diagnostics.insert(code.name, span) { Some(previous_span) => { ecx.span_warn(span, format!( "diagnostic code {} already used", token::get_ident(code).get() @@ -93,7 +93,7 @@ pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt, _ => unreachable!() }; with_registered_diagnostics(|diagnostics| { - if !diagnostics.insert(code.name, description) { + if diagnostics.insert(code.name, description).is_some() { ecx.span_err(span, format!( "diagnostic code {} already registered", token::get_ident(*code).get() ).as_slice()); diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 152b89b86e7..5401da8cd05 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -768,7 +768,7 @@ impl SyntaxEnv { pub fn find(&self, k: &Name) -> Option> { for frame in self.chain.iter().rev() { - match frame.map.find(k) { + match frame.map.get(k) { Some(v) => return Some(v.clone()), None => {} } diff --git a/src/libsyntax/ext/format.rs b/src/libsyntax/ext/format.rs index 486ce910e2b..a28f24e7663 100644 --- a/src/libsyntax/ext/format.rs +++ b/src/libsyntax/ext/format.rs @@ -252,7 +252,7 @@ impl<'a, 'b> Context<'a, 'b> { } Named(name) => { - let span = match self.names.find(&name) { + let span = match self.names.get(&name) { Some(e) => e.span, None => { let msg = format!("there is no argument named `{}`", name); @@ -260,7 +260,7 @@ impl<'a, 'b> Context<'a, 'b> { return; } }; - self.verify_same(span, &ty, self.name_types.find(&name)); + self.verify_same(span, &ty, self.name_types.get(&name)); if !self.name_types.contains_key(&name) { self.name_types.insert(name.clone(), ty); } @@ -555,11 +555,11 @@ impl<'a, 'b> Context<'a, 'b> { heads.push(self.ecx.expr_addr_of(e.span, e)); } for name in self.name_ordering.iter() { - let e = match self.names.pop(name) { + let e = match self.names.remove(name) { Some(e) => e, None => continue }; - let arg_ty = match self.name_types.find(name) { + let arg_ty = match self.name_types.get(name) { Some(ty) => ty, None => continue }; diff --git a/src/libsyntax/ext/mtwt.rs b/src/libsyntax/ext/mtwt.rs index bebe16286c9..15fe7fc42b2 100644 --- a/src/libsyntax/ext/mtwt.rs +++ b/src/libsyntax/ext/mtwt.rs @@ -182,7 +182,7 @@ fn resolve_internal(id: Ident, resolve_table: &mut ResolveTable) -> Name { let key = (id.name, id.ctxt); - match resolve_table.find(&key) { + match resolve_table.get(&key) { Some(&name) => return name, None => {} } diff --git a/src/libsyntax/util/interner.rs b/src/libsyntax/util/interner.rs index e6c98a9e3d0..bc6d6d7a521 100644 --- a/src/libsyntax/util/interner.rs +++ b/src/libsyntax/util/interner.rs @@ -45,7 +45,7 @@ impl Interner { pub fn intern(&self, val: T) -> Name { let mut map = self.map.borrow_mut(); - match (*map).find(&val) { + match (*map).get(&val) { Some(&idx) => return idx, None => (), } diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 74bead9e5f2..4d6aefb2a17 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -1209,7 +1209,7 @@ impl MetricMap { let MetricMap(ref selfmap) = *self; let MetricMap(ref old) = *old; for (k, vold) in old.iter() { - let r = match selfmap.find(k) { + let r = match selfmap.get(k) { None => MetricRemoved, Some(v) => { let delta = v.value - vold.value; @@ -1678,31 +1678,31 @@ mod tests { let diff1 = m2.compare_to_old(&m1, None); - assert_eq!(*(diff1.find(&"in-both-noise".to_string()).unwrap()), LikelyNoise); - assert_eq!(*(diff1.find(&"in-first-noise".to_string()).unwrap()), MetricRemoved); - assert_eq!(*(diff1.find(&"in-second-noise".to_string()).unwrap()), MetricAdded); - assert_eq!(*(diff1.find(&"in-both-want-downwards-but-regressed".to_string()).unwrap()), + assert_eq!(*(diff1.get(&"in-both-noise".to_string()).unwrap()), LikelyNoise); + assert_eq!(*(diff1.get(&"in-first-noise".to_string()).unwrap()), MetricRemoved); + assert_eq!(*(diff1.get(&"in-second-noise".to_string()).unwrap()), MetricAdded); + assert_eq!(*(diff1.get(&"in-both-want-downwards-but-regressed".to_string()).unwrap()), Regression(100.0)); - assert_eq!(*(diff1.find(&"in-both-want-downwards-and-improved".to_string()).unwrap()), + assert_eq!(*(diff1.get(&"in-both-want-downwards-and-improved".to_string()).unwrap()), Improvement(50.0)); - assert_eq!(*(diff1.find(&"in-both-want-upwards-but-regressed".to_string()).unwrap()), + assert_eq!(*(diff1.get(&"in-both-want-upwards-but-regressed".to_string()).unwrap()), Regression(50.0)); - assert_eq!(*(diff1.find(&"in-both-want-upwards-and-improved".to_string()).unwrap()), + assert_eq!(*(diff1.get(&"in-both-want-upwards-and-improved".to_string()).unwrap()), Improvement(100.0)); assert_eq!(diff1.len(), 7); let diff2 = m2.compare_to_old(&m1, Some(200.0)); - assert_eq!(*(diff2.find(&"in-both-noise".to_string()).unwrap()), LikelyNoise); - assert_eq!(*(diff2.find(&"in-first-noise".to_string()).unwrap()), MetricRemoved); - assert_eq!(*(diff2.find(&"in-second-noise".to_string()).unwrap()), MetricAdded); - assert_eq!(*(diff2.find(&"in-both-want-downwards-but-regressed".to_string()).unwrap()), + assert_eq!(*(diff2.get(&"in-both-noise".to_string()).unwrap()), LikelyNoise); + assert_eq!(*(diff2.get(&"in-first-noise".to_string()).unwrap()), MetricRemoved); + assert_eq!(*(diff2.get(&"in-second-noise".to_string()).unwrap()), MetricAdded); + assert_eq!(*(diff2.get(&"in-both-want-downwards-but-regressed".to_string()).unwrap()), LikelyNoise); - assert_eq!(*(diff2.find(&"in-both-want-downwards-and-improved".to_string()).unwrap()), + assert_eq!(*(diff2.get(&"in-both-want-downwards-and-improved".to_string()).unwrap()), LikelyNoise); - assert_eq!(*(diff2.find(&"in-both-want-upwards-but-regressed".to_string()).unwrap()), + assert_eq!(*(diff2.get(&"in-both-want-upwards-but-regressed".to_string()).unwrap()), LikelyNoise); - assert_eq!(*(diff2.find(&"in-both-want-upwards-and-improved".to_string()).unwrap()), + assert_eq!(*(diff2.get(&"in-both-want-upwards-and-improved".to_string()).unwrap()), LikelyNoise); assert_eq!(diff2.len(), 7); } @@ -1727,29 +1727,29 @@ mod tests { let (diff1, ok1) = m2.ratchet(&pth, None); assert_eq!(ok1, false); assert_eq!(diff1.len(), 2); - assert_eq!(*(diff1.find(&"runtime".to_string()).unwrap()), Regression(10.0)); - assert_eq!(*(diff1.find(&"throughput".to_string()).unwrap()), LikelyNoise); + assert_eq!(*(diff1.get(&"runtime".to_string()).unwrap()), Regression(10.0)); + assert_eq!(*(diff1.get(&"throughput".to_string()).unwrap()), LikelyNoise); // Check that it was not rewritten. let m3 = MetricMap::load(&pth); let MetricMap(m3) = m3; assert_eq!(m3.len(), 2); - assert_eq!(*(m3.find(&"runtime".to_string()).unwrap()), Metric::new(1000.0, 2.0)); - assert_eq!(*(m3.find(&"throughput".to_string()).unwrap()), Metric::new(50.0, 2.0)); + assert_eq!(*(m3.get(&"runtime".to_string()).unwrap()), Metric::new(1000.0, 2.0)); + assert_eq!(*(m3.get(&"throughput".to_string()).unwrap()), Metric::new(50.0, 2.0)); // Ask for a ratchet with an explicit noise-percentage override, // that should advance. let (diff2, ok2) = m2.ratchet(&pth, Some(10.0)); assert_eq!(ok2, true); assert_eq!(diff2.len(), 2); - assert_eq!(*(diff2.find(&"runtime".to_string()).unwrap()), LikelyNoise); - assert_eq!(*(diff2.find(&"throughput".to_string()).unwrap()), LikelyNoise); + assert_eq!(*(diff2.get(&"runtime".to_string()).unwrap()), LikelyNoise); + assert_eq!(*(diff2.get(&"throughput".to_string()).unwrap()), LikelyNoise); // Check that it was rewritten. let m4 = MetricMap::load(&pth); let MetricMap(m4) = m4; assert_eq!(m4.len(), 2); - assert_eq!(*(m4.find(&"runtime".to_string()).unwrap()), Metric::new(1100.0, 2.0)); - assert_eq!(*(m4.find(&"throughput".to_string()).unwrap()), Metric::new(50.0, 2.0)); + assert_eq!(*(m4.get(&"runtime".to_string()).unwrap()), Metric::new(1100.0, 2.0)); + assert_eq!(*(m4.get(&"throughput".to_string()).unwrap()), Metric::new(50.0, 2.0)); } } diff --git a/src/test/bench/core-map.rs b/src/test/bench/core-map.rs index 3933a33446d..ac6104cc38b 100644 --- a/src/test/bench/core-map.rs +++ b/src/test/bench/core-map.rs @@ -30,18 +30,18 @@ trait MutableMap { impl MutableMap for TreeMap { fn insert(&mut self, k: uint, v: uint) { self.insert(k, v); } - fn remove(&mut self, k: &uint) -> bool { self.remove(k) } - fn find(&self, k: &uint) -> Option<&uint> { self.find(k) } + fn remove(&mut self, k: &uint) -> bool { self.remove(k).is_some() } + fn find(&self, k: &uint) -> Option<&uint> { self.get(k) } } impl MutableMap for HashMap { fn insert(&mut self, k: uint, v: uint) { self.insert(k, v); } - fn remove(&mut self, k: &uint) -> bool { self.remove(k) } - fn find(&self, k: &uint) -> Option<&uint> { self.find(k) } + fn remove(&mut self, k: &uint) -> bool { self.remove(k).is_some() } + fn find(&self, k: &uint) -> Option<&uint> { self.get(k) } } impl MutableMap for TrieMap { fn insert(&mut self, k: uint, v: uint) { self.insert(k, v); } - fn remove(&mut self, k: &uint) -> bool { self.remove(k) } - fn find(&self, k: &uint) -> Option<&uint> { self.find(k) } + fn remove(&mut self, k: &uint) -> bool { self.remove(k).is_some() } + fn find(&self, k: &uint) -> Option<&uint> { self.get(k) } } fn ascending(map: &mut M, n_keys: uint) { diff --git a/src/test/bench/shootout-chameneos-redux.rs b/src/test/bench/shootout-chameneos-redux.rs index abcd9f90333..191f70ac492 100644 --- a/src/test/bench/shootout-chameneos-redux.rs +++ b/src/test/bench/shootout-chameneos-redux.rs @@ -197,8 +197,8 @@ fn rendezvous(nn: uint, set: Vec) { creatures_met += 2; - to_creature.get_mut(fst_creature.name).send(snd_creature); - to_creature.get_mut(snd_creature.name).send(fst_creature); + to_creature[fst_creature.name].send(snd_creature); + to_creature[snd_creature.name].send(fst_creature); } // tell each creature to stop diff --git a/src/test/bench/shootout-fasta-redux.rs b/src/test/bench/shootout-fasta-redux.rs index e151369ff38..0a3370fa487 100644 --- a/src/test/bench/shootout-fasta-redux.rs +++ b/src/test/bench/shootout-fasta-redux.rs @@ -100,7 +100,7 @@ fn sum_and_scale(a: &'static [AminoAcid]) -> Vec { result.push(a_i); } let result_len = result.len(); - result.get_mut(result_len - 1).p = LOOKUP_SCALE; + result[result_len - 1].p = LOOKUP_SCALE; result } diff --git a/src/test/bench/shootout-k-nucleotide.rs b/src/test/bench/shootout-k-nucleotide.rs index d0e6aacdbb2..6ada34a5a58 100644 --- a/src/test/bench/shootout-k-nucleotide.rs +++ b/src/test/bench/shootout-k-nucleotide.rs @@ -171,13 +171,13 @@ impl Table { next: None, }; c.f(&mut *entry); - *self.items.get_mut(index as uint) = Some(entry); + self.items[index as uint] = Some(entry); return; } } { - let entry = self.items.get_mut(index as uint).as_mut().unwrap(); + let entry = self.items[index as uint].as_mut().unwrap(); if entry.code == key { c.f(&mut **entry); return; diff --git a/src/test/bench/shootout-meteor.rs b/src/test/bench/shootout-meteor.rs index 47e1969172d..d8df3eea83b 100644 --- a/src/test/bench/shootout-meteor.rs +++ b/src/test/bench/shootout-meteor.rs @@ -194,7 +194,7 @@ fn is_board_unfeasible(board: u64, masks: &Vec>>) -> bool { fn filter_masks(masks: &mut Vec>>) { for i in range(0, masks.len()) { for j in range(0, (*masks)[i].len()) { - *masks.get_mut(i).get_mut(j) = + masks[i][j] = (*masks)[i][j].iter().map(|&m| m) .filter(|&m| !is_board_unfeasible(m, masks)) .collect(); @@ -217,7 +217,7 @@ fn to_vec(raw_sol: &List) -> Vec { let id = '0' as u8 + get_id(m); for i in range(0u, 50) { if m & 1 << i != 0 { - *sol.get_mut(i) = id; + sol[i] = id; } } } diff --git a/src/test/bench/shootout-regex-dna.rs b/src/test/bench/shootout-regex-dna.rs index dccdafe9cf8..81de7a12690 100644 --- a/src/test/bench/shootout-regex-dna.rs +++ b/src/test/bench/shootout-regex-dna.rs @@ -114,7 +114,7 @@ fn main() { } for (i, variant) in variant_strs.iter().enumerate() { - println!("{} {}", variant, counts.get_mut(i).get()); + println!("{} {}", variant, counts[i].get()); } println!(""); println!("{}", ilen); diff --git a/src/test/bench/shootout-reverse-complement.rs b/src/test/bench/shootout-reverse-complement.rs index 5ce1b2fc40d..d7d8e94c8a7 100644 --- a/src/test/bench/shootout-reverse-complement.rs +++ b/src/test/bench/shootout-reverse-complement.rs @@ -112,14 +112,15 @@ fn read_to_end(r: &mut R) -> IoResult> { let mut vec = Vec::with_capacity(CHUNK); loop { // workaround: very fast growing - if vec.capacity() - vec.len() < CHUNK { + let len = vec.len(); + if vec.capacity() - len < CHUNK { let cap = vec.capacity(); let mult = if cap < 256 * 1024 * 1024 { 16 } else { 2 }; - vec.reserve_exact(mult * cap); + vec.reserve_exact(mult * cap - len); } match r.push_at_least(1, CHUNK, &mut vec) { Ok(_) => {} diff --git a/src/test/bench/sudoku.rs b/src/test/bench/sudoku.rs index ae7594ea8a2..54824d7259f 100644 --- a/src/test/bench/sudoku.rs +++ b/src/test/bench/sudoku.rs @@ -79,7 +79,7 @@ impl Sudoku { if comps.len() == 3u { let row = from_str::(comps[0]).unwrap() as u8; let col = from_str::(comps[1]).unwrap() as u8; - *g.get_mut(row as uint).get_mut(col as uint) = + g[row as uint][col as uint] = from_str::(comps[2]).unwrap() as u8; } else { @@ -139,10 +139,10 @@ impl Sudoku { // find first remaining color that is available let next = avail.next(); - *self.grid.get_mut(row as uint).get_mut(col as uint) = next; + self.grid[row as uint][col as uint] = next; return 0u8 != next; } - *self.grid.get_mut(row as uint).get_mut(col as uint) = 0u8; + self.grid[row as uint][col as uint] = 0u8; return false; } diff --git a/src/test/compile-fail/borrowck-assign-comp-idx.rs b/src/test/compile-fail/borrowck-assign-comp-idx.rs index 5bc2edba301..e14911d3508 100644 --- a/src/test/compile-fail/borrowck-assign-comp-idx.rs +++ b/src/test/compile-fail/borrowck-assign-comp-idx.rs @@ -19,7 +19,7 @@ fn a() { // Create an immutable pointer into p's contents: let q: &int = &p[0]; - *p.get_mut(0) = 5; //~ ERROR cannot borrow + p[0] = 5; //~ ERROR cannot borrow println!("{}", *q); } @@ -34,7 +34,7 @@ fn b() { borrow( p.as_slice(), - || *p.get_mut(0) = 5); //~ ERROR cannot borrow `p` as mutable + || p[0] = 5); //~ ERROR cannot borrow `p` as mutable } fn c() { @@ -42,7 +42,7 @@ fn c() { // modification: let mut p = vec!(1); borrow(p.as_slice(), ||{}); - *p.get_mut(0) = 5; + p[0] = 5; } fn main() { diff --git a/src/test/compile-fail/borrowck-for-loop-head-linkage.rs b/src/test/compile-fail/borrowck-for-loop-head-linkage.rs index cdfb384d47c..d7128105892 100644 --- a/src/test/compile-fail/borrowck-for-loop-head-linkage.rs +++ b/src/test/compile-fail/borrowck-for-loop-head-linkage.rs @@ -13,7 +13,7 @@ fn main() { for &x in vector.iter() { let cap = vector.capacity(); vector.grow(cap, 0u); //~ ERROR cannot borrow - *vector.get_mut(1u) = 5u; //~ ERROR cannot borrow + vector[1u] = 5u; //~ ERROR cannot borrow } } diff --git a/src/test/compile-fail/borrowck-loan-vec-content.rs b/src/test/compile-fail/borrowck-loan-vec-content.rs index 31b5c44df66..200d208d140 100644 --- a/src/test/compile-fail/borrowck-loan-vec-content.rs +++ b/src/test/compile-fail/borrowck-loan-vec-content.rs @@ -26,7 +26,7 @@ fn has_mut_vec_but_tries_to_change_it() { takes_imm_elt( &v[0], || { //~ ERROR cannot borrow `v` as mutable - *v.get_mut(1) = 4; + v[1] = 4; }) } diff --git a/src/test/run-pass/foreach-nested.rs b/src/test/run-pass/foreach-nested.rs index af6ca3c93d5..2a54f22ee66 100644 --- a/src/test/run-pass/foreach-nested.rs +++ b/src/test/run-pass/foreach-nested.rs @@ -15,7 +15,7 @@ pub fn main() { let mut a: Vec = vec!(-1, -1, -1, -1); let mut p: int = 0; two(|i| { - two(|j| { *a.get_mut(p as uint) = 10 * i + j; p += 1; }) + two(|j| { a[p as uint] = 10 * i + j; p += 1; }) }); assert_eq!(a[0], 0); assert_eq!(a[1], 1); diff --git a/src/test/run-pass/hashmap-memory.rs b/src/test/run-pass/hashmap-memory.rs index 87afd1601f6..4a6a6782fb3 100644 --- a/src/test/run-pass/hashmap-memory.rs +++ b/src/test/run-pass/hashmap-memory.rs @@ -83,7 +83,7 @@ mod map_reduce { mapper_done => { num_mappers -= 1; } find_reducer(k, cc) => { let mut c; - match reducers.find(&str::from_utf8( + match reducers.get(&str::from_utf8( k.as_slice()).unwrap().to_string()) { Some(&_c) => { c = _c; } None => { c = 0; } diff --git a/src/test/run-pass/issue-3563-3.rs b/src/test/run-pass/issue-3563-3.rs index 84f303de705..4e330b9a0e7 100644 --- a/src/test/run-pass/issue-3563-3.rs +++ b/src/test/run-pass/issue-3563-3.rs @@ -86,8 +86,8 @@ impl AsciiArt { // element is: // 1) potentially large // 2) needs to be modified - let row = self.lines.get_mut(v); - *row.get_mut(h) = self.fill; + let row = &mut self.lines[v]; + row[h] = self.fill; } } } diff --git a/src/test/run-pass/issue-3991.rs b/src/test/run-pass/issue-3991.rs index da22da31d5b..37144fb9cce 100644 --- a/src/test/run-pass/issue-3991.rs +++ b/src/test/run-pass/issue-3991.rs @@ -15,7 +15,7 @@ struct HasNested { impl HasNested { fn method_push_local(&mut self) { - self.nest.get_mut(0).push(0); + self.nest[0].push(0); } } diff --git a/src/test/run-pass/overloaded-deref.rs b/src/test/run-pass/overloaded-deref.rs index b63db29cf91..ca820830f02 100644 --- a/src/test/run-pass/overloaded-deref.rs +++ b/src/test/run-pass/overloaded-deref.rs @@ -44,8 +44,8 @@ pub fn main() { assert_eq!(*(*p).borrow(), Point {x: 3, y: 5}); let v = Rc::new(RefCell::new(vec!(1i, 2, 3))); - *(*(*v).borrow_mut()).get_mut(0) = 3; - *(*(*v).borrow_mut()).get_mut(1) += 3; + (*(*v).borrow_mut())[0] = 3; + (*(*v).borrow_mut())[1] += 3; assert_eq!(((*(*v).borrow())[0], (*(*v).borrow())[1], (*(*v).borrow())[2]), (3, 5, 3)); diff --git a/src/test/run-pass/send_str_hashmap.rs b/src/test/run-pass/send_str_hashmap.rs index 1edce811bcb..55003a07b5b 100644 --- a/src/test/run-pass/send_str_hashmap.rs +++ b/src/test/run-pass/send_str_hashmap.rs @@ -16,37 +16,37 @@ use std::option::Some; pub fn main() { let mut map: HashMap = HashMap::new(); - assert!(map.insert(Slice("foo"), 42)); - assert!(!map.insert(Owned("foo".to_string()), 42)); - assert!(!map.insert(Slice("foo"), 42)); - assert!(!map.insert(Owned("foo".to_string()), 42)); + assert!(map.insert(Slice("foo"), 42).is_none()); + assert!(map.insert(Owned("foo".to_string()), 42).is_some()); + assert!(map.insert(Slice("foo"), 42).is_some()); + assert!(map.insert(Owned("foo".to_string()), 42).is_some()); - assert!(!map.insert(Slice("foo"), 43)); - assert!(!map.insert(Owned("foo".to_string()), 44)); - assert!(!map.insert(Slice("foo"), 45)); - assert!(!map.insert(Owned("foo".to_string()), 46)); + assert!(map.insert(Slice("foo"), 43).is_some()); + assert!(map.insert(Owned("foo".to_string()), 44).is_some()); + assert!(map.insert(Slice("foo"), 45).is_some()); + assert!(map.insert(Owned("foo".to_string()), 46).is_some()); let v = 46; - assert_eq!(map.find(&Owned("foo".to_string())), Some(&v)); - assert_eq!(map.find(&Slice("foo")), Some(&v)); + assert_eq!(map.get(&Owned("foo".to_string())), Some(&v)); + assert_eq!(map.get(&Slice("foo")), Some(&v)); let (a, b, c, d) = (50, 51, 52, 53); - assert!(map.insert(Slice("abc"), a)); - assert!(map.insert(Owned("bcd".to_string()), b)); - assert!(map.insert(Slice("cde"), c)); - assert!(map.insert(Owned("def".to_string()), d)); + assert!(map.insert(Slice("abc"), a).is_none()); + assert!(map.insert(Owned("bcd".to_string()), b).is_none()); + assert!(map.insert(Slice("cde"), c).is_none()); + assert!(map.insert(Owned("def".to_string()), d).is_none()); - assert!(!map.insert(Slice("abc"), a)); - assert!(!map.insert(Owned("bcd".to_string()), b)); - assert!(!map.insert(Slice("cde"), c)); - assert!(!map.insert(Owned("def".to_string()), d)); + assert!(map.insert(Slice("abc"), a).is_some()); + assert!(map.insert(Owned("bcd".to_string()), b).is_some()); + assert!(map.insert(Slice("cde"), c).is_some()); + assert!(map.insert(Owned("def".to_string()), d).is_some()); - assert!(!map.insert(Owned("abc".to_string()), a)); - assert!(!map.insert(Slice("bcd"), b)); - assert!(!map.insert(Owned("cde".to_string()), c)); - assert!(!map.insert(Slice("def"), d)); + assert!(map.insert(Owned("abc".to_string()), a).is_some()); + assert!(map.insert(Slice("bcd"), b).is_some()); + assert!(map.insert(Owned("cde".to_string()), c).is_some()); + assert!(map.insert(Slice("def"), d).is_some()); assert_eq!(map.find_equiv("abc"), Some(&a)); assert_eq!(map.find_equiv("bcd"), Some(&b)); diff --git a/src/test/run-pass/send_str_treemap.rs b/src/test/run-pass/send_str_treemap.rs index f73ab8f52d7..c52f9458f99 100644 --- a/src/test/run-pass/send_str_treemap.rs +++ b/src/test/run-pass/send_str_treemap.rs @@ -17,49 +17,49 @@ use std::option::Some; pub fn main() { let mut map: TreeMap = TreeMap::new(); - assert!(map.insert(Slice("foo"), 42)); - assert!(!map.insert(Owned("foo".to_string()), 42)); - assert!(!map.insert(Slice("foo"), 42)); - assert!(!map.insert(Owned("foo".to_string()), 42)); + assert!(map.insert(Slice("foo"), 42).is_none()); + assert!(map.insert(Owned("foo".to_string()), 42).is_some()); + assert!(map.insert(Slice("foo"), 42).is_some()); + assert!(map.insert(Owned("foo".to_string()), 42).is_some()); - assert!(!map.insert(Slice("foo"), 43)); - assert!(!map.insert(Owned("foo".to_string()), 44)); - assert!(!map.insert(Slice("foo"), 45)); - assert!(!map.insert(Owned("foo".to_string()), 46)); + assert!(map.insert(Slice("foo"), 43).is_some()); + assert!(map.insert(Owned("foo".to_string()), 44).is_some()); + assert!(map.insert(Slice("foo"), 45).is_some()); + assert!(map.insert(Owned("foo".to_string()), 46).is_some()); let v = 46; - assert_eq!(map.find(&Owned("foo".to_string())), Some(&v)); - assert_eq!(map.find(&Slice("foo")), Some(&v)); + assert_eq!(map.get(&Owned("foo".to_string())), Some(&v)); + assert_eq!(map.get(&Slice("foo")), Some(&v)); let (a, b, c, d) = (50, 51, 52, 53); - assert!(map.insert(Slice("abc"), a)); - assert!(map.insert(Owned("bcd".to_string()), b)); - assert!(map.insert(Slice("cde"), c)); - assert!(map.insert(Owned("def".to_string()), d)); + assert!(map.insert(Slice("abc"), a).is_none()); + assert!(map.insert(Owned("bcd".to_string()), b).is_none()); + assert!(map.insert(Slice("cde"), c).is_none()); + assert!(map.insert(Owned("def".to_string()), d).is_none()); - assert!(!map.insert(Slice("abc"), a)); - assert!(!map.insert(Owned("bcd".to_string()), b)); - assert!(!map.insert(Slice("cde"), c)); - assert!(!map.insert(Owned("def".to_string()), d)); + assert!(map.insert(Slice("abc"), a).is_some()); + assert!(map.insert(Owned("bcd".to_string()), b).is_some()); + assert!(map.insert(Slice("cde"), c).is_some()); + assert!(map.insert(Owned("def".to_string()), d).is_some()); - assert!(!map.insert(Owned("abc".to_string()), a)); - assert!(!map.insert(Slice("bcd"), b)); - assert!(!map.insert(Owned("cde".to_string()), c)); - assert!(!map.insert(Slice("def"), d)); + assert!(map.insert(Owned("abc".to_string()), a).is_some()); + assert!(map.insert(Slice("bcd"), b).is_some()); + assert!(map.insert(Owned("cde".to_string()), c).is_some()); + assert!(map.insert(Slice("def"), d).is_some()); - assert_eq!(map.find(&Slice("abc")), Some(&a)); - assert_eq!(map.find(&Slice("bcd")), Some(&b)); - assert_eq!(map.find(&Slice("cde")), Some(&c)); - assert_eq!(map.find(&Slice("def")), Some(&d)); + assert_eq!(map.get(&Slice("abc")), Some(&a)); + assert_eq!(map.get(&Slice("bcd")), Some(&b)); + assert_eq!(map.get(&Slice("cde")), Some(&c)); + assert_eq!(map.get(&Slice("def")), Some(&d)); - assert_eq!(map.find(&Owned("abc".to_string())), Some(&a)); - assert_eq!(map.find(&Owned("bcd".to_string())), Some(&b)); - assert_eq!(map.find(&Owned("cde".to_string())), Some(&c)); - assert_eq!(map.find(&Owned("def".to_string())), Some(&d)); + assert_eq!(map.get(&Owned("abc".to_string())), Some(&a)); + assert_eq!(map.get(&Owned("bcd".to_string())), Some(&b)); + assert_eq!(map.get(&Owned("cde".to_string())), Some(&c)); + assert_eq!(map.get(&Owned("def".to_string())), Some(&d)); - assert!(map.pop(&Slice("foo")).is_some()); + assert!(map.remove(&Slice("foo")).is_some()); assert_eq!(map.into_iter().map(|(k, v)| format!("{}{}", k, v)) .collect::>() .concat(), diff --git a/src/test/run-pass/swap-2.rs b/src/test/run-pass/swap-2.rs index 4eb9274551f..3c0f9505736 100644 --- a/src/test/run-pass/swap-2.rs +++ b/src/test/run-pass/swap-2.rs @@ -16,7 +16,7 @@ pub fn main() { assert_eq!(a[2], 4); assert_eq!(a[4], 2); let mut n = 42; - swap(&mut n, a.get_mut(0)); + swap(&mut n, &mut a[0]); assert_eq!(a[0], 42); assert_eq!(n, 0); } diff --git a/src/test/run-pass/unique-in-vec-copy.rs b/src/test/run-pass/unique-in-vec-copy.rs index 33a28ddb2fc..577a8f1430b 100644 --- a/src/test/run-pass/unique-in-vec-copy.rs +++ b/src/test/run-pass/unique-in-vec-copy.rs @@ -17,7 +17,7 @@ pub fn main() { assert_eq!(*b[0], 10); // This should only modify the value in a, not b - **a.get_mut(0) = 20; + *a[0] = 20; assert_eq!(*a[0], 20); assert_eq!(*b[0], 10); -- cgit 1.4.1-3-g733a5