diff --git a/Cargo.lock b/Cargo.lock index d5d66f8998710..2fab6f8a05b38 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3837,6 +3837,7 @@ dependencies = [ "log", "rustc_data_structures", "rustc_index", + "rustc_macros", "serialize", "syntax_pos", ] @@ -4404,6 +4405,7 @@ dependencies = [ "rustc_errors", "rustc_index", "rustc_lexer", + "rustc_macros", "scoped-tls", "serialize", "smallvec 1.0.0", diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index 29e3f7132766e..91c19e269a7f1 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -1086,10 +1086,9 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) { ExprKind::Ret(ref optional_expression) => { walk_list!(visitor, visit_expr, optional_expression); } - ExprKind::InlineAsm(_, ref outputs, ref inputs) => { - for expr in outputs.iter().chain(inputs.iter()) { - visitor.visit_expr(expr) - } + ExprKind::InlineAsm(ref asm) => { + walk_list!(visitor, visit_expr, &asm.outputs_exprs); + walk_list!(visitor, visit_expr, &asm.inputs_exprs); } ExprKind::Yield(ref subexpression, _) => { visitor.visit_expr(subexpression); diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 06a7a6bb301de..ac8173f101a65 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -2170,6 +2170,16 @@ impl<'a> LoweringContext<'a> { impl_trait_return_allow: bool, make_ret_async: Option, ) -> P { + debug!("lower_fn_decl(\ + fn_decl: {:?}, \ + in_band_ty_params: {:?}, \ + impl_trait_return_allow: {}, \ + make_ret_async: {:?})", + decl, + in_band_ty_params, + impl_trait_return_allow, + make_ret_async, + ); let lt_mode = if make_ret_async.is_some() { // In `async fn`, argument-position elided lifetimes // must be transformed into fresh generic parameters so that @@ -2462,7 +2472,7 @@ impl<'a> LoweringContext<'a> { hir::FunctionRetTy::Return(P(hir::Ty { kind: opaque_ty_ref, - span, + span: opaque_ty_span, hir_id: self.next_id(), })) } @@ -2572,7 +2582,7 @@ impl<'a> LoweringContext<'a> { hir::Lifetime { hir_id: self.lower_node_id(id), span, - name: name, + name, } } diff --git a/src/librustc/hir/lowering/expr.rs b/src/librustc/hir/lowering/expr.rs index d5d3ff0db2ebc..929dce7aa0ff1 100644 --- a/src/librustc/hir/lowering/expr.rs +++ b/src/librustc/hir/lowering/expr.rs @@ -966,7 +966,7 @@ impl LoweringContext<'_> { } fn lower_expr_asm(&mut self, asm: &InlineAsm) -> hir::ExprKind { - let hir_asm = hir::InlineAsm { + let inner = hir::InlineAsmInner { inputs: asm.inputs.iter().map(|&(ref c, _)| c.clone()).collect(), outputs: asm.outputs .iter() @@ -984,18 +984,18 @@ impl LoweringContext<'_> { alignstack: asm.alignstack, dialect: asm.dialect, }; - - let outputs = asm.outputs - .iter() - .map(|out| self.lower_expr(&out.expr)) - .collect(); - - let inputs = asm.inputs - .iter() - .map(|&(_, ref input)| self.lower_expr(input)) - .collect(); - - hir::ExprKind::InlineAsm(P(hir_asm), outputs, inputs) + let hir_asm = hir::InlineAsm { + inner, + inputs_exprs: asm.inputs + .iter() + .map(|&(_, ref input)| self.lower_expr(input)) + .collect(), + outputs_exprs: asm.outputs + .iter() + .map(|out| self.lower_expr(&out.expr)) + .collect(), + }; + hir::ExprKind::InlineAsm(P(hir_asm)) } fn lower_field(&mut self, f: &Field) -> hir::Field { diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 465673082e50a..17b13dae37fdb 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -1457,7 +1457,7 @@ pub struct Expr { // `Expr` is used a lot. Make sure it doesn't unintentionally get bigger. #[cfg(target_arch = "x86_64")] -static_assert_size!(Expr, 72); +static_assert_size!(Expr, 64); impl Expr { pub fn precedence(&self) -> ExprPrecedence { @@ -1656,7 +1656,7 @@ pub enum ExprKind { Ret(Option>), /// Inline assembly (from `asm!`), with its outputs and inputs. - InlineAsm(P, HirVec, HirVec), + InlineAsm(P), /// A struct or struct-like variant literal expression. /// @@ -2063,7 +2063,7 @@ pub struct InlineAsmOutput { // NOTE(eddyb) This is used within MIR as well, so unlike the rest of the HIR, // it needs to be `Clone` and use plain `Vec` instead of `HirVec`. #[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] -pub struct InlineAsm { +pub struct InlineAsmInner { pub asm: Symbol, pub asm_str_style: StrStyle, pub outputs: Vec, @@ -2074,6 +2074,13 @@ pub struct InlineAsm { pub dialect: AsmDialect, } +#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] +pub struct InlineAsm { + pub inner: InlineAsmInner, + pub outputs_exprs: HirVec, + pub inputs_exprs: HirVec, +} + /// Represents a parameter in a function header. #[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] pub struct Param { diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index ba618a1da8cef..4cbe0e8099126 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -1365,14 +1365,15 @@ impl<'a> State<'a> { self.print_expr_maybe_paren(&expr, parser::PREC_JUMP); } } - hir::ExprKind::InlineAsm(ref a, ref outputs, ref inputs) => { + hir::ExprKind::InlineAsm(ref a) => { + let i = &a.inner; self.s.word("asm!"); self.popen(); - self.print_string(&a.asm.as_str(), a.asm_str_style); + self.print_string(&i.asm.as_str(), i.asm_str_style); self.word_space(":"); let mut out_idx = 0; - self.commasep(Inconsistent, &a.outputs, |s, out| { + self.commasep(Inconsistent, &i.outputs, |s, out| { let constraint = out.constraint.as_str(); let mut ch = constraint.chars(); match ch.next() { @@ -1383,7 +1384,7 @@ impl<'a> State<'a> { _ => s.print_string(&constraint, ast::StrStyle::Cooked), } s.popen(); - s.print_expr(&outputs[out_idx]); + s.print_expr(&a.outputs_exprs[out_idx]); s.pclose(); out_idx += 1; }); @@ -1391,28 +1392,28 @@ impl<'a> State<'a> { self.word_space(":"); let mut in_idx = 0; - self.commasep(Inconsistent, &a.inputs, |s, co| { + self.commasep(Inconsistent, &i.inputs, |s, co| { s.print_string(&co.as_str(), ast::StrStyle::Cooked); s.popen(); - s.print_expr(&inputs[in_idx]); + s.print_expr(&a.inputs_exprs[in_idx]); s.pclose(); in_idx += 1; }); self.s.space(); self.word_space(":"); - self.commasep(Inconsistent, &a.clobbers, |s, co| { + self.commasep(Inconsistent, &i.clobbers, |s, co| { s.print_string(&co.as_str(), ast::StrStyle::Cooked); }); let mut options = vec![]; - if a.volatile { + if i.volatile { options.push("volatile"); } - if a.alignstack { + if i.alignstack { options.push("alignstack"); } - if a.dialect == ast::AsmDialect::Intel { + if i.dialect == ast::AsmDialect::Intel { options.push("intel"); } diff --git a/src/librustc/ich/impls_hir.rs b/src/librustc/ich/impls_hir.rs index 816e93698bce9..39d1f850f45ef 100644 --- a/src/librustc/ich/impls_hir.rs +++ b/src/librustc/ich/impls_hir.rs @@ -213,11 +213,6 @@ impl<'a> HashStable> for hir::ImplItem { } } -impl_stable_hash_for!(enum ast::CrateSugar { - JustCrate, - PubCrate, -}); - impl<'a> HashStable> for hir::VisibilityKind { fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { mem::discriminant(self).hash_stable(hcx, hasher); diff --git a/src/librustc/ich/impls_misc.rs b/src/librustc/ich/impls_misc.rs deleted file mode 100644 index 417305139e472..0000000000000 --- a/src/librustc/ich/impls_misc.rs +++ /dev/null @@ -1,7 +0,0 @@ -//! This module contains `HashStable` implementations for various data types -//! that don't fit into any of the other impls_xxx modules. - -impl_stable_hash_for!(enum ::rustc_target::spec::PanicStrategy { - Abort, - Unwind -}); diff --git a/src/librustc/ich/impls_syntax.rs b/src/librustc/ich/impls_syntax.rs index b3d82e5522cf2..f8bf8f4ab8a2f 100644 --- a/src/librustc/ich/impls_syntax.rs +++ b/src/librustc/ich/impls_syntax.rs @@ -10,135 +10,12 @@ use syntax::ast; use syntax::feature_gate; use syntax::token; use syntax::tokenstream; -use syntax_pos::symbol::SymbolStr; 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}; - -impl<'a> HashStable> for SymbolStr { - #[inline] - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { - let str = self as &str; - str.hash_stable(hcx, hasher) - } -} - -impl<'a> ToStableHashKey> for SymbolStr { - type KeyType = SymbolStr; - - #[inline] - fn to_stable_hash_key(&self, - _: &StableHashingContext<'a>) - -> SymbolStr { - self.clone() - } -} - -impl<'a> HashStable> for ast::Name { - #[inline] - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { - self.as_str().hash_stable(hcx, hasher); - } -} - -impl<'a> ToStableHashKey> for ast::Name { - type KeyType = SymbolStr; - - #[inline] - fn to_stable_hash_key(&self, - _: &StableHashingContext<'a>) - -> SymbolStr { - self.as_str() - } -} - -impl_stable_hash_for!(enum ::syntax::ast::AsmDialect { - Att, - Intel -}); - -impl_stable_hash_for!(enum ::syntax_pos::hygiene::MacroKind { - Bang, - Attr, - Derive, -}); - - -impl_stable_hash_for!(enum ::rustc_target::spec::abi::Abi { - Cdecl, - Stdcall, - Fastcall, - Vectorcall, - Thiscall, - Aapcs, - Win64, - SysV64, - PtxKernel, - Msp430Interrupt, - X86Interrupt, - AmdGpuKernel, - EfiApi, - Rust, - C, - System, - RustIntrinsic, - RustCall, - PlatformIntrinsic, - Unadjusted -}); - -impl_stable_hash_for!(struct ::syntax::attr::Deprecation { since, note }); -impl_stable_hash_for!(struct ::syntax::attr::Stability { - level, - feature, - rustc_depr, - promotable, - allow_const_fn_ptr, - const_stability -}); - -impl_stable_hash_for!(enum ::syntax::edition::Edition { - Edition2015, - Edition2018, -}); - -impl<'a> HashStable> -for ::syntax::attr::StabilityLevel { - 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 } => { - reason.hash_stable(hcx, hasher); - issue.hash_stable(hcx, hasher); - is_soft.hash_stable(hcx, hasher); - } - ::syntax::attr::StabilityLevel::Stable { ref since } => { - since.hash_stable(hcx, hasher); - } - } - } -} - -impl_stable_hash_for!(struct ::syntax::attr::RustcDeprecation { since, reason, suggestion }); - -impl_stable_hash_for!(enum ::syntax::attr::IntType { - SignedInt(int_ty), - UnsignedInt(uint_ty) -}); - -impl_stable_hash_for!(enum ::syntax::ast::LitIntType { - Signed(int_ty), - Unsigned(int_ty), - Unsuffixed -}); - -impl_stable_hash_for!(enum ::syntax::ast::LitFloatType { - Suffixed(float_ty), - Unsuffixed -}); +use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; impl_stable_hash_for!(struct ::syntax::ast::Lit { kind, @@ -146,32 +23,9 @@ impl_stable_hash_for!(struct ::syntax::ast::Lit { span }); -impl_stable_hash_for!(enum ::syntax::ast::LitKind { - Str(value, style), - ByteStr(value), - Byte(value), - Char(value), - Int(value, lit_int_type), - Float(value, lit_float_type), - Bool(value), - Err(value) -}); - impl_stable_hash_for_spanned!(::syntax::ast::LitKind); -impl_stable_hash_for!(enum ::syntax::ast::IntTy { Isize, I8, I16, I32, I64, I128 }); -impl_stable_hash_for!(enum ::syntax::ast::UintTy { Usize, U8, U16, U32, U64, U128 }); -impl_stable_hash_for!(enum ::syntax::ast::FloatTy { F32, F64 }); -impl_stable_hash_for!(enum ::syntax::ast::Unsafety { Unsafe, Normal }); -impl_stable_hash_for!(enum ::syntax::ast::Constness { Const, NotConst }); -impl_stable_hash_for!(enum ::syntax::ast::Defaultness { Default, Final }); impl_stable_hash_for!(struct ::syntax::ast::Lifetime { id, ident }); -impl_stable_hash_for!(enum ::syntax::ast::StrStyle { Cooked, Raw(pounds) }); -impl_stable_hash_for!(enum ::syntax::ast::AttrStyle { Outer, Inner }); -impl_stable_hash_for!(enum ::syntax::ast::Movability { Static, Movable }); -impl_stable_hash_for!(enum ::syntax::ast::CaptureBy { Value, Ref }); -impl_stable_hash_for!(enum ::syntax::ast::IsAuto { Yes, No }); -impl_stable_hash_for!(enum ::syntax::ast::ImplPolarity { Positive, Negative }); impl<'a> HashStable> for [ast::Attribute] { fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { @@ -255,25 +109,6 @@ for tokenstream::TokenStream { } } -impl_stable_hash_for!(enum token::LitKind { - Bool, - Byte, - Char, - Integer, - Float, - Str, - ByteStr, - StrRaw(n), - ByteStrRaw(n), - Err -}); - -impl_stable_hash_for!(struct token::Lit { - kind, - symbol, - suffix -}); - impl<'a> HashStable> for token::TokenKind { fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { mem::discriminant(self).hash_stable(hcx, hasher); @@ -359,12 +194,6 @@ impl_stable_hash_for!(enum ::syntax::ast::MetaItemKind { NameValue(lit) }); -impl_stable_hash_for!(enum ::syntax_pos::hygiene::Transparency { - Transparent, - SemiTransparent, - Opaque, -}); - impl_stable_hash_for!(struct ::syntax_pos::hygiene::ExpnData { kind, parent -> _, @@ -376,43 +205,6 @@ impl_stable_hash_for!(struct ::syntax_pos::hygiene::ExpnData { edition }); -impl_stable_hash_for!(enum ::syntax_pos::hygiene::ExpnKind { - Root, - Macro(kind, descr), - AstPass(kind), - Desugaring(kind) -}); - -impl_stable_hash_for!(enum ::syntax_pos::hygiene::AstPass { - StdImports, - TestHarness, - ProcMacroHarness, - PluginMacroDefs, -}); - -impl_stable_hash_for!(enum ::syntax_pos::hygiene::DesugaringKind { - CondTemporary, - Async, - Await, - QuestionMark, - OpaqueTy, - ForLoop, - TryBlock -}); - -impl_stable_hash_for!(enum ::syntax_pos::FileName { - Real(pb), - Macros(s), - QuoteExpansion(s), - Anon(s), - MacroExpansion(s), - ProcMacroSourceCode(s), - CliCrateAttr(s), - CfgSpec(s), - Custom(s), - DocTest(pb, line), -}); - impl<'a> HashStable> for SourceFile { fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { let SourceFile { diff --git a/src/librustc/ich/impls_ty.rs b/src/librustc/ich/impls_ty.rs index c643baf11254c..7f50d859cde3a 100644 --- a/src/librustc/ich/impls_ty.rs +++ b/src/librustc/ich/impls_ty.rs @@ -159,11 +159,6 @@ where } } -impl_stable_hash_for!(enum ::syntax::ast::Mutability { - Immutable, - Mutable -}); - impl<'a> ToStableHashKey> for region::Scope { type KeyType = region::Scope; diff --git a/src/librustc/ich/mod.rs b/src/librustc/ich/mod.rs index f3fc7ec8fda15..9e985ffb14ca7 100644 --- a/src/librustc/ich/mod.rs +++ b/src/librustc/ich/mod.rs @@ -10,7 +10,6 @@ mod caching_source_map_view; mod hcx; mod impls_hir; -mod impls_misc; mod impls_ty; mod impls_syntax; diff --git a/src/librustc/infer/error_reporting/nice_region_error/different_lifetimes.rs b/src/librustc/infer/error_reporting/nice_region_error/different_lifetimes.rs index d7cba87e6b132..a431b541fa42f 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/different_lifetimes.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/different_lifetimes.rs @@ -45,7 +45,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { /// /// It will later be extended to trait objects. pub(super) fn try_report_anon_anon_conflict(&self) -> Option { - let (span, sub, sup) = self.get_regions(); + let (span, sub, sup) = self.regions(); // Determine whether the sub and sup consist of both anonymous (elided) regions. let anon_reg_sup = self.tcx().is_suitable_region(sup)?; diff --git a/src/librustc/infer/error_reporting/nice_region_error/mod.rs b/src/librustc/infer/error_reporting/nice_region_error/mod.rs index cd003aa8dab70..09cfbf850a57d 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/mod.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/mod.rs @@ -77,7 +77,7 @@ impl<'cx, 'tcx> NiceRegionError<'cx, 'tcx> { .or_else(|| self.try_report_impl_not_conforming_to_trait()) } - pub fn get_regions(&self) -> (Span, ty::Region<'tcx>, ty::Region<'tcx>) { + pub fn regions(&self) -> (Span, ty::Region<'tcx>, ty::Region<'tcx>) { match (&self.error, self.regions) { (Some(ConcreteFailure(origin, sub, sup)), None) => (origin.span(), sub, sup), (Some(SubSupConflict(_, _, origin, sub, _, sup)), None) => (origin.span(), sub, sup), diff --git a/src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs b/src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs index 3613184919164..0abdeb7199344 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs @@ -11,7 +11,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { /// When given a `ConcreteFailure` for a function with parameters containing a named region and /// an anonymous region, emit an descriptive diagnostic error. pub(super) fn try_report_named_anon_conflict(&self) -> Option> { - let (span, sub, sup) = self.get_regions(); + let (span, sub, sup) = self.regions(); debug!( "try_report_named_anon_conflict(sub={:?}, sup={:?}, error={:?})", diff --git a/src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs b/src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs index 9d405d4ea40c9..01ba748c4e1f9 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs @@ -20,8 +20,9 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { ) = error.clone() { let anon_reg_sup = self.tcx().is_suitable_region(sup_r)?; + let return_ty = self.tcx().return_type_impl_trait(anon_reg_sup.def_id); if sub_r == &RegionKind::ReStatic && - self.tcx().return_type_impl_trait(anon_reg_sup.def_id).is_some() + return_ty.is_some() { let sp = var_origin.span(); let return_sp = sub_origin.span(); @@ -52,17 +53,23 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { }) => name.to_string(), _ => "'_".to_owned(), }; - if let Ok(snippet) = self.tcx().sess.source_map().span_to_snippet(return_sp) { - err.span_suggestion( - return_sp, - &format!( - "you can add a constraint to the return type to make it last \ + let fn_return_span = return_ty.unwrap().1; + if let Ok(snippet) = + self.tcx().sess.source_map().span_to_snippet(fn_return_span) { + // only apply this suggestion onto functions with + // explicit non-desugar'able return. + if fn_return_span.desugaring_kind().is_none() { + err.span_suggestion( + fn_return_span, + &format!( + "you can add a constraint to the return type to make it last \ less than `'static` and match {}", - lifetime, - ), - format!("{} + {}", snippet, lifetime_name), - Applicability::Unspecified, - ); + lifetime, + ), + format!("{} + {}", snippet, lifetime_name), + Applicability::Unspecified, + ); + } } err.emit(); return Some(ErrorReported); diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index bb7ac5d8dbe1a..4571f551aa4d6 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -283,15 +283,15 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { self.borrow_expr(&base, bk); } - hir::ExprKind::InlineAsm(ref ia, ref outputs, ref inputs) => { - for (o, output) in ia.outputs.iter().zip(outputs) { + hir::ExprKind::InlineAsm(ref ia) => { + for (o, output) in ia.inner.outputs.iter().zip(&ia.outputs_exprs) { if o.is_indirect { self.consume_expr(output); } else { self.mutate_expr(output); } } - self.consume_exprs(inputs); + self.consume_exprs(&ia.inputs_exprs); } hir::ExprKind::Continue(..) | diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 79468b68055d4..b7d0f538db5dc 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -6,7 +6,7 @@ use crate::hir::def::{CtorKind, Namespace}; use crate::hir::def_id::DefId; -use crate::hir::{self, InlineAsm as HirInlineAsm}; +use crate::hir; use crate::mir::interpret::{PanicInfo, Scalar}; use crate::mir::visit::MirVisitable; use crate::ty::adjustment::PointerCast; @@ -1638,7 +1638,7 @@ pub enum FakeReadCause { #[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable, TypeFoldable)] pub struct InlineAsm<'tcx> { - pub asm: HirInlineAsm, + pub asm: hir::InlineAsmInner, pub outputs: Box<[Place<'tcx>]>, pub inputs: Box<[(Span, Operand<'tcx>)]>, } diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 41d069bf6ae33..fec0c8bb9223b 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -1529,14 +1529,14 @@ impl<'tcx> TyCtxt<'tcx> { return Some(FreeRegionInfo { def_id: suitable_region_binding_scope, boundregion: bound_region, - is_impl_item: is_impl_item, + is_impl_item, }); } pub fn return_type_impl_trait( &self, scope_def_id: DefId, - ) -> Option> { + ) -> Option<(Ty<'tcx>, Span)> { // HACK: `type_of_def_id()` will fail on these (#55796), so return `None`. let hir_id = self.hir().as_local_hir_id(scope_def_id).unwrap(); match self.hir().get(hir_id) { @@ -1557,7 +1557,8 @@ impl<'tcx> TyCtxt<'tcx> { let sig = ret_ty.fn_sig(*self); let output = self.erase_late_bound_regions(&sig.output()); if output.is_impl_trait() { - Some(output) + let fn_decl = self.hir().fn_decl_by_hir_id(hir_id).unwrap(); + Some((output, fn_decl.output.span())) } else { None } diff --git a/src/librustc/ty/layout.rs b/src/librustc/ty/layout.rs index 972452601ddd5..9e1f6015e273e 100644 --- a/src/librustc/ty/layout.rs +++ b/src/librustc/ty/layout.rs @@ -697,7 +697,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { // SIMD vector types. ty::Adt(def, ..) if def.repr.simd() => { let element = self.layout_of(ty.simd_type(tcx))?; - let count = ty.simd_size(tcx) as u64; + let count = ty.simd_size(tcx); assert!(count > 0); let scalar = match element.abi { Abi::Scalar(ref scalar) => scalar.clone(), @@ -2327,158 +2327,6 @@ where } } -impl<'a> HashStable> for Variants { - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { - use crate::ty::layout::Variants::*; - mem::discriminant(self).hash_stable(hcx, hasher); - - match *self { - Single { index } => { - index.hash_stable(hcx, hasher); - } - Multiple { - ref discr, - ref discr_kind, - discr_index, - ref variants, - } => { - discr.hash_stable(hcx, hasher); - discr_kind.hash_stable(hcx, hasher); - discr_index.hash_stable(hcx, hasher); - variants.hash_stable(hcx, hasher); - } - } - } -} - -impl<'a> HashStable> for DiscriminantKind { - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { - use crate::ty::layout::DiscriminantKind::*; - mem::discriminant(self).hash_stable(hcx, hasher); - - match *self { - Tag => {} - Niche { - dataful_variant, - ref niche_variants, - niche_start, - } => { - dataful_variant.hash_stable(hcx, hasher); - niche_variants.start().hash_stable(hcx, hasher); - niche_variants.end().hash_stable(hcx, hasher); - niche_start.hash_stable(hcx, hasher); - } - } - } -} - -impl<'a> HashStable> for FieldPlacement { - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { - use crate::ty::layout::FieldPlacement::*; - mem::discriminant(self).hash_stable(hcx, hasher); - - match *self { - Union(count) => { - count.hash_stable(hcx, hasher); - } - Array { count, stride } => { - count.hash_stable(hcx, hasher); - stride.hash_stable(hcx, hasher); - } - Arbitrary { ref offsets, ref memory_index } => { - offsets.hash_stable(hcx, hasher); - memory_index.hash_stable(hcx, hasher); - } - } - } -} - -impl<'a> HashStable> for VariantIdx { - 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) { - use crate::ty::layout::Abi::*; - mem::discriminant(self).hash_stable(hcx, hasher); - - match *self { - Uninhabited => {} - Scalar(ref value) => { - value.hash_stable(hcx, hasher); - } - ScalarPair(ref a, ref b) => { - a.hash_stable(hcx, hasher); - b.hash_stable(hcx, hasher); - } - Vector { ref element, count } => { - element.hash_stable(hcx, hasher); - count.hash_stable(hcx, hasher); - } - Aggregate { sized } => { - sized.hash_stable(hcx, hasher); - } - } - } -} - -impl<'a> HashStable> for Scalar { - 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); - valid_range.end().hash_stable(hcx, hasher); - } -} - -impl_stable_hash_for!(struct crate::ty::layout::Niche { - offset, - scalar -}); - -impl_stable_hash_for!(struct crate::ty::layout::LayoutDetails { - variants, - fields, - abi, - largest_niche, - size, - align -}); - -impl_stable_hash_for!(enum crate::ty::layout::Integer { - I8, - I16, - I32, - I64, - I128 -}); - -impl_stable_hash_for!(enum crate::ty::layout::Primitive { - Int(integer, signed), - F32, - F64, - Pointer -}); - -impl_stable_hash_for!(struct crate::ty::layout::AbiAndPrefAlign { - abi, - pref -}); - -impl<'tcx> HashStable> for Align { - 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) { - self.bytes().hash_stable(hcx, hasher); - } -} - impl<'a, 'tcx> HashStable> for LayoutError<'tcx> { fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { use crate::ty::layout::LayoutError::*; diff --git a/src/librustc/ty/structural_impls.rs b/src/librustc/ty/structural_impls.rs index ccac7720914fc..8fbd2e4e6b157 100644 --- a/src/librustc/ty/structural_impls.rs +++ b/src/librustc/ty/structural_impls.rs @@ -301,7 +301,7 @@ CloneTypeFoldableAndLiftImpls! { ::syntax_pos::symbol::Symbol, crate::hir::def::Res, crate::hir::def_id::DefId, - crate::hir::InlineAsm, + crate::hir::InlineAsmInner, crate::hir::MatchSource, crate::hir::Mutability, crate::hir::Unsafety, diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index 07258717cd9d4..ab6a3bc83b1d2 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -1813,20 +1813,30 @@ impl<'tcx> TyS<'tcx> { pub fn simd_type(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> { match self.kind { - Adt(def, substs) => { - def.non_enum_variant().fields[0].ty(tcx, substs) - } + Adt(def, substs) => def.non_enum_variant().fields[0].ty(tcx, substs), _ => bug!("simd_type called on invalid type") } } - pub fn simd_size(&self, _cx: TyCtxt<'_>) -> usize { + pub fn simd_size(&self, _tcx: TyCtxt<'tcx>) -> u64 { + // Parameter currently unused, but probably needed in the future to + // allow `#[repr(simd)] struct Simd([T; N]);`. match self.kind { - Adt(def, _) => def.non_enum_variant().fields.len(), + Adt(def, _) => def.non_enum_variant().fields.len() as u64, _ => bug!("simd_size called on invalid type") } } + pub fn simd_size_and_type(&self, tcx: TyCtxt<'tcx>) -> (u64, Ty<'tcx>) { + match self.kind { + Adt(def, substs) => { + let variant = def.non_enum_variant(); + (variant.fields.len() as u64, variant.fields[0].ty(tcx, substs)) + } + _ => bug!("simd_size_and_type called on invalid type") + } + } + #[inline] pub fn is_region_ptr(&self) -> bool { match self.kind { diff --git a/src/librustc_codegen_llvm/asm.rs b/src/librustc_codegen_llvm/asm.rs index b68ee2cb44d4b..abdd2e3e8dbd7 100644 --- a/src/librustc_codegen_llvm/asm.rs +++ b/src/librustc_codegen_llvm/asm.rs @@ -17,7 +17,7 @@ use libc::{c_uint, c_char}; impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> { fn codegen_inline_asm( &mut self, - ia: &hir::InlineAsm, + ia: &hir::InlineAsmInner, outputs: Vec>, mut inputs: Vec<&'ll Value>, span: Span, diff --git a/src/librustc_codegen_llvm/intrinsic.rs b/src/librustc_codegen_llvm/intrinsic.rs index e1ce7f622e2ef..4277ce1d1f754 100644 --- a/src/librustc_codegen_llvm/intrinsic.rs +++ b/src/librustc_codegen_llvm/intrinsic.rs @@ -1105,8 +1105,8 @@ fn generic_simd_intrinsic( let m_len = match in_ty.kind { // Note that this `.unwrap()` crashes for isize/usize, that's sort // of intentional as there's not currently a use case for that. - ty::Int(i) => i.bit_width().unwrap(), - ty::Uint(i) => i.bit_width().unwrap(), + ty::Int(i) => i.bit_width().unwrap() as u64, + ty::Uint(i) => i.bit_width().unwrap() as u64, _ => return_error!("`{}` is not an integral type", in_ty), }; require_simd!(arg_tys[1], "argument"); @@ -1116,7 +1116,7 @@ fn generic_simd_intrinsic( m_len, v_len ); let i1 = bx.type_i1(); - let i1xn = bx.type_vector(i1, m_len as u64); + let i1xn = bx.type_vector(i1, m_len); let m_i1s = bx.bitcast(args[0].immediate(), i1xn); return Ok(bx.select(m_i1s, args[1].immediate(), args[2].immediate())); } @@ -1160,7 +1160,7 @@ fn generic_simd_intrinsic( } if name.starts_with("simd_shuffle") { - let n: usize = name["simd_shuffle".len()..].parse().unwrap_or_else(|_| + let n: u64 = name["simd_shuffle".len()..].parse().unwrap_or_else(|_| span_bug!(span, "bad `simd_shuffle` instruction only caught in codegen?")); require_simd!(ret_ty, "return"); @@ -1175,7 +1175,7 @@ fn generic_simd_intrinsic( in_elem, in_ty, ret_ty, ret_ty.simd_type(tcx)); - let total_len = in_len as u128 * 2; + let total_len = u128::from(in_len) * 2; let vector = args[2].immediate(); @@ -1251,7 +1251,7 @@ fn generic_simd_intrinsic( // trailing bits. let expected_int_bits = in_len.max(8); match ret_ty.kind { - ty::Uint(i) if i.bit_width() == Some(expected_int_bits) => (), + ty::Uint(i) if i.bit_width() == Some(expected_int_bits as usize) => (), _ => return_error!( "bitmask `{}`, expected `u{}`", ret_ty, expected_int_bits @@ -1276,7 +1276,8 @@ fn generic_simd_intrinsic( // Shift the MSB to the right by "in_elem_bitwidth - 1" into the first bit position. let shift_indices = vec![ - bx.cx.const_int(bx.type_ix(in_elem_bitwidth as _), (in_elem_bitwidth - 1) as _); in_len + bx.cx.const_int(bx.type_ix(in_elem_bitwidth as _), (in_elem_bitwidth - 1) as _); + in_len as _ ]; let i_xn_msb = bx.lshr(i_xn, bx.const_vector(shift_indices.as_slice())); // Truncate vector to an @@ -1291,7 +1292,7 @@ fn generic_simd_intrinsic( name: &str, in_elem: &::rustc::ty::TyS<'_>, in_ty: &::rustc::ty::TyS<'_>, - in_len: usize, + in_len: u64, bx: &mut Builder<'a, 'll, 'tcx>, span: Span, args: &[OperandRef<'tcx, &'ll Value>], @@ -1400,7 +1401,7 @@ fn generic_simd_intrinsic( // FIXME: use: // https://github.com/llvm-mirror/llvm/blob/master/include/llvm/IR/Function.h#L182 // https://github.com/llvm-mirror/llvm/blob/master/include/llvm/IR/Intrinsics.h#L81 - fn llvm_vector_str(elem_ty: Ty<'_>, vec_len: usize, no_pointers: usize) -> String { + fn llvm_vector_str(elem_ty: Ty<'_>, vec_len: u64, no_pointers: usize) -> String { let p0s: String = "p0".repeat(no_pointers); match elem_ty.kind { ty::Int(v) => format!("v{}{}i{}", vec_len, p0s, v.bit_width().unwrap()), @@ -1410,7 +1411,7 @@ fn generic_simd_intrinsic( } } - fn llvm_vector_ty(cx: &CodegenCx<'ll, '_>, elem_ty: Ty<'_>, vec_len: usize, + fn llvm_vector_ty(cx: &CodegenCx<'ll, '_>, elem_ty: Ty<'_>, vec_len: u64, mut no_pointers: usize) -> &'ll Type { // FIXME: use cx.layout_of(ty).llvm_type() ? let mut elem_ty = match elem_ty.kind { @@ -1423,7 +1424,7 @@ fn generic_simd_intrinsic( elem_ty = cx.type_ptr_to(elem_ty); no_pointers -= 1; } - cx.type_vector(elem_ty, vec_len as u64) + cx.type_vector(elem_ty, vec_len) } @@ -1506,7 +1507,7 @@ fn generic_simd_intrinsic( // Truncate the mask vector to a vector of i1s: let (mask, mask_ty) = { let i1 = bx.type_i1(); - let i1xn = bx.type_vector(i1, in_len as u64); + let i1xn = bx.type_vector(i1, in_len); (bx.trunc(args[2].immediate(), i1xn), i1xn) }; @@ -1606,7 +1607,7 @@ fn generic_simd_intrinsic( // Truncate the mask vector to a vector of i1s: let (mask, mask_ty) = { let i1 = bx.type_i1(); - let i1xn = bx.type_vector(i1, in_len as u64); + let i1xn = bx.type_vector(i1, in_len); (bx.trunc(args[2].immediate(), i1xn), i1xn) }; diff --git a/src/librustc_codegen_ssa/traits/asm.rs b/src/librustc_codegen_ssa/traits/asm.rs index c9e1ed86e97e0..612bce2d95854 100644 --- a/src/librustc_codegen_ssa/traits/asm.rs +++ b/src/librustc_codegen_ssa/traits/asm.rs @@ -1,13 +1,13 @@ use super::BackendTypes; use crate::mir::place::PlaceRef; -use rustc::hir::{GlobalAsm, InlineAsm}; +use rustc::hir::{GlobalAsm, InlineAsmInner}; use syntax_pos::Span; pub trait AsmBuilderMethods<'tcx>: BackendTypes { /// Take an inline assembly expression and splat it out via LLVM fn codegen_inline_asm( &mut self, - ia: &InlineAsm, + ia: &InlineAsmInner, outputs: Vec>, inputs: Vec, span: Span, diff --git a/src/librustc_data_structures/stable_hasher.rs b/src/librustc_data_structures/stable_hasher.rs index 092208cfe1db7..ce62021ac1711 100644 --- a/src/librustc_data_structures/stable_hasher.rs +++ b/src/librustc_data_structures/stable_hasher.rs @@ -429,6 +429,16 @@ impl HashStable for ::std::mem::Discriminant { } } +impl HashStable for ::std::ops::RangeInclusive + where T: HashStable +{ + #[inline] + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { + self.start().hash_stable(ctx, hasher); + self.end().hash_stable(ctx, hasher); + } +} + impl HashStable for vec::IndexVec where T: HashStable, { diff --git a/src/librustc_macros/src/hash_stable.rs b/src/librustc_macros/src/hash_stable.rs index 735cfb11b365c..3fb252cbf8d9c 100644 --- a/src/librustc_macros/src/hash_stable.rs +++ b/src/librustc_macros/src/hash_stable.rs @@ -47,6 +47,44 @@ fn parse_attributes(field: &syn::Field) -> Attributes { attrs } +pub fn hash_stable_generic_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream { + let generic: syn::GenericParam = parse_quote!(__CTX); + s.add_bounds(synstructure::AddBounds::Generics); + s.add_impl_generic(generic); + let body = s.each(|bi| { + let attrs = parse_attributes(bi.ast()); + if attrs.ignore { + quote!{} + } else if let Some(project) = attrs.project { + quote!{ + &#bi.#project.hash_stable(__hcx, __hasher); + } + } else { + quote!{ + #bi.hash_stable(__hcx, __hasher); + } + } + }); + + let discriminant = match s.ast().data { + syn::Data::Enum(_) => quote! { + ::std::mem::discriminant(self).hash_stable(__hcx, __hasher); + }, + syn::Data::Struct(_) => quote! {}, + syn::Data::Union(_) => panic!("cannot derive on union"), + }; + + s.bound_impl(quote!(::rustc_data_structures::stable_hasher::HashStable<__CTX>), quote!{ + fn hash_stable( + &self, + __hcx: &mut __CTX, + __hasher: &mut ::rustc_data_structures::stable_hasher::StableHasher) { + #discriminant + match *self { #body } + } + }) +} + pub fn hash_stable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream { let generic: syn::GenericParam = parse_quote!('__ctx); s.add_bounds(synstructure::AddBounds::Generics); diff --git a/src/librustc_macros/src/lib.rs b/src/librustc_macros/src/lib.rs index dce3820d2842c..eee634ffebd92 100644 --- a/src/librustc_macros/src/lib.rs +++ b/src/librustc_macros/src/lib.rs @@ -25,5 +25,10 @@ pub fn symbols(input: TokenStream) -> TokenStream { } decl_derive!([HashStable, attributes(stable_hasher)] => hash_stable::hash_stable_derive); +decl_derive!( + [HashStable_Generic, attributes(stable_hasher)] => + hash_stable::hash_stable_generic_derive +); + decl_derive!([TypeFoldable, attributes(type_foldable)] => type_foldable::type_foldable_derive); decl_derive!([Lift, attributes(lift)] => lift::lift_derive); diff --git a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs index 26b288cb4b24e..e6795dbfd449c 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs @@ -715,10 +715,10 @@ impl<'tcx> RegionInferenceContext<'tcx> { if let (Some(f), Some(ty::RegionKind::ReStatic)) = (self.to_error_region(fr), self.to_error_region(outlived_fr)) { - if let Some(ty::TyS { + if let Some((ty::TyS { kind: ty::Opaque(did, substs), .. - }) = infcx + }, _)) = infcx .tcx .is_suitable_region(f) .map(|r| r.def_id) diff --git a/src/librustc_mir/hair/cx/expr.rs b/src/librustc_mir/hair/cx/expr.rs index 92c9c702c7a83..f25e4b0ae8639 100644 --- a/src/librustc_mir/hair/cx/expr.rs +++ b/src/librustc_mir/hair/cx/expr.rs @@ -533,11 +533,11 @@ fn make_mirror_unadjusted<'a, 'tcx>( convert_path_expr(cx, expr, res) } - hir::ExprKind::InlineAsm(ref asm, ref outputs, ref inputs) => { + hir::ExprKind::InlineAsm(ref asm) => { ExprKind::InlineAsm { - asm, - outputs: outputs.to_ref(), - inputs: inputs.to_ref(), + asm: &asm.inner, + outputs: asm.outputs_exprs.to_ref(), + inputs: asm.inputs_exprs.to_ref(), } } diff --git a/src/librustc_mir/hair/mod.rs b/src/librustc_mir/hair/mod.rs index b43042f2b1745..78e3a17d76632 100644 --- a/src/librustc_mir/hair/mod.rs +++ b/src/librustc_mir/hair/mod.rs @@ -93,6 +93,10 @@ pub enum StmtKind<'tcx> { }, } +// `Expr` is used a lot. Make sure it doesn't unintentionally get bigger. +#[cfg(target_arch = "x86_64")] +rustc_data_structures::static_assert_size!(Expr<'_>, 168); + /// The Hair trait implementor lowers their expressions (`&'tcx H::Expr`) /// into instances of this `Expr` enum. This lowering can be done /// basically as lazily or as eagerly as desired: every recursive @@ -264,7 +268,7 @@ pub enum ExprKind<'tcx> { user_ty: Option>>, }, InlineAsm { - asm: &'tcx hir::InlineAsm, + asm: &'tcx hir::InlineAsmInner, outputs: Vec>, inputs: Vec> }, diff --git a/src/librustc_mir/interpret/intrinsics.rs b/src/librustc_mir/interpret/intrinsics.rs index 6117cf4038a24..23f7b1acb54d4 100644 --- a/src/librustc_mir/interpret/intrinsics.rs +++ b/src/librustc_mir/interpret/intrinsics.rs @@ -302,10 +302,10 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { self.copy_op_transmute(args[0], dest)?; } "simd_insert" => { - let index = self.read_scalar(args[1])?.to_u32()? as u64; - let scalar = args[2]; + let index = u64::from(self.read_scalar(args[1])?.to_u32()?); + let elem = args[2]; let input = args[0]; - let (len, e_ty) = self.read_vector_ty(input); + let (len, e_ty) = input.layout.ty.simd_size_and_type(self.tcx.tcx); assert!( index < len, "Index `{}` must be in bounds of vector type `{}`: `[0, {})`", @@ -317,15 +317,15 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { dest.layout.ty, input.layout.ty ); assert_eq!( - scalar.layout.ty, e_ty, - "Scalar type `{}` must match vector element type `{}`", - scalar.layout.ty, e_ty + elem.layout.ty, e_ty, + "Scalar element type `{}` must match vector element type `{}`", + elem.layout.ty, e_ty ); for i in 0..len { let place = self.place_field(dest, i)?; let value = if i == index { - scalar + elem } else { self.operand_field(input, i)? }; @@ -333,8 +333,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { } } "simd_extract" => { - let index = self.read_scalar(args[1])?.to_u32()? as _; - let (len, e_ty) = self.read_vector_ty(args[0]); + let index = u64::from(self.read_scalar(args[1])?.to_u32()?); + let (len, e_ty) = args[0].layout.ty.simd_size_and_type(self.tcx.tcx); assert!( index < len, "index `{}` is out-of-bounds of vector type `{}` with length `{}`", diff --git a/src/librustc_mir/interpret/operand.rs b/src/librustc_mir/interpret/operand.rs index cfa70164cdce4..62797b313045e 100644 --- a/src/librustc_mir/interpret/operand.rs +++ b/src/librustc_mir/interpret/operand.rs @@ -316,17 +316,6 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { } } - /// Read vector length and element type - pub fn read_vector_ty( - &self, op: OpTy<'tcx, M::PointerTag> - ) -> (u64, &rustc::ty::TyS<'tcx>) { - if let layout::Abi::Vector { .. } = op.layout.abi { - (op.layout.ty.simd_size(*self.tcx) as _, op.layout.ty.simd_type(*self.tcx)) - } else { - bug!("Type `{}` is not a SIMD vector type", op.layout.ty) - } - } - /// Read a scalar from a place pub fn read_scalar( &self, diff --git a/src/librustc_mir/interpret/terminator.rs b/src/librustc_mir/interpret/terminator.rs index 4f9e404b2c635..50c4a249c63c2 100644 --- a/src/librustc_mir/interpret/terminator.rs +++ b/src/librustc_mir/interpret/terminator.rs @@ -264,6 +264,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { match instance.def { ty::InstanceDef::Intrinsic(..) => { + assert!(caller_abi == Abi::RustIntrinsic || caller_abi == Abi::PlatformIntrinsic); + let old_stack = self.cur_frame(); let old_bb = self.frame().block; M::call_intrinsic(self, span, instance, args, dest, ret, unwind)?; diff --git a/src/librustc_passes/liveness.rs b/src/librustc_passes/liveness.rs index 6847e45458a0b..8d7a038812269 100644 --- a/src/librustc_passes/liveness.rs +++ b/src/librustc_passes/liveness.rs @@ -1184,17 +1184,21 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { self.propagate_through_expr(&e, succ) } - hir::ExprKind::InlineAsm(ref ia, ref outputs, ref inputs) => { + hir::ExprKind::InlineAsm(ref asm) => { + let ia = &asm.inner; + let outputs = &asm.outputs_exprs; + let inputs = &asm.inputs_exprs; let succ = ia.outputs.iter().zip(outputs).rev().fold(succ, |succ, (o, output)| { - // see comment on places - // in propagate_through_place_components() - if o.is_indirect { - self.propagate_through_expr(output, succ) - } else { - let acc = if o.is_rw { ACC_WRITE|ACC_READ } else { ACC_WRITE }; - let succ = self.write_place(output, succ, acc); - self.propagate_through_place_components(output, succ) - }}); + // see comment on places + // in propagate_through_place_components() + if o.is_indirect { + self.propagate_through_expr(output, succ) + } else { + let acc = if o.is_rw { ACC_WRITE|ACC_READ } else { ACC_WRITE }; + let succ = self.write_place(output, succ, acc); + self.propagate_through_place_components(output, succ) + } + }); // Inputs are executed first. Propagate last because of rev order self.propagate_through_exprs(inputs, succ) @@ -1395,13 +1399,13 @@ fn check_expr<'tcx>(this: &mut Liveness<'_, 'tcx>, expr: &'tcx Expr) { } } - hir::ExprKind::InlineAsm(ref ia, ref outputs, ref inputs) => { - for input in inputs { + hir::ExprKind::InlineAsm(ref asm) => { + for input in &asm.inputs_exprs { this.visit_expr(input); } // Output operands must be places - for (o, output) in ia.outputs.iter().zip(outputs) { + for (o, output) in asm.inner.outputs.iter().zip(&asm.outputs_exprs) { if !o.is_indirect { this.check_place(output); } diff --git a/src/librustc_target/Cargo.toml b/src/librustc_target/Cargo.toml index c73d0adea38da..0e0732490fbbd 100644 --- a/src/librustc_target/Cargo.toml +++ b/src/librustc_target/Cargo.toml @@ -12,6 +12,7 @@ path = "lib.rs" bitflags = "1.2.1" log = "0.4" rustc_data_structures = { path = "../librustc_data_structures" } +rustc_macros = { path = "../librustc_macros" } rustc_serialize = { path = "../libserialize", package = "serialize" } syntax_pos = { path = "../libsyntax_pos" } rustc_index = { path = "../librustc_index" } diff --git a/src/librustc_target/abi/mod.rs b/src/librustc_target/abi/mod.rs index 2d7e05037ba0d..ac781819cc35e 100644 --- a/src/librustc_target/abi/mod.rs +++ b/src/librustc_target/abi/mod.rs @@ -6,6 +6,7 @@ use crate::spec::Target; use std::ops::{Add, Deref, Sub, Mul, AddAssign, Range, RangeInclusive}; use rustc_index::vec::{Idx, IndexVec}; +use rustc_macros::HashStable_Generic; use syntax_pos::Span; pub mod call; @@ -242,6 +243,7 @@ pub enum Endian { /// Size of a type in bytes. #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)] +#[derive(HashStable_Generic)] pub struct Size { raw: u64 } @@ -365,6 +367,7 @@ impl AddAssign for Size { /// Alignment of a type in bytes (always a power of two). #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)] +#[derive(HashStable_Generic)] pub struct Align { pow2: u8, } @@ -423,6 +426,7 @@ impl Align { /// A pair of aligments, ABI-mandated and preferred. #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable)] +#[derive(HashStable_Generic)] pub struct AbiAndPrefAlign { pub abi: Align, pub pref: Align, @@ -452,7 +456,7 @@ impl AbiAndPrefAlign { } /// Integers, also used for enum discriminants. -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, HashStable_Generic)] pub enum Integer { I8, I16, @@ -533,7 +537,7 @@ impl Integer { } /// Fundamental unit of memory access and layout. -#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, HashStable_Generic)] pub enum Primitive { /// The `bool` is the signedness of the `Integer` type. /// @@ -588,6 +592,7 @@ impl Primitive { /// Information about one scalar component of a Rust type. #[derive(Clone, PartialEq, Eq, Hash, Debug)] +#[derive(HashStable_Generic)] pub struct Scalar { pub value: Primitive, @@ -636,7 +641,7 @@ impl Scalar { } /// Describes how the fields of a type are located in memory. -#[derive(PartialEq, Eq, Hash, Debug)] +#[derive(PartialEq, Eq, Hash, Debug, HashStable_Generic)] pub enum FieldPlacement { /// All fields start at no offset. The `usize` is the field count. /// @@ -752,7 +757,7 @@ impl FieldPlacement { /// Describes how values of the type are passed by target ABIs, /// in terms of categories of C types there are ABI rules for. -#[derive(Clone, PartialEq, Eq, Hash, Debug)] +#[derive(Clone, PartialEq, Eq, Hash, Debug, HashStable_Generic)] pub enum Abi { Uninhabited, Scalar(Scalar), @@ -800,10 +805,12 @@ impl Abi { } rustc_index::newtype_index! { - pub struct VariantIdx { .. } + pub struct VariantIdx { + derive [HashStable_Generic] + } } -#[derive(PartialEq, Eq, Hash, Debug)] +#[derive(PartialEq, Eq, Hash, Debug, HashStable_Generic)] pub enum Variants { /// Single enum variants, structs/tuples, unions, and all non-ADTs. Single { @@ -821,7 +828,7 @@ pub enum Variants { }, } -#[derive(PartialEq, Eq, Hash, Debug)] +#[derive(PartialEq, Eq, Hash, Debug, HashStable_Generic)] pub enum DiscriminantKind { /// Integer tag holding the discriminant value itself. Tag, @@ -842,7 +849,7 @@ pub enum DiscriminantKind { }, } -#[derive(Clone, PartialEq, Eq, Hash, Debug)] +#[derive(Clone, PartialEq, Eq, Hash, Debug, HashStable_Generic)] pub struct Niche { pub offset: Size, pub scalar: Scalar, @@ -906,7 +913,7 @@ impl Niche { } } -#[derive(PartialEq, Eq, Hash, Debug)] +#[derive(PartialEq, Eq, Hash, Debug, HashStable_Generic)] pub struct LayoutDetails { pub variants: Variants, pub fields: FieldPlacement, diff --git a/src/librustc_target/spec/abi.rs b/src/librustc_target/spec/abi.rs index 3a24d30966f63..736358a995b64 100644 --- a/src/librustc_target/spec/abi.rs +++ b/src/librustc_target/spec/abi.rs @@ -1,9 +1,12 @@ use std::fmt; +use rustc_macros::HashStable_Generic; + #[cfg(test)] mod tests; -#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, Clone, Copy, Debug)] +#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, + Clone, Copy, Debug, HashStable_Generic)] pub enum Abi { // N.B., this ordering MUST match the AbiDatas array below. // (This is ensured by the test indices_are_correct().) diff --git a/src/librustc_target/spec/mod.rs b/src/librustc_target/spec/mod.rs index 4cd2f13d09cbd..716aef056a35b 100644 --- a/src/librustc_target/spec/mod.rs +++ b/src/librustc_target/spec/mod.rs @@ -42,6 +42,8 @@ use std::path::{Path, PathBuf}; use std::str::FromStr; use crate::spec::abi::{Abi, lookup as lookup_abi}; +use rustc_macros::HashStable_Generic; + pub mod abi; mod android_base; mod apple_base; @@ -153,7 +155,7 @@ flavor_mappings! { ((LinkerFlavor::Lld(LldFlavor::Link)), "lld-link"), } -#[derive(Clone, Copy, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Clone, Copy, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable, HashStable_Generic)] pub enum PanicStrategy { Unwind, Abort, diff --git a/src/librustc_target/spec/wasm32_base.rs b/src/librustc_target/spec/wasm32_base.rs index 6f00245b00941..e18a9e66468c7 100644 --- a/src/librustc_target/spec/wasm32_base.rs +++ b/src/librustc_target/spec/wasm32_base.rs @@ -140,6 +140,9 @@ pub fn options() -> TargetOptions { has_elf_tls: true, tls_model: "local-exec".to_string(), + // gdb scripts don't work on wasm blobs + emit_debug_gdb_scripts: false, + .. Default::default() } } diff --git a/src/librustc_typeck/check/expr.rs b/src/librustc_typeck/check/expr.rs index 0ba56ba5b3ae9..163412f6a16f5 100644 --- a/src/librustc_typeck/check/expr.rs +++ b/src/librustc_typeck/check/expr.rs @@ -244,8 +244,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ExprKind::Path(ref qpath) => { self.check_expr_path(qpath, expr) } - ExprKind::InlineAsm(_, ref outputs, ref inputs) => { - for expr in outputs.iter().chain(inputs.iter()) { + ExprKind::InlineAsm(ref asm) => { + for expr in asm.outputs_exprs.iter().chain(asm.inputs_exprs.iter()) { self.check_expr(expr); } tcx.mk_unit() diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index bd2a6602e16be..ba481655becb7 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -697,12 +697,10 @@ themePicker.onblur = handleThemeButtonsBlur; static_files::source_serif_pro::ITALIC)?; write(cx.dst.join("SourceSerifPro-LICENSE.md"), static_files::source_serif_pro::LICENSE)?; - write(cx.dst.join("SourceCodePro-Regular.ttf.woff"), + write(cx.dst.join("SourceCodePro-Regular.woff"), static_files::source_code_pro::REGULAR)?; - write(cx.dst.join("SourceCodePro-Semibold.ttf.woff"), + write(cx.dst.join("SourceCodePro-Semibold.woff"), static_files::source_code_pro::SEMIBOLD)?; - write(cx.dst.join("SourceCodePro-It.ttf.woff"), - static_files::source_code_pro::ITALIC)?; write(cx.dst.join("SourceCodePro-LICENSE.txt"), static_files::source_code_pro::LICENSE)?; write(cx.dst.join("LICENSE-MIT.txt"), diff --git a/src/librustdoc/html/static/COPYRIGHT.txt b/src/librustdoc/html/static/COPYRIGHT.txt index 24bdca6544d6d..af77776cca431 100644 --- a/src/librustdoc/html/static/COPYRIGHT.txt +++ b/src/librustdoc/html/static/COPYRIGHT.txt @@ -23,8 +23,7 @@ included, and carry their own copyright notices and license terms: Copyright (c) Nicolas Gallagher and Jonathan Neal. Licensed under the MIT license (see LICENSE-MIT.txt). -* Source Code Pro (SourceCodePro-Regular.ttf.woff, - SourceCodePro-Semibold.ttf.woff, SourceCodePro-It.ttf.woff): +* Source Code Pro (SourceCodePro-Regular.woff, SourceCodePro-Semibold.woff): Copyright 2010, 2012 Adobe Systems Incorporated (http://www.adobe.com/), with Reserved Font Name 'Source'. All Rights Reserved. Source is a trademark diff --git a/src/librustdoc/html/static/SourceCodePro-It.ttf.woff b/src/librustdoc/html/static/SourceCodePro-It.ttf.woff deleted file mode 100644 index ebaaf91de0667..0000000000000 Binary files a/src/librustdoc/html/static/SourceCodePro-It.ttf.woff and /dev/null differ diff --git a/src/librustdoc/html/static/SourceCodePro-Regular.ttf.woff b/src/librustdoc/html/static/SourceCodePro-Regular.ttf.woff deleted file mode 100644 index 117c7e5142c38..0000000000000 Binary files a/src/librustdoc/html/static/SourceCodePro-Regular.ttf.woff and /dev/null differ diff --git a/src/librustdoc/html/static/SourceCodePro-Regular.woff b/src/librustdoc/html/static/SourceCodePro-Regular.woff new file mode 100644 index 0000000000000..5576670903aea Binary files /dev/null and b/src/librustdoc/html/static/SourceCodePro-Regular.woff differ diff --git a/src/librustdoc/html/static/SourceCodePro-Semibold.ttf.woff b/src/librustdoc/html/static/SourceCodePro-Semibold.ttf.woff deleted file mode 100644 index 270873a86a09b..0000000000000 Binary files a/src/librustdoc/html/static/SourceCodePro-Semibold.ttf.woff and /dev/null differ diff --git a/src/librustdoc/html/static/SourceCodePro-Semibold.woff b/src/librustdoc/html/static/SourceCodePro-Semibold.woff new file mode 100644 index 0000000000000..ca972a11dc428 Binary files /dev/null and b/src/librustdoc/html/static/SourceCodePro-Semibold.woff differ diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index b2c48bf089b1b..ca798931953b8 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -39,19 +39,13 @@ font-weight: 400; /* Avoid using locally installed font because bad versions are in circulation: * see https://github.com/rust-lang/rust/issues/24355 */ - src: url("SourceCodePro-Regular.ttf.woff") format('woff'); -} -@font-face { - font-family: 'Source Code Pro'; - font-style: italic; - font-weight: 400; - src: url("SourceCodePro-It.ttf.woff") format('woff'); + src: url("SourceCodePro-Regular.woff") format('woff'); } @font-face { font-family: 'Source Code Pro'; font-style: normal; font-weight: 600; - src: url("SourceCodePro-Semibold.ttf.woff") format('woff'); + src: url("SourceCodePro-Semibold.woff") format('woff'); } * { diff --git a/src/librustdoc/html/static_files.rs b/src/librustdoc/html/static_files.rs index 34055f386fbc0..9fc1d76185fb7 100644 --- a/src/librustdoc/html/static_files.rs +++ b/src/librustdoc/html/static_files.rs @@ -96,15 +96,11 @@ pub mod source_serif_pro { /// Files related to the Source Code Pro font. pub mod source_code_pro { - /// The file `SourceCodePro-Regular.ttf.woff`, the Regular variant of the Source Code Pro font. - pub static REGULAR: &'static [u8] = include_bytes!("static/SourceCodePro-Regular.ttf.woff"); + /// The file `SourceCodePro-Regular.woff`, the Regular variant of the Source Code Pro font. + pub static REGULAR: &'static [u8] = include_bytes!("static/SourceCodePro-Regular.woff"); - /// The file `SourceCodePro-Semibold.ttf.woff`, the Semibold variant of the Source Code Pro - /// font. - pub static SEMIBOLD: &'static [u8] = include_bytes!("static/SourceCodePro-Semibold.ttf.woff"); - - /// The file `SourceCodePro-It.ttf.woff`, the Italic variant of the Source Code Pro font. - pub static ITALIC: &'static [u8] = include_bytes!("static/SourceCodePro-It.ttf.woff"); + /// The file `SourceCodePro-Semibold.woff`, the Semibold variant of the Source Code Pro font. + pub static SEMIBOLD: &'static [u8] = include_bytes!("static/SourceCodePro-Semibold.woff"); /// The file `SourceCodePro-LICENSE.txt`, the license text of the Source Code Pro font. pub static LICENSE: &'static [u8] = include_bytes!("static/SourceCodePro-LICENSE.txt"); diff --git a/src/libsyntax/Cargo.toml b/src/libsyntax/Cargo.toml index d96b5b7a3dde4..dff23076c82e6 100644 --- a/src/libsyntax/Cargo.toml +++ b/src/libsyntax/Cargo.toml @@ -20,5 +20,6 @@ errors = { path = "../librustc_errors", package = "rustc_errors" } rustc_data_structures = { path = "../librustc_data_structures" } rustc_index = { path = "../librustc_index" } rustc_lexer = { path = "../librustc_lexer" } +rustc_macros = { path = "../librustc_macros" } smallvec = { version = "1.0", features = ["union", "may_dangle"] } rustc_error_codes = { path = "../librustc_error_codes" } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index bbf00825acb33..a9f03e4af5b65 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -37,6 +37,7 @@ use rustc_data_structures::sync::Lrc; use rustc_data_structures::thin_vec::ThinVec; use rustc_index::vec::Idx; use rustc_serialize::{self, Decoder, Encoder}; +use rustc_macros::HashStable_Generic; use std::fmt; @@ -722,9 +723,8 @@ pub enum PatKind { Mac(Mac), } -#[derive( - Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, Debug, Copy, -)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, + RustcEncodable, RustcDecodable, Debug, Copy, HashStable_Generic)] pub enum Mutability { Mutable, Immutable, @@ -1328,7 +1328,7 @@ pub struct QSelf { } /// A capture clause used in closures and `async` blocks. -#[derive(Clone, Copy, PartialEq, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Copy, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub enum CaptureBy { /// `move |x| y + x`. Value, @@ -1339,7 +1339,7 @@ pub enum CaptureBy { /// The movability of a generator / closure literal: /// whether a generator contains self-references, causing it to be `!Unpin`. #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, - RustcEncodable, RustcDecodable, Debug, Copy)] + RustcEncodable, RustcDecodable, Debug, Copy, HashStable_Generic)] pub enum Movability { /// May contain self-references, `!Unpin`. Static, @@ -1400,7 +1400,7 @@ impl MacroDef { } // Clippy uses Hash and PartialEq -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, Copy, Hash, PartialEq)] +#[derive(Clone, RustcEncodable, RustcDecodable, Debug, Copy, Hash, PartialEq, HashStable_Generic)] pub enum StrStyle { /// A regular string, like `"foo"`. Cooked, @@ -1451,7 +1451,7 @@ impl StrLit { // Clippy uses Hash and PartialEq /// Type of the integer literal based on provided suffix. -#[derive(Clone, Copy, RustcEncodable, RustcDecodable, Debug, Hash, PartialEq)] +#[derive(Clone, Copy, RustcEncodable, RustcDecodable, Debug, Hash, PartialEq, HashStable_Generic)] pub enum LitIntType { /// e.g. `42_i32`. Signed(IntTy), @@ -1462,7 +1462,7 @@ pub enum LitIntType { } /// Type of the float literal based on provided suffix. -#[derive(Clone, Copy, RustcEncodable, RustcDecodable, Debug, Hash, PartialEq)] +#[derive(Clone, Copy, RustcEncodable, RustcDecodable, Debug, Hash, PartialEq, HashStable_Generic)] pub enum LitFloatType { /// A float literal with a suffix (`1f32` or `1E10f32`). Suffixed(FloatTy), @@ -1474,7 +1474,7 @@ pub enum LitFloatType { /// /// E.g., `"foo"`, `42`, `12.34`, or `bool`. // Clippy uses Hash and PartialEq -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, Hash, PartialEq)] +#[derive(Clone, RustcEncodable, RustcDecodable, Debug, Hash, PartialEq, HashStable_Generic)] pub enum LitKind { /// A string literal (`"foo"`). Str(Symbol, StrStyle), @@ -1609,7 +1609,8 @@ pub enum ImplItemKind { Macro(Mac), } -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, HashStable_Generic, + RustcEncodable, RustcDecodable, Debug)] pub enum FloatTy { F32, F64, @@ -1638,7 +1639,8 @@ impl FloatTy { } } -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, HashStable_Generic, + RustcEncodable, RustcDecodable, Debug)] pub enum IntTy { Isize, I8, @@ -1690,7 +1692,8 @@ impl IntTy { } } -#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, Copy, Debug)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, HashStable_Generic, + RustcEncodable, RustcDecodable, Copy, Debug)] pub enum UintTy { Usize, U8, @@ -1863,7 +1866,7 @@ pub enum TraitObjectSyntax { /// Inline assembly dialect. /// /// E.g., `"intel"` as in `asm!("mov eax, 2" : "={eax}"(result) : : : "intel")`. -#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy)] +#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy, HashStable_Generic)] pub enum AsmDialect { Att, Intel, @@ -2021,14 +2024,14 @@ impl FnDecl { } /// Is the trait definition an auto trait? -#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug)] +#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub enum IsAuto { Yes, No, } #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, - RustcEncodable, RustcDecodable, Debug)] + RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub enum Unsafety { Unsafe, Normal, @@ -2085,7 +2088,7 @@ impl IsAsync { } } -#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug)] +#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub enum Constness { Const, NotConst, @@ -2093,13 +2096,13 @@ pub enum Constness { /// Item defaultness. /// For details see the [RFC #2532](https://github.com/rust-lang/rfcs/pull/2532). -#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug)] +#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub enum Defaultness { Default, Final, } -#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, HashStable_Generic)] pub enum ImplPolarity { /// `impl Trait for Type` Positive, @@ -2233,7 +2236,7 @@ impl UseTree { /// Distinguishes between `Attribute`s that decorate items and Attributes that /// are contained as statements within items. These two cases need to be /// distinguished for pretty-printing. -#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy)] +#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy, HashStable_Generic)] pub enum AttrStyle { Outer, Inner, @@ -2331,7 +2334,7 @@ impl PolyTraitRef { } } -#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub enum CrateSugar { /// Source is `pub(crate)`. PubCrate, diff --git a/src/libsyntax/attr/builtin.rs b/src/libsyntax/attr/builtin.rs index 767fcabc017ed..c10541c8c7e75 100644 --- a/src/libsyntax/attr/builtin.rs +++ b/src/libsyntax/attr/builtin.rs @@ -9,6 +9,7 @@ use errors::{Applicability, Handler}; use std::num::NonZeroU32; use syntax_pos::hygiene::Transparency; use syntax_pos::{symbol::Symbol, symbol::sym, Span}; +use rustc_macros::HashStable_Generic; use super::{mark_used, MetaItemKind}; @@ -141,7 +142,8 @@ pub fn find_unwind_attr(diagnostic: Option<&Handler>, attrs: &[Attribute]) -> Op } /// Represents the #[stable], #[unstable], #[rustc_{deprecated,const_unstable}] attributes. -#[derive(RustcEncodable, RustcDecodable, Copy, Clone, Debug, PartialEq, Eq, Hash)] +#[derive(RustcEncodable, RustcDecodable, Copy, Clone, Debug, + PartialEq, Eq, Hash, HashStable_Generic)] pub struct Stability { pub level: StabilityLevel, pub feature: Symbol, @@ -157,7 +159,8 @@ pub struct Stability { } /// The available stability levels. -#[derive(RustcEncodable, RustcDecodable, PartialEq, PartialOrd, Copy, Clone, Debug, Eq, Hash)] +#[derive(RustcEncodable, RustcDecodable, PartialEq, PartialOrd, + Copy, Clone, Debug, Eq, Hash, HashStable_Generic)] pub enum StabilityLevel { // Reason for the current stability level and the relevant rust-lang issue Unstable { reason: Option, issue: Option, is_soft: bool }, @@ -181,7 +184,8 @@ impl StabilityLevel { } } -#[derive(RustcEncodable, RustcDecodable, PartialEq, PartialOrd, Copy, Clone, Debug, Eq, Hash)] +#[derive(RustcEncodable, RustcDecodable, PartialEq, PartialOrd, + Copy, Clone, Debug, Eq, Hash, HashStable_Generic)] pub struct RustcDeprecation { pub since: Symbol, pub reason: Symbol, @@ -636,7 +640,7 @@ pub fn eval_condition(cfg: &ast::MetaItem, sess: &ParseSess, eval: &mut F) } } -#[derive(RustcEncodable, RustcDecodable, Clone)] +#[derive(RustcEncodable, RustcDecodable, Clone, HashStable_Generic)] pub struct Deprecation { pub since: Option, pub note: Option, @@ -763,7 +767,7 @@ pub enum ReprAttr { ReprAlign(u32), } -#[derive(Eq, PartialEq, Debug, RustcEncodable, RustcDecodable, Copy, Clone)] +#[derive(Eq, PartialEq, Debug, RustcEncodable, RustcDecodable, Copy, Clone, HashStable_Generic)] pub enum IntType { SignedInt(ast::IntTy), UnsignedInt(ast::UintTy) diff --git a/src/libsyntax/token.rs b/src/libsyntax/token.rs index ab798e93d67fc..fd1623384a443 100644 --- a/src/libsyntax/token.rs +++ b/src/libsyntax/token.rs @@ -15,6 +15,7 @@ use syntax_pos::{self, Span, DUMMY_SP}; use std::fmt; use std::mem; use rustc_data_structures::sync::Lrc; +use rustc_macros::HashStable_Generic; #[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] pub enum BinOpToken { @@ -53,7 +54,7 @@ impl DelimToken { } } -#[derive(Clone, Copy, PartialEq, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Copy, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub enum LitKind { Bool, // AST only, must never appear in a `Token` Byte, @@ -68,7 +69,7 @@ pub enum LitKind { } /// A literal token. -#[derive(Clone, Copy, PartialEq, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Copy, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] pub struct Lit { pub kind: LitKind, pub symbol: Symbol, diff --git a/src/libsyntax_pos/edition.rs b/src/libsyntax_pos/edition.rs index 00cd00f283784..727aad546f5f1 100644 --- a/src/libsyntax_pos/edition.rs +++ b/src/libsyntax_pos/edition.rs @@ -2,8 +2,11 @@ use crate::symbol::{Symbol, sym}; use std::fmt; use std::str::FromStr; +use rustc_macros::HashStable_Generic; + /// The edition of the compiler (RFC 2052) -#[derive(Clone, Copy, Hash, PartialEq, PartialOrd, Debug, RustcEncodable, RustcDecodable, Eq)] +#[derive(Clone, Copy, Hash, PartialEq, PartialOrd, Debug, + RustcEncodable, RustcDecodable, Eq, HashStable_Generic)] pub enum Edition { // editions must be kept in order, oldest to newest diff --git a/src/libsyntax_pos/hygiene.rs b/src/libsyntax_pos/hygiene.rs index 2a48f8e44aa12..eb420454f03d3 100644 --- a/src/libsyntax_pos/hygiene.rs +++ b/src/libsyntax_pos/hygiene.rs @@ -30,6 +30,7 @@ use crate::{Span, DUMMY_SP}; use crate::edition::Edition; use crate::symbol::{kw, sym, Symbol}; +use rustc_macros::HashStable_Generic; use rustc_serialize::{Encodable, Decodable, Encoder, Decoder}; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::sync::Lrc; @@ -58,7 +59,8 @@ pub struct ExpnId(u32); /// A property of a macro expansion that determines how identifiers /// produced by that expansion are resolved. -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Hash, Debug, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Hash, Debug, + RustcEncodable, RustcDecodable, HashStable_Generic)] pub enum Transparency { /// Identifier produced by a transparent expansion is always resolved at call-site. /// Call-site spans in procedural macros, hygiene opt-out in `macro` should use this. @@ -683,7 +685,7 @@ impl ExpnData { } /// Expansion kind. -#[derive(Clone, Debug, RustcEncodable, RustcDecodable)] +#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable_Generic)] pub enum ExpnKind { /// No expansion, aka root expansion. Only `ExpnId::root()` has this kind. Root, @@ -707,7 +709,8 @@ impl ExpnKind { } /// The kind of macro invocation or definition. -#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, + Hash, Debug, HashStable_Generic)] pub enum MacroKind { /// A bang macro `foo!()`. Bang, @@ -742,7 +745,7 @@ impl MacroKind { } /// The kind of AST transform. -#[derive(Clone, Copy, PartialEq, Debug, RustcEncodable, RustcDecodable)] +#[derive(Clone, Copy, PartialEq, Debug, RustcEncodable, RustcDecodable, HashStable_Generic)] pub enum AstPass { StdImports, TestHarness, @@ -762,7 +765,7 @@ impl AstPass { } /// The kind of compiler desugaring. -#[derive(Clone, Copy, PartialEq, Debug, RustcEncodable, RustcDecodable)] +#[derive(Clone, Copy, PartialEq, Debug, RustcEncodable, RustcDecodable, HashStable_Generic)] pub enum DesugaringKind { /// We desugar `if c { i } else { e }` to `match $ExprKind::Use(c) { true => i, _ => e }`. /// However, we do not want to blame `c` for unreachability but rather say that `i` diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs index b88d6dbc3f379..720ace90324b9 100644 --- a/src/libsyntax_pos/lib.rs +++ b/src/libsyntax_pos/lib.rs @@ -15,6 +15,7 @@ #![feature(step_trait)] use rustc_serialize::{Encodable, Decodable, Encoder, Decoder}; +use rustc_macros::HashStable_Generic; pub mod source_map; @@ -66,7 +67,8 @@ impl Globals { scoped_tls::scoped_thread_local!(pub static GLOBALS: Globals); /// Differentiates between real files and common virtual files. -#[derive(Debug, Eq, PartialEq, Clone, Ord, PartialOrd, Hash, RustcDecodable, RustcEncodable)] +#[derive(Debug, Eq, PartialEq, Clone, Ord, PartialOrd, Hash, + RustcDecodable, RustcEncodable, HashStable_Generic)] pub enum FileName { Real(PathBuf), /// A macro. This includes the full name of the macro, so that there are no clashes. diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs index 1139bf67a36d0..b5587303b0729 100644 --- a/src/libsyntax_pos/symbol.rs +++ b/src/libsyntax_pos/symbol.rs @@ -8,6 +8,7 @@ use rustc_index::vec::Idx; use rustc_macros::symbols; use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; use rustc_serialize::{UseSpecializedDecodable, UseSpecializedEncodable}; +use rustc_data_structures::stable_hasher::{HashStable, ToStableHashKey, StableHasher}; use std::cmp::{PartialEq, PartialOrd, Ord}; use std::fmt; @@ -940,6 +941,22 @@ impl Decodable for Symbol { } } +impl HashStable for Symbol { + #[inline] + fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { + self.as_str().hash_stable(hcx, hasher); + } +} + +impl ToStableHashKey for Symbol { + type KeyType = SymbolStr; + + #[inline] + fn to_stable_hash_key(&self, _: &CTX) -> SymbolStr { + self.as_str() + } +} + // The `&'static str`s in this type actually point into the arena. #[derive(Default)] pub struct Interner { @@ -1137,3 +1154,19 @@ impl fmt::Display for SymbolStr { fmt::Display::fmt(self.string, f) } } + +impl HashStable for SymbolStr { + #[inline] + fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { + self.string.hash_stable(hcx, hasher) + } +} + +impl ToStableHashKey for SymbolStr { + type KeyType = SymbolStr; + + #[inline] + fn to_stable_hash_key(&self, _: &CTX) -> SymbolStr { + self.clone() + } +} diff --git a/src/test/ui/async-await/issues/issue-62097.nll.stderr b/src/test/ui/async-await/issues/issue-62097.nll.stderr new file mode 100644 index 0000000000000..0c64f90cb9fae --- /dev/null +++ b/src/test/ui/async-await/issues/issue-62097.nll.stderr @@ -0,0 +1,29 @@ +error[E0373]: closure may outlive the current function, but it borrows `self`, which is owned by the current function + --> $DIR/issue-62097.rs:13:13 + | +LL | foo(|| self.bar()).await; + | ^^ ---- `self` is borrowed here + | | + | may outlive borrowed value `self` + | +note: function requires argument type to outlive `'static` + --> $DIR/issue-62097.rs:13:9 + | +LL | foo(|| self.bar()).await; + | ^^^^^^^^^^^^^^^^^^ +help: to force the closure to take ownership of `self` (and any other referenced variables), use the `move` keyword + | +LL | foo(move || self.bar()).await; + | ^^^^^^^ + +error[E0521]: borrowed data escapes outside of function + --> $DIR/issue-62097.rs:13:9 + | +LL | pub async fn run_dummy_fn(&self) { + | ----- `self` is a reference that is only valid in the function body +LL | foo(|| self.bar()).await; + | ^^^^^^^^^^^^^^^^^^ `self` escapes the function body here + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0373`. diff --git a/src/test/ui/async-await/issues/issue-62097.rs b/src/test/ui/async-await/issues/issue-62097.rs new file mode 100644 index 0000000000000..ea482d3667e2b --- /dev/null +++ b/src/test/ui/async-await/issues/issue-62097.rs @@ -0,0 +1,19 @@ +// edition:2018 +async fn foo(fun: F) +where + F: FnOnce() + 'static +{ + fun() +} + +struct Struct; + +impl Struct { + pub async fn run_dummy_fn(&self) { //~ ERROR cannot infer + foo(|| self.bar()).await; + } + + pub fn bar(&self) {} +} + +fn main() {} diff --git a/src/test/ui/async-await/issues/issue-62097.stderr b/src/test/ui/async-await/issues/issue-62097.stderr new file mode 100644 index 0000000000000..94afccc06a9e7 --- /dev/null +++ b/src/test/ui/async-await/issues/issue-62097.stderr @@ -0,0 +1,16 @@ +error: cannot infer an appropriate lifetime + --> $DIR/issue-62097.rs:12:31 + | +LL | pub async fn run_dummy_fn(&self) { + | ^^^^^ ...but this borrow... +LL | foo(|| self.bar()).await; + | --- this return type evaluates to the `'static` lifetime... + | +note: ...can't outlive the lifetime `'_` as defined on the method body at 12:31 + --> $DIR/issue-62097.rs:12:31 + | +LL | pub async fn run_dummy_fn(&self) { + | ^ + +error: aborting due to previous error + diff --git a/src/test/ui/async-await/issues/issue-63388-2.stderr b/src/test/ui/async-await/issues/issue-63388-2.stderr index efec160588fc4..7e45d588c6c6c 100644 --- a/src/test/ui/async-await/issues/issue-63388-2.stderr +++ b/src/test/ui/async-await/issues/issue-63388-2.stderr @@ -20,10 +20,6 @@ note: ...can't outlive the lifetime `'_` as defined on the method body at 11:14 | LL | foo: &dyn Foo, bar: &'a dyn Foo | ^ -help: you can add a constraint to the return type to make it last less than `'static` and match the lifetime `'_` as defined on the method body at 11:14 - | -LL | foo + '_ - | error: aborting due to 2 previous errors diff --git a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.stderr b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.stderr index bce1900ca602c..91075ffbdb605 100644 --- a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.stderr +++ b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.stderr @@ -11,10 +11,6 @@ note: ...can't outlive the lifetime `'_` as defined on the method body at 8:26 | LL | async fn f(self: Pin<&Self>) -> impl Clone { self } | ^ -help: you can add a constraint to the return type to make it last less than `'static` and match the lifetime `'_` as defined on the method body at 8:26 - | -LL | async fn f(self: Pin<&Self>) -> impl Clone + '_ { self } - | ^^^^^^^^^^^^^^^ error: aborting due to previous error