diff --git a/README.md b/README.md index 96d7e938be2f2..495ee46a9acb3 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ or reading the [rustc guide][rustcguidebuild]. * `curl` * `git` * `ssl` which comes in `libssl-dev` or `openssl-devel` + * `pkg-config` if you are on compiling on Linux and targeting Linux 2. Clone the [source] with `git`: diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index d1ebdd2f086ab..05bdd0887f0f6 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -633,9 +633,6 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) { TyKind::Typeof(ref expression) => { visitor.visit_anon_const(expression) } - TyKind::CVarArgs(ref lt) => { - visitor.visit_lifetime(lt) - } TyKind::Infer | TyKind::Err => {} } } diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index d0a9d967a649d..6f51e05881be5 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -1335,13 +1335,8 @@ impl<'a> LoweringContext<'a> { } } } - TyKind::Mac(_) => bug!("`TyMac` should have been expanded by now"), - TyKind::CVarArgs => { - // Create the implicit lifetime of the "spoofed" `VaListImpl`. - let span = self.sess.source_map().next_point(t.span.shrink_to_lo()); - let lt = self.new_implicit_lifetime(span); - hir::TyKind::CVarArgs(lt) - }, + TyKind::Mac(_) => bug!("`TyKind::Mac` should have been expanded by now"), + TyKind::CVarArgs => bug!("`TyKind::CVarArgs` should have been handled elsewhere"), }; hir::Ty { @@ -2093,7 +2088,14 @@ impl<'a> LoweringContext<'a> { } fn lower_fn_params_to_names(&mut self, decl: &FnDecl) -> hir::HirVec { - decl.inputs + // Skip the `...` (`CVarArgs`) trailing arguments from the AST, + // as they are not explicit in HIR/Ty function signatures. + // (instead, the `c_variadic` flag is set to `true`) + let mut inputs = &decl.inputs[..]; + if decl.c_variadic() { + inputs = &inputs[..inputs.len() - 1]; + } + inputs .iter() .map(|param| match param.pat.kind { PatKind::Ident(_, ident, _) => ident, @@ -2130,10 +2132,19 @@ impl<'a> LoweringContext<'a> { self.anonymous_lifetime_mode }; + let c_variadic = decl.c_variadic(); + // Remember how many lifetimes were already around so that we can // only look at the lifetime parameters introduced by the arguments. let inputs = self.with_anonymous_lifetime_mode(lt_mode, |this| { - decl.inputs + // Skip the `...` (`CVarArgs`) trailing arguments from the AST, + // as they are not explicit in HIR/Ty function signatures. + // (instead, the `c_variadic` flag is set to `true`) + let mut inputs = &decl.inputs[..]; + if c_variadic { + inputs = &inputs[..inputs.len() - 1]; + } + inputs .iter() .map(|param| { if let Some((_, ibty)) = &mut in_band_ty_params { @@ -2168,7 +2179,7 @@ impl<'a> LoweringContext<'a> { P(hir::FnDecl { inputs, output, - c_variadic: decl.c_variadic, + c_variadic, implicit_self: decl.inputs.get(0).map_or( hir::ImplicitSelfKind::None, |arg| { diff --git a/src/librustc/hir/lowering/expr.rs b/src/librustc/hir/lowering/expr.rs index 50fceacaa4486..2f0a318d5363e 100644 --- a/src/librustc/hir/lowering/expr.rs +++ b/src/librustc/hir/lowering/expr.rs @@ -450,7 +450,6 @@ impl LoweringContext<'_> { let ast_decl = FnDecl { inputs: vec![], output, - c_variadic: false }; let decl = self.lower_fn_decl(&ast_decl, None, /* impl trait allowed */ false, None); let body_id = self.lower_fn_body(&ast_decl, |this| { @@ -739,7 +738,6 @@ impl LoweringContext<'_> { let outer_decl = FnDecl { inputs: decl.inputs.clone(), output: FunctionRetTy::Default(fn_decl_span), - c_variadic: false, }; // We need to lower the declaration outside the new scope, because we // have to conserve the state of being inside a loop condition for the diff --git a/src/librustc/hir/map/collector.rs b/src/librustc/hir/map/collector.rs index c69d682b6f796..540d456daf3d3 100644 --- a/src/librustc/hir/map/collector.rs +++ b/src/librustc/hir/map/collector.rs @@ -17,7 +17,7 @@ use syntax_pos::Span; use std::iter::repeat; use crate::ich::StableHashingContext; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableHasherResult}; +use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; /// A visitor that walks over the HIR and collects `Node`s into a HIR map. pub(super) struct NodeCollector<'a, 'hir> { @@ -602,9 +602,7 @@ impl<'hir, T> HashStable> for HirItemLike where T: HashStable>, { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'hir>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'hir>, hasher: &mut StableHasher) { hcx.while_hashing_hir_bodies(self.hash_bodies, |hcx| { self.item_like.hash_stable(hcx, hasher); }); diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 6a88ae077c8da..4e8b4337cc6dd 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -2016,9 +2016,6 @@ pub enum TyKind { Infer, /// Placeholder for a type that has failed to be defined. Err, - /// Placeholder for C-variadic arguments. We "spoof" the `VaListImpl` created - /// from the variadic arguments. This type is only valid up to typeck. - CVarArgs(Lifetime), } #[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index 91f2c5a0aaf85..6cffaa8a494c4 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -361,9 +361,6 @@ impl<'a> State<'a> { self.s.word("/*ERROR*/"); self.pclose(); } - hir::TyKind::CVarArgs(_) => { - self.s.word("..."); - } } self.end() } diff --git a/src/librustc/hir/ptr.rs b/src/librustc/hir/ptr.rs index 1976b4c9e54ff..8cdcf5202fcda 100644 --- a/src/librustc/hir/ptr.rs +++ b/src/librustc/hir/ptr.rs @@ -9,8 +9,7 @@ use std::{slice, vec}; use rustc_serialize::{Encodable, Decodable, Encoder, Decoder}; -use rustc_data_structures::stable_hasher::{StableHasher, StableHasherResult, - HashStable}; +use rustc_data_structures::stable_hasher::{StableHasher, HashStable}; /// An owned smart pointer. #[derive(Hash, PartialEq, Eq)] pub struct P { @@ -133,9 +132,7 @@ impl Decodable for P<[T]> { impl HashStable for P where T: ?Sized + HashStable { - fn hash_stable(&self, - hcx: &mut CTX, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { (**self).hash_stable(hcx, hasher); } } diff --git a/src/librustc/ich/hcx.rs b/src/librustc/ich/hcx.rs index 182a9ade8c36e..3e6b271b83497 100644 --- a/src/librustc/ich/hcx.rs +++ b/src/librustc/ich/hcx.rs @@ -20,7 +20,7 @@ use syntax_pos::{Span, DUMMY_SP}; use syntax_pos::hygiene; use rustc_data_structures::stable_hasher::{ - HashStable, StableHasher, StableHasherResult, ToStableHashKey, + HashStable, StableHasher, ToStableHashKey, }; use rustc_data_structures::fx::{FxHashSet, FxHashMap}; use smallvec::SmallVec; @@ -219,9 +219,7 @@ impl<'a> StableHashingContextProvider<'a> for StableHashingContext<'a> { impl<'a> crate::dep_graph::DepGraphSafe for StableHashingContext<'a> {} impl<'a> HashStable> for hir::BodyId { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { if hcx.hash_bodies() { hcx.body_resolver.body(*self).hash_stable(hcx, hasher); } @@ -230,9 +228,7 @@ impl<'a> HashStable> for hir::BodyId { impl<'a> HashStable> for hir::HirId { #[inline] - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { match hcx.node_id_hashing_mode { NodeIdHashingMode::Ignore => { // Don't do anything. @@ -263,9 +259,7 @@ impl<'a> ToStableHashKey> for hir::HirId { } impl<'a> HashStable> for ast::NodeId { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { match hcx.node_id_hashing_mode { NodeIdHashingMode::Ignore => { // Don't do anything. @@ -298,9 +292,7 @@ impl<'a> HashStable> for Span { /// codepoint offsets. For the purpose of the hash that's sufficient. /// Also, hashing filenames is expensive so we avoid doing it twice when the /// span starts and ends in the same file, which is almost always the case. - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { const TAG_VALID_SPAN: u8 = 0; const TAG_INVALID_SPAN: u8 = 1; const TAG_EXPANSION: u8 = 0; @@ -379,24 +371,18 @@ impl<'a> HashStable> for Span { } impl<'a> HashStable> for DelimSpan { - fn hash_stable( - &self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher, - ) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { self.open.hash_stable(hcx, hasher); self.close.hash_stable(hcx, hasher); } } -pub fn hash_stable_trait_impls<'a, W>( +pub fn hash_stable_trait_impls<'a>( hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher, + hasher: &mut StableHasher, blanket_impls: &[DefId], non_blanket_impls: &FxHashMap>, -) where - W: StableHasherResult, -{ +) { { let mut blanket_impls: SmallVec<[_; 8]> = blanket_impls .iter() diff --git a/src/librustc/ich/impls_hir.rs b/src/librustc/ich/impls_hir.rs index 8e74f1e11eb51..c0255e5b8a481 100644 --- a/src/librustc/ich/impls_hir.rs +++ b/src/librustc/ich/impls_hir.rs @@ -6,9 +6,7 @@ use crate::hir::map::DefPathHash; use crate::hir::def_id::{DefId, LocalDefId, CrateNum, CRATE_DEF_INDEX}; use crate::ich::{StableHashingContext, NodeIdHashingMode, Fingerprint}; -use rustc_data_structures::stable_hasher::{ - HashStable, ToStableHashKey, StableHasher, StableHasherResult, -}; +use rustc_data_structures::stable_hasher::{HashStable, ToStableHashKey, StableHasher}; use smallvec::SmallVec; use std::mem; use syntax::ast; @@ -16,9 +14,7 @@ use syntax::attr; impl<'a> HashStable> for DefId { #[inline] - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { hcx.def_path_hash(*self).hash_stable(hcx, hasher); } } @@ -34,9 +30,7 @@ impl<'a> ToStableHashKey> for DefId { impl<'a> HashStable> for LocalDefId { #[inline] - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { hcx.def_path_hash(self.to_def_id()).hash_stable(hcx, hasher); } } @@ -52,9 +46,7 @@ impl<'a> ToStableHashKey> for LocalDefId { impl<'a> HashStable> for CrateNum { #[inline] - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { hcx.def_path_hash(DefId { krate: *self, index: CRATE_DEF_INDEX @@ -92,9 +84,7 @@ for hir::ItemLocalId { // in "DefPath Mode". impl<'a> HashStable> for hir::ItemId { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { let hir::ItemId { id } = *self; @@ -106,9 +96,7 @@ impl<'a> HashStable> for hir::ItemId { } impl<'a> HashStable> for hir::TraitItemId { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { let hir::TraitItemId { hir_id } = * self; @@ -120,9 +108,7 @@ impl<'a> HashStable> for hir::TraitItemId { } impl<'a> HashStable> for hir::ImplItemId { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { let hir::ImplItemId { hir_id } = * self; @@ -138,9 +124,7 @@ impl_stable_hash_for!(struct ast::Label { }); impl<'a> HashStable> for hir::Ty { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { hcx.while_hashing_hir_bodies(true, |hcx| { let hir::Ty { hir_id: _, @@ -166,9 +150,7 @@ impl_stable_hash_for!(struct hir::Stmt { impl_stable_hash_for_spanned!(ast::Name); impl<'a> HashStable> for hir::Expr { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { hcx.while_hashing_hir_bodies(true, |hcx| { let hir::Expr { hir_id: _, @@ -192,9 +174,7 @@ impl_stable_hash_for!(struct ast::Ident { }); impl<'a> HashStable> for hir::TraitItem { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { let hir::TraitItem { hir_id: _, ident, @@ -216,9 +196,7 @@ impl<'a> HashStable> for hir::TraitItem { impl<'a> HashStable> for hir::ImplItem { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { let hir::ImplItem { hir_id: _, ident, @@ -248,9 +226,7 @@ impl_stable_hash_for!(enum ast::CrateSugar { }); impl<'a> HashStable> for hir::VisibilityKind { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { mem::discriminant(self).hash_stable(hcx, hasher); match *self { hir::VisibilityKind::Public | @@ -273,9 +249,7 @@ impl<'a> HashStable> for hir::VisibilityKind { impl_stable_hash_for_spanned!(hir::VisibilityKind); impl<'a> HashStable> for hir::Mod { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { let hir::Mod { inner: ref inner_span, ref item_ids, @@ -305,9 +279,7 @@ impl_stable_hash_for_spanned!(hir::Variant); impl<'a> HashStable> for hir::Item { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { let hir::Item { ident, ref attrs, @@ -328,9 +300,7 @@ impl<'a> HashStable> for hir::Item { } impl<'a> HashStable> for hir::Body { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { let hir::Body { params, value, @@ -359,9 +329,7 @@ impl<'a> ToStableHashKey> for hir::BodyId { impl<'a> HashStable> for hir::def_id::DefIndex { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { hcx.local_def_path_hash(*self).hash_stable(hcx, hasher); } } @@ -376,17 +344,13 @@ impl<'a> ToStableHashKey> for hir::def_id::DefIndex { } impl<'a> HashStable> for crate::middle::lang_items::LangItem { - fn hash_stable(&self, - _: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, _: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { ::std::hash::Hash::hash(self, hasher); } } impl<'a> HashStable> for hir::TraitCandidate { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| { let hir::TraitCandidate { def_id, @@ -418,17 +382,13 @@ impl<'a> ToStableHashKey> for hir::TraitCandidate { } impl<'hir> HashStable> for attr::InlineAttr { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'hir>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'hir>, hasher: &mut StableHasher) { mem::discriminant(self).hash_stable(hcx, hasher); } } impl<'hir> HashStable> for attr::OptimizeAttr { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'hir>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'hir>, hasher: &mut StableHasher) { mem::discriminant(self).hash_stable(hcx, hasher); } } diff --git a/src/librustc/ich/impls_syntax.rs b/src/librustc/ich/impls_syntax.rs index 91c6c968f9853..bdcf9e42ac2a8 100644 --- a/src/librustc/ich/impls_syntax.rs +++ b/src/librustc/ich/impls_syntax.rs @@ -16,14 +16,11 @@ use syntax_pos::SourceFile; use crate::hir::def_id::{DefId, CrateNum, CRATE_DEF_INDEX}; use smallvec::SmallVec; -use rustc_data_structures::stable_hasher::{HashStable, ToStableHashKey, - StableHasher, StableHasherResult}; +use rustc_data_structures::stable_hasher::{HashStable, ToStableHashKey, StableHasher}; impl<'a> HashStable> for InternedString { #[inline] - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { self.with(|s| s.hash_stable(hcx, hasher)) } } @@ -41,9 +38,7 @@ impl<'a> ToStableHashKey> for InternedString { impl<'a> HashStable> for ast::Name { #[inline] - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { self.as_str().hash_stable(hcx, hasher); } } @@ -110,9 +105,7 @@ impl_stable_hash_for!(enum ::syntax::edition::Edition { impl<'a> HashStable> for ::syntax::attr::StabilityLevel { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { mem::discriminant(self).hash_stable(hcx, hasher); match *self { ::syntax::attr::StabilityLevel::Unstable { ref reason, ref issue, ref is_soft } => { @@ -172,9 +165,7 @@ impl_stable_hash_for!(enum ::syntax::ast::StrStyle { Cooked, Raw(pounds) }); impl_stable_hash_for!(enum ::syntax::ast::AttrStyle { Outer, Inner }); impl<'a> HashStable> for [ast::Attribute] { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { if self.len() == 0 { self.len().hash_stable(hcx, hasher); return @@ -197,9 +188,7 @@ impl<'a> HashStable> for [ast::Attribute] { } impl<'a> HashStable> for ast::Path { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { self.segments.len().hash_stable(hcx, hasher); for segment in &self.segments { segment.ident.name.hash_stable(hcx, hasher); @@ -208,9 +197,7 @@ impl<'a> HashStable> for ast::Path { } impl<'a> HashStable> for ast::Attribute { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { // Make sure that these have been filtered out. debug_assert!(!self.ident().map_or(false, |ident| hcx.is_ignored_attr(ident.name))); debug_assert!(!self.is_sugared_doc); @@ -235,9 +222,7 @@ impl<'a> HashStable> for ast::Attribute { impl<'a> HashStable> for tokenstream::TokenTree { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { mem::discriminant(self).hash_stable(hcx, hasher); match *self { tokenstream::TokenTree::Token(ref token) => { @@ -256,9 +241,7 @@ for tokenstream::TokenTree { impl<'a> HashStable> for tokenstream::TokenStream { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { for sub_tt in self.trees() { sub_tt.hash_stable(hcx, hasher); } @@ -285,9 +268,7 @@ impl_stable_hash_for!(struct token::Lit { }); impl<'a> HashStable> for token::TokenKind { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { mem::discriminant(self).hash_stable(hcx, hasher); match *self { token::Eq | @@ -426,9 +407,7 @@ impl_stable_hash_for!(enum ::syntax_pos::FileName { }); impl<'a> HashStable> for SourceFile { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { let SourceFile { name: _, // We hash the smaller name_hash instead of this name_hash, @@ -502,11 +481,7 @@ fn stable_non_narrow_char(swc: ::syntax_pos::NonNarrowChar, } impl<'tcx> HashStable> for feature_gate::Features { - fn hash_stable( - &self, - hcx: &mut StableHashingContext<'tcx>, - hasher: &mut StableHasher, - ) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'tcx>, hasher: &mut StableHasher) { // Unfortunately we cannot exhaustively list fields here, since the // struct is macro generated. self.declared_lang_features.hash_stable(hcx, hasher); diff --git a/src/librustc/ich/impls_ty.rs b/src/librustc/ich/impls_ty.rs index 56b1560772997..c643baf11254c 100644 --- a/src/librustc/ich/impls_ty.rs +++ b/src/librustc/ich/impls_ty.rs @@ -3,8 +3,7 @@ use crate::ich::{Fingerprint, StableHashingContext, NodeIdHashingMode}; use rustc_data_structures::fx::FxHashMap; -use rustc_data_structures::stable_hasher::{HashStable, ToStableHashKey, - StableHasher, StableHasherResult}; +use rustc_data_structures::stable_hasher::{HashStable, ToStableHashKey, StableHasher}; use std::cell::RefCell; use std::mem; use crate::middle::region; @@ -15,9 +14,7 @@ impl<'a, 'tcx, T> HashStable> for &'tcx ty::List where T: HashStable>, { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { thread_local! { static CACHE: RefCell> = RefCell::new(Default::default()); @@ -57,18 +54,14 @@ where } impl<'a, 'tcx> HashStable> for ty::subst::GenericArg<'tcx> { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { self.unpack().hash_stable(hcx, hasher); } } impl<'a> HashStable> for ty::RegionKind { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { mem::discriminant(self).hash_stable(hcx, hasher); match *self { ty::ReErased | @@ -112,31 +105,21 @@ for ty::RegionKind { impl<'a> HashStable> for ty::RegionVid { #[inline] - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { self.index().hash_stable(hcx, hasher); } } impl<'a, 'tcx> HashStable> for ty::ConstVid<'tcx> { #[inline] - fn hash_stable( - &self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher, - ) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { self.index.hash_stable(hcx, hasher); } } impl<'tcx> HashStable> for ty::BoundVar { #[inline] - fn hash_stable( - &self, - hcx: &mut StableHashingContext<'tcx>, - hasher: &mut StableHasher, - ) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'tcx>, hasher: &mut StableHasher) { self.index().hash_stable(hcx, hasher); } } @@ -145,20 +128,14 @@ impl<'a, T> HashStable> for ty::Binder where T: HashStable>, { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { self.skip_binder().hash_stable(hcx, hasher); } } // AllocIds get resolved to whatever they point to (to be stable) impl<'a> HashStable> for mir::interpret::AllocId { - fn hash_stable( - &self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher, - ) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { ty::tls::with_opt(|tcx| { trace!("hashing {:?}", *self); let tcx = tcx.expect("can't hash AllocIds during hir lowering"); @@ -174,11 +151,7 @@ for mir::interpret::Relocations where Tag: HashStable>, { - fn hash_stable( - &self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher, - ) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { self.len().hash_stable(hcx, hasher); for reloc in self.iter() { reloc.hash_stable(hcx, hasher); @@ -201,9 +174,7 @@ impl<'a> ToStableHashKey> for region::Scope { } impl<'a> HashStable> for ty::TyVid { - fn hash_stable(&self, - _hcx: &mut StableHashingContext<'a>, - _hasher: &mut StableHasher) { + fn hash_stable(&self, _hcx: &mut StableHashingContext<'a>, _hasher: &mut StableHasher) { // `TyVid` values are confined to an inference context and hence // should not be hashed. bug!("ty::TyKind::hash_stable() - can't hash a TyVid {:?}.", *self) @@ -211,9 +182,7 @@ impl<'a> HashStable> for ty::TyVid { } impl<'a> HashStable> for ty::IntVid { - fn hash_stable(&self, - _hcx: &mut StableHashingContext<'a>, - _hasher: &mut StableHasher) { + fn hash_stable(&self, _hcx: &mut StableHashingContext<'a>, _hasher: &mut StableHasher) { // `IntVid` values are confined to an inference context and hence // should not be hashed. bug!("ty::TyKind::hash_stable() - can't hash an IntVid {:?}.", *self) @@ -221,9 +190,7 @@ impl<'a> HashStable> for ty::IntVid { } impl<'a> HashStable> for ty::FloatVid { - fn hash_stable(&self, - _hcx: &mut StableHashingContext<'a>, - _hasher: &mut StableHasher) { + fn hash_stable(&self, _hcx: &mut StableHashingContext<'a>, _hasher: &mut StableHasher) { // `FloatVid` values are confined to an inference context and hence // should not be hashed. bug!("ty::TyKind::hash_stable() - can't hash a FloatVid {:?}.", *self) @@ -234,18 +201,14 @@ impl<'a, T> HashStable> for ty::steal::Steal where T: HashStable>, { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { self.borrow().hash_stable(hcx, hasher); } } impl<'a> HashStable> for crate::middle::privacy::AccessLevels { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| { let crate::middle::privacy::AccessLevels { ref map diff --git a/src/librustc/lint/levels.rs b/src/librustc/lint/levels.rs index 16d19e41db4f4..28afe9730a034 100644 --- a/src/librustc/lint/levels.rs +++ b/src/librustc/lint/levels.rs @@ -8,8 +8,7 @@ use crate::lint::{self, Lint, LintId, Level, LintSource}; use crate::session::Session; use crate::util::nodemap::FxHashMap; use errors::{Applicability, DiagnosticBuilder}; -use rustc_data_structures::stable_hasher::{HashStable, ToStableHashKey, - StableHasher, StableHasherResult}; +use rustc_data_structures::stable_hasher::{HashStable, ToStableHashKey, StableHasher}; use syntax::ast; use syntax::attr; use syntax::feature_gate; @@ -526,9 +525,7 @@ impl LintLevelMap { impl<'a> HashStable> for LintLevelMap { #[inline] - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { let LintLevelMap { ref sets, ref id_to_set, @@ -567,9 +564,7 @@ impl<'a> HashStable> for LintLevelMap { impl HashStable for LintId { #[inline] - fn hash_stable(&self, - hcx: &mut HCX, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) { self.lint_name_raw().hash_stable(hcx, hasher); } } diff --git a/src/librustc/macros.rs b/src/librustc/macros.rs index 09fa924efc7ab..256a08d7e90c3 100644 --- a/src/librustc/macros.rs +++ b/src/librustc/macros.rs @@ -97,9 +97,9 @@ macro_rules! impl_stable_hash_for { where $($T: ::rustc_data_structures::stable_hasher::HashStable<$crate::ich::StableHashingContext<'a>>),* { #[inline] - fn hash_stable(&self, - __ctx: &mut $crate::ich::StableHashingContext<'a>, - __hasher: &mut ::rustc_data_structures::stable_hasher::StableHasher) { + fn hash_stable(&self, + __ctx: &mut $crate::ich::StableHashingContext<'a>, + __hasher: &mut ::rustc_data_structures::stable_hasher::StableHasher) { use $enum_path::*; ::std::mem::discriminant(self).hash_stable(__ctx, __hasher); @@ -128,9 +128,9 @@ macro_rules! impl_stable_hash_for { where $($T: ::rustc_data_structures::stable_hasher::HashStable<$crate::ich::StableHashingContext<'a>>),* { #[inline] - fn hash_stable(&self, - __ctx: &mut $crate::ich::StableHashingContext<'a>, - __hasher: &mut ::rustc_data_structures::stable_hasher::StableHasher) { + fn hash_stable(&self, + __ctx: &mut $crate::ich::StableHashingContext<'a>, + __hasher: &mut ::rustc_data_structures::stable_hasher::StableHasher) { let $struct_name { $(ref $field),* } = *self; @@ -153,9 +153,9 @@ macro_rules! impl_stable_hash_for { where $($T: ::rustc_data_structures::stable_hasher::HashStable<$crate::ich::StableHashingContext<'a>>),* { #[inline] - fn hash_stable(&self, - __ctx: &mut $crate::ich::StableHashingContext<'a>, - __hasher: &mut ::rustc_data_structures::stable_hasher::StableHasher) { + fn hash_stable(&self, + __ctx: &mut $crate::ich::StableHashingContext<'a>, + __hasher: &mut ::rustc_data_structures::stable_hasher::StableHasher) { let $struct_name ( $(ref $field),* ) = *self; @@ -173,9 +173,9 @@ macro_rules! impl_stable_hash_for_spanned { impl HashStable> for ::syntax::source_map::Spanned<$T> { #[inline] - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, + hcx: &mut StableHashingContext<'a>, + hasher: &mut StableHasher) { self.node.hash_stable(hcx, hasher); self.span.hash_stable(hcx, hasher); } diff --git a/src/librustc/middle/exported_symbols.rs b/src/librustc/middle/exported_symbols.rs index 202788093046a..4d14299751c3d 100644 --- a/src/librustc/middle/exported_symbols.rs +++ b/src/librustc/middle/exported_symbols.rs @@ -1,7 +1,6 @@ use crate::hir::def_id::{DefId, LOCAL_CRATE}; use crate::ich::StableHashingContext; -use rustc_data_structures::stable_hasher::{StableHasher, HashStable, - StableHasherResult}; +use rustc_data_structures::stable_hasher::{StableHasher, HashStable}; use std::cmp; use std::mem; use crate::ty::{self, TyCtxt}; @@ -94,9 +93,7 @@ pub fn metadata_symbol_name(tcx: TyCtxt<'_>) -> String { } impl<'a, 'tcx> HashStable> for ExportedSymbol<'tcx> { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { mem::discriminant(self).hash_stable(hcx, hasher); match *self { ExportedSymbol::NonGeneric(def_id) => { diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index 28bf88321ae66..05e4d11c3f990 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -17,7 +17,7 @@ use crate::ty::{self, DefIdTree, TyCtxt}; use crate::ty::query::Providers; use rustc_data_structures::indexed_vec::Idx; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableHasherResult}; +use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_macros::HashStable; use syntax::source_map; use syntax_pos::{Span, DUMMY_SP}; @@ -1491,9 +1491,7 @@ pub fn provide(providers: &mut Providers<'_>) { } impl<'a> HashStable> for ScopeTree { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { let ScopeTree { root_body, root_parent, diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 94a85a97d36c9..31d250fa08215 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -764,13 +764,6 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { }); } } - hir::TyKind::CVarArgs(ref lt) => { - // Resolve the generated lifetime for the C-variadic arguments. - // The lifetime is generated in AST -> HIR lowering. - if lt.name.is_elided() { - self.resolve_elided_lifetimes(vec![lt]) - } - } _ => intravisit::walk_ty(self, ty), } } @@ -2378,7 +2371,6 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { self.visit_lifetime(lifetime); } } - hir::TyKind::CVarArgs(_) => {} _ => { intravisit::walk_ty(self, ty); } diff --git a/src/librustc/mir/cache.rs b/src/librustc/mir/cache.rs index 1f604877841a7..d8d3383903d4b 100644 --- a/src/librustc/mir/cache.rs +++ b/src/librustc/mir/cache.rs @@ -1,6 +1,6 @@ use rustc_data_structures::indexed_vec::IndexVec; use rustc_data_structures::sync::{RwLock, MappedReadGuard, ReadGuard}; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableHasherResult}; +use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_serialize::{Encodable, Encoder, Decodable, Decoder}; use crate::ich::StableHashingContext; use crate::mir::{Body, BasicBlock}; @@ -24,9 +24,7 @@ impl rustc_serialize::Decodable for Cache { } impl<'a> HashStable> for Cache { - fn hash_stable(&self, - _: &mut StableHashingContext<'a>, - _: &mut StableHasher) { + fn hash_stable(&self, _: &mut StableHashingContext<'a>, _: &mut StableHasher) { // Do nothing. } } diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index cf82184ab032c..5e12c4dfe75a5 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -682,14 +682,10 @@ impl_stable_hash_for!(enum self::MirPhase { mod binding_form_impl { use crate::ich::StableHashingContext; - use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableHasherResult}; + use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; impl<'a, 'tcx> HashStable> for super::BindingForm<'tcx> { - fn hash_stable( - &self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher, - ) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { use super::BindingForm::*; ::std::mem::discriminant(self).hash_stable(hcx, hasher); diff --git a/src/librustc/mir/mono.rs b/src/librustc/mir/mono.rs index a061e6f48f4c0..313b2a5d50a30 100644 --- a/src/librustc/mir/mono.rs +++ b/src/librustc/mir/mono.rs @@ -8,8 +8,7 @@ use crate::util::nodemap::FxHashMap; use crate::ty::print::obsolete::DefPathBasedNames; use crate::dep_graph::{WorkProductId, DepNode, WorkProduct, DepConstructor}; use rustc_data_structures::base_n; -use rustc_data_structures::stable_hasher::{HashStable, StableHasherResult, - StableHasher}; +use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use crate::ich::{Fingerprint, StableHashingContext, NodeIdHashingMode}; use crate::session::config::OptLevel; use std::fmt; @@ -223,9 +222,7 @@ impl<'tcx> MonoItem<'tcx> { } impl<'a, 'tcx> HashStable> for MonoItem<'tcx> { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { ::std::mem::discriminant(self).hash_stable(hcx, hasher); match *self { @@ -419,9 +416,7 @@ impl<'tcx> CodegenUnit<'tcx> { } impl<'a, 'tcx> HashStable> for CodegenUnit<'tcx> { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { let CodegenUnit { ref items, name, diff --git a/src/librustc/traits/query/outlives_bounds.rs b/src/librustc/traits/query/outlives_bounds.rs index f5808b6b5faaf..eee084b78963c 100644 --- a/src/librustc/traits/query/outlives_bounds.rs +++ b/src/librustc/traits/query/outlives_bounds.rs @@ -7,8 +7,7 @@ use crate::traits::query::NoSolution; use crate::ty::{self, Ty, TyCtxt}; use crate::ich::StableHashingContext; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher, - StableHasherResult}; +use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use std::mem; /// Outlives bounds are relationships between generic parameters, @@ -43,9 +42,7 @@ EnumTypeFoldableImpl! { } impl<'a, 'tcx> HashStable> for OutlivesBound<'tcx> { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { mem::discriminant(self).hash_stable(hcx, hasher); match *self { OutlivesBound::RegionSubRegion(ref a, ref b) => { diff --git a/src/librustc/traits/specialize/specialization_graph.rs b/src/librustc/traits/specialize/specialization_graph.rs index ce0f43021378b..43f558d64430e 100644 --- a/src/librustc/traits/specialize/specialization_graph.rs +++ b/src/librustc/traits/specialize/specialization_graph.rs @@ -2,8 +2,7 @@ use super::OverlapError; use crate::hir::def_id::DefId; use crate::ich::{self, StableHashingContext}; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher, - StableHasherResult}; +use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use crate::traits; use crate::ty::{self, TyCtxt, TypeFoldable}; use crate::ty::fast_reject::{self, SimplifiedType}; @@ -512,9 +511,7 @@ pub fn ancestors( } impl<'a> HashStable> for Children { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { let Children { ref nonblanket_impls, ref blanket_impls, diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index efbc820365e2d..6c5d9a6dfdf22 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -50,7 +50,7 @@ use errors::DiagnosticBuilder; use arena::SyncDroplessArena; use smallvec::SmallVec; use rustc_data_structures::stable_hasher::{ - HashStable, StableHasher, StableHasherResult, StableVec, hash_stable_hashmap, + HashStable, StableHasher, StableVec, hash_stable_hashmap, }; use rustc_data_structures::indexed_vec::{Idx, IndexVec}; use rustc_data_structures::sharded::ShardedHashMap; @@ -705,9 +705,7 @@ impl<'tcx> TypeckTables<'tcx> { } impl<'a, 'tcx> HashStable> for TypeckTables<'tcx> { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { let ty::TypeckTables { local_id_root, ref type_dependent_defs, diff --git a/src/librustc/ty/fast_reject.rs b/src/librustc/ty/fast_reject.rs index 7d6ae3f815af1..038b54f1f26dd 100644 --- a/src/librustc/ty/fast_reject.rs +++ b/src/librustc/ty/fast_reject.rs @@ -1,7 +1,6 @@ use crate::hir::def_id::DefId; use crate::ich::StableHashingContext; -use rustc_data_structures::stable_hasher::{StableHasher, StableHasherResult, - HashStable}; +use rustc_data_structures::stable_hasher::{StableHasher, HashStable}; use std::fmt::Debug; use std::hash::Hash; use std::mem; @@ -158,9 +157,7 @@ impl<'a, D> HashStable> for SimplifiedTypeGen where D: Copy + Debug + Ord + Eq + Hash + HashStable>, { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { mem::discriminant(self).hash_stable(hcx, hasher); match *self { BoolSimplifiedType | diff --git a/src/librustc/ty/layout.rs b/src/librustc/ty/layout.rs index 3accbdf9bcbc6..6ab4f4c6112f7 100644 --- a/src/librustc/ty/layout.rs +++ b/src/librustc/ty/layout.rs @@ -19,13 +19,12 @@ use crate::ty::GeneratorSubsts; use crate::ty::subst::Subst; use rustc_data_structures::bit_set::BitSet; use rustc_data_structures::indexed_vec::{IndexVec, Idx}; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher, - StableHasherResult}; +use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; pub use rustc_target::abi::*; use rustc_target::spec::{HasTargetSpec, abi::Abi as SpecAbi}; use rustc_target::abi::call::{ - ArgAttribute, ArgAttributes, ArgType, Conv, FnType, IgnoreMode, PassMode, Reg, RegKind + ArgAttribute, ArgAttributes, ArgType, Conv, FnType, PassMode, Reg, RegKind }; pub trait IntegerExt { @@ -2323,9 +2322,7 @@ where } impl<'a> HashStable> for Variants { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { use crate::ty::layout::Variants::*; mem::discriminant(self).hash_stable(hcx, hasher); @@ -2349,9 +2346,7 @@ impl<'a> HashStable> for Variants { } impl<'a> HashStable> for DiscriminantKind { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { use crate::ty::layout::DiscriminantKind::*; mem::discriminant(self).hash_stable(hcx, hasher); @@ -2372,9 +2367,7 @@ impl<'a> HashStable> for DiscriminantKind { } impl<'a> HashStable> for FieldPlacement { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { use crate::ty::layout::FieldPlacement::*; mem::discriminant(self).hash_stable(hcx, hasher); @@ -2395,19 +2388,13 @@ impl<'a> HashStable> for FieldPlacement { } impl<'a> HashStable> for VariantIdx { - fn hash_stable( - &self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher, - ) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { self.as_u32().hash_stable(hcx, hasher) } } impl<'a> HashStable> for Abi { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { use crate::ty::layout::Abi::*; mem::discriminant(self).hash_stable(hcx, hasher); @@ -2432,9 +2419,7 @@ impl<'a> HashStable> for Abi { } impl<'a> HashStable> for Scalar { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { let Scalar { value, ref valid_range } = *self; value.hash_stable(hcx, hasher); valid_range.start().hash_stable(hcx, hasher); @@ -2476,29 +2461,19 @@ impl_stable_hash_for!(struct crate::ty::layout::AbiAndPrefAlign { }); impl<'tcx> HashStable> for Align { - fn hash_stable( - &self, - hcx: &mut StableHashingContext<'tcx>, - hasher: &mut StableHasher, - ) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'tcx>, hasher: &mut StableHasher) { self.bytes().hash_stable(hcx, hasher); } } impl<'tcx> HashStable> for Size { - fn hash_stable( - &self, - hcx: &mut StableHashingContext<'tcx>, - hasher: &mut StableHasher, - ) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'tcx>, hasher: &mut StableHasher) { self.bytes().hash_stable(hcx, hasher); } } impl<'a, 'tcx> HashStable> for LayoutError<'tcx> { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { use crate::ty::layout::LayoutError::*; mem::discriminant(self).hash_stable(hcx, hasher); @@ -2722,14 +2697,6 @@ where } }; - // Store the index of the last argument. This is useful for working with - // C-compatible variadic arguments. - let last_arg_idx = if sig.inputs().is_empty() { - None - } else { - Some(sig.inputs().len() - 1) - }; - let arg_of = |ty: Ty<'tcx>, arg_idx: Option| { let is_return = arg_idx.is_none(); let mut arg = mk_arg_type(ty, arg_idx); @@ -2739,30 +2706,7 @@ where // The same is true for s390x-unknown-linux-gnu // and sparc64-unknown-linux-gnu. if is_return || rust_abi || (!win_x64_gnu && !linux_s390x && !linux_sparc64) { - arg.mode = PassMode::Ignore(IgnoreMode::Zst); - } - } - - // If this is a C-variadic function, this is not the return value, - // and there is one or more fixed arguments; ensure that the `VaListImpl` - // is ignored as an argument. - if sig.c_variadic { - match (last_arg_idx, arg_idx) { - (Some(last_idx), Some(cur_idx)) if last_idx == cur_idx => { - let va_list_did = match cx.tcx().lang_items().va_list() { - Some(did) => did, - None => bug!("`va_list` lang item required for C-variadic functions"), - }; - match ty.kind { - ty::Adt(def, _) if def.did == va_list_did => { - // This is the "spoofed" `VaListImpl`. Set the arguments mode - // so that it will be ignored. - arg.mode = PassMode::Ignore(IgnoreMode::CVarArgs); - } - _ => (), - } - } - _ => {} + arg.mode = PassMode::Ignore; } } diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 0e9600449f62c..731aca854a422 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -52,8 +52,7 @@ use syntax_pos::Span; use smallvec; use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::indexed_vec::{Idx, IndexVec}; -use rustc_data_structures::stable_hasher::{StableHasher, StableHasherResult, - HashStable}; +use rustc_data_structures::stable_hasher::{StableHasher, HashStable}; use crate::hir; @@ -577,9 +576,7 @@ impl<'tcx> TyS<'tcx> { } impl<'a, 'tcx> HashStable> for ty::TyS<'tcx> { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { let ty::TyS { ref kind, @@ -1633,11 +1630,7 @@ impl<'a, T> HashStable> for Placeholder where T: HashStable>, { - fn hash_stable( - &self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher - ) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { self.universe.hash_stable(hcx, hasher); self.name.hash_stable(hcx, hasher); } @@ -1774,9 +1767,7 @@ impl<'a, 'tcx, T> HashStable> for ParamEnvAnd<'tcx, T> where T: HashStable>, { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { let ParamEnvAnd { ref param_env, ref value @@ -2010,9 +2001,7 @@ impl<'tcx> rustc_serialize::UseSpecializedDecodable for &'tcx AdtDef {} impl<'a> HashStable> for AdtDef { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { thread_local! { static CACHE: RefCell> = Default::default(); } diff --git a/src/librustc/ty/query/job.rs b/src/librustc/ty/query/job.rs index a25560ff762a1..391ea762a083b 100644 --- a/src/librustc/ty/query/job.rs +++ b/src/librustc/ty/query/job.rs @@ -334,13 +334,13 @@ fn pick_query<'a, 'tcx, T, F: Fn(&T) -> (Span, Lrc>)>( let mut hcx = tcx.create_stable_hashing_context(); queries.iter().min_by_key(|v| { let (span, query) = f(v); - let mut stable_hasher = StableHasher::::new(); + let mut stable_hasher = StableHasher::new(); query.info.query.hash_stable(&mut hcx, &mut stable_hasher); // Prefer entry points which have valid spans for nicer error messages // We add an integer to the tuple ensuring that entry points // with valid spans are picked first let span_cmp = if span == DUMMY_SP { 1 } else { 0 }; - (span_cmp, stable_hasher.finish()) + (span_cmp, stable_hasher.finish::()) }).unwrap() } diff --git a/src/librustc/ty/query/plumbing.rs b/src/librustc/ty/query/plumbing.rs index d247c0f9f69f3..32858d30b0cc4 100644 --- a/src/librustc/ty/query/plumbing.rs +++ b/src/librustc/ty/query/plumbing.rs @@ -15,6 +15,7 @@ use errors::DiagnosticBuilder; use errors::Level; use errors::Diagnostic; use errors::FatalError; +use errors::Handler; use rustc_data_structures::fx::{FxHashMap}; use rustc_data_structures::sync::{Lrc, Lock}; use rustc_data_structures::sharded::Sharded; @@ -321,9 +322,12 @@ impl<'tcx> TyCtxt<'tcx> { }) } - pub fn try_print_query_stack() { + pub fn try_print_query_stack(handler: &Handler) { eprintln!("query stack during panic:"); + // Be careful reyling on global state here: this code is called from + // a panic hook, which means that the global `Handler` may be in a weird + // state if it was responsible for triggering the panic. tls::with_context_opt(|icx| { if let Some(icx) = icx { let mut current_query = icx.query.clone(); @@ -336,7 +340,7 @@ impl<'tcx> TyCtxt<'tcx> { query.info.query.name(), query.info.query.describe(icx.tcx))); diag.span = icx.tcx.sess.source_map().def_span(query.info.span).into(); - icx.tcx.sess.diagnostic().force_print_diagnostic(diag); + handler.force_print_diagnostic(diag); current_query = query.parent.clone(); i += 1; @@ -716,7 +720,6 @@ macro_rules! define_queries_inner { use rustc_data_structures::sharded::Sharded; use crate::{ rustc_data_structures::stable_hasher::HashStable, - rustc_data_structures::stable_hasher::StableHasherResult, rustc_data_structures::stable_hasher::StableHasher, ich::StableHashingContext }; @@ -925,9 +928,7 @@ macro_rules! define_queries_inner { } impl<'a, $tcx> HashStable> for Query<$tcx> { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { mem::discriminant(self).hash_stable(hcx, hasher); match *self { $(Query::$name(key) => key.hash_stable(hcx, hasher),)* diff --git a/src/librustc/ty/trait_def.rs b/src/librustc/ty/trait_def.rs index 2bb9c258f8b67..49ec908231548 100644 --- a/src/librustc/ty/trait_def.rs +++ b/src/librustc/ty/trait_def.rs @@ -8,8 +8,7 @@ use crate::ty::fold::TypeFoldable; use crate::ty::{Ty, TyCtxt}; use rustc_data_structures::fx::FxHashMap; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher, - StableHasherResult}; +use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_macros::HashStable; /// A trait's definition with type information. @@ -194,9 +193,7 @@ pub(super) fn trait_impls_of_provider( } impl<'a> HashStable> for TraitImpls { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { let TraitImpls { ref blanket_impls, ref non_blanket_impls, diff --git a/src/librustc_codegen_llvm/abi.rs b/src/librustc_codegen_llvm/abi.rs index 2ca517dc3b1a7..ae5cfc4d97b59 100644 --- a/src/librustc_codegen_llvm/abi.rs +++ b/src/librustc_codegen_llvm/abi.rs @@ -264,7 +264,7 @@ impl ArgTypeExt<'ll, 'tcx> for ArgType<'tcx, Ty<'tcx>> { val }; match self.mode { - PassMode::Ignore(_) => {} + PassMode::Ignore => {} PassMode::Pair(..) => { OperandValue::Pair(next(), next()).store(bx, dst); } @@ -319,9 +319,7 @@ impl<'tcx> FnTypeLlvmExt<'tcx> for FnType<'tcx, Ty<'tcx>> { ); let llreturn_ty = match self.ret.mode { - PassMode::Ignore(IgnoreMode::Zst) => cx.type_void(), - PassMode::Ignore(IgnoreMode::CVarArgs) => - bug!("`va_list` should never be a return type"), + PassMode::Ignore => cx.type_void(), PassMode::Direct(_) | PassMode::Pair(..) => { self.ret.layout.immediate_llvm_type(cx) } @@ -339,7 +337,7 @@ impl<'tcx> FnTypeLlvmExt<'tcx> for FnType<'tcx, Ty<'tcx>> { } let llarg_ty = match arg.mode { - PassMode::Ignore(_) => continue, + PassMode::Ignore => continue, PassMode::Direct(_) => arg.layout.immediate_llvm_type(cx), PassMode::Pair(..) => { llargument_tys.push(arg.layout.scalar_pair_element_llvm_type(cx, 0, true)); @@ -408,7 +406,7 @@ impl<'tcx> FnTypeLlvmExt<'tcx> for FnType<'tcx, Ty<'tcx>> { apply(&ArgAttributes::new(), None); } match arg.mode { - PassMode::Ignore(_) => {} + PassMode::Ignore => {} PassMode::Direct(ref attrs) | PassMode::Indirect(ref attrs, None) => apply(attrs, Some(arg.layout.llvm_type(cx))), PassMode::Indirect(ref attrs, Some(ref extra_attrs)) => { @@ -455,7 +453,7 @@ impl<'tcx> FnTypeLlvmExt<'tcx> for FnType<'tcx, Ty<'tcx>> { apply(&ArgAttributes::new(), None); } match arg.mode { - PassMode::Ignore(_) => {} + PassMode::Ignore => {} PassMode::Direct(ref attrs) | PassMode::Indirect(ref attrs, None) => apply(attrs, Some(arg.layout.llvm_type(bx))), PassMode::Indirect(ref attrs, Some(ref extra_attrs)) => { diff --git a/src/librustc_codegen_llvm/debuginfo/metadata.rs b/src/librustc_codegen_llvm/debuginfo/metadata.rs index 1696e56c01eff..544d6794e2191 100644 --- a/src/librustc_codegen_llvm/debuginfo/metadata.rs +++ b/src/librustc_codegen_llvm/debuginfo/metadata.rs @@ -187,7 +187,7 @@ impl TypeMap<'ll, 'tcx> { // The hasher we are using to generate the UniqueTypeId. We want // something that provides more than the 64 bits of the DefaultHasher. - let mut hasher = StableHasher::::new(); + let mut hasher = StableHasher::new(); let mut hcx = cx.tcx.create_stable_hashing_context(); let type_ = cx.tcx.erase_regions(&type_); hcx.while_hashing_spans(false, |hcx| { @@ -195,7 +195,7 @@ impl TypeMap<'ll, 'tcx> { type_.hash_stable(hcx, &mut hasher); }); }); - let unique_type_id = hasher.finish().to_hex(); + let unique_type_id = hasher.finish::().to_hex(); let key = self.unique_id_interner.intern(&unique_type_id); self.type_to_unique_id.insert(type_, UniqueTypeId(key)); diff --git a/src/librustc_codegen_ssa/common.rs b/src/librustc_codegen_ssa/common.rs index 6376512ca4025..e3aa35ef4eb5e 100644 --- a/src/librustc_codegen_ssa/common.rs +++ b/src/librustc_codegen_ssa/common.rs @@ -109,14 +109,11 @@ pub enum TypeKind { // for now we content ourselves with providing a no-op HashStable // implementation for CGUs. mod temp_stable_hash_impls { - use rustc_data_structures::stable_hasher::{StableHasherResult, StableHasher, - HashStable}; + use rustc_data_structures::stable_hasher::{StableHasher, HashStable}; use crate::ModuleCodegen; impl HashStable for ModuleCodegen { - fn hash_stable(&self, - _: &mut HCX, - _: &mut StableHasher) { + fn hash_stable(&self, _: &mut HCX, _: &mut StableHasher) { // do nothing } } diff --git a/src/librustc_codegen_ssa/mir/block.rs b/src/librustc_codegen_ssa/mir/block.rs index 3069199a21256..7ebdfbdcdeb2d 100644 --- a/src/librustc_codegen_ssa/mir/block.rs +++ b/src/librustc_codegen_ssa/mir/block.rs @@ -1,9 +1,10 @@ +use rustc_data_structures::indexed_vec::Idx; use rustc::middle::lang_items; use rustc::ty::{self, Ty, TypeFoldable, Instance}; use rustc::ty::layout::{self, LayoutOf, HasTyCtxt, FnTypeExt}; use rustc::mir::{self, Place, PlaceBase, Static, StaticKind}; use rustc::mir::interpret::PanicInfo; -use rustc_target::abi::call::{ArgType, FnType, PassMode, IgnoreMode}; +use rustc_target::abi::call::{ArgType, FnType, PassMode}; use rustc_target::spec::abi::Abi; use crate::base; use crate::MemFlags; @@ -224,14 +225,15 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { } fn codegen_return_terminator(&mut self, mut bx: Bx) { + // Call `va_end` if this is the definition of a C-variadic function. if self.fn_ty.c_variadic { - match self.va_list_ref { - Some(va_list) => { + // The `VaList` "spoofed" argument is just after all the real arguments. + let va_list_arg_idx = self.fn_ty.args.len(); + match self.locals[mir::Local::new(1 + va_list_arg_idx)] { + LocalRef::Place(va_list) => { bx.va_end(va_list.llval); } - None => { - bug!("C-variadic function must have a `va_list_ref`"); - } + _ => bug!("C-variadic function must have a `VaList` place"), } } if self.fn_ty.ret.layout.abi.is_uninhabited() { @@ -242,15 +244,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { return; } let llval = match self.fn_ty.ret.mode { - PassMode::Ignore(IgnoreMode::Zst) | PassMode::Indirect(..) => { + PassMode::Ignore | PassMode::Indirect(..) => { bx.ret_void(); return; } - PassMode::Ignore(IgnoreMode::CVarArgs) => { - bug!("C-variadic arguments should never be the return type"); - } - PassMode::Direct(_) | PassMode::Pair(..) => { let op = self.codegen_consume(&mut bx, &mir::Place::return_place().as_ref()); @@ -502,10 +500,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { return; } - // The "spoofed" `VaListImpl` added to a C-variadic functions signature - // should not be included in the `extra_args` calculation. - let extra_args_start_idx = sig.inputs().len() - if sig.c_variadic { 1 } else { 0 }; - let extra_args = &args[extra_args_start_idx..]; + let extra_args = &args[sig.inputs().len()..]; let extra_args = extra_args.iter().map(|op_arg| { let op_ty = op_arg.ty(self.mir, bx.tcx()); self.monomorphize(&op_ty) @@ -691,26 +686,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { (&args[..], None) }; - // Useful determining if the current argument is the "spoofed" `VaListImpl` - let last_arg_idx = if sig.inputs().is_empty() { - None - } else { - Some(sig.inputs().len() - 1) - }; 'make_args: for (i, arg) in first_args.iter().enumerate() { - // If this is a C-variadic function the function signature contains - // an "spoofed" `VaListImpl`. This argument is ignored, but we need to - // populate it with a dummy operand so that the users real arguments - // are not overwritten. - let i = if sig.c_variadic && last_arg_idx.map(|x| i >= x).unwrap_or(false) { - if i + 1 < fn_ty.args.len() { - i + 1 - } else { - break 'make_args - } - } else { - i - }; let mut op = self.codegen_operand(&mut bx, arg); if let (0, Some(ty::InstanceDef::Virtual(_, idx))) = (i, def) { diff --git a/src/librustc_codegen_ssa/mir/mod.rs b/src/librustc_codegen_ssa/mir/mod.rs index c341c0685c6a7..4f3a8bdb540b5 100644 --- a/src/librustc_codegen_ssa/mir/mod.rs +++ b/src/librustc_codegen_ssa/mir/mod.rs @@ -2,7 +2,7 @@ use rustc::ty::{self, Ty, TypeFoldable, UpvarSubsts, Instance}; use rustc::ty::layout::{TyLayout, HasTyCtxt, FnTypeExt}; use rustc::mir::{self, Body}; use rustc::session::config::DebugInfo; -use rustc_target::abi::call::{FnType, PassMode, IgnoreMode}; +use rustc_target::abi::call::{FnType, PassMode}; use rustc_target::abi::{Variants, VariantIdx}; use crate::base; use crate::debuginfo::{self, VariableAccess, VariableKind, FunctionDebugContext}; @@ -81,10 +81,6 @@ pub struct FunctionCx<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> { /// Debug information for MIR scopes. scopes: IndexVec>, - - /// If this function is a C-variadic function, this contains the `PlaceRef` of the - /// "spoofed" `VaListImpl`. - va_list_ref: Option>, } impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { @@ -236,18 +232,13 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( scopes, locals: IndexVec::new(), debug_context, - va_list_ref: None, }; let memory_locals = analyze::non_ssa_locals(&fx); // Allocate variable and temp allocas fx.locals = { - // FIXME(dlrobertson): This is ugly. Find a better way of getting the `PlaceRef` or - // `LocalRef` from `arg_local_refs` - let mut va_list_ref = None; - let args = arg_local_refs(&mut bx, &fx, &memory_locals, &mut va_list_ref); - fx.va_list_ref = va_list_ref; + let args = arg_local_refs(&mut bx, &fx, &memory_locals); let mut allocate_local = |local| { let decl = &mir.local_decls[local]; @@ -426,7 +417,6 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( bx: &mut Bx, fx: &FunctionCx<'a, 'tcx, Bx>, memory_locals: &BitSet, - va_list_ref: &mut Option>, ) -> Vec> { let mir = fx.mir; let tcx = fx.cx.tcx(); @@ -441,15 +431,6 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( None }; - // Store the index of the last argument. This is used to - // call va_start on the va_list instead of attempting - // to store_fn_arg. - let last_arg_idx = if fx.fn_ty.args.is_empty() { - None - } else { - Some(fx.fn_ty.args.len() - 1) - }; - mir.args_iter().enumerate().map(|(arg_index, local)| { let arg_decl = &mir.local_decls[local]; @@ -503,6 +484,31 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( return LocalRef::Place(place); } + if fx.fn_ty.c_variadic && arg_index == fx.fn_ty.args.len() { + let arg_ty = fx.monomorphize(&arg_decl.ty); + + let va_list = PlaceRef::alloca(bx, bx.layout_of(arg_ty)); + bx.set_var_name(va_list.llval, name); + bx.va_start(va_list.llval); + + arg_scope.map(|scope| { + let variable_access = VariableAccess::DirectVariable { + alloca: va_list.llval + }; + bx.declare_local( + &fx.debug_context, + arg_decl.name.unwrap_or(kw::Invalid), + va_list.layout.ty, + scope, + variable_access, + VariableKind::ArgumentVariable(arg_index + 1), + DUMMY_SP + ); + }); + + return LocalRef::Place(va_list); + } + let arg = &fx.fn_ty.args[idx]; idx += 1; if arg.pad.is_some() { @@ -515,10 +521,9 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( // of putting everything in allocas just so we can use llvm.dbg.declare. let local = |op| LocalRef::Operand(Some(op)); match arg.mode { - PassMode::Ignore(IgnoreMode::Zst) => { + PassMode::Ignore => { return local(OperandRef::new_zst(bx, arg.layout)); } - PassMode::Ignore(IgnoreMode::CVarArgs) => {} PassMode::Direct(_) => { let llarg = bx.get_param(llarg_idx); bx.set_var_name(llarg, &name); @@ -568,22 +573,7 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( } else { let tmp = PlaceRef::alloca(bx, arg.layout); bx.set_var_name(tmp.llval, name); - if fx.fn_ty.c_variadic && last_arg_idx.map(|idx| arg_index == idx).unwrap_or(false) { - let va_list_did = match tcx.lang_items().va_list() { - Some(did) => did, - None => bug!("`va_list` lang item required for C-variadic functions"), - }; - match arg_decl.ty.kind { - ty::Adt(def, _) if def.did == va_list_did => { - // Call `va_start` on the spoofed `VaListImpl`. - bx.va_start(tmp.llval); - *va_list_ref = Some(tmp); - }, - _ => bug!("last argument of variadic function is not a `va_list`") - } - } else { - bx.store_fn_arg(arg, &mut llarg_idx, tmp); - } + bx.store_fn_arg(arg, &mut llarg_idx, tmp); tmp }; let upvar_debuginfo = &mir.__upvar_debuginfo_codegen_only_do_not_use; diff --git a/src/librustc_codegen_utils/symbol_names/legacy.rs b/src/librustc_codegen_utils/symbol_names/legacy.rs index 277aa2db33a1b..a9866c8c0b282 100644 --- a/src/librustc_codegen_utils/symbol_names/legacy.rs +++ b/src/librustc_codegen_utils/symbol_names/legacy.rs @@ -89,7 +89,7 @@ fn get_symbol_hash<'tcx>( def_id, substs ); - let mut hasher = StableHasher::::new(); + let mut hasher = StableHasher::new(); let mut hcx = tcx.create_stable_hashing_context(); record_time(&tcx.sess.perf_stats.symbol_hash_time, || { @@ -132,7 +132,7 @@ fn get_symbol_hash<'tcx>( }); // 64 bits should be enough to avoid collisions. - hasher.finish() + hasher.finish::() } // Follow C++ namespace-mangling style, see diff --git a/src/librustc_data_structures/fingerprint.rs b/src/librustc_data_structures/fingerprint.rs index c8012bb942461..b43df6045d6aa 100644 --- a/src/librustc_data_structures/fingerprint.rs +++ b/src/librustc_data_structures/fingerprint.rs @@ -76,7 +76,7 @@ impl ::std::fmt::Display for Fingerprint { impl stable_hasher::StableHasherResult for Fingerprint { #[inline] - fn finish(hasher: stable_hasher::StableHasher) -> Self { + fn finish(hasher: stable_hasher::StableHasher) -> Self { let (_0, _1) = hasher.finalize(); Fingerprint(_0, _1) } diff --git a/src/librustc_data_structures/stable_hasher.rs b/src/librustc_data_structures/stable_hasher.rs index 47dfc1d1688d0..53dff794ff0ae 100644 --- a/src/librustc_data_structures/stable_hasher.rs +++ b/src/librustc_data_structures/stable_hasher.rs @@ -1,5 +1,4 @@ use std::hash::{Hash, Hasher, BuildHasher}; -use std::marker::PhantomData; use std::mem; use smallvec::SmallVec; use crate::sip128::SipHasher128; @@ -13,55 +12,53 @@ use crate::bit_set; /// To that end we always convert integers to little-endian format before /// hashing and the architecture dependent `isize` and `usize` types are /// extended to 64 bits if needed. -pub struct StableHasher { +pub struct StableHasher { state: SipHasher128, - width: PhantomData, } -impl ::std::fmt::Debug for StableHasher { +impl ::std::fmt::Debug for StableHasher { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { write!(f, "{:?}", self.state) } } pub trait StableHasherResult: Sized { - fn finish(hasher: StableHasher) -> Self; + fn finish(hasher: StableHasher) -> Self; } -impl StableHasher { +impl StableHasher { pub fn new() -> Self { StableHasher { state: SipHasher128::new_with_keys(0, 0), - width: PhantomData, } } - pub fn finish(self) -> W { + pub fn finish(self) -> W { W::finish(self) } } impl StableHasherResult for u128 { - fn finish(hasher: StableHasher) -> Self { + fn finish(hasher: StableHasher) -> Self { let (_0, _1) = hasher.finalize(); u128::from(_0) | (u128::from(_1) << 64) } } impl StableHasherResult for u64 { - fn finish(hasher: StableHasher) -> Self { + fn finish(hasher: StableHasher) -> Self { hasher.finalize().0 } } -impl StableHasher { +impl StableHasher { #[inline] pub fn finalize(self) -> (u64, u64) { self.state.finish128() } } -impl Hasher for StableHasher { +impl Hasher for StableHasher { fn finish(&self) -> u64 { panic!("use StableHasher::finalize instead"); } @@ -165,9 +162,7 @@ impl Hasher for StableHasher { /// `StableHasher` takes care of endianness and `isize`/`usize` platform /// differences. pub trait HashStable { - fn hash_stable(&self, - hcx: &mut CTX, - hasher: &mut StableHasher); + fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher); } /// Implement this for types that can be turned into stable keys like, for @@ -185,10 +180,10 @@ macro_rules! impl_stable_hash_via_hash { ($t:ty) => ( impl $crate::stable_hasher::HashStable for $t { #[inline] - fn hash_stable( + fn hash_stable( &self, _: &mut CTX, - hasher: &mut $crate::stable_hasher::StableHasher + hasher: &mut $crate::stable_hasher::StableHasher ) { ::std::hash::Hash::hash(self, hasher); } @@ -215,17 +210,13 @@ impl_stable_hash_via_hash!(char); impl_stable_hash_via_hash!(()); impl HashStable for ::std::num::NonZeroU32 { - fn hash_stable(&self, - ctx: &mut CTX, - hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { self.get().hash_stable(ctx, hasher) } } impl HashStable for f32 { - fn hash_stable(&self, - ctx: &mut CTX, - hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { let val: u32 = unsafe { ::std::mem::transmute(*self) }; @@ -234,9 +225,7 @@ impl HashStable for f32 { } impl HashStable for f64 { - fn hash_stable(&self, - ctx: &mut CTX, - hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { let val: u64 = unsafe { ::std::mem::transmute(*self) }; @@ -245,26 +234,20 @@ impl HashStable for f64 { } impl HashStable for ::std::cmp::Ordering { - fn hash_stable(&self, - ctx: &mut CTX, - hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { (*self as i8).hash_stable(ctx, hasher); } } impl, CTX> HashStable for (T1,) { - fn hash_stable(&self, - ctx: &mut CTX, - hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { let (ref _0,) = *self; _0.hash_stable(ctx, hasher); } } impl, T2: HashStable, CTX> HashStable for (T1, T2) { - fn hash_stable(&self, - ctx: &mut CTX, - hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { let (ref _0, ref _1) = *self; _0.hash_stable(ctx, hasher); _1.hash_stable(ctx, hasher); @@ -276,9 +259,7 @@ impl HashStable for (T1, T2, T3) T2: HashStable, T3: HashStable, { - fn hash_stable(&self, - ctx: &mut CTX, - hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { let (ref _0, ref _1, ref _2) = *self; _0.hash_stable(ctx, hasher); _1.hash_stable(ctx, hasher); @@ -292,9 +273,7 @@ impl HashStable for (T1, T2, T3, T4) T3: HashStable, T4: HashStable, { - fn hash_stable(&self, - ctx: &mut CTX, - hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { let (ref _0, ref _1, ref _2, ref _3) = *self; _0.hash_stable(ctx, hasher); _1.hash_stable(ctx, hasher); @@ -304,9 +283,7 @@ impl HashStable for (T1, T2, T3, T4) } impl, CTX> HashStable for [T] { - default fn hash_stable(&self, - ctx: &mut CTX, - hasher: &mut StableHasher) { + default fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { self.len().hash_stable(ctx, hasher); for item in self { item.hash_stable(ctx, hasher); @@ -316,9 +293,7 @@ impl, CTX> HashStable for [T] { impl, CTX> HashStable for Vec { #[inline] - fn hash_stable(&self, - ctx: &mut CTX, - hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { (&self[..]).hash_stable(ctx, hasher); } } @@ -329,9 +304,7 @@ impl HashStable for indexmap::IndexMap R: BuildHasher, { #[inline] - fn hash_stable(&self, - ctx: &mut CTX, - hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { self.len().hash_stable(ctx, hasher); for kv in self { kv.hash_stable(ctx, hasher); @@ -344,9 +317,7 @@ impl HashStable for indexmap::IndexSet R: BuildHasher, { #[inline] - fn hash_stable(&self, - ctx: &mut CTX, - hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { self.len().hash_stable(ctx, hasher); for key in self { key.hash_stable(ctx, hasher); @@ -356,45 +327,35 @@ impl HashStable for indexmap::IndexSet impl HashStable for SmallVec<[A; 1]> where A: HashStable { #[inline] - fn hash_stable(&self, - ctx: &mut CTX, - hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { (&self[..]).hash_stable(ctx, hasher); } } impl, CTX> HashStable for Box { #[inline] - fn hash_stable(&self, - ctx: &mut CTX, - hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { (**self).hash_stable(ctx, hasher); } } impl, CTX> HashStable for ::std::rc::Rc { #[inline] - fn hash_stable(&self, - ctx: &mut CTX, - hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { (**self).hash_stable(ctx, hasher); } } impl, CTX> HashStable for ::std::sync::Arc { #[inline] - fn hash_stable(&self, - ctx: &mut CTX, - hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { (**self).hash_stable(ctx, hasher); } } impl HashStable for str { #[inline] - fn hash_stable(&self, - _: &mut CTX, - hasher: &mut StableHasher) { + fn hash_stable(&self, _: &mut CTX, hasher: &mut StableHasher) { self.len().hash(hasher); self.as_bytes().hash(hasher); } @@ -403,9 +364,7 @@ impl HashStable for str { impl HashStable for String { #[inline] - fn hash_stable(&self, - hcx: &mut CTX, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { (&self[..]).hash_stable(hcx, hasher); } } @@ -420,9 +379,7 @@ impl ToStableHashKey for String { impl HashStable for bool { #[inline] - fn hash_stable(&self, - ctx: &mut CTX, - hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { (if *self { 1u8 } else { 0u8 }).hash_stable(ctx, hasher); } } @@ -432,9 +389,7 @@ impl HashStable for Option where T: HashStable { #[inline] - fn hash_stable(&self, - ctx: &mut CTX, - hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { if let Some(ref value) = *self { 1u8.hash_stable(ctx, hasher); value.hash_stable(ctx, hasher); @@ -449,9 +404,7 @@ impl HashStable for Result T2: HashStable, { #[inline] - fn hash_stable(&self, - ctx: &mut CTX, - hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { mem::discriminant(self).hash_stable(ctx, hasher); match *self { Ok(ref x) => x.hash_stable(ctx, hasher), @@ -464,18 +417,14 @@ impl<'a, T, CTX> HashStable for &'a T where T: HashStable + ?Sized { #[inline] - fn hash_stable(&self, - ctx: &mut CTX, - hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { (**self).hash_stable(ctx, hasher); } } impl HashStable for ::std::mem::Discriminant { #[inline] - fn hash_stable(&self, - _: &mut CTX, - hasher: &mut StableHasher) { + fn hash_stable(&self, _: &mut CTX, hasher: &mut StableHasher) { ::std::hash::Hash::hash(self, hasher); } } @@ -483,9 +432,7 @@ impl HashStable for ::std::mem::Discriminant { impl HashStable for indexed_vec::IndexVec where T: HashStable, { - fn hash_stable(&self, - ctx: &mut CTX, - hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { self.len().hash_stable(ctx, hasher); for v in &self.raw { v.hash_stable(ctx, hasher); @@ -496,9 +443,7 @@ impl HashStable for indexed_vec::IndexVec HashStable for bit_set::BitSet { - fn hash_stable(&self, - ctx: &mut CTX, - hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { self.words().hash_stable(ctx, hasher); } } @@ -506,9 +451,7 @@ impl HashStable for bit_set::BitSet impl HashStable for bit_set::BitMatrix { - fn hash_stable(&self, - ctx: &mut CTX, - hasher: &mut StableHasher) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { self.words().hash_stable(ctx, hasher); } } @@ -522,9 +465,7 @@ impl HashStable for ::std::collections::HashMap R: BuildHasher, { #[inline] - fn hash_stable(&self, - hcx: &mut HCX, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) { hash_stable_hashmap(hcx, hasher, self, ToStableHashKey::to_stable_hash_key); } } @@ -533,9 +474,7 @@ impl HashStable for ::std::collections::HashSet where K: ToStableHashKey + Eq + Hash, R: BuildHasher, { - fn hash_stable(&self, - hcx: &mut HCX, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) { let mut keys: Vec<_> = self.iter() .map(|k| k.to_stable_hash_key(hcx)) .collect(); @@ -548,9 +487,7 @@ impl HashStable for ::std::collections::BTreeMap where K: ToStableHashKey, V: HashStable, { - fn hash_stable(&self, - hcx: &mut HCX, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) { let mut entries: Vec<_> = self.iter() .map(|(k, v)| (k.to_stable_hash_key(hcx), v)) .collect(); @@ -562,9 +499,7 @@ impl HashStable for ::std::collections::BTreeMap impl HashStable for ::std::collections::BTreeSet where K: ToStableHashKey, { - fn hash_stable(&self, - hcx: &mut HCX, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) { let mut keys: Vec<_> = self.iter() .map(|k| k.to_stable_hash_key(hcx)) .collect(); @@ -573,9 +508,9 @@ impl HashStable for ::std::collections::BTreeSet } } -pub fn hash_stable_hashmap( +pub fn hash_stable_hashmap( hcx: &mut HCX, - hasher: &mut StableHasher, + hasher: &mut StableHasher, map: &::std::collections::HashMap, to_stable_hash_key: F) where K: Eq + Hash, @@ -583,7 +518,6 @@ pub fn hash_stable_hashmap( R: BuildHasher, SK: HashStable + Ord + Clone, F: Fn(&K, &HCX) -> SK, - W: StableHasherResult, { let mut entries: Vec<_> = map.iter() .map(|(k, v)| (to_stable_hash_key(k, hcx), v)) @@ -614,9 +548,7 @@ impl ::std::ops::Deref for StableVec { impl HashStable for StableVec where T: HashStable + ToStableHashKey { - fn hash_stable(&self, - hcx: &mut HCX, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) { let StableVec(ref v) = *self; let mut sorted: Vec<_> = v.iter() diff --git a/src/librustc_data_structures/svh.rs b/src/librustc_data_structures/svh.rs index 3123c182b0f4c..64042264d794f 100644 --- a/src/librustc_data_structures/svh.rs +++ b/src/librustc_data_structures/svh.rs @@ -61,11 +61,7 @@ impl Decodable for Svh { impl stable_hasher::HashStable for Svh { #[inline] - fn hash_stable( - &self, - ctx: &mut T, - hasher: &mut stable_hasher::StableHasher - ) { + fn hash_stable(&self, ctx: &mut T, hasher: &mut stable_hasher::StableHasher) { let Svh { hash } = *self; diff --git a/src/librustc_data_structures/thin_vec.rs b/src/librustc_data_structures/thin_vec.rs index 6692903cd4fe9..93a8b7f525fff 100644 --- a/src/librustc_data_structures/thin_vec.rs +++ b/src/librustc_data_structures/thin_vec.rs @@ -1,4 +1,4 @@ -use crate::stable_hasher::{StableHasher, StableHasherResult, HashStable}; +use crate::stable_hasher::{StableHasher, HashStable}; /// A vector type optimized for cases where this size is usually 0 (cf. `SmallVector`). /// The `Option>` wrapping allows us to represent a zero sized vector with `None`, @@ -60,9 +60,7 @@ impl Extend for ThinVec { } impl, CTX> HashStable for ThinVec { - fn hash_stable(&self, - hcx: &mut CTX, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { (**self).hash_stable(hcx, hasher) } } diff --git a/src/librustc_data_structures/transitive_relation.rs b/src/librustc_data_structures/transitive_relation.rs index ffc964ddb5ae2..9c5447f3f5a44 100644 --- a/src/librustc_data_structures/transitive_relation.rs +++ b/src/librustc_data_structures/transitive_relation.rs @@ -1,6 +1,6 @@ use crate::bit_set::BitMatrix; use crate::fx::FxHashMap; -use crate::stable_hasher::{HashStable, StableHasher, StableHasherResult}; +use crate::stable_hasher::{HashStable, StableHasher}; use crate::sync::Lock; use rustc_serialize::{Encodable, Encoder, Decodable, Decoder}; use std::fmt::Debug; @@ -442,9 +442,7 @@ impl Decodable for TransitiveRelation impl HashStable for TransitiveRelation where T: HashStable + Eq + Debug + Clone + Hash { - fn hash_stable(&self, - hcx: &mut CTX, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { // We are assuming here that the relation graph has been built in a // deterministic way and we can just hash it the way it is. let TransitiveRelation { @@ -462,9 +460,7 @@ impl HashStable for TransitiveRelation } impl HashStable for Edge { - fn hash_stable(&self, - hcx: &mut CTX, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { let Edge { ref source, ref target, @@ -476,9 +472,7 @@ impl HashStable for Edge { } impl HashStable for Index { - fn hash_stable(&self, - hcx: &mut CTX, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { let Index(idx) = *self; idx.hash_stable(hcx, hasher); } diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 774a5af1b1ca8..dd088b68a239a 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -1231,7 +1231,7 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) { let backtrace = env::var_os("RUST_BACKTRACE").map(|x| &x != "0").unwrap_or(false); if backtrace { - TyCtxt::try_print_query_stack(); + TyCtxt::try_print_query_stack(&handler); } #[cfg(windows)] diff --git a/src/librustc_interface/util.rs b/src/librustc_interface/util.rs index 72df875fc8f4f..e73195fbb8c2d 100644 --- a/src/librustc_interface/util.rs +++ b/src/librustc_interface/util.rs @@ -502,7 +502,7 @@ pub(crate) fn compute_crate_disambiguator(session: &Session) -> CrateDisambiguat // into various other hashes quite a bit (symbol hashes, incr. comp. hashes, // debuginfo type IDs, etc), so we don't want it to be too wide. 128 bits // should still be safe enough to avoid collisions in practice. - let mut hasher = StableHasher::::new(); + let mut hasher = StableHasher::new(); let mut metadata = session.opts.cg.metadata.clone(); // We don't want the crate_disambiguator to dependent on the order @@ -528,7 +528,7 @@ pub(crate) fn compute_crate_disambiguator(session: &Session) -> CrateDisambiguat .contains(&config::CrateType::Executable); hasher.write(if is_exe { b"exe" } else { b"lib" }); - CrateDisambiguator::from(hasher.finish()) + CrateDisambiguator::from(hasher.finish::()) } pub fn collect_crate_types(session: &Session, attrs: &[ast::Attribute]) -> Vec { diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index e4567dc8265d8..150719c1dbc0e 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -944,15 +944,8 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { let def_id = self.cx.tcx.hir().local_def_id(id); let sig = self.cx.tcx.fn_sig(def_id); let sig = self.cx.tcx.erase_late_bound_regions(&sig); - let inputs = if sig.c_variadic { - // Don't include the spoofed `VaListImpl` in the functions list - // of inputs. - &sig.inputs()[..sig.inputs().len() - 1] - } else { - &sig.inputs()[..] - }; - for (input_ty, input_hir) in inputs.iter().zip(&decl.inputs) { + for (input_ty, input_hir) in sig.inputs().iter().zip(&decl.inputs) { self.check_type_for_ffi_and_report_errors(input_hir.span, input_ty); } diff --git a/src/librustc_macros/src/hash_stable.rs b/src/librustc_macros/src/hash_stable.rs index 6d7590c7d1cd3..a708f3191dcf8 100644 --- a/src/librustc_macros/src/hash_stable.rs +++ b/src/librustc_macros/src/hash_stable.rs @@ -76,10 +76,10 @@ pub fn hash_stable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::To s.bound_impl(quote!(::rustc_data_structures::stable_hasher::HashStable <::rustc::ich::StableHashingContext<'__ctx>>), quote!{ - fn hash_stable<__W: ::rustc_data_structures::stable_hasher::StableHasherResult>( + fn hash_stable( &self, __hcx: &mut ::rustc::ich::StableHashingContext<'__ctx>, - __hasher: &mut ::rustc_data_structures::stable_hasher::StableHasher<__W>) { + __hasher: &mut ::rustc_data_structures::stable_hasher::StableHasher) { #discriminant match *self { #body } } diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index 0bb4f52be14c2..9beeacbe72d80 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -368,9 +368,9 @@ impl<'tcx> EncodeContext<'tcx> { let mut adapted = (**source_file).clone(); adapted.name = Path::new(&working_dir).join(name).into(); adapted.name_hash = { - let mut hasher: StableHasher = StableHasher::new(); + let mut hasher: StableHasher = StableHasher::new(); adapted.name.hash(&mut hasher); - hasher.finish() + hasher.finish::() }; Lrc::new(adapted) }, diff --git a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs index c4b508e030f39..8b1ba59c6df7e 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs @@ -399,7 +399,6 @@ impl<'tcx> RegionInferenceContext<'tcx> { self.universal_regions.unnormalized_input_tys[implicit_inputs + argument_index]; if let Some(region_name) = self.give_name_if_we_can_match_hir_ty_from_argument( infcx, - body, mir_def_id, fr, arg_ty, @@ -415,7 +414,6 @@ impl<'tcx> RegionInferenceContext<'tcx> { fn give_name_if_we_can_match_hir_ty_from_argument( &self, infcx: &InferCtxt<'_, 'tcx>, - body: &Body<'tcx>, mir_def_id: DefId, needle_fr: RegionVid, argument_ty: Ty<'tcx>, @@ -424,18 +422,14 @@ impl<'tcx> RegionInferenceContext<'tcx> { ) -> Option { let mir_hir_id = infcx.tcx.hir().as_local_hir_id(mir_def_id)?; let fn_decl = infcx.tcx.hir().fn_decl_by_hir_id(mir_hir_id)?; - let argument_hir_ty: &hir::Ty = &fn_decl.inputs[argument_index]; + let argument_hir_ty: &hir::Ty = fn_decl.inputs.get(argument_index)?; match argument_hir_ty.kind { // This indicates a variable with no type annotation, like // `|x|`... in that case, we can't highlight the type but // must highlight the variable. - hir::TyKind::Infer => self.give_name_if_we_cannot_match_hir_ty( - infcx, - body, - needle_fr, - argument_ty, - renctx, - ), + // NOTE(eddyb) this is handled in/by the sole caller + // (`give_name_if_anonymous_region_appears_in_arguments`). + hir::TyKind::Infer => None, _ => self.give_name_if_we_can_match_hir_ty( infcx.tcx, diff --git a/src/librustc_mir/borrow_check/nll/type_check/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/mod.rs index b981c76905c14..fa326062fe2c9 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs @@ -1726,17 +1726,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { from_hir_call: bool, ) { debug!("check_call_inputs({:?}, {:?})", sig, args); - // Do not count the `VaListImpl` argument as a "true" argument to - // a C-variadic function. - let inputs = if sig.c_variadic { - &sig.inputs()[..sig.inputs().len() - 1] - } else { - &sig.inputs()[..] - }; - if args.len() < inputs.len() || (args.len() > inputs.len() && !sig.c_variadic) { + if args.len() < sig.inputs().len() || (args.len() > sig.inputs().len() && !sig.c_variadic) { span_mirbug!(self, term, "call to {:?} with wrong # of args", sig); } - for (n, (fn_arg, op_arg)) in inputs.iter().zip(args).enumerate() { + for (n, (fn_arg, op_arg)) in sig.inputs().iter().zip(args).enumerate() { let op_arg_ty = op_arg.ty(body, self.tcx()); let category = if from_hir_call { ConstraintCategory::CallArgument diff --git a/src/librustc_mir/borrow_check/nll/universal_regions.rs b/src/librustc_mir/borrow_check/nll/universal_regions.rs index 9f9450188fa94..7053bdca25957 100644 --- a/src/librustc_mir/borrow_check/nll/universal_regions.rs +++ b/src/librustc_mir/borrow_check/nll/universal_regions.rs @@ -16,8 +16,9 @@ use either::Either; use rustc::hir::def_id::DefId; use rustc::hir::{self, BodyOwnerKind, HirId}; use rustc::infer::{InferCtxt, NLLRegionVariableOrigin}; +use rustc::middle::lang_items; use rustc::ty::fold::TypeFoldable; -use rustc::ty::subst::{InternalSubsts, SubstsRef}; +use rustc::ty::subst::{InternalSubsts, SubstsRef, Subst}; use rustc::ty::{self, ClosureSubsts, GeneratorSubsts, RegionVid, Ty, TyCtxt}; use rustc::util::nodemap::FxHashMap; use rustc_data_structures::indexed_vec::{Idx, IndexVec}; @@ -425,12 +426,33 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { .replace_late_bound_regions_with_nll_infer_vars(self.mir_def_id, &mut indices); } + let (unnormalized_output_ty, mut unnormalized_input_tys) = + inputs_and_output.split_last().unwrap(); + + // C-variadic fns also have a `VaList` input that's not listed in the signature + // (as it's created inside the body itself, not passed in from outside). + if let DefiningTy::FnDef(def_id, _) = defining_ty { + if self.infcx.tcx.fn_sig(def_id).c_variadic() { + let va_list_did = self.infcx.tcx.require_lang_item( + lang_items::VaListTypeLangItem, + Some(self.infcx.tcx.def_span(self.mir_def_id),), + ); + let region = self.infcx.tcx.mk_region(ty::ReVar( + self.infcx.next_nll_region_var(FR).to_region_vid(), + )); + let va_list_ty = self.infcx.tcx.type_of(va_list_did) + .subst(self.infcx.tcx, &[region.into()]); + + unnormalized_input_tys = self.infcx.tcx.mk_type_list( + unnormalized_input_tys.iter().copied() + .chain(iter::once(va_list_ty)), + ); + } + } + let fr_fn_body = self.infcx.next_nll_region_var(FR).to_region_vid(); let num_universals = self.infcx.num_region_vars(); - let (unnormalized_output_ty, unnormalized_input_tys) = - inputs_and_output.split_last().unwrap(); - debug!( "build: global regions = {}..{}", FIRST_GLOBAL_INDEX, first_extern_index diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index f1e045302eced..17932ae855767 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -7,9 +7,11 @@ use crate::util as mir_util; use rustc::hir; use rustc::hir::Node; use rustc::hir::def_id::DefId; +use rustc::middle::lang_items; use rustc::middle::region; use rustc::mir::*; use rustc::ty::{self, Ty, TyCtxt}; +use rustc::ty::subst::Subst; use rustc::util::nodemap::HirIdMap; use rustc_target::spec::PanicStrategy; use rustc_data_structures::indexed_vec::{IndexVec, Idx}; @@ -102,9 +104,7 @@ pub fn mir_build(tcx: TyCtxt<'_>, def_id: DefId) -> Body<'_> { let opt_ty_info; let self_arg; if let Some(ref fn_decl) = tcx.hir().fn_decl_by_hir_id(owner_id) { - let ty_hir_id = fn_decl.inputs[index].hir_id; - let ty_span = tcx.hir().span(ty_hir_id); - opt_ty_info = Some(ty_span); + opt_ty_info = fn_decl.inputs.get(index).map(|ty| ty.span); self_arg = if index == 0 && fn_decl.implicit_self.has_implicit_self() { match fn_decl.implicit_self { hir::ImplicitSelfKind::Imm => Some(ImplicitSelfKind::Imm), @@ -121,7 +121,24 @@ pub fn mir_build(tcx: TyCtxt<'_>, def_id: DefId) -> Body<'_> { self_arg = None; } - ArgInfo(fn_sig.inputs()[index], opt_ty_info, Some(&arg), self_arg) + // C-variadic fns also have a `VaList` input that's not listed in `fn_sig` + // (as it's created inside the body itself, not passed in from outside). + let ty = if fn_sig.c_variadic && index == fn_sig.inputs().len() { + let va_list_did = tcx.require_lang_item( + lang_items::VaListTypeLangItem, + Some(arg.span), + ); + let region = tcx.mk_region(ty::ReScope(region::Scope { + id: body.value.hir_id.local_id, + data: region::ScopeData::CallSite + })); + + tcx.type_of(va_list_did).subst(tcx, &[region.into()]) + } else { + fn_sig.inputs()[index] + }; + + ArgInfo(ty, opt_ty_info, Some(&arg), self_arg) }); let arguments = implicit_argument.into_iter().chain(explicit_arguments); diff --git a/src/librustc_mir/interpret/snapshot.rs b/src/librustc_mir/interpret/snapshot.rs index 2cac8bb0c517e..4c7d0dcb69721 100644 --- a/src/librustc_mir/interpret/snapshot.rs +++ b/src/librustc_mir/interpret/snapshot.rs @@ -52,9 +52,9 @@ impl<'mir, 'tcx> InfiniteLoopDetector<'mir, 'tcx> { ) -> InterpResult<'tcx, ()> { // Compute stack's hash before copying anything let mut hcx = tcx.get_stable_hashing_context(); - let mut hasher = StableHasher::::new(); + let mut hasher = StableHasher::new(); stack.hash_stable(&mut hcx, &mut hasher); - let hash = hasher.finish(); + let hash = hasher.finish::(); // Check if we know that hash already if self.hashes.is_empty() { @@ -428,9 +428,9 @@ impl<'mir, 'tcx> Hash for InterpSnapshot<'mir, 'tcx> { fn hash(&self, state: &mut H) { // Implement in terms of hash stable, so that k1 == k2 -> hash(k1) == hash(k2) let mut hcx = self.memory.tcx.get_stable_hashing_context(); - let mut hasher = StableHasher::::new(); + let mut hasher = StableHasher::new(); self.hash_stable(&mut hcx, &mut hasher); - hasher.finish().hash(state) + hasher.finish::().hash(state) } } diff --git a/src/librustc_target/abi/call/mod.rs b/src/librustc_target/abi/call/mod.rs index fbbd120f934be..bc21113527ecf 100644 --- a/src/librustc_target/abi/call/mod.rs +++ b/src/librustc_target/abi/call/mod.rs @@ -23,18 +23,10 @@ mod x86_64; mod x86_win64; mod wasm32; -#[derive(Clone, Copy, PartialEq, Eq, Debug)] -pub enum IgnoreMode { - /// C-variadic arguments. - CVarArgs, - /// A zero-sized type. - Zst, -} - #[derive(Clone, Copy, PartialEq, Eq, Debug)] pub enum PassMode { - /// Ignore the argument (useful for empty structs and C-variadic args). - Ignore(IgnoreMode), + /// Ignore the argument. + Ignore, /// Pass the argument directly. Direct(ArgAttributes), /// Pass a pair's elements directly in two arguments. @@ -490,7 +482,7 @@ impl<'a, Ty> ArgType<'a, Ty> { pub fn is_ignore(&self) -> bool { match self.mode { - PassMode::Ignore(_) => true, + PassMode::Ignore => true, _ => false } } diff --git a/src/librustc_target/abi/call/x86.rs b/src/librustc_target/abi/call/x86.rs index 6ca3ce88bd6eb..2e809571ab18b 100644 --- a/src/librustc_target/abi/call/x86.rs +++ b/src/librustc_target/abi/call/x86.rs @@ -88,7 +88,7 @@ pub fn compute_abi_info<'a, Ty, C>(cx: &C, fty: &mut FnType<'a, Ty>, flavor: Fla for arg in &mut fty.args { let attrs = match arg.mode { - PassMode::Ignore(_) | + PassMode::Ignore | PassMode::Indirect(_, None) => continue, PassMode::Direct(ref mut attrs) => attrs, PassMode::Pair(..) | diff --git a/src/librustc_target/spec/aarch64_unknown_none.rs b/src/librustc_target/spec/aarch64_unknown_none.rs index 8c02bc61088b4..b9549ec2120dd 100644 --- a/src/librustc_target/spec/aarch64_unknown_none.rs +++ b/src/librustc_target/spec/aarch64_unknown_none.rs @@ -1,4 +1,4 @@ -// Generic AArch64 target for bare-metal code +// Generic AArch64 target for bare-metal code - Floating point enabled // // Can be used in conjunction with the `target-feature` and // `target-cpu` compiler flags to opt-in more hardware-specific @@ -11,7 +11,7 @@ use super::{LldFlavor, LinkerFlavor, Target, TargetOptions, PanicStrategy}; pub fn target() -> Result { let opts = TargetOptions { linker: Some("rust-lld".to_owned()), - features: "+strict-align".to_string(), + features: "+strict-align,+neon,+fp-armv8".to_string(), executables: true, relocation_model: "static".to_string(), disable_redzone: true, diff --git a/src/librustc_target/spec/aarch64_unknown_none_softfloat.rs b/src/librustc_target/spec/aarch64_unknown_none_softfloat.rs new file mode 100644 index 0000000000000..b91f2af68ecb8 --- /dev/null +++ b/src/librustc_target/spec/aarch64_unknown_none_softfloat.rs @@ -0,0 +1,37 @@ +// Generic AArch64 target for bare-metal code - Floating point disabled +// +// Can be used in conjunction with the `target-feature` and +// `target-cpu` compiler flags to opt-in more hardware-specific +// features. +// +// For example, `-C target-cpu=cortex-a53`. + +use super::{LldFlavor, LinkerFlavor, Target, TargetOptions, PanicStrategy}; + +pub fn target() -> Result { + let opts = TargetOptions { + linker: Some("rust-lld".to_owned()), + features: "+strict-align,-neon,-fp-armv8".to_string(), + executables: true, + relocation_model: "static".to_string(), + disable_redzone: true, + linker_is_gnu: true, + max_atomic_width: Some(128), + panic_strategy: PanicStrategy::Abort, + abi_blacklist: super::arm_base::abi_blacklist(), + .. Default::default() + }; + Ok(Target { + llvm_target: "aarch64-unknown-none".to_string(), + target_endian: "little".to_string(), + target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), + target_os: "none".to_string(), + target_env: String::new(), + target_vendor: String::new(), + data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(), + arch: "aarch64".to_string(), + linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld), + options: opts, + }) +} diff --git a/src/librustc_target/spec/mod.rs b/src/librustc_target/spec/mod.rs index 626fa374a1bd4..25add0cc6a4be 100644 --- a/src/librustc_target/spec/mod.rs +++ b/src/librustc_target/spec/mod.rs @@ -489,6 +489,7 @@ supported_targets! { ("riscv64gc-unknown-none-elf", riscv64gc_unknown_none_elf), ("aarch64-unknown-none", aarch64_unknown_none), + ("aarch64-unknown-none-softfloat", aarch64_unknown_none_softfloat), ("x86_64-fortanix-unknown-sgx", x86_64_fortanix_unknown_sgx), diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 5ab2ca280d5cd..fd6744da06067 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -2148,15 +2148,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { // handled specially and will not descend into this routine. self.ty_infer(None, ast_ty.span) } - hir::TyKind::CVarArgs(lt) => { - let va_list_did = match tcx.lang_items().va_list() { - Some(did) => did, - None => span_bug!(ast_ty.span, - "`va_list` lang item required for variadics"), - }; - let region = self.ast_region_to_region(<, None); - tcx.type_of(va_list_did).subst(tcx, &[region.into()]) - } hir::TyKind::Err => { tcx.types.err } diff --git a/src/librustc_typeck/check/callee.rs b/src/librustc_typeck/check/callee.rs index 7e0a3e781883e..290b87388ebbe 100644 --- a/src/librustc_typeck/check/callee.rs +++ b/src/librustc_typeck/check/callee.rs @@ -397,27 +397,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .0; let fn_sig = self.normalize_associated_types_in(call_expr.span, &fn_sig); - let inputs = if fn_sig.c_variadic { - if fn_sig.inputs().len() > 1 { - &fn_sig.inputs()[..fn_sig.inputs().len() - 1] - } else { - span_bug!(call_expr.span, - "C-variadic functions are only valid with one or more fixed arguments"); - } - } else { - &fn_sig.inputs()[..] - }; // Call the generic checker. let expected_arg_tys = self.expected_inputs_for_expected_output( call_expr.span, expected, fn_sig.output(), - inputs, + fn_sig.inputs(), ); self.check_argument_types( call_expr.span, call_expr, - inputs, + fn_sig.inputs(), &expected_arg_tys[..], arg_exprs, fn_sig.c_variadic, diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 9f2c991fdd236..a7832b8c2cf17 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -1132,8 +1132,29 @@ fn check_fn<'a, 'tcx>( let outer_hir_id = fcx.tcx.hir().as_local_hir_id(outer_def_id).unwrap(); GatherLocalsVisitor { fcx: &fcx, parent_id: outer_hir_id, }.visit_body(body); + // C-variadic fns also have a `VaList` input that's not listed in `fn_sig` + // (as it's created inside the body itself, not passed in from outside). + let maybe_va_list = if fn_sig.c_variadic { + let va_list_did = fcx.tcx.require_lang_item( + lang_items::VaListTypeLangItem, + Some(body.params.last().unwrap().span), + ); + let region = fcx.tcx.mk_region(ty::ReScope(region::Scope { + id: body.value.hir_id.local_id, + data: region::ScopeData::CallSite + })); + + Some(fcx.tcx.type_of(va_list_did).subst(fcx.tcx, &[region.into()])) + } else { + None + }; + // Add formal parameters. - for (param_ty, param) in fn_sig.inputs().iter().zip(&body.params) { + for (param_ty, param) in + fn_sig.inputs().iter().copied() + .chain(maybe_va_list) + .zip(&body.params) + { // Check the pattern. fcx.check_pat_top(¶m.pat, param_ty, None); diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index ce21447105815..b530851b80de7 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -2032,6 +2032,7 @@ impl Clean for doctree::Function<'_> { pub struct FnDecl { pub inputs: Arguments, pub output: FunctionRetTy, + pub c_variadic: bool, pub attrs: Attributes, } @@ -2110,6 +2111,7 @@ impl<'a, A: Copy> Clean for (&'a hir::FnDecl, A) FnDecl { inputs: (&self.0.inputs[..], self.1).clean(cx), output: self.0.output.clean(cx), + c_variadic: self.0.c_variadic, attrs: Attributes::default(), } } @@ -2127,6 +2129,7 @@ impl<'tcx> Clean for (DefId, ty::PolyFnSig<'tcx>) { FnDecl { output: Return(sig.skip_binder().output().clean(cx)), attrs: Attributes::default(), + c_variadic: sig.skip_binder().c_variadic, inputs: Arguments { values: sig.skip_binder().inputs().iter().map(|t| { Argument { @@ -2545,7 +2548,6 @@ pub enum Type { Slice(Box), Array(Box, String), Never, - CVarArgs, RawPointer(Mutability, Box), BorrowedRef { lifetime: Option, @@ -2583,7 +2585,6 @@ pub enum PrimitiveType { Reference, Fn, Never, - CVarArgs, } #[derive(Clone, Copy, Debug)] @@ -2787,7 +2788,6 @@ impl PrimitiveType { Reference => "reference", Fn => "fn", Never => "never", - CVarArgs => "...", } } @@ -3032,7 +3032,6 @@ impl Clean for hir::Ty { TyKind::BareFn(ref barefn) => BareFunction(box barefn.clean(cx)), TyKind::Infer | TyKind::Err => Infer, TyKind::Typeof(..) => panic!("unimplemented type {:?}", self.kind), - TyKind::CVarArgs(_) => CVarArgs, } } } @@ -3980,7 +3979,6 @@ fn build_deref_target_impls(cx: &DocContext<'_>, Reference => None, Fn => None, Never => None, - CVarArgs => tcx.lang_items().va_list(), }; if let Some(did) = did { if !did.is_local() { diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index fafd43cb60b69..4cde868201eef 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -657,7 +657,6 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter<'_>, use_absolute: bool) -> primitive_link(f, PrimitiveType::Array, &format!("; {}]", n)) } clean::Never => primitive_link(f, PrimitiveType::Never, "!"), - clean::CVarArgs => primitive_link(f, PrimitiveType::CVarArgs, "..."), clean::RawPointer(m, ref t) => { let m = match m { clean::Immutable => "const", @@ -903,12 +902,15 @@ impl clean::BareFunctionDecl { impl clean::FnDecl { crate fn print(&self) -> impl fmt::Display + '_ { display_fn(move |f| { + let ellipsis = if self.c_variadic { ", ..." } else { "" }; if f.alternate() { write!(f, - "({args:#}){arrow:#}", args = self.inputs.print(), arrow = self.output.print()) + "({args:#}{ellipsis}){arrow:#}", + args = self.inputs.print(), ellipsis = ellipsis, arrow = self.output.print()) } else { write!(f, - "({args}){arrow}", args = self.inputs.print(), arrow = self.output.print()) + "({args}{ellipsis}){arrow}", + args = self.inputs.print(), ellipsis = ellipsis, arrow = self.output.print()) } }) } @@ -975,7 +977,12 @@ impl Function<'_> { } } - let args_plain = format!("({})", args_plain); + let mut args_plain = format!("({})", args_plain); + + if decl.c_variadic { + args.push_str(",
..."); + args_plain.push_str(", ..."); + } let output = if let hir::IsAsync::Async = asyncness { Cow::Owned(decl.sugared_async_return_type()) diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index a7f035dc9ecc7..bc468c1ad0ebe 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1893,7 +1893,6 @@ impl Param { pub struct FnDecl { pub inputs: Vec, pub output: FunctionRetTy, - pub c_variadic: bool, } impl FnDecl { @@ -1903,6 +1902,12 @@ impl FnDecl { pub fn has_self(&self) -> bool { self.inputs.get(0).map(Param::is_self).unwrap_or(false) } + pub fn c_variadic(&self) -> bool { + self.inputs.last().map(|arg| match arg.ty.kind { + TyKind::CVarArgs => true, + _ => false, + }).unwrap_or(false) + } } /// Is the trait definition an auto trait? diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 6b93d045588b9..8c5289671c98e 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -562,7 +562,6 @@ impl<'a> ExtCtxt<'a> { P(ast::FnDecl { inputs, output, - c_variadic: false }) } diff --git a/src/libsyntax/feature_gate/check.rs b/src/libsyntax/feature_gate/check.rs index 622b48ab9281e..d7fc74955bbbd 100644 --- a/src/libsyntax/feature_gate/check.rs +++ b/src/libsyntax/feature_gate/check.rs @@ -531,7 +531,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { self.check_abi(header.abi, span); } - if fn_decl.c_variadic { + if fn_decl.c_variadic() { gate_feature_post!(&self, c_variadic, span, "C-variadic functions are unstable"); } @@ -564,7 +564,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { if block.is_none() { self.check_abi(sig.header.abi, ti.span); } - if sig.decl.c_variadic { + if sig.decl.c_variadic() { gate_feature_post!(&self, c_variadic, ti.span, "C-variadic functions are unstable"); } @@ -601,7 +601,12 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { } match ii.kind { - ast::ImplItemKind::Method(..) => {} + ast::ImplItemKind::Method(ref sig, _) => { + if sig.decl.c_variadic() { + gate_feature_post!(&self, c_variadic, ii.span, + "C-variadic functions are unstable"); + } + } ast::ImplItemKind::OpaqueTy(..) => { gate_feature_post!( &self, diff --git a/src/libsyntax/mut_visit.rs b/src/libsyntax/mut_visit.rs index 43b5df38e143c..80dfe9e5be0ad 100644 --- a/src/libsyntax/mut_visit.rs +++ b/src/libsyntax/mut_visit.rs @@ -717,7 +717,7 @@ pub fn noop_visit_asyncness(asyncness: &mut IsAsync, vis: &mut T) } pub fn noop_visit_fn_decl(decl: &mut P, vis: &mut T) { - let FnDecl { inputs, output, c_variadic: _ } = decl.deref_mut(); + let FnDecl { inputs, output } = decl.deref_mut(); inputs.flat_map_in_place(|param| vis.flat_map_param(param)); match output { FunctionRetTy::Default(span) => vis.visit_span(span), diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index cc582819b6b61..f22fd5ad703d9 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1194,7 +1194,7 @@ impl<'a> Parser<'a> { } fn parse_fn_params(&mut self, named_params: bool, allow_c_variadic: bool) - -> PResult<'a, (Vec , bool)> { + -> PResult<'a, Vec> { let sp = self.token.span; let mut c_variadic = false; let (params, _): (Vec>, _) = self.parse_paren_comma_seq(|p| { @@ -1218,6 +1218,8 @@ impl<'a> Parser<'a> { let span = p.token.span; p.span_err(span, "`...` must be the last argument of a C-variadic function"); + // FIXME(eddyb) this should probably still push `CVarArgs`. + // Maybe AST validation/HIR lowering should emit the above error? Ok(None) } else { Ok(Some(param)) @@ -1245,7 +1247,7 @@ impl<'a> Parser<'a> { "C-variadic function must be declared with at least one named argument"); } - Ok((params, c_variadic)) + Ok(params) } /// Returns the parsed optional self parameter and whether a self shortcut was used. @@ -1414,7 +1416,6 @@ impl<'a> Parser<'a> { Ok(P(FnDecl { inputs: fn_inputs, output: self.parse_ret_ty(true)?, - c_variadic: false })) } diff --git a/src/libsyntax/parse/parser/expr.rs b/src/libsyntax/parse/parser/expr.rs index c776704b285aa..23674ad589dc5 100644 --- a/src/libsyntax/parse/parser/expr.rs +++ b/src/libsyntax/parse/parser/expr.rs @@ -1176,7 +1176,6 @@ impl<'a> Parser<'a> { Ok(P(FnDecl { inputs: inputs_captures, output, - c_variadic: false })) } diff --git a/src/libsyntax/parse/parser/item.rs b/src/libsyntax/parse/parser/item.rs index 370030d02c717..92b19b73e5719 100644 --- a/src/libsyntax/parse/parser/item.rs +++ b/src/libsyntax/parse/parser/item.rs @@ -1292,13 +1292,12 @@ impl<'a> Parser<'a> { /// Parses the argument list and result type of a function declaration. fn parse_fn_decl(&mut self, allow_c_variadic: bool) -> PResult<'a, P> { - let (args, c_variadic) = self.parse_fn_params(true, allow_c_variadic)?; + let args = self.parse_fn_params(true, allow_c_variadic)?; let ret_ty = self.parse_ret_ty(true)?; Ok(P(FnDecl { inputs: args, output: ret_ty, - c_variadic, })) } diff --git a/src/libsyntax/parse/parser/ty.rs b/src/libsyntax/parse/parser/ty.rs index b4c006ca2b119..c52d3733b5e0a 100644 --- a/src/libsyntax/parse/parser/ty.rs +++ b/src/libsyntax/parse/parser/ty.rs @@ -292,12 +292,11 @@ impl<'a> Parser<'a> { }; self.expect_keyword(kw::Fn)?; - let (inputs, c_variadic) = self.parse_fn_params(false, true)?; + let inputs = self.parse_fn_params(false, true)?; let ret_ty = self.parse_ret_ty(false)?; let decl = P(FnDecl { inputs, output: ret_ty, - c_variadic, }); Ok(TyKind::BareFn(P(BareFnTy { abi, diff --git a/src/libsyntax/print/pprust/tests.rs b/src/libsyntax/print/pprust/tests.rs index 05d78cdd87ec6..faa70edbfa29b 100644 --- a/src/libsyntax/print/pprust/tests.rs +++ b/src/libsyntax/print/pprust/tests.rs @@ -29,7 +29,6 @@ fn test_fun_to_string() { let decl = ast::FnDecl { inputs: Vec::new(), output: ast::FunctionRetTy::Default(syntax_pos::DUMMY_SP), - c_variadic: false }; let generics = ast::Generics::default(); assert_eq!( diff --git a/src/libsyntax/ptr.rs b/src/libsyntax/ptr.rs index b5eb8ca94c07a..7300ce249548b 100644 --- a/src/libsyntax/ptr.rs +++ b/src/libsyntax/ptr.rs @@ -33,8 +33,7 @@ use std::{slice, vec}; use rustc_serialize::{Encodable, Decodable, Encoder, Decoder}; -use rustc_data_structures::stable_hasher::{StableHasher, StableHasherResult, - HashStable}; +use rustc_data_structures::stable_hasher::{StableHasher, HashStable}; /// An owned smart pointer. #[derive(Hash, PartialEq, Eq)] pub struct P { @@ -218,9 +217,7 @@ impl Decodable for P<[T]> { impl HashStable for P where T: ?Sized + HashStable { - fn hash_stable(&self, - hcx: &mut CTX, - hasher: &mut StableHasher) { + fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { (**self).hash_stable(hcx, hasher); } } diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs index ca177eb4a3616..674f17de618e9 100644 --- a/src/libsyntax_pos/lib.rs +++ b/src/libsyntax_pos/lib.rs @@ -1067,14 +1067,14 @@ impl SourceFile { normalize_newlines(&mut src); let src_hash = { - let mut hasher: StableHasher = StableHasher::new(); + let mut hasher: StableHasher = StableHasher::new(); hasher.write(src.as_bytes()); - hasher.finish() + hasher.finish::() }; let name_hash = { - let mut hasher: StableHasher = StableHasher::new(); + let mut hasher: StableHasher = StableHasher::new(); name.hash(&mut hasher); - hasher.finish() + hasher.finish::() }; let end_pos = start_pos.to_usize() + src.len(); if end_pos > u32::max_value() as usize { @@ -1120,10 +1120,10 @@ impl SourceFile { // Check that no-one else have provided the source while we were getting it if *external_src == ExternalSource::AbsentOk { if let Some(src) = src { - let mut hasher: StableHasher = StableHasher::new(); + let mut hasher: StableHasher = StableHasher::new(); hasher.write(src.as_bytes()); - if hasher.finish() == self.src_hash { + if hasher.finish::() == self.src_hash { *external_src = ExternalSource::Present(src); return true; } diff --git a/src/test/rustdoc/variadic.rs b/src/test/rustdoc/variadic.rs index 5af2aea21fcac..bd8f1775b3d04 100644 --- a/src/test/rustdoc/variadic.rs +++ b/src/test/rustdoc/variadic.rs @@ -1,4 +1,4 @@ extern "C" { - // @has variadic/fn.foo.html //pre 'pub unsafe extern "C" fn foo(x: i32, _: ...)' + // @has variadic/fn.foo.html //pre 'pub unsafe extern "C" fn foo(x: i32, ...)' pub fn foo(x: i32, ...); } diff --git a/src/test/ui-fulldeps/pprust-expr-roundtrip.rs b/src/test/ui-fulldeps/pprust-expr-roundtrip.rs index 784f71a61fd72..d4aff73590734 100644 --- a/src/test/ui-fulldeps/pprust-expr-roundtrip.rs +++ b/src/test/ui-fulldeps/pprust-expr-roundtrip.rs @@ -114,7 +114,6 @@ fn iter_exprs(depth: usize, f: &mut dyn FnMut(P)) { let decl = P(FnDecl { inputs: vec![], output: FunctionRetTy::Default(DUMMY_SP), - c_variadic: false, }); iter_exprs(depth - 1, &mut |e| g( ExprKind::Closure(CaptureBy::Value, diff --git a/src/test/ui/c-variadic/variadic-ffi-1.stderr b/src/test/ui/c-variadic/variadic-ffi-1.stderr index 695eba2a7ee40..73f72a177bcaa 100644 --- a/src/test/ui/c-variadic/variadic-ffi-1.stderr +++ b/src/test/ui/c-variadic/variadic-ffi-1.stderr @@ -29,7 +29,7 @@ LL | let x: unsafe extern "C" fn(f: isize, x: u8) = foo; | ^^^ expected non-variadic fn, found variadic function | = note: expected type `unsafe extern "C" fn(isize, u8)` - found type `for<'r> unsafe extern "C" fn(isize, u8, std::ffi::VaListImpl<'r>, ...) {foo}` + found type `unsafe extern "C" fn(isize, u8, ...) {foo}` error[E0308]: mismatched types --> $DIR/variadic-ffi-1.rs:20:54 @@ -37,7 +37,7 @@ error[E0308]: mismatched types LL | let y: extern "C" fn(f: isize, x: u8, ...) = bar; | ^^^ expected variadic fn, found non-variadic function | - = note: expected type `for<'r> extern "C" fn(isize, u8, std::ffi::VaListImpl<'r>, ...)` + = note: expected type `extern "C" fn(isize, u8, ...)` found type `extern "C" fn(isize, u8) {bar}` error[E0617]: can't pass `f32` to variadic function diff --git a/src/test/ui/c-variadic/variadic-ffi-4.nll.stderr b/src/test/ui/c-variadic/variadic-ffi-4.nll.stderr index ab8398ec5e935..8b70b15fa6e50 100644 --- a/src/test/ui/c-variadic/variadic-ffi-4.nll.stderr +++ b/src/test/ui/c-variadic/variadic-ffi-4.nll.stderr @@ -1,18 +1,30 @@ -error[E0621]: explicit lifetime required in the type of `ap` +error: lifetime may not live long enough + --> $DIR/variadic-ffi-4.rs:8:5 + | +LL | pub unsafe extern "C" fn no_escape0<'f>(_: usize, ap: ...) -> VaListImpl<'f> { + | -- -- has type `core::ffi::VaListImpl<'1>` + | | + | lifetime `'f` defined here +LL | ap + | ^^ function was supposed to return data with lifetime `'1` but it is returning data with lifetime `'f` + +error: lifetime may not live long enough --> $DIR/variadic-ffi-4.rs:8:5 | LL | pub unsafe extern "C" fn no_escape0<'f>(_: usize, ap: ...) -> VaListImpl<'f> { - | --- help: add explicit lifetime `'f` to the type of `ap`: `core::ffi::VaListImpl<'f>` + | -- -- has type `core::ffi::VaListImpl<'1>` + | | + | lifetime `'f` defined here LL | ap - | ^^ lifetime `'f` required + | ^^ returning this value requires that `'1` must outlive `'f` -error[E0621]: explicit lifetime required in the type of `ap` +error: lifetime may not live long enough --> $DIR/variadic-ffi-4.rs:12:5 | LL | pub unsafe extern "C" fn no_escape1(_: usize, ap: ...) -> VaListImpl<'static> { - | --- help: add explicit lifetime `'static` to the type of `ap`: `core::ffi::VaListImpl<'static>` + | -- has type `core::ffi::VaListImpl<'1>` LL | ap - | ^^ lifetime `'static` required + | ^^ returning this value requires that `'1` must outlive `'static` error: lifetime may not live long enough --> $DIR/variadic-ffi-4.rs:16:33 @@ -44,7 +56,7 @@ LL | *ap0 = ap1; | ^^^^ assignment requires that `'2` must outlive `'1` error: lifetime may not live long enough - --> $DIR/variadic-ffi-4.rs:25:5 + --> $DIR/variadic-ffi-4.rs:24:5 | LL | pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) { | --- ------- has type `core::ffi::VaListImpl<'2>` @@ -54,7 +66,7 @@ LL | ap0 = &mut ap1; | ^^^^^^^^^^^^^^ assignment requires that `'1` must outlive `'2` error: lifetime may not live long enough - --> $DIR/variadic-ffi-4.rs:25:5 + --> $DIR/variadic-ffi-4.rs:24:5 | LL | pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) { | --- ------- has type `core::ffi::VaListImpl<'2>` @@ -64,7 +76,7 @@ LL | ap0 = &mut ap1; | ^^^^^^^^^^^^^^ assignment requires that `'2` must outlive `'1` error[E0384]: cannot assign to immutable argument `ap0` - --> $DIR/variadic-ffi-4.rs:25:5 + --> $DIR/variadic-ffi-4.rs:24:5 | LL | pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) { | --- help: make this binding mutable: `mut ap0` @@ -72,7 +84,7 @@ LL | ap0 = &mut ap1; | ^^^^^^^^^^^^^^ cannot assign to immutable argument error[E0597]: `ap1` does not live long enough - --> $DIR/variadic-ffi-4.rs:25:11 + --> $DIR/variadic-ffi-4.rs:24:11 | LL | pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) { | - let's call the lifetime of this reference `'1` @@ -86,7 +98,7 @@ LL | } | - `ap1` dropped here while still borrowed error: lifetime may not live long enough - --> $DIR/variadic-ffi-4.rs:33:12 + --> $DIR/variadic-ffi-4.rs:31:12 | LL | pub unsafe extern "C" fn no_escape5(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) { | ------- ------- has type `core::ffi::VaListImpl<'2>` @@ -96,7 +108,7 @@ LL | *ap0 = ap1.clone(); | ^^^^^^^^^^^ argument requires that `'1` must outlive `'2` error: lifetime may not live long enough - --> $DIR/variadic-ffi-4.rs:33:12 + --> $DIR/variadic-ffi-4.rs:31:12 | LL | pub unsafe extern "C" fn no_escape5(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) { | ------- ------- has type `core::ffi::VaListImpl<'2>` @@ -105,7 +117,7 @@ LL | pub unsafe extern "C" fn no_escape5(_: usize, mut ap0: &mut VaListImpl, mut LL | *ap0 = ap1.clone(); | ^^^^^^^^^^^ argument requires that `'2` must outlive `'1` -error: aborting due to 11 previous errors +error: aborting due to 12 previous errors -Some errors have detailed explanations: E0384, E0597, E0621. +Some errors have detailed explanations: E0384, E0597. For more information about an error, try `rustc --explain E0384`. diff --git a/src/test/ui/c-variadic/variadic-ffi-4.rs b/src/test/ui/c-variadic/variadic-ffi-4.rs index 4a50d352a5b20..a4d658cef1630 100644 --- a/src/test/ui/c-variadic/variadic-ffi-4.rs +++ b/src/test/ui/c-variadic/variadic-ffi-4.rs @@ -5,11 +5,11 @@ use core::ffi::{VaList, VaListImpl}; pub unsafe extern "C" fn no_escape0<'f>(_: usize, ap: ...) -> VaListImpl<'f> { - ap //~ ERROR: explicit lifetime required + ap //~ ERROR: mismatched types } pub unsafe extern "C" fn no_escape1(_: usize, ap: ...) -> VaListImpl<'static> { - ap //~ ERROR: explicit lifetime required + ap //~ ERROR: mismatched types } pub unsafe extern "C" fn no_escape2(_: usize, ap: ...) { @@ -18,18 +18,15 @@ pub unsafe extern "C" fn no_escape2(_: usize, ap: ...) { pub unsafe extern "C" fn no_escape3(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) { *ap0 = ap1; //~ ERROR: mismatched types - //~^ ERROR: mismatched types } pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) { ap0 = &mut ap1; //~^ ERROR: a value of type `core::ffi::VaListImpl<'_>` is borrowed for too long - //~^^ ERROR: mismatched types - //~^^^ ERROR: mismatched types - //~^^^^ ERROR: cannot infer an appropriate lifetime + //~| ERROR: mismatched types + //~| ERROR: cannot infer an appropriate lifetime } pub unsafe extern "C" fn no_escape5(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) { *ap0 = ap1.clone(); //~ ERROR: mismatched types - //~^ ERROR: mismatched types } diff --git a/src/test/ui/c-variadic/variadic-ffi-4.stderr b/src/test/ui/c-variadic/variadic-ffi-4.stderr index 7aa510e611304..b986d0c243506 100644 --- a/src/test/ui/c-variadic/variadic-ffi-4.stderr +++ b/src/test/ui/c-variadic/variadic-ffi-4.stderr @@ -1,18 +1,42 @@ -error[E0621]: explicit lifetime required in the type of `ap` +error[E0308]: mismatched types --> $DIR/variadic-ffi-4.rs:8:5 | -LL | pub unsafe extern "C" fn no_escape0<'f>(_: usize, ap: ...) -> VaListImpl<'f> { - | --- help: add explicit lifetime `'f` to the type of `ap`: `core::ffi::VaListImpl<'f>` LL | ap - | ^^ lifetime `'f` required + | ^^ lifetime mismatch + | + = note: expected type `core::ffi::VaListImpl<'f>` + found type `core::ffi::VaListImpl<'_>` +note: the scope of call-site for function at 7:78... + --> $DIR/variadic-ffi-4.rs:7:78 + | +LL | pub unsafe extern "C" fn no_escape0<'f>(_: usize, ap: ...) -> VaListImpl<'f> { + | ______________________________________________________________________________^ +LL | | ap +LL | | } + | |_^ +note: ...does not necessarily outlive the lifetime 'f as defined on the function body at 7:37 + --> $DIR/variadic-ffi-4.rs:7:37 + | +LL | pub unsafe extern "C" fn no_escape0<'f>(_: usize, ap: ...) -> VaListImpl<'f> { + | ^^ -error[E0621]: explicit lifetime required in the type of `ap` +error[E0308]: mismatched types --> $DIR/variadic-ffi-4.rs:12:5 | -LL | pub unsafe extern "C" fn no_escape1(_: usize, ap: ...) -> VaListImpl<'static> { - | --- help: add explicit lifetime `'static` to the type of `ap`: `core::ffi::VaListImpl<'static>` LL | ap - | ^^ lifetime `'static` required + | ^^ lifetime mismatch + | + = note: expected type `core::ffi::VaListImpl<'static>` + found type `core::ffi::VaListImpl<'_>` +note: the scope of call-site for function at 11:79... + --> $DIR/variadic-ffi-4.rs:11:79 + | +LL | pub unsafe extern "C" fn no_escape1(_: usize, ap: ...) -> VaListImpl<'static> { + | _______________________________________________________________________________^ +LL | | ap +LL | | } + | |_^ + = note: ...does not necessarily outlive the static lifetime error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements --> $DIR/variadic-ffi-4.rs:16:33 @@ -47,12 +71,12 @@ LL | *ap0 = ap1; | = note: expected type `core::ffi::VaListImpl<'_>` found type `core::ffi::VaListImpl<'_>` -note: the anonymous lifetime #3 defined on the function body at 19:1... - --> $DIR/variadic-ffi-4.rs:19:1 +note: the scope of call-site for function at 19:87... + --> $DIR/variadic-ffi-4.rs:19:87 | -LL | / pub unsafe extern "C" fn no_escape3(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) { +LL | pub unsafe extern "C" fn no_escape3(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) { + | _______________________________________________________________________________________^ LL | | *ap0 = ap1; -LL | | LL | | } | |_^ note: ...does not necessarily outlive the anonymous lifetime #2 defined on the function body at 19:1 @@ -60,216 +84,129 @@ note: ...does not necessarily outlive the anonymous lifetime #2 defined on the f | LL | / pub unsafe extern "C" fn no_escape3(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) { LL | | *ap0 = ap1; -LL | | -LL | | } - | |_^ - -error[E0308]: mismatched types - --> $DIR/variadic-ffi-4.rs:20:12 - | -LL | *ap0 = ap1; - | ^^^ lifetime mismatch - | - = note: expected type `core::ffi::VaListImpl<'_>` - found type `core::ffi::VaListImpl<'_>` -note: the anonymous lifetime #2 defined on the function body at 19:1... - --> $DIR/variadic-ffi-4.rs:19:1 - | -LL | / pub unsafe extern "C" fn no_escape3(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) { -LL | | *ap0 = ap1; -LL | | -LL | | } - | |_^ -note: ...does not necessarily outlive the anonymous lifetime #3 defined on the function body at 19:1 - --> $DIR/variadic-ffi-4.rs:19:1 - | -LL | / pub unsafe extern "C" fn no_escape3(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) { -LL | | *ap0 = ap1; -LL | | LL | | } | |_^ error[E0490]: a value of type `core::ffi::VaListImpl<'_>` is borrowed for too long - --> $DIR/variadic-ffi-4.rs:25:11 + --> $DIR/variadic-ffi-4.rs:24:11 | LL | ap0 = &mut ap1; | ^^^^^^^^ | -note: the type is valid for the anonymous lifetime #1 defined on the function body at 24:1 - --> $DIR/variadic-ffi-4.rs:24:1 - | -LL | / pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) { -LL | | ap0 = &mut ap1; -LL | | -LL | | -LL | | -LL | | -LL | | } - | |_^ -note: but the borrow lasts for the anonymous lifetime #3 defined on the function body at 24:1 - --> $DIR/variadic-ffi-4.rs:24:1 - | -LL | / pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) { -LL | | ap0 = &mut ap1; -LL | | -LL | | -LL | | -LL | | -LL | | } - | |_^ - -error[E0308]: mismatched types - --> $DIR/variadic-ffi-4.rs:25:11 - | -LL | ap0 = &mut ap1; - | ^^^^^^^^ lifetime mismatch - | - = note: expected type `&mut core::ffi::VaListImpl<'_>` - found type `&mut core::ffi::VaListImpl<'_>` -note: the anonymous lifetime #3 defined on the function body at 24:1... - --> $DIR/variadic-ffi-4.rs:24:1 +note: the type is valid for the anonymous lifetime #1 defined on the function body at 23:1 + --> $DIR/variadic-ffi-4.rs:23:1 | LL | / pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) { LL | | ap0 = &mut ap1; LL | | LL | | LL | | -LL | | LL | | } | |_^ -note: ...does not necessarily outlive the anonymous lifetime #2 defined on the function body at 24:1 - --> $DIR/variadic-ffi-4.rs:24:1 +note: but the borrow lasts for the scope of call-site for function at 23:83 + --> $DIR/variadic-ffi-4.rs:23:83 | -LL | / pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) { +LL | pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) { + | ___________________________________________________________________________________^ LL | | ap0 = &mut ap1; LL | | LL | | LL | | -LL | | LL | | } | |_^ error[E0308]: mismatched types - --> $DIR/variadic-ffi-4.rs:25:11 + --> $DIR/variadic-ffi-4.rs:24:11 | LL | ap0 = &mut ap1; | ^^^^^^^^ lifetime mismatch | = note: expected type `&mut core::ffi::VaListImpl<'_>` found type `&mut core::ffi::VaListImpl<'_>` -note: the anonymous lifetime #2 defined on the function body at 24:1... - --> $DIR/variadic-ffi-4.rs:24:1 +note: the scope of call-site for function at 23:83... + --> $DIR/variadic-ffi-4.rs:23:83 | -LL | / pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) { +LL | pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) { + | ___________________________________________________________________________________^ LL | | ap0 = &mut ap1; LL | | LL | | LL | | -LL | | LL | | } | |_^ -note: ...does not necessarily outlive the anonymous lifetime #3 defined on the function body at 24:1 - --> $DIR/variadic-ffi-4.rs:24:1 +note: ...does not necessarily outlive the anonymous lifetime #2 defined on the function body at 23:1 + --> $DIR/variadic-ffi-4.rs:23:1 | LL | / pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) { LL | | ap0 = &mut ap1; LL | | LL | | LL | | -LL | | LL | | } | |_^ error[E0495]: cannot infer an appropriate lifetime for borrow expression due to conflicting requirements - --> $DIR/variadic-ffi-4.rs:25:11 + --> $DIR/variadic-ffi-4.rs:24:11 | LL | ap0 = &mut ap1; | ^^^^^^^^ | -note: first, the lifetime cannot outlive the anonymous lifetime #3 defined on the function body at 24:1... - --> $DIR/variadic-ffi-4.rs:24:1 +note: first, the lifetime cannot outlive the scope of call-site for function at 23:83... + --> $DIR/variadic-ffi-4.rs:23:83 | -LL | / pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) { +LL | pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) { + | ___________________________________________________________________________________^ LL | | ap0 = &mut ap1; LL | | LL | | LL | | -LL | | LL | | } | |_^ note: ...so that the type `core::ffi::VaListImpl<'_>` is not borrowed for too long - --> $DIR/variadic-ffi-4.rs:25:11 + --> $DIR/variadic-ffi-4.rs:24:11 | LL | ap0 = &mut ap1; | ^^^^^^^^ -note: but, the lifetime must be valid for the anonymous lifetime #1 defined on the function body at 24:1... - --> $DIR/variadic-ffi-4.rs:24:1 +note: but, the lifetime must be valid for the anonymous lifetime #1 defined on the function body at 23:1... + --> $DIR/variadic-ffi-4.rs:23:1 | LL | / pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaListImpl, mut ap1: ...) { LL | | ap0 = &mut ap1; LL | | LL | | LL | | -LL | | LL | | } | |_^ note: ...so that reference does not outlive borrowed content - --> $DIR/variadic-ffi-4.rs:25:11 + --> $DIR/variadic-ffi-4.rs:24:11 | LL | ap0 = &mut ap1; | ^^^^^^^^ error[E0308]: mismatched types - --> $DIR/variadic-ffi-4.rs:33:12 + --> $DIR/variadic-ffi-4.rs:31:12 | LL | *ap0 = ap1.clone(); | ^^^^^^^^^^^ lifetime mismatch | = note: expected type `core::ffi::VaListImpl<'_>` found type `core::ffi::VaListImpl<'_>` -note: the anonymous lifetime #3 defined on the function body at 32:1... - --> $DIR/variadic-ffi-4.rs:32:1 +note: the scope of call-site for function at 30:87... + --> $DIR/variadic-ffi-4.rs:30:87 | -LL | / pub unsafe extern "C" fn no_escape5(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) { +LL | pub unsafe extern "C" fn no_escape5(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) { + | _______________________________________________________________________________________^ LL | | *ap0 = ap1.clone(); -LL | | LL | | } | |_^ -note: ...does not necessarily outlive the anonymous lifetime #2 defined on the function body at 32:1 - --> $DIR/variadic-ffi-4.rs:32:1 +note: ...does not necessarily outlive the anonymous lifetime #2 defined on the function body at 30:1 + --> $DIR/variadic-ffi-4.rs:30:1 | LL | / pub unsafe extern "C" fn no_escape5(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) { LL | | *ap0 = ap1.clone(); -LL | | -LL | | } - | |_^ - -error[E0308]: mismatched types - --> $DIR/variadic-ffi-4.rs:33:12 - | -LL | *ap0 = ap1.clone(); - | ^^^^^^^^^^^ lifetime mismatch - | - = note: expected type `core::ffi::VaListImpl<'_>` - found type `core::ffi::VaListImpl<'_>` -note: the anonymous lifetime #2 defined on the function body at 32:1... - --> $DIR/variadic-ffi-4.rs:32:1 - | -LL | / pub unsafe extern "C" fn no_escape5(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) { -LL | | *ap0 = ap1.clone(); -LL | | -LL | | } - | |_^ -note: ...does not necessarily outlive the anonymous lifetime #3 defined on the function body at 32:1 - --> $DIR/variadic-ffi-4.rs:32:1 - | -LL | / pub unsafe extern "C" fn no_escape5(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) { -LL | | *ap0 = ap1.clone(); -LL | | LL | | } | |_^ -error: aborting due to 11 previous errors +error: aborting due to 8 previous errors -Some errors have detailed explanations: E0308, E0621. -For more information about an error, try `rustc --explain E0308`. +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/error-codes/E0617.rs b/src/test/ui/error-codes/E0617.rs index 439c3db576864..c832e09ac1118 100644 --- a/src/test/ui/error-codes/E0617.rs +++ b/src/test/ui/error-codes/E0617.rs @@ -1,5 +1,3 @@ -// ignore-tidy-linelength - extern { fn printf(c: *const i8, ...); } @@ -22,7 +20,7 @@ fn main() { //~^ ERROR can't pass `u16` to variadic function //~| HELP cast the value to `c_uint` printf(::std::ptr::null(), printf); - //~^ ERROR can't pass `for<'r> unsafe extern "C" fn(*const i8, std::ffi::VaListImpl<'r>, ...) {printf}` to variadic function - //~| HELP cast the value to `for<'r> unsafe extern "C" fn(*const i8, std::ffi::VaListImpl<'r>, ...)` + //~^ ERROR can't pass `unsafe extern "C" fn(*const i8, ...) {printf}` to variadic function + //~| HELP cast the value to `unsafe extern "C" fn(*const i8, ...)` } } diff --git a/src/test/ui/error-codes/E0617.stderr b/src/test/ui/error-codes/E0617.stderr index d866320bbcdf7..7c4df099d0dd1 100644 --- a/src/test/ui/error-codes/E0617.stderr +++ b/src/test/ui/error-codes/E0617.stderr @@ -1,42 +1,42 @@ error[E0617]: can't pass `f32` to variadic function - --> $DIR/E0617.rs:9:36 + --> $DIR/E0617.rs:7:36 | LL | printf(::std::ptr::null(), 0f32); | ^^^^ help: cast the value to `c_double`: `0f32 as c_double` error[E0617]: can't pass `i8` to variadic function - --> $DIR/E0617.rs:12:36 + --> $DIR/E0617.rs:10:36 | LL | printf(::std::ptr::null(), 0i8); | ^^^ help: cast the value to `c_int`: `0i8 as c_int` error[E0617]: can't pass `i16` to variadic function - --> $DIR/E0617.rs:15:36 + --> $DIR/E0617.rs:13:36 | LL | printf(::std::ptr::null(), 0i16); | ^^^^ help: cast the value to `c_int`: `0i16 as c_int` error[E0617]: can't pass `u8` to variadic function - --> $DIR/E0617.rs:18:36 + --> $DIR/E0617.rs:16:36 | LL | printf(::std::ptr::null(), 0u8); | ^^^ help: cast the value to `c_uint`: `0u8 as c_uint` error[E0617]: can't pass `u16` to variadic function - --> $DIR/E0617.rs:21:36 + --> $DIR/E0617.rs:19:36 | LL | printf(::std::ptr::null(), 0u16); | ^^^^ help: cast the value to `c_uint`: `0u16 as c_uint` -error[E0617]: can't pass `for<'r> unsafe extern "C" fn(*const i8, std::ffi::VaListImpl<'r>, ...) {printf}` to variadic function - --> $DIR/E0617.rs:24:36 +error[E0617]: can't pass `unsafe extern "C" fn(*const i8, ...) {printf}` to variadic function + --> $DIR/E0617.rs:22:36 | LL | printf(::std::ptr::null(), printf); | ^^^^^^ -help: cast the value to `for<'r> unsafe extern "C" fn(*const i8, std::ffi::VaListImpl<'r>, ...)` +help: cast the value to `unsafe extern "C" fn(*const i8, ...)` | -LL | printf(::std::ptr::null(), printf as for<'r> unsafe extern "C" fn(*const i8, std::ffi::VaListImpl<'r>, ...)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | printf(::std::ptr::null(), printf as unsafe extern "C" fn(*const i8, ...)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 6 previous errors diff --git a/src/test/ui/symbol-names/impl1.legacy.stderr b/src/test/ui/symbol-names/impl1.legacy.stderr index c1d22a919d900..a3d966bb0b035 100644 --- a/src/test/ui/symbol-names/impl1.legacy.stderr +++ b/src/test/ui/symbol-names/impl1.legacy.stderr @@ -46,26 +46,26 @@ error: def-path(bar::::baz) LL | #[rustc_def_path] | ^^^^^^^^^^^^^^^^^ -error: symbol-name(_ZN198_$LT$$u5b$$RF$dyn$u20$impl1..Foo$u2b$Assoc$u20$$u3d$$u20$extern$u20$$u22$C$u22$$u20$fn$LP$$RF$u8$RP$$u2b$impl1..AutoTrait$u3b$$u20$_$u5d$$u20$as$u20$impl1..main..$u7b$$u7b$closure$u7d$$u7d$..Bar$GT$6method17h6f205aef6a8ccc7bE) - --> $DIR/impl1.rs:63:13 +error: symbol-name(_ZN209_$LT$$u5b$$RF$dyn$u20$impl1..Foo$u2b$Assoc$u20$$u3d$$u20$extern$u20$$u22$C$u22$$u20$fn$LP$$RF$u8$C$$u20$...$RP$$u2b$impl1..AutoTrait$u3b$$u20$_$u5d$$u20$as$u20$impl1..main..$u7b$$u7b$closure$u7d$$u7d$..Bar$GT$6method17h059bf53000885489E) + --> $DIR/impl1.rs:61:13 | LL | #[rustc_symbol_name] | ^^^^^^^^^^^^^^^^^^^^ -error: demangling(<[&dyn impl1::Foo+Assoc = extern "C" fn(&u8)+impl1::AutoTrait; _] as impl1::main::{{closure}}::Bar>::method::h6f205aef6a8ccc7b) - --> $DIR/impl1.rs:63:13 +error: demangling(<[&dyn impl1::Foo+Assoc = extern "C" fn(&u8, ::.)+impl1::AutoTrait; _] as impl1::main::{{closure}}::Bar>::method::h059bf53000885489) + --> $DIR/impl1.rs:61:13 | LL | #[rustc_symbol_name] | ^^^^^^^^^^^^^^^^^^^^ -error: demangling-alt(<[&dyn impl1::Foo+Assoc = extern "C" fn(&u8)+impl1::AutoTrait; _] as impl1::main::{{closure}}::Bar>::method) - --> $DIR/impl1.rs:63:13 +error: demangling-alt(<[&dyn impl1::Foo+Assoc = extern "C" fn(&u8, ::.)+impl1::AutoTrait; _] as impl1::main::{{closure}}::Bar>::method) + --> $DIR/impl1.rs:61:13 | LL | #[rustc_symbol_name] | ^^^^^^^^^^^^^^^^^^^^ -error: def-path(<[&dyn Foo extern "C" fn(&'r u8)> + AutoTrait; _] as main::{{closure}}#1::Bar>::method) - --> $DIR/impl1.rs:70:13 +error: def-path(<[&dyn Foo extern "C" fn(&'r u8, ...)> + AutoTrait; _] as main::{{closure}}#1::Bar>::method) + --> $DIR/impl1.rs:68:13 | LL | #[rustc_def_path] | ^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/symbol-names/impl1.rs b/src/test/ui/symbol-names/impl1.rs index 137b72dcd9c44..add0d10ea6cb0 100644 --- a/src/test/ui/symbol-names/impl1.rs +++ b/src/test/ui/symbol-names/impl1.rs @@ -57,19 +57,17 @@ fn main() { } // Test type mangling, by putting them in an `impl` header. - // FIXME(eddyb) test C varargs when `core::ffi::VaListImpl` stops leaking into the signature - // (which is a problem because `core` has an unpredictable hash) - see also #44930. - impl Bar for [&'_ (dyn Foo + AutoTrait); 3] { + impl Bar for [&'_ (dyn Foo + AutoTrait); 3] { #[rustc_symbol_name] - //[legacy]~^ ERROR symbol-name(_ZN198_$LT$$u5b$$RF$dyn$u20$impl1..Foo$u2b$Assoc$u20$$u3d$$u20$extern$u20$$u22$C$u22$$u20$fn$LP$$RF$u8$RP$$u2b$impl1..AutoTrait$u3b$$u20$_$u5d$$u20$as$u20$impl1..main..$u7b$$u7b$closure$u7d$$u7d$..Bar$GT$6method - //[legacy]~| ERROR demangling(<[&dyn impl1::Foo+Assoc = extern "C" fn(&u8)+impl1::AutoTrait; _] as impl1::main::{{closure}}::Bar>::method - //[legacy]~| ERROR demangling-alt(<[&dyn impl1::Foo+Assoc = extern "C" fn(&u8)+impl1::AutoTrait; _] as impl1::main::{{closure}}::Bar>::method) - //[v0]~^^^^ ERROR symbol-name(_RNvXNCNvCs4fqI2P2rA04_5impl14mains_0ARDNtB6_3Foop5AssocFG_KCRL0_hEuNtB6_9AutoTraitEL_j3_NtB2_3Bar6method) - //[v0]~| ERROR demangling(<[&dyn impl1[317d481089b8c8fe]::Foo extern "C" fn(&'a u8)> + impl1[317d481089b8c8fe]::AutoTrait; 3: usize] as impl1[317d481089b8c8fe]::main::{closure#1}::Bar>::method) - //[v0]~| ERROR demangling-alt(<[&dyn impl1::Foo extern "C" fn(&'a u8)> + impl1::AutoTrait; 3] as impl1::main::{closure#1}::Bar>::method) + //[legacy]~^ ERROR symbol-name(_ZN209_$LT$$u5b$$RF$dyn$u20$impl1..Foo$u2b$Assoc$u20$$u3d$$u20$extern$u20$$u22$C$u22$$u20$fn$LP$$RF$u8$C$$u20$...$RP$$u2b$impl1..AutoTrait$u3b$$u20$_$u5d$$u20$as$u20$impl1..main..$u7b$$u7b$closure$u7d$$u7d$..Bar$GT$6method + //[legacy]~| ERROR demangling(<[&dyn impl1::Foo+Assoc = extern "C" fn(&u8, ::.)+impl1::AutoTrait; _] as impl1::main::{{closure}}::Bar>::method + //[legacy]~| ERROR demangling-alt(<[&dyn impl1::Foo+Assoc = extern "C" fn(&u8, ::.)+impl1::AutoTrait; _] as impl1::main::{{closure}}::Bar>::method) + //[v0]~^^^^ ERROR symbol-name(_RNvXNCNvCs4fqI2P2rA04_5impl14mains_0ARDNtB6_3Foop5AssocFG_KCRL0_hvEuNtB6_9AutoTraitEL_j3_NtB2_3Bar6method) + //[v0]~| ERROR demangling(<[&dyn impl1[317d481089b8c8fe]::Foo extern "C" fn(&'a u8, ...)> + impl1[317d481089b8c8fe]::AutoTrait; 3: usize] as impl1[317d481089b8c8fe]::main::{closure#1}::Bar>::method) + //[v0]~| ERROR demangling-alt(<[&dyn impl1::Foo extern "C" fn(&'a u8, ...)> + impl1::AutoTrait; 3] as impl1::main::{closure#1}::Bar>::method) #[rustc_def_path] - //[legacy]~^ ERROR def-path(<[&dyn Foo extern "C" fn(&'r u8)> + AutoTrait; _] as main::{{closure}}#1::Bar>::method) - //[v0]~^^ ERROR def-path(<[&dyn Foo extern "C" fn(&'r u8)> + AutoTrait; _] as main::{{closure}}#1::Bar>::method) + //[legacy]~^ ERROR def-path(<[&dyn Foo extern "C" fn(&'r u8, ...)> + AutoTrait; _] as main::{{closure}}#1::Bar>::method) + //[v0]~^^ ERROR def-path(<[&dyn Foo extern "C" fn(&'r u8, ...)> + AutoTrait; _] as main::{{closure}}#1::Bar>::method) fn method(&self) {} } }; diff --git a/src/test/ui/symbol-names/impl1.v0.stderr b/src/test/ui/symbol-names/impl1.v0.stderr index e024799df867c..01fe39ddf6cf9 100644 --- a/src/test/ui/symbol-names/impl1.v0.stderr +++ b/src/test/ui/symbol-names/impl1.v0.stderr @@ -46,26 +46,26 @@ error: def-path(bar::::baz) LL | #[rustc_def_path] | ^^^^^^^^^^^^^^^^^ -error: symbol-name(_RNvXNCNvCs4fqI2P2rA04_5impl14mains_0ARDNtB6_3Foop5AssocFG_KCRL0_hEuNtB6_9AutoTraitEL_j3_NtB2_3Bar6method) - --> $DIR/impl1.rs:63:13 +error: symbol-name(_RNvXNCNvCs4fqI2P2rA04_5impl14mains_0ARDNtB6_3Foop5AssocFG_KCRL0_hvEuNtB6_9AutoTraitEL_j3_NtB2_3Bar6method) + --> $DIR/impl1.rs:61:13 | LL | #[rustc_symbol_name] | ^^^^^^^^^^^^^^^^^^^^ -error: demangling(<[&dyn impl1[317d481089b8c8fe]::Foo extern "C" fn(&'a u8)> + impl1[317d481089b8c8fe]::AutoTrait; 3: usize] as impl1[317d481089b8c8fe]::main::{closure#1}::Bar>::method) - --> $DIR/impl1.rs:63:13 +error: demangling(<[&dyn impl1[317d481089b8c8fe]::Foo extern "C" fn(&'a u8, ...)> + impl1[317d481089b8c8fe]::AutoTrait; 3: usize] as impl1[317d481089b8c8fe]::main::{closure#1}::Bar>::method) + --> $DIR/impl1.rs:61:13 | LL | #[rustc_symbol_name] | ^^^^^^^^^^^^^^^^^^^^ -error: demangling-alt(<[&dyn impl1::Foo extern "C" fn(&'a u8)> + impl1::AutoTrait; 3] as impl1::main::{closure#1}::Bar>::method) - --> $DIR/impl1.rs:63:13 +error: demangling-alt(<[&dyn impl1::Foo extern "C" fn(&'a u8, ...)> + impl1::AutoTrait; 3] as impl1::main::{closure#1}::Bar>::method) + --> $DIR/impl1.rs:61:13 | LL | #[rustc_symbol_name] | ^^^^^^^^^^^^^^^^^^^^ -error: def-path(<[&dyn Foo extern "C" fn(&'r u8)> + AutoTrait; _] as main::{{closure}}#1::Bar>::method) - --> $DIR/impl1.rs:70:13 +error: def-path(<[&dyn Foo extern "C" fn(&'r u8, ...)> + AutoTrait; _] as main::{{closure}}#1::Bar>::method) + --> $DIR/impl1.rs:68:13 | LL | #[rustc_def_path] | ^^^^^^^^^^^^^^^^^