diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 9599491462e92..6b7f491effb30 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -136,7 +136,7 @@ #![stable(feature = "rust1", since = "1.0.0")] use crate::iter::{FromIterator, FusedIterator, TrustedLen}; -use crate::{hint, mem, ops::{self, Deref}}; +use crate::{convert, hint, mem, ops::{self, Deref}}; use crate::pin::Pin; // Note that this is not a lang item per se, but it has a hidden dependency on @@ -1413,3 +1413,33 @@ impl ops::Try for Option { None } } + +impl Option> { + /// Converts from `Option>` to `Option` + /// + /// # Examples + /// Basic usage: + /// ``` + /// #![feature(option_flattening)] + /// let x: Option> = Some(Some(6)); + /// assert_eq!(Some(6), x.flatten()); + /// + /// let x: Option> = Some(None); + /// assert_eq!(None, x.flatten()); + /// + /// let x: Option> = None; + /// assert_eq!(None, x.flatten()); + /// ``` + /// Flattening once only removes one level of nesting: + /// ``` + /// #![feature(option_flattening)] + /// let x: Option>> = Some(Some(Some(6))); + /// assert_eq!(Some(Some(6)), x.flatten()); + /// assert_eq!(Some(6), x.flatten().flatten()); + /// ``` + #[inline] + #[unstable(feature = "option_flattening", issue = "60258")] + pub fn flatten(self) -> Option { + self.and_then(convert::identity) + } +} diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index 7a5511ee1dc8b..45421848cec5d 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -2214,7 +2214,7 @@ impl str { /// modified in a way that it remains valid UTF-8. /// /// [`u8`]: primitive.u8.html - #[unstable(feature = "str_as_mut_ptr", issue = "58215")] + #[stable(feature = "str_as_mut_ptr", since = "1.36.0")] #[inline] pub fn as_mut_ptr(&mut self) -> *mut u8 { self as *mut str as *mut u8 @@ -4061,7 +4061,7 @@ impl str { /// Both are equivalent to: /// /// ``` - /// println!("\\u{{2764}}\n!"); + /// println!("\\u{{2764}}\\n!"); /// ``` /// /// Using `to_string`: diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index bcf1b30814f29..df455a725c5ba 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -260,12 +260,6 @@ enum ParamMode { Optional, } -#[derive(Debug)] -struct LoweredNodeId { - node_id: NodeId, - hir_id: hir::HirId, -} - enum ParenthesizedGenericArgs { Ok, Warn, @@ -429,7 +423,7 @@ impl<'a> LoweringContext<'a> { UseTreeKind::Glob => (), UseTreeKind::Nested(ref trees) => { for &(ref use_tree, id) in trees { - let hir_id = self.lctx.allocate_hir_id_counter(id).hir_id; + let hir_id = self.lctx.allocate_hir_id_counter(id); self.allocate_use_tree_hir_id_counters(use_tree, hir_id.owner); } } @@ -489,7 +483,7 @@ impl<'a> LoweringContext<'a> { } fn visit_item(&mut self, item: &'lcx Item) { - let hir_id = self.lctx.allocate_hir_id_counter(item.id).hir_id; + let hir_id = self.lctx.allocate_hir_id_counter(item.id); match item.node { ItemKind::Struct(_, ref generics) @@ -698,24 +692,21 @@ impl<'a> LoweringContext<'a> { self.modules.get_mut(&self.current_module).unwrap().items.insert(id); } - fn allocate_hir_id_counter(&mut self, owner: NodeId) -> LoweredNodeId { + fn allocate_hir_id_counter(&mut self, owner: NodeId) -> hir::HirId { // Setup the counter if needed self.item_local_id_counters.entry(owner).or_insert(0); // Always allocate the first `HirId` for the owner itself. let lowered = self.lower_node_id_with_owner(owner, owner); - debug_assert_eq!(lowered.hir_id.local_id.as_u32(), 0); + debug_assert_eq!(lowered.local_id.as_u32(), 0); lowered } - fn lower_node_id_generic(&mut self, ast_node_id: NodeId, alloc_hir_id: F) -> LoweredNodeId + fn lower_node_id_generic(&mut self, ast_node_id: NodeId, alloc_hir_id: F) -> hir::HirId where F: FnOnce(&mut Self) -> hir::HirId, { if ast_node_id == DUMMY_NODE_ID { - return LoweredNodeId { - node_id: DUMMY_NODE_ID, - hir_id: hir::DUMMY_HIR_ID, - }; + return hir::DUMMY_HIR_ID; } let min_size = ast_node_id.as_usize() + 1; @@ -730,15 +721,10 @@ impl<'a> LoweringContext<'a> { // Generate a new `HirId`. let hir_id = alloc_hir_id(self); self.node_id_to_hir_id[ast_node_id] = hir_id; - LoweredNodeId { - node_id: ast_node_id, - hir_id, - } + + hir_id } else { - LoweredNodeId { - node_id: ast_node_id, - hir_id: existing_hir_id, - } + existing_hir_id } } @@ -770,7 +756,7 @@ impl<'a> LoweringContext<'a> { /// actually used in the HIR, as that would trigger an assertion in the /// `HirIdValidator` later on, which makes sure that all `NodeId`s got mapped /// properly. Calling the method twice with the same `NodeId` is fine though. - fn lower_node_id(&mut self, ast_node_id: NodeId) -> LoweredNodeId { + fn lower_node_id(&mut self, ast_node_id: NodeId) -> hir::HirId { self.lower_node_id_generic(ast_node_id, |this| { let &mut (def_index, ref mut local_id_counter) = this.current_hir_id_owner.last_mut().unwrap(); @@ -783,7 +769,7 @@ impl<'a> LoweringContext<'a> { }) } - fn lower_node_id_with_owner(&mut self, ast_node_id: NodeId, owner: NodeId) -> LoweredNodeId { + fn lower_node_id_with_owner(&mut self, ast_node_id: NodeId, owner: NodeId) -> hir::HirId { self.lower_node_id_generic(ast_node_id, |this| { let local_id_counter = this .item_local_id_counters @@ -822,7 +808,7 @@ impl<'a> LoweringContext<'a> { id } - fn next_id(&mut self) -> LoweredNodeId { + fn next_id(&mut self) -> hir::HirId { self.lower_node_id(self.sess.next_node_id()) } @@ -830,7 +816,7 @@ impl<'a> LoweringContext<'a> { def.map_id(|id| { self.lower_node_id_generic(id, |_| { panic!("expected node_id to be lowered already for def {:#?}", def) - }).hir_id + }) }) } @@ -942,7 +928,7 @@ impl<'a> LoweringContext<'a> { hir_name: ParamName, parent_index: DefIndex, ) -> hir::GenericParam { - let LoweredNodeId { node_id, hir_id } = self.next_id(); + let node_id = self.sess.next_node_id(); // Get the name we'll use to make the def-path. Note // that collisions are ok here and this shouldn't @@ -973,7 +959,7 @@ impl<'a> LoweringContext<'a> { ); hir::GenericParam { - hir_id, + hir_id: self.lower_node_id(node_id), name: hir_name, attrs: hir_vec![], bounds: hir_vec![], @@ -1158,10 +1144,9 @@ impl<'a> LoweringContext<'a> { self.is_generator = prev_is_generator; let capture_clause = self.lower_capture_clause(capture_clause); - let closure_hir_id = self.lower_node_id(closure_node_id).hir_id; let decl = self.lower_fn_decl(&decl, None, /* impl trait allowed */ false, None); let generator = hir::Expr { - hir_id: closure_hir_id, + hir_id: self.lower_node_id(closure_node_id), node: hir::ExprKind::Closure(capture_clause, decl, body_id, span, Some(hir::GeneratorMovability::Static)), span, @@ -1267,7 +1252,7 @@ impl<'a> LoweringContext<'a> { let target_id = match destination { Some((id, _)) => { if let Def::Label(loop_id) = self.expect_full_def(id) { - Ok(self.lower_node_id(loop_id).hir_id) + Ok(self.lower_node_id(loop_id)) } else { Err(hir::LoopIdError::UnresolvedLabel) } @@ -1276,7 +1261,7 @@ impl<'a> LoweringContext<'a> { self.loop_scopes .last() .cloned() - .map(|id| Ok(self.lower_node_id(id).hir_id)) + .map(|id| Ok(self.lower_node_id(id))) .unwrap_or(Err(hir::LoopIdError::OutsideLoopScope)) .into() } @@ -1350,10 +1335,8 @@ impl<'a> LoweringContext<'a> { fn lower_ty_binding(&mut self, b: &TypeBinding, itctx: ImplTraitContext<'_>) -> hir::TypeBinding { - let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(b.id); - hir::TypeBinding { - hir_id, + hir_id: self.lower_node_id(b.id), ident: b.ident, ty: self.lower_ty(&b.ty, itctx), span: b.span, @@ -1487,7 +1470,6 @@ impl<'a> LoweringContext<'a> { ) } ImplTraitContext::Universal(in_band_ty_params) => { - let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(def_node_id); // Add a definition for the in-band `Param`. let def_index = self .resolver @@ -1502,7 +1484,7 @@ impl<'a> LoweringContext<'a> { // Set the name to `impl Bound1 + Bound2`. let ident = Ident::from_str(&pprust::ty_to_string(t)).with_span_pos(span); in_band_ty_params.push(hir::GenericParam { - hir_id, + hir_id: self.lower_node_id(def_node_id), name: ParamName::Plain(ident), pure_wrt_drop: false, attrs: hir_vec![], @@ -1557,11 +1539,10 @@ impl<'a> LoweringContext<'a> { }, }; - let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(t.id); hir::Ty { node: kind, span: t.span, - hir_id, + hir_id: self.lower_node_id(t.id), } } @@ -1600,12 +1581,11 @@ impl<'a> LoweringContext<'a> { ); self.with_hir_id_owner(exist_ty_node_id, |lctx| { - let LoweredNodeId { node_id: _, hir_id } = lctx.next_id(); let exist_ty_item = hir::ExistTy { generics: hir::Generics { params: lifetime_defs, where_clause: hir::WhereClause { - hir_id, + hir_id: lctx.next_id(), predicates: hir_vec![], }, span, @@ -1624,7 +1604,7 @@ impl<'a> LoweringContext<'a> { ); // `impl Trait` now just becomes `Foo<'a, 'b, ..>`. - hir::TyKind::Def(hir::ItemId { id: exist_ty_id.hir_id }, lifetimes) + hir::TyKind::Def(hir::ItemId { id: exist_ty_id }, lifetimes) }) } @@ -1636,13 +1616,13 @@ impl<'a> LoweringContext<'a> { exist_ty_item: hir::ExistTy, span: Span, exist_ty_span: Span, - ) -> LoweredNodeId { + ) -> hir::HirId { let exist_ty_item_kind = hir::ItemKind::Existential(exist_ty_item); let exist_ty_id = self.lower_node_id(exist_ty_node_id); // Generate an `existential type Foo: Trait;` declaration. trace!("registering existential type with id {:#?}", exist_ty_id); let exist_ty_item = hir::Item { - hir_id: exist_ty_id.hir_id, + hir_id: exist_ty_id, ident: keywords::Invalid.ident(), attrs: Default::default(), node: exist_ty_item_kind, @@ -1757,15 +1737,14 @@ impl<'a> LoweringContext<'a> { && !self.already_defined_lifetimes.contains(&name) { self.already_defined_lifetimes.insert(name); - let LoweredNodeId { node_id: _, hir_id } = self.context.next_id(); self.output_lifetimes.push(hir::GenericArg::Lifetime(hir::Lifetime { - hir_id, + hir_id: self.context.next_id(), span: lifetime.span, name, })); let def_node_id = self.context.sess.next_node_id(); - let LoweredNodeId { node_id: _, hir_id } = + let hir_id = self.context.lower_node_id_with_owner(def_node_id, self.exist_ty_id); self.context.resolver.definitions().create_def_with_parent( self.parent, @@ -1840,11 +1819,10 @@ impl<'a> LoweringContext<'a> { } fn lower_variant(&mut self, v: &Variant) -> hir::Variant { - let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(v.node.id); Spanned { node: hir::VariantKind { ident: v.node.ident, - id: hir_id, + id: self.lower_node_id(v.node.id), attrs: self.lower_attrs(&v.node.attrs), data: self.lower_variant_data(&v.node.data), disr_expr: v.node.disr_expr.as_ref().map(|e| self.lower_anon_const(e)), @@ -2157,7 +2135,7 @@ impl<'a> LoweringContext<'a> { hir::PathSegment::new( segment.ident, - Some(id.hir_id), + Some(id), Some(self.lower_def(def)), generic_args, infer_types, @@ -2201,17 +2179,14 @@ impl<'a> LoweringContext<'a> { .map(|ty| this.lower_ty_direct(ty, ImplTraitContext::disallowed())) .collect(); let mk_tup = |this: &mut Self, tys, span| { - let LoweredNodeId { node_id: _, hir_id } = this.next_id(); - hir::Ty { node: hir::TyKind::Tup(tys), hir_id, span } + hir::Ty { node: hir::TyKind::Tup(tys), hir_id: this.next_id(), span } }; - let LoweredNodeId { node_id: _, hir_id } = this.next_id(); - ( hir::GenericArgs { args: hir_vec![GenericArg::Type(mk_tup(this, inputs, span))], bindings: hir_vec![ hir::TypeBinding { - hir_id, + hir_id: this.next_id(), ident: Ident::from_str(FN_OUTPUT_NAME), ty: output .as_ref() @@ -2229,7 +2204,6 @@ impl<'a> LoweringContext<'a> { } fn lower_local(&mut self, l: &Local) -> (hir::Local, SmallVec<[NodeId; 1]>) { - let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(l.id); let mut ids = SmallVec::<[NodeId; 1]>::new(); if self.sess.features_untracked().impl_trait_in_bindings { if let Some(ref ty) = l.ty { @@ -2239,7 +2213,7 @@ impl<'a> LoweringContext<'a> { } let parent_def_id = DefId::local(self.current_hir_id_owner.last().unwrap().0); (hir::Local { - hir_id, + hir_id: self.lower_node_id(l.id), ty: l.ty .as_ref() .map(|t| self.lower_ty(t, @@ -2276,9 +2250,8 @@ impl<'a> LoweringContext<'a> { } fn lower_arg(&mut self, arg: &Arg) -> hir::Arg { - let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(arg.id); hir::Arg { - hir_id, + hir_id: self.lower_node_id(arg.id), pat: self.lower_pat(&arg.pat), source: self.lower_arg_source(&arg.source), } @@ -2437,7 +2410,7 @@ impl<'a> LoweringContext<'a> { self.allocate_hir_id_counter(exist_ty_node_id); - let (exist_ty_node_id, lifetime_params) = self.with_hir_id_owner(exist_ty_node_id, |this| { + let (exist_ty_id, lifetime_params) = self.with_hir_id_owner(exist_ty_node_id, |this| { let future_bound = this.with_anonymous_lifetime_mode( AnonymousLifetimeMode::Replace(elided_lt_replacement), |this| this.lower_async_fn_output_type_to_future_bound( @@ -2468,12 +2441,11 @@ impl<'a> LoweringContext<'a> { }) .collect(); - let LoweredNodeId { node_id: _, hir_id } = this.next_id(); let exist_ty_item = hir::ExistTy { generics: hir::Generics { params: generic_params, where_clause: hir::WhereClause { - hir_id, + hir_id: this.next_id(), predicates: hir_vec![], }, span, @@ -2491,30 +2463,27 @@ impl<'a> LoweringContext<'a> { exist_ty_span, ); - (exist_ty_id.node_id, lifetime_params) + (exist_ty_id, lifetime_params) }); let generic_args = lifetime_params .iter().cloned() .map(|(span, hir_name)| { - let LoweredNodeId { node_id: _, hir_id } = self.next_id(); GenericArg::Lifetime(hir::Lifetime { - hir_id, + hir_id: self.next_id(), span, name: hir::LifetimeName::Param(hir_name), }) }) .collect(); - let exist_ty_hir_id = self.lower_node_id(exist_ty_node_id).hir_id; - let exist_ty_ref = hir::TyKind::Def(hir::ItemId { id: exist_ty_hir_id }, generic_args); + let exist_ty_ref = hir::TyKind::Def(hir::ItemId { id: exist_ty_id }, generic_args); - let LoweredNodeId { node_id: _, hir_id } = self.next_id(); hir::FunctionRetTy::Return(P(hir::Ty { node: exist_ty_ref, span, - hir_id, + hir_id: self.next_id(), })) } @@ -2531,9 +2500,8 @@ impl<'a> LoweringContext<'a> { self.lower_ty(ty, ImplTraitContext::Existential(Some(fn_def_id))) } FunctionRetTy::Default(ret_ty_span) => { - let LoweredNodeId { node_id: _, hir_id } = self.next_id(); P(hir::Ty { - hir_id, + hir_id: self.next_id(), node: hir::TyKind::Tup(hir_vec![]), span: *ret_ty_span, }) @@ -2541,13 +2509,12 @@ impl<'a> LoweringContext<'a> { }; // "" - let LoweredNodeId { node_id: _, hir_id } = self.next_id(); let future_params = P(hir::GenericArgs { args: hir_vec![], bindings: hir_vec![hir::TypeBinding { ident: Ident::from_str(FN_OUTPUT_NAME), ty: output_ty, - hir_id, + hir_id: self.next_id(), span, }], parenthesized: false, @@ -2557,12 +2524,11 @@ impl<'a> LoweringContext<'a> { let future_path = self.std_path(span, &["future", "Future"], Some(future_params), false); - let LoweredNodeId { node_id: _, hir_id } = self.next_id(); hir::GenericBound::Trait( hir::PolyTraitRef { trait_ref: hir::TraitRef { path: future_path, - hir_ref_id: hir_id, + hir_ref_id: self.next_id(), }, bound_generic_params: hir_vec![], span, @@ -2608,7 +2574,7 @@ impl<'a> LoweringContext<'a> { AnonymousLifetimeMode::ReportError => self.new_error_lifetime(Some(l.id), span), AnonymousLifetimeMode::Replace(replacement) => { - let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(l.id); + let hir_id = self.lower_node_id(l.id); self.replace_elided_lifetime(hir_id, span, replacement) } }, @@ -2626,10 +2592,8 @@ impl<'a> LoweringContext<'a> { span: Span, name: hir::LifetimeName, ) -> hir::Lifetime { - let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(id); - hir::Lifetime { - hir_id, + hir_id: self.lower_node_id(id), span, name: name, } @@ -2751,10 +2715,8 @@ impl<'a> LoweringContext<'a> { } }; - let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(param.id); - hir::GenericParam { - hir_id, + hir_id: self.lower_node_id(param.id), name, span: param.ident.span, pure_wrt_drop: attr::contains_name(¶m.attrs, "may_dangle"), @@ -2834,10 +2796,8 @@ impl<'a> LoweringContext<'a> { self.with_anonymous_lifetime_mode( AnonymousLifetimeMode::ReportError, |this| { - let LoweredNodeId { node_id: _, hir_id } = this.lower_node_id(wc.id); - hir::WhereClause { - hir_id, + hir_id: this.lower_node_id(wc.id), predicates: wc.predicates .iter() .map(|predicate| this.lower_where_predicate(predicate)) @@ -2897,10 +2857,8 @@ impl<'a> LoweringContext<'a> { ref rhs_ty, span, }) => { - let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(id); - hir::WherePredicate::EqPredicate(hir::WhereEqPredicate { - hir_id, + hir_id: self.lower_node_id(id), lhs_ty: self.lower_ty(lhs_ty, ImplTraitContext::disallowed()), rhs_ty: self.lower_ty(rhs_ty, ImplTraitContext::disallowed()), span, @@ -2916,20 +2874,17 @@ impl<'a> LoweringContext<'a> { recovered, ), VariantData::Tuple(ref fields, id) => { - let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(id); - hir::VariantData::Tuple( fields .iter() .enumerate() .map(|f| self.lower_struct_field(f)) .collect(), - hir_id, + self.lower_node_id(id), ) }, VariantData::Unit(id) => { - let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(id); - hir::VariantData::Unit(hir_id) + hir::VariantData::Unit(self.lower_node_id(id)) }, } } @@ -2939,10 +2894,9 @@ impl<'a> LoweringContext<'a> { hir::QPath::Resolved(None, path) => path.and_then(|path| path), qpath => bug!("lower_trait_ref: unexpected QPath `{:?}`", qpath), }; - let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(p.ref_id); hir::TraitRef { path, - hir_ref_id: hir_id, + hir_ref_id: self.lower_node_id(p.ref_id), } } @@ -2969,11 +2923,9 @@ impl<'a> LoweringContext<'a> { } fn lower_struct_field(&mut self, (index, f): (usize, &StructField)) -> hir::StructField { - let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(f.id); - hir::StructField { span: f.span, - hir_id, + hir_id: self.lower_node_id(f.id), ident: match f.ident { Some(ident) => ident, // FIXME(jseyfried): positional field hygiene @@ -2986,10 +2938,8 @@ impl<'a> LoweringContext<'a> { } fn lower_field(&mut self, f: &Field) -> hir::Field { - let LoweredNodeId { node_id: _, hir_id } = self.next_id(); - hir::Field { - hir_id, + hir_id: self.next_id(), ident: f.ident, expr: P(self.lower_expr(&f.expr)), span: f.span, @@ -3026,10 +2976,8 @@ impl<'a> LoweringContext<'a> { } } - let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(b.id); - P(hir::Block { - hir_id, + hir_id: self.lower_node_id(b.id), stmts: stmts.into(), expr, rules: self.lower_block_check_mode(&b.rules), @@ -3220,7 +3168,7 @@ impl<'a> LoweringContext<'a> { // method, it will not be considered an in-band // lifetime to be added, but rather a reference to a // parent lifetime. - let lowered_trait_impl_id = self.lower_node_id(id).hir_id; + let lowered_trait_impl_id = self.lower_node_id(id); let (generics, (trait_ref, lowered_ty)) = self.add_in_band_defs( ast_generics, def_id, @@ -3358,11 +3306,10 @@ impl<'a> LoweringContext<'a> { hir::VisibilityKind::Crate(sugar) => hir::VisibilityKind::Crate(sugar), hir::VisibilityKind::Inherited => hir::VisibilityKind::Inherited, hir::VisibilityKind::Restricted { ref path, hir_id: _ } => { - let id = this.next_id(); let path = this.renumber_segment_ids(path); hir::VisibilityKind::Restricted { path, - hir_id: id.hir_id, + hir_id: this.next_id(), } } }; @@ -3370,7 +3317,7 @@ impl<'a> LoweringContext<'a> { this.insert_item( hir::Item { - hir_id: new_id.hir_id, + hir_id: new_id, ident, attrs: attrs.clone(), node: item, @@ -3428,10 +3375,7 @@ impl<'a> LoweringContext<'a> { // Add all the nested `PathListItem`s to the HIR. for &(ref use_tree, id) in trees { - let LoweredNodeId { - node_id: new_id, - hir_id: new_hir_id, - } = self.lower_node_id(id); + let new_hir_id = self.lower_node_id(id); let mut vis = vis.clone(); let mut ident = ident.clone(); @@ -3447,10 +3391,10 @@ impl<'a> LoweringContext<'a> { // the current owner, since we want each desugared import to // own its own names, we have to adjust the owner before // lowering the rest of the import. - self.with_hir_id_owner(new_id, |this| { + self.with_hir_id_owner(id, |this| { let item = this.lower_use_tree(use_tree, &prefix, - new_id, + id, &mut vis, &mut ident, attrs); @@ -3460,11 +3404,10 @@ impl<'a> LoweringContext<'a> { hir::VisibilityKind::Crate(sugar) => hir::VisibilityKind::Crate(sugar), hir::VisibilityKind::Inherited => hir::VisibilityKind::Inherited, hir::VisibilityKind::Restricted { ref path, hir_id: _ } => { - let id = this.next_id(); let path = this.renumber_segment_ids(path); hir::VisibilityKind::Restricted { path: path, - hir_id: id.hir_id, + hir_id: this.next_id(), } } }; @@ -3520,15 +3463,14 @@ impl<'a> LoweringContext<'a> { let mut path = path.clone(); for seg in path.segments.iter_mut() { if seg.hir_id.is_some() { - seg.hir_id = Some(self.next_id().hir_id); + seg.hir_id = Some(self.next_id()); } } path } fn lower_trait_item(&mut self, i: &TraitItem) -> hir::TraitItem { - let LoweredNodeId { node_id, hir_id } = self.lower_node_id(i.id); - let trait_item_def_id = self.resolver.definitions().local_def_id(node_id); + let trait_item_def_id = self.resolver.definitions().local_def_id(i.id); let (generics, node) = match i.node { TraitItemKind::Const(ref ty, ref default) => ( @@ -3578,7 +3520,7 @@ impl<'a> LoweringContext<'a> { }; hir::TraitItem { - hir_id, + hir_id: self.lower_node_id(i.id), ident: i.ident, attrs: self.lower_attrs(&i.attrs), generics, @@ -3604,7 +3546,7 @@ impl<'a> LoweringContext<'a> { TraitItemKind::Macro(..) => unimplemented!(), }; hir::TraitItemRef { - id: hir::TraitItemId { hir_id: self.lower_node_id(i.id).hir_id }, + id: hir::TraitItemId { hir_id: self.lower_node_id(i.id) }, ident: i.ident, span: i.span, defaultness: self.lower_defaultness(Defaultness::Default, has_default), @@ -3613,8 +3555,7 @@ impl<'a> LoweringContext<'a> { } fn lower_impl_item(&mut self, i: &ImplItem) -> hir::ImplItem { - let LoweredNodeId { node_id, hir_id } = self.lower_node_id(i.id); - let impl_item_def_id = self.resolver.definitions().local_def_id(node_id); + let impl_item_def_id = self.resolver.definitions().local_def_id(i.id); let (generics, node) = match i.node { ImplItemKind::Const(ref ty, ref expr) => { @@ -3671,7 +3612,7 @@ impl<'a> LoweringContext<'a> { }; hir::ImplItem { - hir_id, + hir_id: self.lower_node_id(i.id), ident: i.ident, attrs: self.lower_attrs(&i.attrs), generics, @@ -3686,7 +3627,7 @@ impl<'a> LoweringContext<'a> { fn lower_impl_item_ref(&mut self, i: &ImplItem) -> hir::ImplItemRef { hir::ImplItemRef { - id: hir::ImplItemId { hir_id: self.lower_node_id(i.id).hir_id }, + id: hir::ImplItemId { hir_id: self.lower_node_id(i.id) }, ident: i.ident, span: i.span, vis: self.lower_visibility(&i.vis, Some(i.id)), @@ -3742,7 +3683,7 @@ impl<'a> LoweringContext<'a> { }; node_ids.into_iter().map(|node_id| hir::ItemId { - id: self.allocate_hir_id_counter(node_id).hir_id + id: self.allocate_hir_id_counter(node_id) }).collect() } @@ -3776,7 +3717,7 @@ impl<'a> LoweringContext<'a> { if !def.legacy || attr::contains_name(&i.attrs, "macro_export") || attr::contains_name(&i.attrs, "rustc_doc_only_macro") { let body = self.lower_token_stream(def.stream()); - let hir_id = self.lower_node_id(i.id).hir_id; + let hir_id = self.lower_node_id(i.id); self.exported_macros.push(hir::MacroDef { name: ident.name, vis, @@ -3792,10 +3733,8 @@ impl<'a> LoweringContext<'a> { let node = self.lower_item_kind(i.id, &mut ident, &attrs, &mut vis, &i.node); - let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(i.id); - Some(hir::Item { - hir_id, + hir_id: self.lower_node_id(i.id), ident, attrs, node, @@ -3805,10 +3744,9 @@ impl<'a> LoweringContext<'a> { } fn lower_foreign_item(&mut self, i: &ForeignItem) -> hir::ForeignItem { - let LoweredNodeId { node_id, hir_id } = self.lower_node_id(i.id); - let def_id = self.resolver.definitions().local_def_id(node_id); + let def_id = self.resolver.definitions().local_def_id(i.id); hir::ForeignItem { - hir_id, + hir_id: self.lower_node_id(i.id), ident: i.ident, attrs: self.lower_attrs(&i.attrs), node: match i.node { @@ -3948,7 +3886,7 @@ impl<'a> LoweringContext<'a> { hir::PatKind::Binding( self.lower_binding_mode(binding_mode), - self.lower_node_id(canonical_id).hir_id, + self.lower_node_id(canonical_id), ident, sub.as_ref().map(|x| self.lower_pat(x)), ) @@ -4000,12 +3938,10 @@ impl<'a> LoweringContext<'a> { let fs = fields .iter() .map(|f| { - let LoweredNodeId { node_id: _, hir_id } = self.next_id(); - Spanned { span: f.span, node: hir::FieldPat { - hir_id, + hir_id: self.next_id(), ident: f.node.ident, pat: self.lower_pat(&f.node.pat), is_shorthand: f.node.is_shorthand, @@ -4036,9 +3972,8 @@ impl<'a> LoweringContext<'a> { PatKind::Mac(_) => panic!("Shouldn't exist here"), }; - let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(p.id); P(hir::Pat { - hir_id, + hir_id: self.lower_node_id(p.id), node, span: p.span, }) @@ -4053,9 +3988,8 @@ impl<'a> LoweringContext<'a> { fn lower_anon_const(&mut self, c: &AnonConst) -> hir::AnonConst { self.with_new_scopes(|this| { - let LoweredNodeId { node_id: _, hir_id } = this.lower_node_id(c.id); hir::AnonConst { - hir_id, + hir_id: this.lower_node_id(c.id), body: this.lower_body(None, |this| this.lower_expr(&c.value)), } }) @@ -4130,11 +4064,10 @@ impl<'a> LoweringContext<'a> { // Wrap the `if let` expr in a block. let span = els.span; let els = P(self.lower_expr(els)); - let LoweredNodeId { node_id: _, hir_id } = self.next_id(); let blk = P(hir::Block { stmts: hir_vec![], expr: Some(els), - hir_id, + hir_id: self.next_id(), rules: hir::DefaultBlock, span, targeted_by_break: false, @@ -4176,13 +4109,12 @@ impl<'a> LoweringContext<'a> { let mut block = this.lower_block(body, true).into_inner(); let tail = block.expr.take().map_or_else( || { - let LoweredNodeId { node_id: _, hir_id } = this.next_id(); let span = this.sess.source_map().end_point(unstable_span); hir::Expr { span, node: hir::ExprKind::Tup(hir_vec![]), attrs: ThinVec::new(), - hir_id, + hir_id: this.next_id(), } }, |x: P| x.into_inner(), @@ -4363,10 +4295,8 @@ impl<'a> LoweringContext<'a> { let struct_path = self.std_path(e.span, &struct_path, None, is_unit); let struct_path = hir::QPath::Resolved(None, P(struct_path)); - let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(e.id); - return hir::Expr { - hir_id, + hir_id: self.lower_node_id(e.id), node: if is_unit { hir::ExprKind::Path(struct_path) } else { @@ -4667,9 +4597,8 @@ impl<'a> LoweringContext<'a> { ThinVec::new(), )) }; - let LoweredNodeId { node_id: _, hir_id } = self.next_id(); let match_stmt = hir::Stmt { - hir_id, + hir_id: self.next_id(), node: hir::StmtKind::Expr(match_expr), span: head_sp, }; @@ -4695,9 +4624,8 @@ impl<'a> LoweringContext<'a> { let body_block = self.with_loop_scope(e.id, |this| this.lower_block(body, false)); let body_expr = P(self.expr_block(body_block, ThinVec::new())); - let LoweredNodeId { node_id: _, hir_id } = self.next_id(); let body_stmt = hir::Stmt { - hir_id, + hir_id: self.next_id(), node: hir::StmtKind::Expr(body_expr), span: body.span, }; @@ -4714,9 +4642,8 @@ impl<'a> LoweringContext<'a> { self.lower_label(opt_label), hir::LoopSource::ForLoop, ); - let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(e.id); let loop_expr = P(hir::Expr { - hir_id, + hir_id: self.lower_node_id(e.id), node: loop_expr, span: e.span, attrs: ThinVec::new(), @@ -4834,7 +4761,7 @@ impl<'a> LoweringContext<'a> { let thin_attrs = ThinVec::from(attrs); let catch_scope = self.catch_scopes.last().map(|x| *x); let ret_expr = if let Some(catch_node) = catch_scope { - let target_id = Ok(self.lower_node_id(catch_node).hir_id); + let target_id = Ok(self.lower_node_id(catch_node)); P(self.expr( try_span, hir::ExprKind::Break( @@ -4864,10 +4791,8 @@ impl<'a> LoweringContext<'a> { ExprKind::Mac(_) => panic!("Shouldn't exist here"), }; - let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(e.id); - hir::Expr { - hir_id, + hir_id: self.lower_node_id(e.id), node: kind, span: e.span, attrs: e.attrs.clone(), @@ -4881,21 +4806,18 @@ impl<'a> LoweringContext<'a> { let mut ids: SmallVec<[hir::Stmt; 1]> = item_ids .into_iter() .map(|item_id| { - let item_id = hir::ItemId { id: self.lower_node_id(item_id).hir_id }; - let LoweredNodeId { node_id: _, hir_id } = self.next_id(); + let item_id = hir::ItemId { id: self.lower_node_id(item_id) }; hir::Stmt { - hir_id, + hir_id: self.next_id(), node: hir::StmtKind::Item(item_id), span: s.span, } }) .collect(); ids.push({ - let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(s.id); - hir::Stmt { - hir_id, + hir_id: self.lower_node_id(s.id), node: hir::StmtKind::Local(P(l)), span: s.span, } @@ -4908,7 +4830,7 @@ impl<'a> LoweringContext<'a> { return self.lower_item_id(it) .into_iter() .map(|item_id| { - let LoweredNodeId { node_id: _, hir_id } = id.take() + let hir_id = id.take() .map(|id| self.lower_node_id(id)) .unwrap_or_else(|| self.next_id()); @@ -4921,19 +4843,15 @@ impl<'a> LoweringContext<'a> { .collect(); } StmtKind::Expr(ref e) => { - let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(s.id); - hir::Stmt { - hir_id, + hir_id: self.lower_node_id(s.id), node: hir::StmtKind::Expr(P(self.lower_expr(e))), span: s.span, } }, StmtKind::Semi(ref e) => { - let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(s.id); - hir::Stmt { - hir_id, + hir_id: self.lower_node_id(s.id), node: hir::StmtKind::Semi(P(self.lower_expr(e))), span: s.span, } @@ -4978,7 +4896,7 @@ impl<'a> LoweringContext<'a> { ParamMode::Explicit, explicit_owner, )), - hir_id: lowered_id.hir_id, + hir_id: lowered_id, } }, VisibilityKind::Inherited => hir::VisibilityKind::Inherited, @@ -5047,10 +4965,8 @@ impl<'a> LoweringContext<'a> { } fn field(&mut self, ident: Ident, expr: P, span: Span) -> hir::Field { - let LoweredNodeId { node_id: _, hir_id } = self.next_id(); - hir::Field { - hir_id, + hir_id: self.next_id(), ident, span, expr, @@ -5144,9 +5060,8 @@ impl<'a> LoweringContext<'a> { } fn expr(&mut self, span: Span, node: hir::ExprKind, attrs: ThinVec) -> hir::Expr { - let LoweredNodeId { node_id: _, hir_id } = self.next_id(); hir::Expr { - hir_id, + hir_id: self.next_id(), node, span, attrs, @@ -5160,21 +5075,18 @@ impl<'a> LoweringContext<'a> { pat: P, source: hir::LocalSource, ) -> hir::Stmt { - let LoweredNodeId { node_id: _, hir_id } = self.next_id(); - let local = hir::Local { pat, ty: None, init: ex, - hir_id, + hir_id: self.next_id(), span: sp, attrs: ThinVec::new(), source, }; - let LoweredNodeId { node_id: _, hir_id } = self.next_id(); hir::Stmt { - hir_id, + hir_id: self.next_id(), node: hir::StmtKind::Local(P(local)), span: sp } @@ -5190,12 +5102,10 @@ impl<'a> LoweringContext<'a> { stmts: hir::HirVec, expr: Option>, ) -> hir::Block { - let LoweredNodeId { node_id: _, hir_id } = self.next_id(); - hir::Block { stmts, expr, - hir_id, + hir_id: self.next_id(), rules: hir::DefaultBlock, span, targeted_by_break: false, @@ -5244,7 +5154,7 @@ impl<'a> LoweringContext<'a> { ident: Ident, bm: hir::BindingAnnotation, ) -> (P, hir::HirId) { - let LoweredNodeId { node_id: _, hir_id } = self.next_id(); + let hir_id = self.next_id(); ( P(hir::Pat { @@ -5261,9 +5171,8 @@ impl<'a> LoweringContext<'a> { } fn pat(&mut self, span: Span, pat: hir::PatKind) -> P { - let LoweredNodeId { node_id: _, hir_id } = self.next_id(); P(hir::Pat { - hir_id, + hir_id: self.next_id(), node: pat, span, }) @@ -5286,14 +5195,13 @@ impl<'a> LoweringContext<'a> { for seg in path.segments.iter_mut() { if seg.hir_id.is_some() { - seg.hir_id = Some(self.next_id().hir_id); + seg.hir_id = Some(self.next_id()); } } path } - fn ty_path(&mut self, id: LoweredNodeId, span: Span, qpath: hir::QPath) -> hir::Ty { - let mut id = id; + fn ty_path(&mut self, mut hir_id: hir::HirId, span: Span, qpath: hir::QPath) -> hir::Ty { let node = match qpath { hir::QPath::Resolved(None, path) => { // Turn trait object paths into `TyKind::TraitObject` instead. @@ -5303,14 +5211,14 @@ impl<'a> LoweringContext<'a> { bound_generic_params: hir::HirVec::new(), trait_ref: hir::TraitRef { path: path.and_then(|path| path), - hir_ref_id: id.hir_id, + hir_ref_id: hir_id, }, span, }; // The original ID is taken by the `PolyTraitRef`, // so the `Ty` itself needs a different one. - id = self.next_id(); + hir_id = self.next_id(); hir::TyKind::TraitObject(hir_vec![principal], self.elided_dyn_bound(span)) } _ => hir::TyKind::Path(hir::QPath::Resolved(None, path)), @@ -5319,7 +5227,7 @@ impl<'a> LoweringContext<'a> { _ => hir::TyKind::Path(qpath), }; hir::Ty { - hir_id: id.hir_id, + hir_id, node, span, } @@ -5335,9 +5243,8 @@ impl<'a> LoweringContext<'a> { // `'f`. AnonymousLifetimeMode::CreateParameter => { let fresh_name = self.collect_fresh_in_band_lifetime(span); - let LoweredNodeId { node_id: _, hir_id } = self.next_id(); hir::Lifetime { - hir_id, + hir_id: self.next_id(), span, name: hir::LifetimeName::Param(fresh_name), } @@ -5360,7 +5267,7 @@ impl<'a> LoweringContext<'a> { Some(id) => (id, "`'_` cannot be used here", "`'_` is a reserved lifetime name"), None => ( - self.next_id().node_id, + self.sess.next_node_id(), "`&` without an explicit lifetime name cannot be used here", "explicit lifetime name needed here", ), @@ -5451,15 +5358,13 @@ impl<'a> LoweringContext<'a> { replacement: LtReplacement, span: Span, ) -> hir::Lifetime { - let LoweredNodeId { node_id: _, hir_id } = self.next_id(); + let hir_id = self.next_id(); self.replace_elided_lifetime(hir_id, span, replacement) } fn new_implicit_lifetime(&mut self, span: Span) -> hir::Lifetime { - let LoweredNodeId { node_id: _, hir_id } = self.next_id(); - hir::Lifetime { - hir_id, + hir_id: self.next_id(), span, name: hir::LifetimeName::Implicit, } diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index 58e0df1cd7ce9..4dddf811c0523 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -627,6 +627,8 @@ impl<'a> Resolver<'a> { let dummy_binding = self.import(dummy_binding, directive); self.per_ns(|this, ns| { let _ = this.try_define(directive.parent_scope.module, target, ns, dummy_binding); + // Consider erroneous imports used to avoid duplicate diagnostics. + this.record_use(target, ns, dummy_binding, false); }); } } diff --git a/src/librustc_typeck/error_codes.rs b/src/librustc_typeck/error_codes.rs index fdca3230904a8..6dd3c0113cdcd 100644 --- a/src/librustc_typeck/error_codes.rs +++ b/src/librustc_typeck/error_codes.rs @@ -1942,9 +1942,11 @@ E0207: r##" Any type parameter or lifetime parameter of an `impl` must meet at least one of the following criteria: - - it appears in the self type of the impl - - for a trait impl, it appears in the trait reference - - it is bound as an associated type + - it appears in the _implementing type_ of the impl, e.g. `impl Foo` + - for a trait impl, it appears in the _implemented trait_, e.g. + `impl SomeTrait for Foo` + - it is bound as an associated type, e.g. `impl SomeTrait for T + where T: AnotherTrait` ### Error example 1 @@ -1963,9 +1965,9 @@ impl Foo { } ``` -The problem is that the parameter `T` does not appear in the self type (`Foo`) -of the impl. In this case, we can fix the error by moving the type parameter -from the `impl` to the method `get`: +The problem is that the parameter `T` does not appear in the implementing type +(`Foo`) of the impl. In this case, we can fix the error by moving the type +parameter from the `impl` to the method `get`: ``` diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs index 04672da2b66a7..eaf5d619f5454 100644 --- a/src/libstd/fs.rs +++ b/src/libstd/fs.rs @@ -11,7 +11,7 @@ use crate::fmt; use crate::ffi::OsString; -use crate::io::{self, SeekFrom, Seek, Read, Initializer, Write, IoVec, IoVecMut}; +use crate::io::{self, SeekFrom, Seek, Read, Initializer, Write, IoSlice, IoSliceMut}; use crate::path::{Path, PathBuf}; use crate::sys::fs as fs_imp; use crate::sys_common::{AsInnerMut, FromInner, AsInner, IntoInner}; @@ -617,7 +617,7 @@ impl Read for File { self.inner.read(buf) } - fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { self.inner.read_vectored(bufs) } @@ -632,7 +632,7 @@ impl Write for File { self.inner.write(buf) } - fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result { self.inner.write_vectored(bufs) } @@ -650,7 +650,7 @@ impl Read for &File { self.inner.read(buf) } - fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { self.inner.read_vectored(bufs) } @@ -665,7 +665,7 @@ impl Write for &File { self.inner.write(buf) } - fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result { self.inner.write_vectored(bufs) } diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index e6c8e26fa92d8..5be2687d8f5ff 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -5,7 +5,8 @@ use crate::io::prelude::*; use crate::cmp; use crate::error; use crate::fmt; -use crate::io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom, IoVec, IoVecMut}; +use crate::io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom, IoSlice, + IoSliceMut}; use crate::memchr; /// The `BufReader` struct adds buffering to any reader. @@ -249,7 +250,7 @@ impl Read for BufReader { Ok(nread) } - fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { let total_len = bufs.iter().map(|b| b.len()).sum::(); if self.pos == self.cap && total_len >= self.buf.len() { self.discard_buffer(); @@ -609,7 +610,7 @@ impl Write for BufWriter { } } - fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result { let total_len = bufs.iter().map(|b| b.len()).sum::(); if self.buf.len() + total_len > self.buf.capacity() { self.flush_buf()?; diff --git a/src/libstd/io/cursor.rs b/src/libstd/io/cursor.rs index 247d45c3ec91f..64f8659b8f8fe 100644 --- a/src/libstd/io/cursor.rs +++ b/src/libstd/io/cursor.rs @@ -1,7 +1,7 @@ use crate::io::prelude::*; use crate::cmp; -use crate::io::{self, Initializer, SeekFrom, Error, ErrorKind, IoVec, IoVecMut}; +use crate::io::{self, Initializer, SeekFrom, Error, ErrorKind, IoSlice, IoSliceMut}; use core::convert::TryInto; @@ -230,7 +230,7 @@ impl Read for Cursor where T: AsRef<[u8]> { Ok(n) } - fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { let mut nread = 0; for buf in bufs { let n = self.read(buf)?; @@ -275,7 +275,7 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result], + bufs: &[IoSlice<'_>], ) -> io::Result { let mut nwritten = 0; @@ -319,7 +319,7 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result, - bufs: &[IoVec<'_>], + bufs: &[IoSlice<'_>], ) -> io::Result { let mut nwritten = 0; @@ -337,7 +337,7 @@ impl Write for Cursor<&mut [u8]> { } #[inline] - fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result { slice_write_vectored(&mut self.pos, self.inner, bufs) } @@ -350,7 +350,7 @@ impl Write for Cursor<&mut Vec> { vec_write(&mut self.pos, self.inner, buf) } - fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result { vec_write_vectored(&mut self.pos, self.inner, bufs) } @@ -363,7 +363,7 @@ impl Write for Cursor> { vec_write(&mut self.pos, &mut self.inner, buf) } - fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result { vec_write_vectored(&mut self.pos, &mut self.inner, bufs) } @@ -378,7 +378,7 @@ impl Write for Cursor> { } #[inline] - fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result { slice_write_vectored(&mut self.pos, &mut self.inner, bufs) } @@ -388,7 +388,7 @@ impl Write for Cursor> { #[cfg(test)] mod tests { use crate::io::prelude::*; - use crate::io::{Cursor, SeekFrom, IoVec, IoVecMut}; + use crate::io::{Cursor, SeekFrom, IoSlice, IoSliceMut}; #[test] fn test_vec_writer() { @@ -397,7 +397,7 @@ mod tests { assert_eq!(writer.write(&[1, 2, 3]).unwrap(), 3); assert_eq!(writer.write(&[4, 5, 6, 7]).unwrap(), 4); assert_eq!(writer.write_vectored( - &[IoVec::new(&[]), IoVec::new(&[8, 9]), IoVec::new(&[10])], + &[IoSlice::new(&[]), IoSlice::new(&[8, 9]), IoSlice::new(&[10])], ).unwrap(), 3); let b: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; assert_eq!(writer, b); @@ -410,7 +410,7 @@ mod tests { assert_eq!(writer.write(&[1, 2, 3]).unwrap(), 3); assert_eq!(writer.write(&[4, 5, 6, 7]).unwrap(), 4); assert_eq!(writer.write_vectored( - &[IoVec::new(&[]), IoVec::new(&[8, 9]), IoVec::new(&[10])], + &[IoSlice::new(&[]), IoSlice::new(&[8, 9]), IoSlice::new(&[10])], ).unwrap(), 3); let b: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; assert_eq!(&writer.get_ref()[..], b); @@ -424,7 +424,7 @@ mod tests { assert_eq!(writer.write(&[1, 2, 3]).unwrap(), 3); assert_eq!(writer.write(&[4, 5, 6, 7]).unwrap(), 4); assert_eq!(writer.write_vectored( - &[IoVec::new(&[]), IoVec::new(&[8, 9]), IoVec::new(&[10])], + &[IoSlice::new(&[]), IoSlice::new(&[8, 9]), IoSlice::new(&[10])], ).unwrap(), 3); let b: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; assert_eq!(&writer.get_ref()[..], b); @@ -452,18 +452,21 @@ mod tests { fn test_box_slice_writer_vectored() { let mut writer = Cursor::new(vec![0u8; 9].into_boxed_slice()); assert_eq!(writer.position(), 0); - assert_eq!(writer.write_vectored(&[IoVec::new(&[0])]).unwrap(), 1); + assert_eq!(writer.write_vectored(&[IoSlice::new(&[0])]).unwrap(), 1); assert_eq!(writer.position(), 1); assert_eq!( - writer.write_vectored(&[IoVec::new(&[1, 2, 3]), IoVec::new(&[4, 5, 6, 7])]).unwrap(), + writer.write_vectored(&[ + IoSlice::new(&[1, 2, 3]), + IoSlice::new(&[4, 5, 6, 7]), + ]).unwrap(), 7, ); assert_eq!(writer.position(), 8); assert_eq!(writer.write_vectored(&[]).unwrap(), 0); assert_eq!(writer.position(), 8); - assert_eq!(writer.write_vectored(&[IoVec::new(&[8, 9])]).unwrap(), 1); - assert_eq!(writer.write_vectored(&[IoVec::new(&[10])]).unwrap(), 0); + assert_eq!(writer.write_vectored(&[IoSlice::new(&[8, 9])]).unwrap(), 1); + assert_eq!(writer.write_vectored(&[IoSlice::new(&[10])]).unwrap(), 0); let b: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8]; assert_eq!(&**writer.get_ref(), b); } @@ -495,11 +498,11 @@ mod tests { { let mut writer = Cursor::new(&mut buf[..]); assert_eq!(writer.position(), 0); - assert_eq!(writer.write_vectored(&[IoVec::new(&[0])]).unwrap(), 1); + assert_eq!(writer.write_vectored(&[IoSlice::new(&[0])]).unwrap(), 1); assert_eq!(writer.position(), 1); assert_eq!( writer.write_vectored( - &[IoVec::new(&[1, 2, 3]), IoVec::new(&[4, 5, 6, 7])], + &[IoSlice::new(&[1, 2, 3]), IoSlice::new(&[4, 5, 6, 7])], ).unwrap(), 7, ); @@ -507,8 +510,8 @@ mod tests { assert_eq!(writer.write_vectored(&[]).unwrap(), 0); assert_eq!(writer.position(), 8); - assert_eq!(writer.write_vectored(&[IoVec::new(&[8, 9])]).unwrap(), 1); - assert_eq!(writer.write_vectored(&[IoVec::new(&[10])]).unwrap(), 0); + assert_eq!(writer.write_vectored(&[IoSlice::new(&[8, 9])]).unwrap(), 1); + assert_eq!(writer.write_vectored(&[IoSlice::new(&[10])]).unwrap(), 0); } let b: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8]; assert_eq!(buf, b); @@ -578,11 +581,14 @@ mod tests { fn test_mem_reader_vectored() { let mut reader = Cursor::new(vec![0, 1, 2, 3, 4, 5, 6, 7]); let mut buf = []; - assert_eq!(reader.read_vectored(&mut [IoVecMut::new(&mut buf)]).unwrap(), 0); + assert_eq!(reader.read_vectored(&mut [IoSliceMut::new(&mut buf)]).unwrap(), 0); assert_eq!(reader.position(), 0); let mut buf = [0]; assert_eq!( - reader.read_vectored(&mut [IoVecMut::new(&mut []), IoVecMut::new(&mut buf)]).unwrap(), + reader.read_vectored(&mut [ + IoSliceMut::new(&mut []), + IoSliceMut::new(&mut buf), + ]).unwrap(), 1, ); assert_eq!(reader.position(), 1); @@ -591,9 +597,10 @@ mod tests { let mut buf1 = [0; 4]; let mut buf2 = [0; 4]; assert_eq!( - reader.read_vectored( - &mut [IoVecMut::new(&mut buf1), IoVecMut::new(&mut buf2)], - ).unwrap(), + reader.read_vectored(&mut [ + IoSliceMut::new(&mut buf1), + IoSliceMut::new(&mut buf2), + ]).unwrap(), 7, ); let b1: &[_] = &[1, 2, 3, 4]; @@ -629,11 +636,14 @@ mod tests { fn test_boxed_slice_reader_vectored() { let mut reader = Cursor::new(vec![0, 1, 2, 3, 4, 5, 6, 7].into_boxed_slice()); let mut buf = []; - assert_eq!(reader.read_vectored(&mut [IoVecMut::new(&mut buf)]).unwrap(), 0); + assert_eq!(reader.read_vectored(&mut [IoSliceMut::new(&mut buf)]).unwrap(), 0); assert_eq!(reader.position(), 0); let mut buf = [0]; assert_eq!( - reader.read_vectored(&mut [IoVecMut::new(&mut []), IoVecMut::new(&mut buf)]).unwrap(), + reader.read_vectored(&mut [ + IoSliceMut::new(&mut []), + IoSliceMut::new(&mut buf), + ]).unwrap(), 1, ); assert_eq!(reader.position(), 1); @@ -643,7 +653,7 @@ mod tests { let mut buf2 = [0; 4]; assert_eq!( reader.read_vectored( - &mut [IoVecMut::new(&mut buf1), IoVecMut::new(&mut buf2)], + &mut [IoSliceMut::new(&mut buf1), IoSliceMut::new(&mut buf2)], ).unwrap(), 7, ); @@ -689,10 +699,13 @@ mod tests { let in_buf = vec![0, 1, 2, 3, 4, 5, 6, 7]; let reader = &mut &in_buf[..]; let mut buf = []; - assert_eq!(reader.read_vectored(&mut [IoVecMut::new(&mut buf)]).unwrap(), 0); + assert_eq!(reader.read_vectored(&mut [IoSliceMut::new(&mut buf)]).unwrap(), 0); let mut buf = [0]; assert_eq!( - reader.read_vectored(&mut [IoVecMut::new(&mut []), IoVecMut::new(&mut buf)]).unwrap(), + reader.read_vectored(&mut [ + IoSliceMut::new(&mut []), + IoSliceMut::new(&mut buf), + ]).unwrap(), 1, ); assert_eq!(reader.len(), 7); @@ -702,7 +715,7 @@ mod tests { let mut buf2 = [0; 4]; assert_eq!( reader.read_vectored( - &mut [IoVecMut::new(&mut buf1), IoVecMut::new(&mut buf2)], + &mut [IoSliceMut::new(&mut buf1), IoSliceMut::new(&mut buf2)], ).unwrap(), 7, ); diff --git a/src/libstd/io/impls.rs b/src/libstd/io/impls.rs index 0eac96fc39a4b..c959f2d389b11 100644 --- a/src/libstd/io/impls.rs +++ b/src/libstd/io/impls.rs @@ -1,6 +1,6 @@ use crate::cmp; -use crate::io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind, IoVecMut, - IoVec}; +use crate::io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind, + IoSliceMut, IoSlice}; use crate::fmt; use crate::mem; @@ -15,7 +15,7 @@ impl Read for &mut R { } #[inline] - fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { (**self).read_vectored(bufs) } @@ -45,7 +45,7 @@ impl Write for &mut W { fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } #[inline] - fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result { (**self).write_vectored(bufs) } @@ -94,7 +94,7 @@ impl Read for Box { } #[inline] - fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { (**self).read_vectored(bufs) } @@ -124,7 +124,7 @@ impl Write for Box { fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } #[inline] - fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result { (**self).write_vectored(bufs) } @@ -207,7 +207,7 @@ impl Read for &[u8] { } #[inline] - fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { let mut nread = 0; for buf in bufs { nread += self.read(buf)?; @@ -280,7 +280,7 @@ impl Write for &mut [u8] { } #[inline] - fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result { let mut nwritten = 0; for buf in bufs { nwritten += self.write(buf)?; @@ -316,7 +316,7 @@ impl Write for Vec { } #[inline] - fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result { let len = bufs.iter().map(|b| b.len()).sum(); self.reserve(len); for buf in bufs { diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 1ce66b931df14..8fea6251e652a 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -390,7 +390,7 @@ fn read_to_end_with_reservation(r: &mut R, ret } -pub(crate) fn default_read_vectored(read: F, bufs: &mut [IoVecMut<'_>]) -> Result +pub(crate) fn default_read_vectored(read: F, bufs: &mut [IoSliceMut<'_>]) -> Result where F: FnOnce(&mut [u8]) -> Result { @@ -401,7 +401,7 @@ where read(buf) } -pub(crate) fn default_write_vectored(write: F, bufs: &[IoVec<'_>]) -> Result +pub(crate) fn default_write_vectored(write: F, bufs: &[IoSlice<'_>]) -> Result where F: FnOnce(&[u8]) -> Result { @@ -554,8 +554,8 @@ pub trait Read { /// /// The default implementation calls `read` with either the first nonempty /// buffer provided, or an empty one if none exists. - #[unstable(feature = "iovec", issue = "58452")] - fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> Result { + #[stable(feature = "iovec", since = "1.36.0")] + fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result { default_read_vectored(|b| self.read(b), bufs) } @@ -911,32 +911,32 @@ pub trait Read { /// It is semantically a wrapper around an `&mut [u8]`, but is guaranteed to be /// ABI compatible with the `iovec` type on Unix platforms and `WSABUF` on /// Windows. -#[unstable(feature = "iovec", issue = "58452")] +#[stable(feature = "iovec", since = "1.36.0")] #[repr(transparent)] -pub struct IoVecMut<'a>(sys::io::IoVecMut<'a>); +pub struct IoSliceMut<'a>(sys::io::IoSliceMut<'a>); -#[unstable(feature = "iovec", issue = "58452")] -impl<'a> fmt::Debug for IoVecMut<'a> { +#[stable(feature = "iovec", since = "1.36.0")] +impl<'a> fmt::Debug for IoSliceMut<'a> { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Debug::fmt(self.0.as_slice(), fmt) } } -impl<'a> IoVecMut<'a> { - /// Creates a new `IoVecMut` wrapping a byte slice. +impl<'a> IoSliceMut<'a> { + /// Creates a new `IoSliceMut` wrapping a byte slice. /// /// # Panics /// /// Panics on Windows if the slice is larger than 4GB. - #[unstable(feature = "iovec", issue = "58452")] + #[stable(feature = "iovec", since = "1.36.0")] #[inline] - pub fn new(buf: &'a mut [u8]) -> IoVecMut<'a> { - IoVecMut(sys::io::IoVecMut::new(buf)) + pub fn new(buf: &'a mut [u8]) -> IoSliceMut<'a> { + IoSliceMut(sys::io::IoSliceMut::new(buf)) } } -#[unstable(feature = "iovec", issue = "58452")] -impl<'a> Deref for IoVecMut<'a> { +#[stable(feature = "iovec", since = "1.36.0")] +impl<'a> Deref for IoSliceMut<'a> { type Target = [u8]; #[inline] @@ -945,8 +945,8 @@ impl<'a> Deref for IoVecMut<'a> { } } -#[unstable(feature = "iovec", issue = "58452")] -impl<'a> DerefMut for IoVecMut<'a> { +#[stable(feature = "iovec", since = "1.36.0")] +impl<'a> DerefMut for IoSliceMut<'a> { #[inline] fn deref_mut(&mut self) -> &mut [u8] { self.0.as_mut_slice() @@ -958,32 +958,32 @@ impl<'a> DerefMut for IoVecMut<'a> { /// It is semantically a wrapper around an `&[u8]`, but is guaranteed to be /// ABI compatible with the `iovec` type on Unix platforms and `WSABUF` on /// Windows. -#[unstable(feature = "iovec", issue = "58452")] +#[stable(feature = "iovec", since = "1.36.0")] #[repr(transparent)] -pub struct IoVec<'a>(sys::io::IoVec<'a>); +pub struct IoSlice<'a>(sys::io::IoSlice<'a>); -#[unstable(feature = "iovec", issue = "58452")] -impl<'a> fmt::Debug for IoVec<'a> { +#[stable(feature = "iovec", since = "1.36.0")] +impl<'a> fmt::Debug for IoSlice<'a> { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Debug::fmt(self.0.as_slice(), fmt) } } -impl<'a> IoVec<'a> { - /// Creates a new `IoVec` wrapping a byte slice. +impl<'a> IoSlice<'a> { + /// Creates a new `IoSlice` wrapping a byte slice. /// /// # Panics /// /// Panics on Windows if the slice is larger than 4GB. - #[unstable(feature = "iovec", issue = "58452")] + #[stable(feature = "iovec", since = "1.36.0")] #[inline] - pub fn new(buf: &'a [u8]) -> IoVec<'a> { - IoVec(sys::io::IoVec::new(buf)) + pub fn new(buf: &'a [u8]) -> IoSlice<'a> { + IoSlice(sys::io::IoSlice::new(buf)) } } -#[unstable(feature = "iovec", issue = "58452")] -impl<'a> Deref for IoVec<'a> { +#[stable(feature = "iovec", since = "1.36.0")] +impl<'a> Deref for IoSlice<'a> { type Target = [u8]; #[inline] @@ -1141,8 +1141,8 @@ pub trait Write { /// /// The default implementation calls `write` with either the first nonempty /// buffer provided, or an empty one if none exists. - #[unstable(feature = "iovec", issue = "58452")] - fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> Result { + #[stable(feature = "iovec", since = "1.36.0")] + fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result { default_write_vectored(|b| self.write(b), bufs) } @@ -1926,7 +1926,7 @@ impl Read for Chain { self.second.read(buf) } - fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> Result { + fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result { if !self.done_first { match self.first.read_vectored(bufs)? { 0 if bufs.iter().any(|b| !b.is_empty()) => self.done_first = true, diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index 1848ddeab6556..990c0eb8955e4 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -5,7 +5,7 @@ use crate::io::prelude::*; use crate::cell::RefCell; use crate::fmt; use crate::io::lazy::Lazy; -use crate::io::{self, Initializer, BufReader, LineWriter, IoVec, IoVecMut}; +use crate::io::{self, Initializer, BufReader, LineWriter, IoSlice, IoSliceMut}; use crate::sync::{Arc, Mutex, MutexGuard}; use crate::sys::stdio; use crate::sys_common::remutex::{ReentrantMutex, ReentrantMutexGuard}; @@ -75,7 +75,7 @@ fn stderr_raw() -> io::Result { stdio::Stderr::new().map(StderrRaw) } impl Read for StdinRaw { fn read(&mut self, buf: &mut [u8]) -> io::Result { self.0.read(buf) } - fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { self.0.read_vectored(bufs) } @@ -87,7 +87,7 @@ impl Read for StdinRaw { impl Write for StdoutRaw { fn write(&mut self, buf: &[u8]) -> io::Result { self.0.write(buf) } - fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result { self.0.write_vectored(bufs) } @@ -96,7 +96,7 @@ impl Write for StdoutRaw { impl Write for StderrRaw { fn write(&mut self, buf: &[u8]) -> io::Result { self.0.write(buf) } - fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result { self.0.write_vectored(bufs) } @@ -116,7 +116,7 @@ impl io::Write for Maybe { } } - fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result { let total = bufs.iter().map(|b| b.len()).sum(); match self { Maybe::Real(w) => handle_ebadf(w.write_vectored(bufs), total), @@ -140,7 +140,7 @@ impl io::Read for Maybe { } } - fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { match self { Maybe::Real(r) => handle_ebadf(r.read_vectored(bufs), 0), Maybe::Fake => Ok(0) @@ -334,7 +334,7 @@ impl Read for Stdin { fn read(&mut self, buf: &mut [u8]) -> io::Result { self.lock().read(buf) } - fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { self.lock().read_vectored(bufs) } #[inline] @@ -358,7 +358,7 @@ impl Read for StdinLock<'_> { self.inner.read(buf) } - fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { self.inner.read_vectored(bufs) } @@ -520,7 +520,7 @@ impl Write for Stdout { fn write(&mut self, buf: &[u8]) -> io::Result { self.lock().write(buf) } - fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result { self.lock().write_vectored(bufs) } fn flush(&mut self) -> io::Result<()> { @@ -538,7 +538,7 @@ impl Write for StdoutLock<'_> { fn write(&mut self, buf: &[u8]) -> io::Result { self.inner.borrow_mut().write(buf) } - fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result { self.inner.borrow_mut().write_vectored(bufs) } fn flush(&mut self) -> io::Result<()> { @@ -679,7 +679,7 @@ impl Write for Stderr { fn write(&mut self, buf: &[u8]) -> io::Result { self.lock().write(buf) } - fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result { self.lock().write_vectored(bufs) } fn flush(&mut self) -> io::Result<()> { @@ -697,7 +697,7 @@ impl Write for StderrLock<'_> { fn write(&mut self, buf: &[u8]) -> io::Result { self.inner.borrow_mut().write(buf) } - fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result { self.inner.borrow_mut().write_vectored(bufs) } fn flush(&mut self) -> io::Result<()> { diff --git a/src/libstd/io/util.rs b/src/libstd/io/util.rs index d2638be4e2db5..7c4eae6512df4 100644 --- a/src/libstd/io/util.rs +++ b/src/libstd/io/util.rs @@ -1,7 +1,7 @@ #![allow(missing_copy_implementations)] use crate::fmt; -use crate::io::{self, Read, Initializer, Write, ErrorKind, BufRead, IoVec, IoVecMut}; +use crate::io::{self, Read, Initializer, Write, ErrorKind, BufRead, IoSlice, IoSliceMut}; use crate::mem; /// Copies the entire contents of a reader into a writer. @@ -153,7 +153,7 @@ impl Read for Repeat { } #[inline] - fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { let mut nwritten = 0; for buf in bufs { nwritten += self.read(buf)?; @@ -206,7 +206,7 @@ impl Write for Sink { fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } #[inline] - fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result { let total_len = bufs.iter().map(|b| b.len()).sum(); Ok(total_len) } diff --git a/src/libstd/net/tcp.rs b/src/libstd/net/tcp.rs index cb8928866cbce..0460ac9d75354 100644 --- a/src/libstd/net/tcp.rs +++ b/src/libstd/net/tcp.rs @@ -1,7 +1,7 @@ use crate::io::prelude::*; use crate::fmt; -use crate::io::{self, Initializer, IoVec, IoVecMut}; +use crate::io::{self, Initializer, IoSlice, IoSliceMut}; use crate::net::{ToSocketAddrs, SocketAddr, Shutdown}; use crate::sys_common::net as net_imp; use crate::sys_common::{AsInner, FromInner, IntoInner}; @@ -569,7 +569,7 @@ impl TcpStream { impl Read for TcpStream { fn read(&mut self, buf: &mut [u8]) -> io::Result { self.0.read(buf) } - fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { self.0.read_vectored(bufs) } @@ -582,7 +582,7 @@ impl Read for TcpStream { impl Write for TcpStream { fn write(&mut self, buf: &[u8]) -> io::Result { self.0.write(buf) } - fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result { self.0.write_vectored(bufs) } @@ -592,7 +592,7 @@ impl Write for TcpStream { impl Read for &TcpStream { fn read(&mut self, buf: &mut [u8]) -> io::Result { self.0.read(buf) } - fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { self.0.read_vectored(bufs) } @@ -605,7 +605,7 @@ impl Read for &TcpStream { impl Write for &TcpStream { fn write(&mut self, buf: &[u8]) -> io::Result { self.0.write(buf) } - fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result { self.0.write_vectored(bufs) } @@ -930,7 +930,7 @@ impl fmt::Debug for TcpListener { #[cfg(all(test, not(any(target_os = "cloudabi", target_os = "emscripten"))))] mod tests { use crate::fmt; - use crate::io::{ErrorKind, IoVec, IoVecMut}; + use crate::io::{ErrorKind, IoSlice, IoSliceMut}; use crate::io::prelude::*; use crate::net::*; use crate::net::test::{next_test_ip4, next_test_ip6}; @@ -1216,7 +1216,7 @@ mod tests { let mut b = [0]; let mut c = [0; 3]; let len = t!(s2.read_vectored( - &mut [IoVecMut::new(&mut a), IoVecMut::new(&mut b), IoVecMut::new(&mut c)], + &mut [IoSliceMut::new(&mut a), IoSliceMut::new(&mut b), IoSliceMut::new(&mut c)], )); assert!(len > 0); assert_eq!(b, [10]); @@ -1235,7 +1235,7 @@ mod tests { let a = []; let b = [10]; let c = [11, 12]; - t!(s1.write_vectored(&[IoVec::new(&a), IoVec::new(&b), IoVec::new(&c)])); + t!(s1.write_vectored(&[IoSlice::new(&a), IoSlice::new(&b), IoSlice::new(&c)])); let mut buf = [0; 4]; let len = t!(s2.read(&mut buf)); diff --git a/src/libstd/process.rs b/src/libstd/process.rs index ef5626700e87a..c1addb46a0a23 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -111,7 +111,7 @@ use crate::io::prelude::*; use crate::ffi::OsStr; use crate::fmt; use crate::fs; -use crate::io::{self, Initializer, IoVec, IoVecMut}; +use crate::io::{self, Initializer, IoSlice, IoSliceMut}; use crate::path::Path; use crate::str; use crate::sys::pipe::{read2, AnonPipe}; @@ -225,7 +225,7 @@ impl Write for ChildStdin { self.inner.write(buf) } - fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result { self.inner.write_vectored(bufs) } @@ -276,7 +276,7 @@ impl Read for ChildStdout { self.inner.read(buf) } - fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { self.inner.read_vectored(bufs) } @@ -328,7 +328,7 @@ impl Read for ChildStderr { self.inner.read(buf) } - fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { self.inner.read_vectored(bufs) } diff --git a/src/libstd/sys/cloudabi/io.rs b/src/libstd/sys/cloudabi/io.rs index 8b02d3fd19d30..4b423a5cbc11a 100644 --- a/src/libstd/sys/cloudabi/io.rs +++ b/src/libstd/sys/cloudabi/io.rs @@ -1,9 +1,9 @@ -pub struct IoVec<'a>(&'a [u8]); +pub struct IoSlice<'a>(&'a [u8]); -impl<'a> IoVec<'a> { +impl<'a> IoSlice<'a> { #[inline] - pub fn new(buf: &'a [u8]) -> IoVec<'a> { - IoVec(buf) + pub fn new(buf: &'a [u8]) -> IoSlice<'a> { + IoSlice(buf) } #[inline] @@ -12,12 +12,12 @@ impl<'a> IoVec<'a> { } } -pub struct IoVecMut<'a>(&'a mut [u8]); +pub struct IoSliceMut<'a>(&'a mut [u8]); -impl<'a> IoVecMut<'a> { +impl<'a> IoSliceMut<'a> { #[inline] - pub fn new(buf: &'a mut [u8]) -> IoVecMut<'a> { - IoVecMut(buf) + pub fn new(buf: &'a mut [u8]) -> IoSliceMut<'a> { + IoSliceMut(buf) } #[inline] diff --git a/src/libstd/sys/cloudabi/shims/fs.rs b/src/libstd/sys/cloudabi/shims/fs.rs index abd7f0fd3ee57..05f91541011e6 100644 --- a/src/libstd/sys/cloudabi/shims/fs.rs +++ b/src/libstd/sys/cloudabi/shims/fs.rs @@ -1,7 +1,7 @@ use crate::ffi::OsString; use crate::fmt; use crate::hash::{Hash, Hasher}; -use crate::io::{self, SeekFrom, IoVec, IoVecMut}; +use crate::io::{self, SeekFrom, IoSlice, IoSliceMut}; use crate::path::{Path, PathBuf}; use crate::sys::time::SystemTime; use crate::sys::{unsupported, Void}; @@ -198,7 +198,7 @@ impl File { match self.0 {} } - pub fn read_vectored(&self, _bufs: &mut [IoVecMut<'_>]) -> io::Result { + pub fn read_vectored(&self, _bufs: &mut [IoSliceMut<'_>]) -> io::Result { match self.0 {} } @@ -206,7 +206,7 @@ impl File { match self.0 {} } - pub fn write_vectored(&self, _bufs: &[IoVec<'_>]) -> io::Result { + pub fn write_vectored(&self, _bufs: &[IoSlice<'_>]) -> io::Result { match self.0 {} } diff --git a/src/libstd/sys/cloudabi/shims/net.rs b/src/libstd/sys/cloudabi/shims/net.rs index 7cf23748e1bf0..8d609cdfad5dc 100644 --- a/src/libstd/sys/cloudabi/shims/net.rs +++ b/src/libstd/sys/cloudabi/shims/net.rs @@ -1,5 +1,5 @@ use crate::fmt; -use crate::io::{self, IoVec, IoVecMut}; +use crate::io::{self, IoSlice, IoSliceMut}; use crate::net::{Ipv4Addr, Ipv6Addr, Shutdown, SocketAddr}; use crate::time::Duration; use crate::sys::{unsupported, Void}; @@ -43,7 +43,7 @@ impl TcpStream { match self.0 {} } - pub fn read_vectored(&self, _: &mut [IoVecMut<'_>]) -> io::Result { + pub fn read_vectored(&self, _: &mut [IoSliceMut<'_>]) -> io::Result { match self.0 {} } @@ -51,7 +51,7 @@ impl TcpStream { match self.0 {} } - pub fn write_vectored(&self, _: &[IoVec<'_>]) -> io::Result { + pub fn write_vectored(&self, _: &[IoSlice<'_>]) -> io::Result { match self.0 {} } diff --git a/src/libstd/sys/cloudabi/shims/pipe.rs b/src/libstd/sys/cloudabi/shims/pipe.rs index 804d3e001ac15..fb14dc5910181 100644 --- a/src/libstd/sys/cloudabi/shims/pipe.rs +++ b/src/libstd/sys/cloudabi/shims/pipe.rs @@ -1,4 +1,4 @@ -use crate::io::{self, IoVec, IoVecMut}; +use crate::io::{self, IoSlice, IoSliceMut}; use crate::sys::Void; pub struct AnonPipe(Void); @@ -8,7 +8,7 @@ impl AnonPipe { match self.0 {} } - pub fn read_vectored(&self, _bufs: &mut [IoVecMut<'_>]) -> io::Result { + pub fn read_vectored(&self, _bufs: &mut [IoSliceMut<'_>]) -> io::Result { match self.0 {} } @@ -16,7 +16,7 @@ impl AnonPipe { match self.0 {} } - pub fn write_vectored(&self, _bufs: &[IoVec<'_>]) -> io::Result { + pub fn write_vectored(&self, _bufs: &[IoSlice<'_>]) -> io::Result { match self.0 {} } diff --git a/src/libstd/sys/redox/fs.rs b/src/libstd/sys/redox/fs.rs index c86c6000eaead..b80a1a349e338 100644 --- a/src/libstd/sys/redox/fs.rs +++ b/src/libstd/sys/redox/fs.rs @@ -2,7 +2,7 @@ use crate::os::unix::prelude::*; use crate::ffi::{OsString, OsStr}; use crate::fmt; -use crate::io::{self, Error, SeekFrom, IoVec, IoVecMut}; +use crate::io::{self, Error, SeekFrom, IoSlice, IoSliceMut}; use crate::path::{Path, PathBuf}; use crate::sync::Arc; use crate::sys::fd::FileDesc; @@ -278,7 +278,7 @@ impl File { self.0.read(buf) } - pub fn read_vectored(&self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { crate::io::default_read_vectored(|buf| self.read(buf), bufs) } @@ -286,7 +286,7 @@ impl File { self.0.write(buf) } - pub fn write_vectored(&self, bufs: &[IoVec<'_>]) -> io::Result { + pub fn write_vectored(&self, bufs: &[IoSlice<'_>]) -> io::Result { crate::io::default_write_vectored(|buf| self.write(buf), bufs) } diff --git a/src/libstd/sys/redox/io.rs b/src/libstd/sys/redox/io.rs index 8b02d3fd19d30..4b423a5cbc11a 100644 --- a/src/libstd/sys/redox/io.rs +++ b/src/libstd/sys/redox/io.rs @@ -1,9 +1,9 @@ -pub struct IoVec<'a>(&'a [u8]); +pub struct IoSlice<'a>(&'a [u8]); -impl<'a> IoVec<'a> { +impl<'a> IoSlice<'a> { #[inline] - pub fn new(buf: &'a [u8]) -> IoVec<'a> { - IoVec(buf) + pub fn new(buf: &'a [u8]) -> IoSlice<'a> { + IoSlice(buf) } #[inline] @@ -12,12 +12,12 @@ impl<'a> IoVec<'a> { } } -pub struct IoVecMut<'a>(&'a mut [u8]); +pub struct IoSliceMut<'a>(&'a mut [u8]); -impl<'a> IoVecMut<'a> { +impl<'a> IoSliceMut<'a> { #[inline] - pub fn new(buf: &'a mut [u8]) -> IoVecMut<'a> { - IoVecMut(buf) + pub fn new(buf: &'a mut [u8]) -> IoSliceMut<'a> { + IoSliceMut(buf) } #[inline] diff --git a/src/libstd/sys/redox/net/tcp.rs b/src/libstd/sys/redox/net/tcp.rs index 3f2f6166a791a..494f943c96b53 100644 --- a/src/libstd/sys/redox/net/tcp.rs +++ b/src/libstd/sys/redox/net/tcp.rs @@ -1,5 +1,5 @@ use crate::cmp; -use crate::io::{self, Error, ErrorKind, Result, IoVec, IoVecMut}; +use crate::io::{self, Error, ErrorKind, Result, IoSlice, IoSliceMut}; use crate::mem; use crate::net::{SocketAddr, Shutdown}; use crate::path::Path; @@ -34,7 +34,7 @@ impl TcpStream { self.0.read(buf) } - pub fn read_vectored(&self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { io::default_read_vectored(|b| self.read(b), bufs) } @@ -42,7 +42,7 @@ impl TcpStream { self.0.write(buf) } - pub fn write_vectored(&self, bufs: &[IoVec<'_>]) -> io::Result { + pub fn write_vectored(&self, bufs: &[IoSlice<'_>]) -> io::Result { io::default_write_vectored(|b| self.write(b), bufs) } diff --git a/src/libstd/sys/redox/pipe.rs b/src/libstd/sys/redox/pipe.rs index b926968f7b325..29cacb6d562f2 100644 --- a/src/libstd/sys/redox/pipe.rs +++ b/src/libstd/sys/redox/pipe.rs @@ -1,4 +1,4 @@ -use crate::io::{self, IoVec, IoVecMut}; +use crate::io::{self, IoSlice, IoSliceMut}; use crate::sys::{cvt, syscall}; use crate::sys::fd::FileDesc; @@ -24,7 +24,7 @@ impl AnonPipe { self.0.read(buf) } - pub fn read_vectored(&self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { crate::io::default_read_vectored(|buf| self.read(buf), bufs) } @@ -32,7 +32,7 @@ impl AnonPipe { self.0.write(buf) } - pub fn write_vectored(&self, bufs: &[IoVec<'_>]) -> io::Result { + pub fn write_vectored(&self, bufs: &[IoSlice<'_>]) -> io::Result { crate::io::default_write_vectored(|buf| self.write(buf), bufs) } diff --git a/src/libstd/sys/sgx/fs.rs b/src/libstd/sys/sgx/fs.rs index c3c898eb23e56..e9095b375fe5d 100644 --- a/src/libstd/sys/sgx/fs.rs +++ b/src/libstd/sys/sgx/fs.rs @@ -1,7 +1,7 @@ use crate::ffi::OsString; use crate::fmt; use crate::hash::{Hash, Hasher}; -use crate::io::{self, SeekFrom, IoVec, IoVecMut}; +use crate::io::{self, SeekFrom, IoSlice, IoSliceMut}; use crate::path::{Path, PathBuf}; use crate::sys::time::SystemTime; use crate::sys::{unsupported, Void}; @@ -200,7 +200,7 @@ impl File { match self.0 {} } - pub fn read_vectored(&self, _bufs: &mut [IoVecMut<'_>]) -> io::Result { + pub fn read_vectored(&self, _bufs: &mut [IoSliceMut<'_>]) -> io::Result { match self.0 {} } @@ -208,7 +208,7 @@ impl File { match self.0 {} } - pub fn write_vectored(&self, _bufs: &[IoVec<'_>]) -> io::Result { + pub fn write_vectored(&self, _bufs: &[IoSlice<'_>]) -> io::Result { match self.0 {} } diff --git a/src/libstd/sys/sgx/io.rs b/src/libstd/sys/sgx/io.rs index 8b02d3fd19d30..4b423a5cbc11a 100644 --- a/src/libstd/sys/sgx/io.rs +++ b/src/libstd/sys/sgx/io.rs @@ -1,9 +1,9 @@ -pub struct IoVec<'a>(&'a [u8]); +pub struct IoSlice<'a>(&'a [u8]); -impl<'a> IoVec<'a> { +impl<'a> IoSlice<'a> { #[inline] - pub fn new(buf: &'a [u8]) -> IoVec<'a> { - IoVec(buf) + pub fn new(buf: &'a [u8]) -> IoSlice<'a> { + IoSlice(buf) } #[inline] @@ -12,12 +12,12 @@ impl<'a> IoVec<'a> { } } -pub struct IoVecMut<'a>(&'a mut [u8]); +pub struct IoSliceMut<'a>(&'a mut [u8]); -impl<'a> IoVecMut<'a> { +impl<'a> IoSliceMut<'a> { #[inline] - pub fn new(buf: &'a mut [u8]) -> IoVecMut<'a> { - IoVecMut(buf) + pub fn new(buf: &'a mut [u8]) -> IoSliceMut<'a> { + IoSliceMut(buf) } #[inline] diff --git a/src/libstd/sys/sgx/net.rs b/src/libstd/sys/sgx/net.rs index 10cc644a55ec6..76b0b81186aeb 100644 --- a/src/libstd/sys/sgx/net.rs +++ b/src/libstd/sys/sgx/net.rs @@ -1,5 +1,5 @@ use crate::fmt; -use crate::io::{self, IoVec, IoVecMut}; +use crate::io::{self, IoSlice, IoSliceMut}; use crate::net::{SocketAddr, Shutdown, Ipv4Addr, Ipv6Addr, ToSocketAddrs}; use crate::time::Duration; use crate::sys::{unsupported, Void, sgx_ineffective, AsInner, FromInner, IntoInner, TryIntoInner}; @@ -136,7 +136,7 @@ impl TcpStream { self.inner.inner.read(buf) } - pub fn read_vectored(&self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { io::default_read_vectored(|b| self.read(b), bufs) } @@ -144,7 +144,7 @@ impl TcpStream { self.inner.inner.write(buf) } - pub fn write_vectored(&self, bufs: &[IoVec<'_>]) -> io::Result { + pub fn write_vectored(&self, bufs: &[IoSlice<'_>]) -> io::Result { io::default_write_vectored(|b| self.write(b), bufs) } diff --git a/src/libstd/sys/sgx/pipe.rs b/src/libstd/sys/sgx/pipe.rs index 804d3e001ac15..fb14dc5910181 100644 --- a/src/libstd/sys/sgx/pipe.rs +++ b/src/libstd/sys/sgx/pipe.rs @@ -1,4 +1,4 @@ -use crate::io::{self, IoVec, IoVecMut}; +use crate::io::{self, IoSlice, IoSliceMut}; use crate::sys::Void; pub struct AnonPipe(Void); @@ -8,7 +8,7 @@ impl AnonPipe { match self.0 {} } - pub fn read_vectored(&self, _bufs: &mut [IoVecMut<'_>]) -> io::Result { + pub fn read_vectored(&self, _bufs: &mut [IoSliceMut<'_>]) -> io::Result { match self.0 {} } @@ -16,7 +16,7 @@ impl AnonPipe { match self.0 {} } - pub fn write_vectored(&self, _bufs: &[IoVec<'_>]) -> io::Result { + pub fn write_vectored(&self, _bufs: &[IoSlice<'_>]) -> io::Result { match self.0 {} } diff --git a/src/libstd/sys/unix/ext/net.rs b/src/libstd/sys/unix/ext/net.rs index 406863a6cba24..45a850aa4a85c 100644 --- a/src/libstd/sys/unix/ext/net.rs +++ b/src/libstd/sys/unix/ext/net.rs @@ -18,7 +18,7 @@ mod libc { use crate::ascii; use crate::ffi::OsStr; use crate::fmt; -use crate::io::{self, Initializer, IoVec, IoVecMut}; +use crate::io::{self, Initializer, IoSlice, IoSliceMut}; use crate::mem; use crate::net::{self, Shutdown}; use crate::os::unix::ffi::OsStrExt; @@ -551,7 +551,7 @@ impl io::Read for UnixStream { io::Read::read(&mut &*self, buf) } - fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { io::Read::read_vectored(&mut &*self, bufs) } @@ -567,7 +567,7 @@ impl<'a> io::Read for &'a UnixStream { self.0.read(buf) } - fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { self.0.read_vectored(bufs) } @@ -583,7 +583,7 @@ impl io::Write for UnixStream { io::Write::write(&mut &*self, buf) } - fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result { io::Write::write_vectored(&mut &*self, bufs) } @@ -598,7 +598,7 @@ impl<'a> io::Write for &'a UnixStream { self.0.write(buf) } - fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result { self.0.write_vectored(bufs) } @@ -1531,14 +1531,14 @@ mod test { let (mut s1, mut s2) = or_panic!(UnixStream::pair()); let len = or_panic!(s1.write_vectored( - &[IoVec::new(b"hello"), IoVec::new(b" "), IoVec::new(b"world!")], + &[IoSlice::new(b"hello"), IoSlice::new(b" "), IoSlice::new(b"world!")], )); assert_eq!(len, 12); let mut buf1 = [0; 6]; let mut buf2 = [0; 7]; let len = or_panic!(s2.read_vectored( - &mut [IoVecMut::new(&mut buf1), IoVecMut::new(&mut buf2)], + &mut [IoSliceMut::new(&mut buf1), IoSliceMut::new(&mut buf2)], )); assert_eq!(len, 12); assert_eq!(&buf1, b"hello "); diff --git a/src/libstd/sys/unix/fd.rs b/src/libstd/sys/unix/fd.rs index c274ad26cb1fe..6d23963e141aa 100644 --- a/src/libstd/sys/unix/fd.rs +++ b/src/libstd/sys/unix/fd.rs @@ -1,7 +1,7 @@ #![unstable(reason = "not public", issue = "0", feature = "fd")] use crate::cmp; -use crate::io::{self, Read, Initializer, IoVec, IoVecMut}; +use crate::io::{self, Read, Initializer, IoSlice, IoSliceMut}; use crate::mem; use crate::sync::atomic::{AtomicBool, Ordering}; use crate::sys::cvt; @@ -53,7 +53,7 @@ impl FileDesc { Ok(ret as usize) } - pub fn read_vectored(&self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { let ret = cvt(unsafe { libc::readv(self.fd, bufs.as_ptr() as *const libc::iovec, @@ -115,7 +115,7 @@ impl FileDesc { Ok(ret as usize) } - pub fn write_vectored(&self, bufs: &[IoVec<'_>]) -> io::Result { + pub fn write_vectored(&self, bufs: &[IoSlice<'_>]) -> io::Result { let ret = cvt(unsafe { libc::writev(self.fd, bufs.as_ptr() as *const libc::iovec, diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs index 761f1d8c6731f..e653f6721f062 100644 --- a/src/libstd/sys/unix/fs.rs +++ b/src/libstd/sys/unix/fs.rs @@ -2,7 +2,7 @@ use crate::os::unix::prelude::*; use crate::ffi::{CString, CStr, OsString, OsStr}; use crate::fmt; -use crate::io::{self, Error, ErrorKind, SeekFrom, IoVec, IoVecMut}; +use crate::io::{self, Error, ErrorKind, SeekFrom, IoSlice, IoSliceMut}; use crate::mem; use crate::path::{Path, PathBuf}; use crate::ptr; @@ -567,7 +567,7 @@ impl File { self.0.read(buf) } - pub fn read_vectored(&self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { self.0.read_vectored(bufs) } @@ -579,7 +579,7 @@ impl File { self.0.write(buf) } - pub fn write_vectored(&self, bufs: &[IoVec<'_>]) -> io::Result { + pub fn write_vectored(&self, bufs: &[IoSlice<'_>]) -> io::Result { self.0.write_vectored(bufs) } diff --git a/src/libstd/sys/unix/io.rs b/src/libstd/sys/unix/io.rs index eb3fa470a6525..72954ff20ef95 100644 --- a/src/libstd/sys/unix/io.rs +++ b/src/libstd/sys/unix/io.rs @@ -4,15 +4,15 @@ use crate::slice; use libc::{iovec, c_void}; #[repr(transparent)] -pub struct IoVec<'a> { +pub struct IoSlice<'a> { vec: iovec, _p: PhantomData<&'a [u8]>, } -impl<'a> IoVec<'a> { +impl<'a> IoSlice<'a> { #[inline] - pub fn new(buf: &'a [u8]) -> IoVec<'a> { - IoVec { + pub fn new(buf: &'a [u8]) -> IoSlice<'a> { + IoSlice { vec: iovec { iov_base: buf.as_ptr() as *mut u8 as *mut c_void, iov_len: buf.len() @@ -29,15 +29,15 @@ impl<'a> IoVec<'a> { } } -pub struct IoVecMut<'a> { +pub struct IoSliceMut<'a> { vec: iovec, _p: PhantomData<&'a mut [u8]>, } -impl<'a> IoVecMut<'a> { +impl<'a> IoSliceMut<'a> { #[inline] - pub fn new(buf: &'a mut [u8]) -> IoVecMut<'a> { - IoVecMut { + pub fn new(buf: &'a mut [u8]) -> IoSliceMut<'a> { + IoSliceMut { vec: iovec { iov_base: buf.as_mut_ptr() as *mut c_void, iov_len: buf.len() diff --git a/src/libstd/sys/unix/l4re.rs b/src/libstd/sys/unix/l4re.rs index f52fe8070906e..2c6f21aa21a3a 100644 --- a/src/libstd/sys/unix/l4re.rs +++ b/src/libstd/sys/unix/l4re.rs @@ -5,7 +5,7 @@ macro_rules! unimpl { pub mod net { #![allow(warnings)] use crate::fmt; - use crate::io::{self, IoVec, IoVecMut}; + use crate::io::{self, IoSlice, IoSliceMut}; use crate::net::{SocketAddr, Shutdown, Ipv4Addr, Ipv6Addr}; use crate::sys_common::{AsInner, FromInner, IntoInner}; use crate::sys::fd::FileDesc; @@ -46,7 +46,7 @@ pub mod net { unimpl!(); } - pub fn read_vectored(&self, _: &mut [IoVecMut<'_>]) -> io::Result { + pub fn read_vectored(&self, _: &mut [IoSliceMut<'_>]) -> io::Result { unimpl!(); } @@ -66,7 +66,7 @@ pub mod net { unimpl!(); } - pub fn write_vectored(&self, _: &[IoVec<'_>]) -> io::Result { + pub fn write_vectored(&self, _: &[IoSlice<'_>]) -> io::Result { unimpl!(); } @@ -152,7 +152,7 @@ pub mod net { unimpl!(); } - pub fn read_vectored(&self, _: &mut [IoVecMut<'_>]) -> io::Result { + pub fn read_vectored(&self, _: &mut [IoSliceMut<'_>]) -> io::Result { unimpl!(); } @@ -160,7 +160,7 @@ pub mod net { unimpl!(); } - pub fn write_vectored(&self, _: &[IoVec<'_>]) -> io::Result { + pub fn write_vectored(&self, _: &[IoSlice<'_>]) -> io::Result { unimpl!(); } diff --git a/src/libstd/sys/unix/net.rs b/src/libstd/sys/unix/net.rs index 7712a41ded46f..75750b5c4e588 100644 --- a/src/libstd/sys/unix/net.rs +++ b/src/libstd/sys/unix/net.rs @@ -1,5 +1,5 @@ use crate::ffi::CStr; -use crate::io::{self, IoVec, IoVecMut}; +use crate::io::{self, IoSlice, IoSliceMut}; use crate::mem; use crate::net::{SocketAddr, Shutdown}; use crate::str; @@ -244,7 +244,7 @@ impl Socket { self.recv_with_flags(buf, MSG_PEEK) } - pub fn read_vectored(&self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { self.0.read_vectored(bufs) } @@ -276,7 +276,7 @@ impl Socket { self.0.write(buf) } - pub fn write_vectored(&self, bufs: &[IoVec<'_>]) -> io::Result { + pub fn write_vectored(&self, bufs: &[IoSlice<'_>]) -> io::Result { self.0.write_vectored(bufs) } diff --git a/src/libstd/sys/unix/pipe.rs b/src/libstd/sys/unix/pipe.rs index a7792d42af9ed..d36e94df63f8c 100644 --- a/src/libstd/sys/unix/pipe.rs +++ b/src/libstd/sys/unix/pipe.rs @@ -1,4 +1,4 @@ -use crate::io::{self, IoVec, IoVecMut}; +use crate::io::{self, IoSlice, IoSliceMut}; use crate::mem; use crate::sync::atomic::{AtomicBool, Ordering}; use crate::sys::fd::FileDesc; @@ -60,7 +60,7 @@ impl AnonPipe { self.0.read(buf) } - pub fn read_vectored(&self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { self.0.read_vectored(bufs) } @@ -68,7 +68,7 @@ impl AnonPipe { self.0.write(buf) } - pub fn write_vectored(&self, bufs: &[IoVec<'_>]) -> io::Result { + pub fn write_vectored(&self, bufs: &[IoSlice<'_>]) -> io::Result { self.0.write_vectored(bufs) } diff --git a/src/libstd/sys/unix/stdio.rs b/src/libstd/sys/unix/stdio.rs index bc2986f624e5c..f9b017df24088 100644 --- a/src/libstd/sys/unix/stdio.rs +++ b/src/libstd/sys/unix/stdio.rs @@ -1,4 +1,4 @@ -use crate::io::{self, IoVec, IoVecMut}; +use crate::io::{self, IoSlice, IoSliceMut}; use crate::sys::fd::FileDesc; use crate::mem::ManuallyDrop; @@ -15,7 +15,7 @@ impl io::Read for Stdin { ManuallyDrop::new(FileDesc::new(libc::STDIN_FILENO)).read(buf) } - fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { ManuallyDrop::new(FileDesc::new(libc::STDIN_FILENO)).read_vectored(bufs) } } @@ -29,7 +29,7 @@ impl io::Write for Stdout { ManuallyDrop::new(FileDesc::new(libc::STDOUT_FILENO)).write(buf) } - fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result { ManuallyDrop::new(FileDesc::new(libc::STDOUT_FILENO)).write_vectored(bufs) } @@ -47,7 +47,7 @@ impl io::Write for Stderr { ManuallyDrop::new(FileDesc::new(libc::STDERR_FILENO)).write(buf) } - fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result { ManuallyDrop::new(FileDesc::new(libc::STDERR_FILENO)).write_vectored(bufs) } diff --git a/src/libstd/sys/wasi/ext/fs.rs b/src/libstd/sys/wasi/ext/fs.rs index 53f415c78219e..0ec4122f385da 100644 --- a/src/libstd/sys/wasi/ext/fs.rs +++ b/src/libstd/sys/wasi/ext/fs.rs @@ -3,7 +3,7 @@ #![unstable(feature = "wasi_ext", issue = "0")] use crate::fs::{self, File, Metadata, OpenOptions}; -use crate::io::{self, IoVec, IoVecMut}; +use crate::io::{self, IoSlice, IoSliceMut}; use crate::os::wasi::ffi::OsStrExt; use crate::path::{Path, PathBuf}; use crate::sys_common::{AsInner, AsInnerMut, FromInner}; @@ -25,7 +25,7 @@ pub trait FileExt { /// return with a short read. /// /// [`File::read`]: ../../../../std/fs/struct.File.html#method.read_vectored - fn read_at(&self, bufs: &mut [IoVecMut<'_>], offset: u64) -> io::Result; + fn read_at(&self, bufs: &mut [IoSliceMut<'_>], offset: u64) -> io::Result; /// Writes a number of bytes starting from a given offset. /// @@ -43,7 +43,7 @@ pub trait FileExt { /// short write. /// /// [`File::write`]: ../../../../std/fs/struct.File.html#method.write_vectored - fn write_at(&self, bufs: &[IoVec<'_>], offset: u64) -> io::Result; + fn write_at(&self, bufs: &[IoSlice<'_>], offset: u64) -> io::Result; /// Returns the current position within the file. /// @@ -105,11 +105,11 @@ pub trait FileExt { // FIXME: bind __wasi_random_get maybe? - on crates.io for unix impl FileExt for fs::File { - fn read_at(&self, bufs: &mut [IoVecMut<'_>], offset: u64) -> io::Result { + fn read_at(&self, bufs: &mut [IoSliceMut<'_>], offset: u64) -> io::Result { self.as_inner().fd().pread(bufs, offset) } - fn write_at(&self, bufs: &[IoVec<'_>], offset: u64) -> io::Result { + fn write_at(&self, bufs: &[IoSlice<'_>], offset: u64) -> io::Result { self.as_inner().fd().pwrite(bufs, offset) } diff --git a/src/libstd/sys/wasi/fd.rs b/src/libstd/sys/wasi/fd.rs index 0b68b6f4d9c72..25692ec086801 100644 --- a/src/libstd/sys/wasi/fd.rs +++ b/src/libstd/sys/wasi/fd.rs @@ -1,6 +1,6 @@ #![allow(dead_code)] -use crate::io::{self, IoVec, IoVecMut, SeekFrom}; +use crate::io::{self, IoSlice, IoSliceMut, SeekFrom}; use crate::mem; use crate::net::Shutdown; use crate::sys::cvt_wasi; @@ -24,25 +24,25 @@ pub type RiFlags = u16; pub type RoFlags = u16; pub type SiFlags = u16; -fn iovec(a: &mut [IoVecMut<'_>]) -> (*const libc::__wasi_iovec_t, usize) { +fn iovec(a: &mut [IoSliceMut<'_>]) -> (*const libc::__wasi_iovec_t, usize) { assert_eq!( - mem::size_of::>(), + mem::size_of::>(), mem::size_of::() ); assert_eq!( - mem::align_of::>(), + mem::align_of::>(), mem::align_of::() ); (a.as_ptr() as *const libc::__wasi_iovec_t, a.len()) } -fn ciovec(a: &[IoVec<'_>]) -> (*const libc::__wasi_ciovec_t, usize) { +fn ciovec(a: &[IoSlice<'_>]) -> (*const libc::__wasi_ciovec_t, usize) { assert_eq!( - mem::size_of::>(), + mem::size_of::>(), mem::size_of::() ); assert_eq!( - mem::align_of::>(), + mem::align_of::>(), mem::align_of::() ); (a.as_ptr() as *const libc::__wasi_ciovec_t, a.len()) @@ -67,28 +67,28 @@ impl WasiFd { cvt_wasi(unsafe { libc::__wasi_fd_datasync(self.fd) }) } - pub fn pread(&self, bufs: &mut [IoVecMut<'_>], offset: u64) -> io::Result { + pub fn pread(&self, bufs: &mut [IoSliceMut<'_>], offset: u64) -> io::Result { let mut read = 0; let (ptr, len) = iovec(bufs); cvt_wasi(unsafe { libc::__wasi_fd_pread(self.fd, ptr, len, offset, &mut read) })?; Ok(read) } - pub fn pwrite(&self, bufs: &[IoVec<'_>], offset: u64) -> io::Result { + pub fn pwrite(&self, bufs: &[IoSlice<'_>], offset: u64) -> io::Result { let mut read = 0; let (ptr, len) = ciovec(bufs); cvt_wasi(unsafe { libc::__wasi_fd_pwrite(self.fd, ptr, len, offset, &mut read) })?; Ok(read) } - pub fn read(&self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + pub fn read(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { let mut read = 0; let (ptr, len) = iovec(bufs); cvt_wasi(unsafe { libc::__wasi_fd_read(self.fd, ptr, len, &mut read) })?; Ok(read) } - pub fn write(&self, bufs: &[IoVec<'_>]) -> io::Result { + pub fn write(&self, bufs: &[IoSlice<'_>]) -> io::Result { let mut read = 0; let (ptr, len) = ciovec(bufs); cvt_wasi(unsafe { libc::__wasi_fd_write(self.fd, ptr, len, &mut read) })?; @@ -309,7 +309,7 @@ impl WasiFd { pub fn sock_recv( &self, - ri_data: &mut [IoVecMut<'_>], + ri_data: &mut [IoSliceMut<'_>], ri_flags: RiFlags, ) -> io::Result<(usize, RoFlags)> { let mut ro_datalen = 0; @@ -321,7 +321,7 @@ impl WasiFd { Ok((ro_datalen, ro_flags)) } - pub fn sock_send(&self, si_data: &[IoVec<'_>], si_flags: SiFlags) -> io::Result { + pub fn sock_send(&self, si_data: &[IoSlice<'_>], si_flags: SiFlags) -> io::Result { let mut so_datalen = 0; let (ptr, len) = ciovec(si_data); cvt_wasi(unsafe { libc::__wasi_sock_send(self.fd, ptr, len, si_flags, &mut so_datalen) })?; diff --git a/src/libstd/sys/wasi/fs.rs b/src/libstd/sys/wasi/fs.rs index 589593299d609..172c60385b317 100644 --- a/src/libstd/sys/wasi/fs.rs +++ b/src/libstd/sys/wasi/fs.rs @@ -1,6 +1,6 @@ use crate::ffi::{CStr, CString, OsStr, OsString}; use crate::fmt; -use crate::io::{self, IoVec, IoVecMut, SeekFrom}; +use crate::io::{self, IoSlice, IoSliceMut, SeekFrom}; use crate::iter; use crate::mem::{self, ManuallyDrop}; use crate::os::wasi::ffi::{OsStrExt, OsStringExt}; @@ -414,18 +414,18 @@ impl File { } pub fn read(&self, buf: &mut [u8]) -> io::Result { - self.read_vectored(&mut [IoVecMut::new(buf)]) + self.read_vectored(&mut [IoSliceMut::new(buf)]) } - pub fn read_vectored(&self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { self.fd.read(bufs) } pub fn write(&self, buf: &[u8]) -> io::Result { - self.write_vectored(&[IoVec::new(buf)]) + self.write_vectored(&[IoSlice::new(buf)]) } - pub fn write_vectored(&self, bufs: &[IoVec<'_>]) -> io::Result { + pub fn write_vectored(&self, bufs: &[IoSlice<'_>]) -> io::Result { self.fd.write(bufs) } diff --git a/src/libstd/sys/wasi/io.rs b/src/libstd/sys/wasi/io.rs index 5f0315d279e8e..cc8f1e16fa01d 100644 --- a/src/libstd/sys/wasi/io.rs +++ b/src/libstd/sys/wasi/io.rs @@ -4,15 +4,15 @@ use crate::slice; use libc::{__wasi_ciovec_t, __wasi_iovec_t, c_void}; #[repr(transparent)] -pub struct IoVec<'a> { +pub struct IoSlice<'a> { vec: __wasi_ciovec_t, _p: PhantomData<&'a [u8]>, } -impl<'a> IoVec<'a> { +impl<'a> IoSlice<'a> { #[inline] - pub fn new(buf: &'a [u8]) -> IoVec<'a> { - IoVec { + pub fn new(buf: &'a [u8]) -> IoSlice<'a> { + IoSlice { vec: __wasi_ciovec_t { buf: buf.as_ptr() as *const c_void, buf_len: buf.len(), @@ -29,15 +29,15 @@ impl<'a> IoVec<'a> { } } -pub struct IoVecMut<'a> { +pub struct IoSliceMut<'a> { vec: __wasi_iovec_t, _p: PhantomData<&'a mut [u8]>, } -impl<'a> IoVecMut<'a> { +impl<'a> IoSliceMut<'a> { #[inline] - pub fn new(buf: &'a mut [u8]) -> IoVecMut<'a> { - IoVecMut { + pub fn new(buf: &'a mut [u8]) -> IoSliceMut<'a> { + IoSliceMut { vec: __wasi_iovec_t { buf: buf.as_mut_ptr() as *mut c_void, buf_len: buf.len() diff --git a/src/libstd/sys/wasi/net.rs b/src/libstd/sys/wasi/net.rs index 5486cdec4c044..80f633a8e1f2b 100644 --- a/src/libstd/sys/wasi/net.rs +++ b/src/libstd/sys/wasi/net.rs @@ -1,5 +1,5 @@ use crate::fmt; -use crate::io::{self, IoVec, IoVecMut}; +use crate::io::{self, IoSlice, IoSliceMut}; use crate::net::{SocketAddr, Shutdown, Ipv4Addr, Ipv6Addr}; use crate::time::Duration; use crate::sys::{unsupported, Void}; @@ -44,7 +44,7 @@ impl TcpStream { unsupported() } - pub fn read_vectored(&self, _: &mut [IoVecMut<'_>]) -> io::Result { + pub fn read_vectored(&self, _: &mut [IoSliceMut<'_>]) -> io::Result { unsupported() } @@ -52,7 +52,7 @@ impl TcpStream { unsupported() } - pub fn write_vectored(&self, _: &[IoVec<'_>]) -> io::Result { + pub fn write_vectored(&self, _: &[IoSlice<'_>]) -> io::Result { unsupported() } diff --git a/src/libstd/sys/wasi/pipe.rs b/src/libstd/sys/wasi/pipe.rs index aa6bf8076f649..9f07f054362fe 100644 --- a/src/libstd/sys/wasi/pipe.rs +++ b/src/libstd/sys/wasi/pipe.rs @@ -1,4 +1,4 @@ -use crate::io::{self, IoVec, IoVecMut}; +use crate::io::{self, IoSlice, IoSliceMut}; use crate::sys::Void; pub struct AnonPipe(Void); @@ -8,7 +8,7 @@ impl AnonPipe { match self.0 {} } - pub fn read_vectored(&self, _bufs: &mut [IoVecMut<'_>]) -> io::Result { + pub fn read_vectored(&self, _bufs: &mut [IoSliceMut<'_>]) -> io::Result { match self.0 {} } @@ -16,7 +16,7 @@ impl AnonPipe { match self.0 {} } - pub fn write_vectored(&self, _bufs: &[IoVec<'_>]) -> io::Result { + pub fn write_vectored(&self, _bufs: &[IoSlice<'_>]) -> io::Result { match self.0 {} } diff --git a/src/libstd/sys/wasi/stdio.rs b/src/libstd/sys/wasi/stdio.rs index bdad40848916e..2bf8d803c01bb 100644 --- a/src/libstd/sys/wasi/stdio.rs +++ b/src/libstd/sys/wasi/stdio.rs @@ -1,4 +1,4 @@ -use crate::io::{self, IoVec, IoVecMut}; +use crate::io::{self, IoSlice, IoSliceMut}; use crate::libc; use crate::mem::ManuallyDrop; use crate::sys::fd::WasiFd; @@ -13,10 +13,10 @@ impl Stdin { } pub fn read(&self, data: &mut [u8]) -> io::Result { - self.read_vectored(&mut [IoVecMut::new(data)]) + self.read_vectored(&mut [IoSliceMut::new(data)]) } - pub fn read_vectored(&self, data: &mut [IoVecMut<'_>]) -> io::Result { + pub fn read_vectored(&self, data: &mut [IoSliceMut<'_>]) -> io::Result { ManuallyDrop::new(unsafe { WasiFd::from_raw(libc::STDIN_FILENO as u32) }) .read(data) } @@ -28,10 +28,10 @@ impl Stdout { } pub fn write(&self, data: &[u8]) -> io::Result { - self.write_vectored(&[IoVec::new(data)]) + self.write_vectored(&[IoSlice::new(data)]) } - pub fn write_vectored(&self, data: &[IoVec<'_>]) -> io::Result { + pub fn write_vectored(&self, data: &[IoSlice<'_>]) -> io::Result { ManuallyDrop::new(unsafe { WasiFd::from_raw(libc::STDOUT_FILENO as u32) }) .write(data) } @@ -47,10 +47,10 @@ impl Stderr { } pub fn write(&self, data: &[u8]) -> io::Result { - self.write_vectored(&[IoVec::new(data)]) + self.write_vectored(&[IoSlice::new(data)]) } - pub fn write_vectored(&self, data: &[IoVec<'_>]) -> io::Result { + pub fn write_vectored(&self, data: &[IoSlice<'_>]) -> io::Result { ManuallyDrop::new(unsafe { WasiFd::from_raw(libc::STDERR_FILENO as u32) }) .write(data) } diff --git a/src/libstd/sys/wasm/fs.rs b/src/libstd/sys/wasm/fs.rs index c3c898eb23e56..e9095b375fe5d 100644 --- a/src/libstd/sys/wasm/fs.rs +++ b/src/libstd/sys/wasm/fs.rs @@ -1,7 +1,7 @@ use crate::ffi::OsString; use crate::fmt; use crate::hash::{Hash, Hasher}; -use crate::io::{self, SeekFrom, IoVec, IoVecMut}; +use crate::io::{self, SeekFrom, IoSlice, IoSliceMut}; use crate::path::{Path, PathBuf}; use crate::sys::time::SystemTime; use crate::sys::{unsupported, Void}; @@ -200,7 +200,7 @@ impl File { match self.0 {} } - pub fn read_vectored(&self, _bufs: &mut [IoVecMut<'_>]) -> io::Result { + pub fn read_vectored(&self, _bufs: &mut [IoSliceMut<'_>]) -> io::Result { match self.0 {} } @@ -208,7 +208,7 @@ impl File { match self.0 {} } - pub fn write_vectored(&self, _bufs: &[IoVec<'_>]) -> io::Result { + pub fn write_vectored(&self, _bufs: &[IoSlice<'_>]) -> io::Result { match self.0 {} } diff --git a/src/libstd/sys/wasm/io.rs b/src/libstd/sys/wasm/io.rs index 8b02d3fd19d30..4b423a5cbc11a 100644 --- a/src/libstd/sys/wasm/io.rs +++ b/src/libstd/sys/wasm/io.rs @@ -1,9 +1,9 @@ -pub struct IoVec<'a>(&'a [u8]); +pub struct IoSlice<'a>(&'a [u8]); -impl<'a> IoVec<'a> { +impl<'a> IoSlice<'a> { #[inline] - pub fn new(buf: &'a [u8]) -> IoVec<'a> { - IoVec(buf) + pub fn new(buf: &'a [u8]) -> IoSlice<'a> { + IoSlice(buf) } #[inline] @@ -12,12 +12,12 @@ impl<'a> IoVec<'a> { } } -pub struct IoVecMut<'a>(&'a mut [u8]); +pub struct IoSliceMut<'a>(&'a mut [u8]); -impl<'a> IoVecMut<'a> { +impl<'a> IoSliceMut<'a> { #[inline] - pub fn new(buf: &'a mut [u8]) -> IoVecMut<'a> { - IoVecMut(buf) + pub fn new(buf: &'a mut [u8]) -> IoSliceMut<'a> { + IoSliceMut(buf) } #[inline] diff --git a/src/libstd/sys/wasm/net.rs b/src/libstd/sys/wasm/net.rs index 38552eab0a655..d50f989d2bb5f 100644 --- a/src/libstd/sys/wasm/net.rs +++ b/src/libstd/sys/wasm/net.rs @@ -1,5 +1,5 @@ use crate::fmt; -use crate::io::{self, IoVec, IoVecMut}; +use crate::io::{self, IoSlice, IoSliceMut}; use crate::net::{SocketAddr, Shutdown, Ipv4Addr, Ipv6Addr}; use crate::time::Duration; use crate::sys::{unsupported, Void}; @@ -40,7 +40,7 @@ impl TcpStream { match self.0 {} } - pub fn read_vectored(&self, _: &mut [IoVecMut<'_>]) -> io::Result { + pub fn read_vectored(&self, _: &mut [IoSliceMut<'_>]) -> io::Result { match self.0 {} } @@ -48,7 +48,7 @@ impl TcpStream { match self.0 {} } - pub fn write_vectored(&self, _: &[IoVec<'_>]) -> io::Result { + pub fn write_vectored(&self, _: &[IoSlice<'_>]) -> io::Result { match self.0 {} } diff --git a/src/libstd/sys/wasm/pipe.rs b/src/libstd/sys/wasm/pipe.rs index aa6bf8076f649..9f07f054362fe 100644 --- a/src/libstd/sys/wasm/pipe.rs +++ b/src/libstd/sys/wasm/pipe.rs @@ -1,4 +1,4 @@ -use crate::io::{self, IoVec, IoVecMut}; +use crate::io::{self, IoSlice, IoSliceMut}; use crate::sys::Void; pub struct AnonPipe(Void); @@ -8,7 +8,7 @@ impl AnonPipe { match self.0 {} } - pub fn read_vectored(&self, _bufs: &mut [IoVecMut<'_>]) -> io::Result { + pub fn read_vectored(&self, _bufs: &mut [IoSliceMut<'_>]) -> io::Result { match self.0 {} } @@ -16,7 +16,7 @@ impl AnonPipe { match self.0 {} } - pub fn write_vectored(&self, _bufs: &[IoVec<'_>]) -> io::Result { + pub fn write_vectored(&self, _bufs: &[IoSlice<'_>]) -> io::Result { match self.0 {} } diff --git a/src/libstd/sys/windows/fs.rs b/src/libstd/sys/windows/fs.rs index 1d8e47a4793ef..d5cb205c85f52 100644 --- a/src/libstd/sys/windows/fs.rs +++ b/src/libstd/sys/windows/fs.rs @@ -2,7 +2,7 @@ use crate::os::windows::prelude::*; use crate::ffi::OsString; use crate::fmt; -use crate::io::{self, Error, SeekFrom, IoVec, IoVecMut}; +use crate::io::{self, Error, SeekFrom, IoSlice, IoSliceMut}; use crate::mem; use crate::path::{Path, PathBuf}; use crate::ptr; @@ -314,7 +314,7 @@ impl File { self.handle.read(buf) } - pub fn read_vectored(&self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { self.handle.read_vectored(bufs) } @@ -326,7 +326,7 @@ impl File { self.handle.write(buf) } - pub fn write_vectored(&self, bufs: &[IoVec<'_>]) -> io::Result { + pub fn write_vectored(&self, bufs: &[IoSlice<'_>]) -> io::Result { self.handle.write_vectored(bufs) } diff --git a/src/libstd/sys/windows/handle.rs b/src/libstd/sys/windows/handle.rs index c3fa6c4e0bd51..3e5aa69335461 100644 --- a/src/libstd/sys/windows/handle.rs +++ b/src/libstd/sys/windows/handle.rs @@ -1,7 +1,7 @@ #![unstable(issue = "0", feature = "windows_handle")] use crate::cmp; -use crate::io::{self, ErrorKind, Read, IoVec, IoVecMut}; +use crate::io::{self, ErrorKind, Read, IoSlice, IoSliceMut}; use crate::mem; use crate::ops::Deref; use crate::ptr; @@ -89,7 +89,7 @@ impl RawHandle { } } - pub fn read_vectored(&self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { crate::io::default_read_vectored(|buf| self.read(buf), bufs) } @@ -173,7 +173,7 @@ impl RawHandle { Ok(amt as usize) } - pub fn write_vectored(&self, bufs: &[IoVec<'_>]) -> io::Result { + pub fn write_vectored(&self, bufs: &[IoSlice<'_>]) -> io::Result { crate::io::default_write_vectored(|buf| self.write(buf), bufs) } @@ -208,7 +208,7 @@ impl<'a> Read for &'a RawHandle { (**self).read(buf) } - fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { (**self).read_vectored(bufs) } } diff --git a/src/libstd/sys/windows/io.rs b/src/libstd/sys/windows/io.rs index 54dd271c9d666..c045a63e9118f 100644 --- a/src/libstd/sys/windows/io.rs +++ b/src/libstd/sys/windows/io.rs @@ -3,16 +3,16 @@ use crate::slice; use crate::sys::c; #[repr(transparent)] -pub struct IoVec<'a> { +pub struct IoSlice<'a> { vec: c::WSABUF, _p: PhantomData<&'a [u8]>, } -impl<'a> IoVec<'a> { +impl<'a> IoSlice<'a> { #[inline] - pub fn new(buf: &'a [u8]) -> IoVec<'a> { + pub fn new(buf: &'a [u8]) -> IoSlice<'a> { assert!(buf.len() <= c::ULONG::max_value() as usize); - IoVec { + IoSlice { vec: c::WSABUF { len: buf.len() as c::ULONG, buf: buf.as_ptr() as *mut u8 as *mut c::CHAR, @@ -29,16 +29,16 @@ impl<'a> IoVec<'a> { } } -pub struct IoVecMut<'a> { +pub struct IoSliceMut<'a> { vec: c::WSABUF, _p: PhantomData<&'a mut [u8]>, } -impl<'a> IoVecMut<'a> { +impl<'a> IoSliceMut<'a> { #[inline] - pub fn new(buf: &'a mut [u8]) -> IoVecMut<'a> { + pub fn new(buf: &'a mut [u8]) -> IoSliceMut<'a> { assert!(buf.len() <= c::ULONG::max_value() as usize); - IoVecMut { + IoSliceMut { vec: c::WSABUF { len: buf.len() as c::ULONG, buf: buf.as_mut_ptr() as *mut c::CHAR, diff --git a/src/libstd/sys/windows/net.rs b/src/libstd/sys/windows/net.rs index 1231fd55e252e..7dd1af5441bfb 100644 --- a/src/libstd/sys/windows/net.rs +++ b/src/libstd/sys/windows/net.rs @@ -1,7 +1,7 @@ #![unstable(issue = "0", feature = "windows_net")] use crate::cmp; -use crate::io::{self, Read, IoVec, IoVecMut}; +use crate::io::{self, Read, IoSlice, IoSliceMut}; use crate::mem; use crate::net::{SocketAddr, Shutdown}; use crate::ptr; @@ -208,7 +208,7 @@ impl Socket { self.recv_with_flags(buf, 0) } - pub fn read_vectored(&self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { // On unix when a socket is shut down all further reads return 0, so we // do the same on windows to map a shut down socket to returning EOF. let len = cmp::min(bufs.len(), c::DWORD::max_value() as usize) as c::DWORD; @@ -268,7 +268,7 @@ impl Socket { self.recv_from_with_flags(buf, c::MSG_PEEK) } - pub fn write_vectored(&self, bufs: &[IoVec<'_>]) -> io::Result { + pub fn write_vectored(&self, bufs: &[IoSlice<'_>]) -> io::Result { let len = cmp::min(bufs.len(), c::DWORD::max_value() as usize) as c::DWORD; let mut nwritten = 0; unsafe { diff --git a/src/libstd/sys/windows/pipe.rs b/src/libstd/sys/windows/pipe.rs index 6613d3a056775..493ee8a9a2d7c 100644 --- a/src/libstd/sys/windows/pipe.rs +++ b/src/libstd/sys/windows/pipe.rs @@ -1,7 +1,7 @@ use crate::os::windows::prelude::*; use crate::ffi::OsStr; -use crate::io::{self, IoVec, IoVecMut}; +use crate::io::{self, IoSlice, IoSliceMut}; use crate::mem; use crate::path::Path; use crate::ptr; @@ -166,7 +166,7 @@ impl AnonPipe { self.inner.read(buf) } - pub fn read_vectored(&self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { self.inner.read_vectored(bufs) } @@ -174,7 +174,7 @@ impl AnonPipe { self.inner.write(buf) } - pub fn write_vectored(&self, bufs: &[IoVec<'_>]) -> io::Result { + pub fn write_vectored(&self, bufs: &[IoSlice<'_>]) -> io::Result { self.inner.write_vectored(bufs) } } diff --git a/src/libstd/sys_common/net.rs b/src/libstd/sys_common/net.rs index 02bd91c438104..cf1dc20b52fc6 100644 --- a/src/libstd/sys_common/net.rs +++ b/src/libstd/sys_common/net.rs @@ -1,7 +1,7 @@ use crate::cmp; use crate::ffi::CString; use crate::fmt; -use crate::io::{self, Error, ErrorKind, IoVec, IoVecMut}; +use crate::io::{self, Error, ErrorKind, IoSlice, IoSliceMut}; use crate::mem; use crate::net::{SocketAddr, Shutdown, Ipv4Addr, Ipv6Addr}; use crate::ptr; @@ -256,7 +256,7 @@ impl TcpStream { self.inner.read(buf) } - pub fn read_vectored(&self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { self.inner.read_vectored(bufs) } @@ -271,7 +271,7 @@ impl TcpStream { Ok(ret as usize) } - pub fn write_vectored(&self, bufs: &[IoVec<'_>]) -> io::Result { + pub fn write_vectored(&self, bufs: &[IoSlice<'_>]) -> io::Result { self.inner.write_vectored(bufs) } diff --git a/src/test/run-pass/consts/const-labeled-break.rs b/src/test/run-pass/consts/const-labeled-break.rs new file mode 100644 index 0000000000000..9417159e6fb78 --- /dev/null +++ b/src/test/run-pass/consts/const-labeled-break.rs @@ -0,0 +1,10 @@ +// Using labeled break in a while loop has caused an illegal instruction being +// generated, and an ICE later. +// +// See https://github.com/rust-lang/rust/issues/51350 for more information. + +const CRASH: () = 'a: while break 'a {}; + +fn main() { + println!("{:?}", CRASH); +} diff --git a/src/test/ui/async-with-closure.rs b/src/test/ui/async-with-closure.rs new file mode 100644 index 0000000000000..856a778078a61 --- /dev/null +++ b/src/test/ui/async-with-closure.rs @@ -0,0 +1,26 @@ +// compile-pass +// edition:2018 + +#![feature(async_await, await_macro)] + +trait MyClosure { + type Args; +} + +impl MyClosure for dyn FnMut() -> R +where R: 'static { + type Args = (); +} + +struct MyStream { + x: C::Args, +} + +async fn get_future(_stream: MyStream) {} + +async fn f() { + let messages: MyStream = unimplemented!(); + await!(get_future(messages)); +} + +fn main() {} diff --git a/src/test/ui/imports/unresolved-imports-used.rs b/src/test/ui/imports/unresolved-imports-used.rs new file mode 100644 index 0000000000000..d1461e7b041c5 --- /dev/null +++ b/src/test/ui/imports/unresolved-imports-used.rs @@ -0,0 +1,12 @@ +// There should be *no* unused import errors. +#![deny(unused_imports)] + +mod qux { + fn quz() {} +} + +use qux::quz; //~ ERROR function `quz` is private +use qux::bar; //~ ERROR unresolved import `qux::bar` +use foo::bar; //~ ERROR unresolved import `foo` + +fn main() {} diff --git a/src/test/ui/imports/unresolved-imports-used.stderr b/src/test/ui/imports/unresolved-imports-used.stderr new file mode 100644 index 0000000000000..f20db881c8628 --- /dev/null +++ b/src/test/ui/imports/unresolved-imports-used.stderr @@ -0,0 +1,22 @@ +error[E0432]: unresolved import `qux::bar` + --> $DIR/unresolved-imports-used.rs:9:5 + | +LL | use qux::bar; + | ^^^^^^^^ no `bar` in `qux` + +error[E0432]: unresolved import `foo` + --> $DIR/unresolved-imports-used.rs:10:5 + | +LL | use foo::bar; + | ^^^ maybe a missing `extern crate foo;`? + +error[E0603]: function `quz` is private + --> $DIR/unresolved-imports-used.rs:8:10 + | +LL | use qux::quz; + | ^^^ + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0432, E0603. +For more information about an error, try `rustc --explain E0432`. diff --git a/src/tools/linkchecker/main.rs b/src/tools/linkchecker/main.rs index 9a6c97dbca015..e2bcd4d40af7f 100644 --- a/src/tools/linkchecker/main.rs +++ b/src/tools/linkchecker/main.rs @@ -135,8 +135,8 @@ fn check(cache: &mut Cache, file.ends_with("ty/struct.Slice.html") || file.ends_with("ty/enum.Attributes.html") || file.ends_with("ty/struct.SymbolName.html") || - file.ends_with("io/struct.IoVec.html") || - file.ends_with("io/struct.IoVecMut.html") { + file.ends_with("io/struct.IoSlice.html") || + file.ends_with("io/struct.IoSliceMut.html") { return None; } // FIXME(#32553)